4 * Copyright 2004 Kevin Koltzau
5 * Copyright 2004 Jacek Caban
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/test.h"
34 #define DEFINE_EXPECT(func) \
35 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37 #define SET_EXPECT(func) \
38 expect_ ## func = TRUE
40 #define CHECK_EXPECT(func) \
42 ok(expect_ ##func, "unexpected call " #func "\n"); \
43 expect_ ## func = FALSE; \
44 called_ ## func = TRUE; \
47 #define CHECK_EXPECT2(func) \
49 ok(expect_ ##func, "unexpected call " #func "\n"); \
50 called_ ## func = TRUE; \
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
56 expect_ ## func = called_ ## func = FALSE; \
59 #define CHECK_NOT_CALLED(func) \
61 ok(!called_ ## func, "unexpected " #func "\n"); \
62 expect_ ## func = called_ ## func = FALSE; \
65 #define CLEAR_CALLED(func) \
66 expect_ ## func = called_ ## func = FALSE
68 DEFINE_EXPECT(QueryInterface_IServiceProvider);
69 DEFINE_EXPECT(QueryInterface_IHttpNegotiate);
70 DEFINE_EXPECT(BeginningTransaction);
71 DEFINE_EXPECT(OnResponse);
72 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
73 DEFINE_EXPECT(GetRootSecurityId);
74 DEFINE_EXPECT(GetBindInfo);
75 DEFINE_EXPECT(OnStartBinding);
76 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
77 DEFINE_EXPECT(OnProgress_CONNECTING);
78 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
79 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
80 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
81 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
82 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
83 DEFINE_EXPECT(OnStopBinding);
84 DEFINE_EXPECT(OnDataAvailable);
87 DEFINE_EXPECT(LockRequest);
88 DEFINE_EXPECT(Terminate);
89 DEFINE_EXPECT(UnlockRequest);
91 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
92 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
94 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
95 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
96 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
97 static WCHAR INDEX_HTML[MAX_PATH];
98 static const WCHAR ITS_URL[] =
99 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
100 static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
101 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
105 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
107 static BOOL stopped_binding = FALSE, emulate_protocol = FALSE,
108 data_available = FALSE, http_is_first = TRUE;
109 static DWORD read = 0, bindf = 0;
111 static const LPCWSTR urls[] = {
133 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
136 IMoniker *mon1 = NULL;
137 IMoniker *mon2 = NULL;
139 hr = CreateURLMoniker(NULL, url1, &mon1);
140 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
142 hr = CreateURLMoniker(mon1, url2, &mon2);
143 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
145 if(mon1) IMoniker_Release(mon1);
146 if(mon2) IMoniker_Release(mon2);
149 static void test_create(void)
151 test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
154 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
156 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
162 return E_NOINTERFACE;
165 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
170 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
175 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
176 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
177 DWORD grfPI, DWORD dwReserved)
179 BINDINFO bindinfo, bi = {sizeof(bi), 0};
180 DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
184 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
190 ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url\n");
191 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
192 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
193 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
194 ok(dwReserved == 0, "dwReserved=%d, expected 0\n", dwReserved);
196 memset(&bindinfo, 0, sizeof(bindinfo));
197 bindinfo.cbSize = sizeof(bindinfo);
198 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
199 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
201 if(test_protocol == FILE_TEST || test_protocol == MK_TEST) {
202 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
204 "bindf=%08x\n", bindf);
206 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA|
207 BINDF_FROMURLMON|BINDF_NEEDFILE),
208 "bindf=%08x\n", bindf);
211 ok(!memcmp(&bindinfo, &bi, sizeof(bindinfo)), "wrong bindinfo\n");
213 switch(test_protocol) {
215 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
216 BINDSTATUS_DIRECTBIND, NULL);
218 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
222 SET_EXPECT(OnProgress_SENDINGREQUEST);
223 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
224 BINDSTATUS_SENDINGREQUEST, &null_char);
226 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
227 CHECK_CALLED(OnProgress_SENDINGREQUEST);
232 if(test_protocol == FILE_TEST) {
233 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
234 BINDSTATUS_CACHEFILENAMEAVAILABLE, &null_char);
236 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
238 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
239 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
240 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
242 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
243 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
245 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
246 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
248 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
251 if(test_protocol == ABOUT_TEST)
252 bscf |= BSCF_DATAFULLYAVAILABLE;
253 if(test_protocol == ITS_TEST)
254 bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
257 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
258 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
259 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
260 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
261 SET_EXPECT(LockRequest);
262 SET_EXPECT(OnDataAvailable);
263 SET_EXPECT(OnStopBinding);
265 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
266 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
269 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
270 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
271 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
272 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
273 CHECK_CALLED(LockRequest);
274 CHECK_CALLED(OnDataAvailable);
275 CHECK_CALLED(OnStopBinding);
277 if(test_protocol == ITS_TEST) {
279 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
280 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
284 SET_EXPECT(Terminate);
285 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
286 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
287 CHECK_CALLED(Terminate);
292 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
293 PROTOCOLDATA *pProtocolData)
295 ok(0, "unexpected call\n");
299 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
302 ok(0, "unexpected call\n");
306 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
308 CHECK_EXPECT(Terminate);
309 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
313 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
315 ok(0, "unexpected call\n");
319 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
321 ok(0, "unexpected call\n");
325 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
326 ULONG cb, ULONG *pcbRead)
328 static const char data[] = "<HTML></HTML>";
337 ok(pv != NULL, "pv == NULL\n");
338 ok(cb != 0, "cb == 0\n");
339 ok(pcbRead != NULL, "pcbRead == NULL\n");
341 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
342 read += *pcbRead = sizeof(data)-1;
345 memcpy(pv, data, sizeof(data));
350 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
351 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
353 ok(0, "unexpected call\n");
357 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
359 CHECK_EXPECT(LockRequest);
363 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
365 CHECK_EXPECT(UnlockRequest);
369 static const IInternetProtocolVtbl ProtocolVtbl = {
370 Protocol_QueryInterface,
381 Protocol_LockRequest,
382 Protocol_UnlockRequest
385 static IInternetProtocol Protocol = { &ProtocolVtbl };
387 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
389 if(IsEqualGUID(&IID_IUnknown, riid)
390 || IsEqualGUID(&IID_IHttpNegotiate, riid)
391 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
396 ok(0, "unexpected call\n");
397 return E_NOINTERFACE;
400 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
405 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
410 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
411 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
413 CHECK_EXPECT(BeginningTransaction);
415 ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
416 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
417 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
418 if(pszAdditionalHeaders)
419 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
424 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
425 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
427 CHECK_EXPECT(OnResponse);
429 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
430 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
431 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
432 /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
433 ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
434 if(pszAdditionalRequestHeaders)
435 ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
440 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
441 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
443 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
445 CHECK_EXPECT(GetRootSecurityId);
447 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
448 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
449 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
452 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
453 *pcbSecurityId = sizeof(sec_id);
457 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
462 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
463 HttpNegotiate_QueryInterface,
464 HttpNegotiate_AddRef,
465 HttpNegotiate_Release,
466 HttpNegotiate_BeginningTransaction,
467 HttpNegotiate_OnResponse,
468 HttpNegotiate_GetRootSecurityId
471 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
473 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallback *iface, REFIID riid, void **ppv)
475 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
476 if(emulate_protocol) {
480 return E_NOINTERFACE;
483 else if (IsEqualGUID(&IID_IServiceProvider, riid))
485 CHECK_EXPECT(QueryInterface_IServiceProvider);
487 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
489 CHECK_EXPECT(QueryInterface_IHttpNegotiate);
490 *ppv = &HttpNegotiate;
493 else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
495 CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
496 *ppv = &HttpNegotiate;
500 return E_NOINTERFACE;
503 static ULONG WINAPI statusclb_AddRef(IBindStatusCallback *iface)
508 static ULONG WINAPI statusclb_Release(IBindStatusCallback *iface)
513 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallback *iface, DWORD dwReserved,
519 CHECK_EXPECT(OnStartBinding);
521 ok(pib != NULL, "pib should not be NULL\n");
523 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
524 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
526 IMoniker_Release(mon);
531 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
533 ok(0, "unexpected call\n");
537 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
539 ok(0, "unexpected call\n");
543 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
544 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
546 switch(ulStatusCode) {
547 case BINDSTATUS_FINDINGRESOURCE:
548 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
550 case BINDSTATUS_CONNECTING:
551 CHECK_EXPECT(OnProgress_CONNECTING);
553 case BINDSTATUS_SENDINGREQUEST:
554 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
556 case BINDSTATUS_MIMETYPEAVAILABLE:
557 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
558 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
561 case BINDSTATUS_BEGINDOWNLOADDATA:
562 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
563 ok(szStatusText != NULL, "szStatusText == NULL\n");
565 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText\n");
566 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
568 download_state = DOWNLOADING;
570 case BINDSTATUS_DOWNLOADINGDATA:
571 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
572 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
575 case BINDSTATUS_ENDDOWNLOADDATA:
576 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
577 ok(szStatusText != NULL, "szStatusText == NULL\n");
579 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText\n");
580 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
582 download_state = END_DOWNLOAD;
584 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
585 ok(szStatusText != NULL, "szStatusText == NULL\n");
586 if(szStatusText && test_protocol == FILE_TEST)
587 ok(!lstrcmpW(INDEX_HTML+7, szStatusText), "wrong szStatusText\n");
590 todo_wine { ok(0, "unexpexted code %d\n", ulStatusCode); }
595 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
597 CHECK_EXPECT(OnStopBinding);
599 /* ignore DNS failure */
600 if (hresult != HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
602 ok(SUCCEEDED(hresult), "Download failed: %08x\n", hresult);
603 ok(szError == NULL, "szError should be NULL\n");
605 stopped_binding = TRUE;
610 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
614 CHECK_EXPECT(GetBindInfo);
617 cbSize = pbindinfo->cbSize;
618 memset(pbindinfo, 0, cbSize);
619 pbindinfo->cbSize = cbSize;
624 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
625 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
631 CHECK_EXPECT2(OnDataAvailable);
632 ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
633 "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
635 data_available = TRUE;
639 /* FIXME: Uncomment after removing BindToStorage hack. */
640 ok(pformatetc != NULL, "pformatetx == NULL\n");
642 ok(pformatetc->cfFormat == 0xc02d, "clipformat=%x\n", pformatetc->cfFormat);
643 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
644 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
645 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
646 ok(pformatetc->tymed == TYMED_ISTREAM, "tymed=%u\n", pformatetc->tymed);
649 ok(pstgmed != NULL, "stgmeg == NULL\n");
651 ok(pstgmed->tymed == TYMED_ISTREAM, "tymed=%u\n", pstgmed->tymed);
652 ok(U(*pstgmed).pstm != NULL, "pstm == NULL\n");
653 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
657 if(U(*pstgmed).pstm) {
658 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
660 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
666 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
668 ok(0, "unexpected call\n");
672 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
673 statusclb_QueryInterface,
676 statusclb_OnStartBinding,
677 statusclb_GetPriority,
678 statusclb_OnLowResource,
679 statusclb_OnProgress,
680 statusclb_OnStopBinding,
681 statusclb_GetBindInfo,
682 statusclb_OnDataAvailable,
683 statusclb_OnObjectAvailable
686 static IBindStatusCallback bsc = { &BindStatusCallbackVtbl };
688 static void test_CreateAsyncBindCtx(void)
690 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
695 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
696 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
697 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
699 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
700 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
702 SET_EXPECT(QueryInterface_IServiceProvider);
703 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
704 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n", hres);
705 todo_wine CHECK_CALLED(QueryInterface_IServiceProvider);
707 bindopts.cbStruct = sizeof(bindopts);
708 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
709 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
710 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
711 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
712 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
713 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
715 ok(bindopts.dwTickCountDeadline == 0,
716 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
718 ref = IBindCtx_Release(bctx);
719 ok(ref == 0, "bctx should be destroyed here\n");
722 static void test_CreateAsyncBindCtxEx(void)
724 IBindCtx *bctx = NULL, *bctx_arg = NULL;
728 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
729 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
731 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
732 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
734 if(SUCCEEDED(hres)) {
735 bindopts.cbStruct = sizeof(bindopts);
736 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
737 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
738 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
739 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
740 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
741 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
743 ok(bindopts.dwTickCountDeadline == 0,
744 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
746 IBindCtx_Release(bctx);
749 CreateBindCtx(0, &bctx_arg);
750 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
751 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
753 if(SUCCEEDED(hres)) {
754 bindopts.cbStruct = sizeof(bindopts);
755 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
756 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
757 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
758 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
759 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
760 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
762 ok(bindopts.dwTickCountDeadline == 0,
763 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
765 IBindCtx_Release(bctx);
768 IBindCtx_Release(bctx_arg);
770 SET_EXPECT(QueryInterface_IServiceProvider);
771 hres = CreateAsyncBindCtxEx(NULL, 0, &bsc, NULL, &bctx, 0);
772 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
773 todo_wine CHECK_CALLED(QueryInterface_IServiceProvider);
776 IBindCtx_Release(bctx);
779 static void test_BindToStorage(int protocol, BOOL emul)
783 LPOLESTR display_name;
786 IBindStatusCallback *previousclb;
787 IUnknown *unk = (IUnknown*)0x00ff00ff;
790 test_protocol = protocol;
791 emulate_protocol = emul;
792 download_state = BEFORE_DOWNLOAD;
793 stopped_binding = FALSE;
794 data_available = FALSE;
796 SET_EXPECT(QueryInterface_IServiceProvider);
797 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
798 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
801 todo_wine CHECK_CALLED(QueryInterface_IServiceProvider);
803 SET_EXPECT(QueryInterface_IServiceProvider);
804 hres = RegisterBindStatusCallback(bctx, &bsc, &previousclb, 0);
805 ok(SUCCEEDED(hres), "RegisterBindStatusCallback failed: %08x\n", hres);
806 ok(previousclb == &bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
807 todo_wine CHECK_CALLED(QueryInterface_IServiceProvider);
809 IBindStatusCallback_Release(previousclb);
811 hres = CreateURLMoniker(NULL, urls[test_protocol], &mon);
812 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
814 IBindCtx_Release(bctx);
818 if(test_protocol == FILE_TEST && INDEX_HTML[7] == '/')
819 memmove(INDEX_HTML+7, INDEX_HTML+8, lstrlenW(INDEX_HTML+7)*sizeof(WCHAR));
821 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
822 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
824 IBinding_Release(bind);
826 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
827 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
828 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
830 SET_EXPECT(QueryInterface_IServiceProvider);
831 SET_EXPECT(GetBindInfo);
832 SET_EXPECT(OnStartBinding);
833 if(emulate_protocol) {
835 SET_EXPECT(UnlockRequest);
837 if(test_protocol == HTTP_TEST) {
838 SET_EXPECT(QueryInterface_IHttpNegotiate);
839 SET_EXPECT(BeginningTransaction);
840 SET_EXPECT(QueryInterface_IHttpNegotiate2);
841 SET_EXPECT(GetRootSecurityId);
842 SET_EXPECT(OnProgress_FINDINGRESOURCE);
843 SET_EXPECT(OnProgress_CONNECTING);
845 if(test_protocol == HTTP_TEST || test_protocol == FILE_TEST)
846 SET_EXPECT(OnProgress_SENDINGREQUEST);
847 if(test_protocol == HTTP_TEST)
848 SET_EXPECT(OnResponse);
849 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
850 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
851 if(test_protocol == HTTP_TEST)
852 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
853 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
854 SET_EXPECT(OnDataAvailable);
855 SET_EXPECT(OnStopBinding);
858 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
859 if (test_protocol == HTTP_TEST && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
861 trace( "Network unreachable, skipping tests\n" );
864 if (!SUCCEEDED(hres)) return;
866 if((bindf & BINDF_ASYNCHRONOUS) && !data_available) {
867 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
868 ok(unk == NULL, "istr should be NULL\n");
870 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
871 ok(unk != NULL, "unk == NULL\n");
874 IUnknown_Release(unk);
876 while((bindf & BINDF_ASYNCHRONOUS) &&
877 !stopped_binding && GetMessage(&msg,NULL,0,0)) {
878 TranslateMessage(&msg);
879 DispatchMessage(&msg);
882 CHECK_CALLED(GetBindInfo);
883 CHECK_CALLED(OnStartBinding);
884 if(emulate_protocol) {
885 todo_wine CHECK_NOT_CALLED(QueryInterface_IServiceProvider);
887 CHECK_CALLED(UnlockRequest);
889 if(test_protocol == HTTP_TEST) {
890 CHECK_NOT_CALLED(QueryInterface_IServiceProvider);
891 todo_wine CHECK_CALLED(QueryInterface_IHttpNegotiate);
892 todo_wine CHECK_CALLED(BeginningTransaction);
893 /* QueryInterface_IHttpNegotiate2 and GetRootSecurityId
894 * called on WinXP but not on Win98 */
895 CLEAR_CALLED(QueryInterface_IHttpNegotiate2);
896 CLEAR_CALLED(GetRootSecurityId);
898 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
899 CHECK_CALLED(OnProgress_CONNECTING);
901 CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
902 CHECK_NOT_CALLED(OnProgress_CONNECTING);
904 CHECK_CALLED(OnProgress_SENDINGREQUEST);
905 todo_wine CHECK_CALLED(OnResponse);
906 todo_wine { CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE); }
908 todo_wine CHECK_NOT_CALLED(QueryInterface_IServiceProvider);
909 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
911 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
912 if(test_protocol == HTTP_TEST)
913 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
914 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
915 CHECK_CALLED(OnDataAvailable);
916 CHECK_CALLED(OnStopBinding);
919 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
920 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
922 if(test_protocol == HTTP_TEST)
923 http_is_first = FALSE;
926 static void set_file_url(void)
930 static const WCHAR wszFile[] = {'f','i','l','e',':','/','/'};
932 memcpy(INDEX_HTML, wszFile, sizeof(wszFile));
933 len = sizeof(wszFile)/sizeof(WCHAR);
934 INDEX_HTML[len++] = '/';
935 len += GetCurrentDirectoryW(sizeof(INDEX_HTML)/sizeof(WCHAR)-len, INDEX_HTML+len);
936 INDEX_HTML[len++] = '\\';
937 memcpy(INDEX_HTML+len, wszIndexHtml, sizeof(wszIndexHtml));
940 static void create_file(void)
945 static const char html_doc[] = "<HTML></HTML>";
947 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
948 FILE_ATTRIBUTE_NORMAL, NULL);
949 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
950 if(file == INVALID_HANDLE_VALUE)
953 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
959 static void test_BindToStorage_fail(void)
961 IMoniker *mon = NULL;
962 IBindCtx *bctx = NULL;
966 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
967 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
971 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
972 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
974 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
975 ok(hres == MK_E_SYNTAX, "hres=%08x, expected INET_E_SYNTAX\n", hres);
977 IBindCtx_Release(bctx);
979 IMoniker_Release(mon);
985 test_CreateAsyncBindCtx();
986 test_CreateAsyncBindCtxEx();
988 trace("synchronous http test...\n");
989 test_BindToStorage(HTTP_TEST, FALSE);
991 trace("synchronous file test...\n");
993 test_BindToStorage(FILE_TEST, FALSE);
994 DeleteFileW(wszIndexHtml);
996 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
998 trace("http test...\n");
999 test_BindToStorage(HTTP_TEST, FALSE);
1001 trace("about test...\n");
1003 test_BindToStorage(ABOUT_TEST, FALSE);
1006 trace("emulated about test...\n");
1007 test_BindToStorage(ABOUT_TEST, TRUE);
1009 trace("file test...\n");
1011 test_BindToStorage(FILE_TEST, FALSE);
1012 DeleteFileW(wszIndexHtml);
1014 trace("emulated file test...\n");
1016 test_BindToStorage(FILE_TEST, TRUE);
1018 trace("emulated its test...\n");
1019 test_BindToStorage(ITS_TEST, TRUE);
1021 trace("emulated mk test...\n");
1022 test_BindToStorage(MK_TEST, TRUE);
1024 test_BindToStorage_fail();