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_EXPECT(GetBindInfo);
60 DEFINE_EXPECT(OnStartBinding);
61 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
62 DEFINE_EXPECT(OnProgress_CONNECTING);
63 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
64 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
65 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
66 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
67 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
68 DEFINE_EXPECT(OnStopBinding);
69 DEFINE_EXPECT(OnDataAvailable);
72 DEFINE_EXPECT(LockRequest);
73 DEFINE_EXPECT(Terminate);
74 DEFINE_EXPECT(UnlockRequest);
76 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
77 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
79 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
80 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
81 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
82 static WCHAR INDEX_HTML[MAX_PATH];
84 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
86 static BOOL stopped_binding = FALSE, emulate_protocol = FALSE;
87 static DWORD read = 0;
89 static const LPCWSTR urls[] = {
101 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
104 IMoniker *mon1 = NULL;
105 IMoniker *mon2 = NULL;
107 hr = CreateURLMoniker(NULL, url1, &mon1);
108 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
110 hr = CreateURLMoniker(mon1, url2, &mon2);
111 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
113 if(mon1) IMoniker_Release(mon1);
114 if(mon2) IMoniker_Release(mon2);
117 static void test_create(void)
119 test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
122 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
124 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
130 return E_NOINTERFACE;
133 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
138 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
143 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
144 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
145 DWORD grfPI, DWORD dwReserved)
147 BINDINFO bindinfo, bi = {sizeof(bi), 0};
148 DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
152 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
158 ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url\n");
159 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
160 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
161 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
162 ok(dwReserved == 0, "dwReserved=%d, expected 0\n", dwReserved);
164 memset(&bindinfo, 0, sizeof(bindinfo));
165 bindinfo.cbSize = sizeof(bindinfo);
166 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
167 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
169 if(test_protocol == FILE_TEST) {
170 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
172 "bindf=%08x\n", bindf);
174 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA|
175 BINDF_FROMURLMON|BINDF_NEEDFILE),
176 "bindf=%08x\n", bindf);
179 ok(!memcmp(&bindinfo, &bi, sizeof(bindinfo)), "wrong bindinfo\n");
181 if(test_protocol == FILE_TEST) {
182 SET_EXPECT(OnProgress_SENDINGREQUEST);
183 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
184 BINDSTATUS_SENDINGREQUEST, &null_char);
186 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
187 CHECK_CALLED(OnProgress_SENDINGREQUEST);
189 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
190 BINDSTATUS_CACHEFILENAMEAVAILABLE, &null_char);
192 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
194 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
195 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
196 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
198 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
199 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
201 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
202 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
204 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
207 if(test_protocol == ABOUT_TEST)
208 bscf |= BSCF_DATAFULLYAVAILABLE;
211 if(test_protocol != FILE_TEST)
212 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
213 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
214 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
215 SET_EXPECT(LockRequest);
216 SET_EXPECT(OnDataAvailable);
217 SET_EXPECT(OnStopBinding);
219 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
220 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
223 if(test_protocol != FILE_TEST)
224 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
225 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
226 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
227 CHECK_CALLED(LockRequest);
228 CHECK_CALLED(OnDataAvailable);
229 CHECK_CALLED(OnStopBinding);
231 SET_EXPECT(Terminate);
232 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
233 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
234 CHECK_CALLED(Terminate);
239 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
240 PROTOCOLDATA *pProtocolData)
242 ok(0, "unexpected call\n");
246 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
249 ok(0, "unexpected call\n");
253 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
255 CHECK_EXPECT(Terminate);
256 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
260 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
262 ok(0, "unexpected call\n");
266 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
268 ok(0, "unexpected call\n");
272 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
273 ULONG cb, ULONG *pcbRead)
275 static const char data[] = "<HTML></HTML>";
284 ok(pv != NULL, "pv == NULL\n");
285 ok(cb != 0, "cb == 0\n");
286 ok(pcbRead != NULL, "pcbRead == NULL\n");
288 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
293 memcpy(pv, data, sizeof(data));
298 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
299 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
301 ok(0, "unexpected call\n");
305 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
307 CHECK_EXPECT(LockRequest);
311 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
313 CHECK_EXPECT(UnlockRequest);
317 static const IInternetProtocolVtbl ProtocolVtbl = {
318 Protocol_QueryInterface,
329 Protocol_LockRequest,
330 Protocol_UnlockRequest
333 static IInternetProtocol Protocol = { &ProtocolVtbl };
335 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallback *iface, REFIID riid, void **ppv)
337 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
338 if(emulate_protocol) {
342 return E_NOINTERFACE;
346 return E_NOINTERFACE;
349 static ULONG WINAPI statusclb_AddRef(IBindStatusCallback *iface)
354 static ULONG WINAPI statusclb_Release(IBindStatusCallback *iface)
359 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallback *iface, DWORD dwReserved,
365 CHECK_EXPECT(OnStartBinding);
367 ok(pib != NULL, "pib should not be NULL\n");
369 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
370 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
372 IMoniker_Release(mon);
377 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
379 ok(0, "unexpected call\n");
383 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
385 ok(0, "unexpected call\n");
389 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
390 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
392 switch(ulStatusCode) {
393 case BINDSTATUS_FINDINGRESOURCE:
394 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
396 case BINDSTATUS_CONNECTING:
397 CHECK_EXPECT(OnProgress_CONNECTING);
399 case BINDSTATUS_SENDINGREQUEST:
400 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
402 case BINDSTATUS_MIMETYPEAVAILABLE:
403 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
405 case BINDSTATUS_BEGINDOWNLOADDATA:
406 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
407 ok(szStatusText != NULL, "szStatusText == NULL\n");
409 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText\n");
411 case BINDSTATUS_DOWNLOADINGDATA:
412 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
414 case BINDSTATUS_ENDDOWNLOADDATA:
415 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
416 ok(szStatusText != NULL, "szStatusText == NULL\n");
418 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText\n");
420 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
421 ok(szStatusText != NULL, "szStatusText == NULL\n");
422 if(szStatusText && test_protocol == FILE_TEST)
423 ok(!lstrcmpW(INDEX_HTML+7, szStatusText), "wrong szStatusText\n");
426 todo_wine { ok(0, "unexpexted code %d\n", ulStatusCode); }
431 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
433 CHECK_EXPECT(OnStopBinding);
435 /* ignore DNS failure */
436 if (hresult != HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
438 ok(SUCCEEDED(hresult), "Download failed: %08x\n", hresult);
439 ok(szError == NULL, "szError should be NULL\n");
441 stopped_binding = TRUE;
446 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
450 CHECK_EXPECT(GetBindInfo);
452 *grfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
453 cbSize = pbindinfo->cbSize;
454 memset(pbindinfo, 0, cbSize);
455 pbindinfo->cbSize = cbSize;
460 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
461 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
467 CHECK_EXPECT2(OnDataAvailable);
469 #if 0 /* Uncomment after removing BindToStorage hack. */
470 ok(pformatetc != NULL, "pformatetx == NULL\n");
472 ok(pformatetc->cfFormat == 0xc02d, "clipformat=%x\n", pformatetc->cfFormat);
473 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
474 ok(pformatetc->dwAspect == 1, "dwAspect=%ld\n", pformatetc->dwAspect);
475 ok(pformatetc->lindex == -1, "lindex=%ld\n", pformatetc->lindex);
476 ok(pformatetc->tymed == TYMED_ISTREAM, "tymed=%ld\n", pformatetc->tymed);
479 ok(pstgmed != NULL, "stgmeg == NULL\n");
481 ok(pstgmed->tymed == TYMED_ISTREAM, "tymed=%ld\n", pstgmed->tymed);
482 ok(U(*pstgmed).pstm != NULL, "pstm == NULL\n");
483 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
487 if(U(*pstgmed).pstm) {
488 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
490 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
496 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
498 ok(0, "unexpected call\n");
502 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
503 statusclb_QueryInterface,
506 statusclb_OnStartBinding,
507 statusclb_GetPriority,
508 statusclb_OnLowResource,
509 statusclb_OnProgress,
510 statusclb_OnStopBinding,
511 statusclb_GetBindInfo,
512 statusclb_OnDataAvailable,
513 statusclb_OnObjectAvailable
516 static IBindStatusCallback bsc = { &BindStatusCallbackVtbl };
518 static void test_CreateAsyncBindCtx(void)
520 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
525 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
526 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
527 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
529 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
530 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
532 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
533 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n", hres);
535 bindopts.cbStruct = sizeof(bindopts);
536 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
537 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
538 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
539 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
540 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
541 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
543 ok(bindopts.dwTickCountDeadline == 0,
544 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
546 ref = IBindCtx_Release(bctx);
547 ok(ref == 0, "bctx should be destroyed here\n");
550 static void test_CreateAsyncBindCtxEx(void)
552 IBindCtx *bctx = NULL, *bctx_arg = NULL;
556 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
557 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
559 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
560 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
562 if(SUCCEEDED(hres)) {
563 bindopts.cbStruct = sizeof(bindopts);
564 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
565 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
566 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
567 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
568 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
569 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
571 ok(bindopts.dwTickCountDeadline == 0,
572 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
574 IBindCtx_Release(bctx);
577 CreateBindCtx(0, &bctx_arg);
578 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
579 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
581 if(SUCCEEDED(hres)) {
582 bindopts.cbStruct = sizeof(bindopts);
583 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
584 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
585 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
586 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
587 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
588 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
590 ok(bindopts.dwTickCountDeadline == 0,
591 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
593 IBindCtx_Release(bctx);
596 IBindCtx_Release(bctx_arg);
598 hres = CreateAsyncBindCtxEx(NULL, 0, &bsc, NULL, &bctx, 0);
599 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
602 IBindCtx_Release(bctx);
605 static void test_BindToStorage(void)
609 LPOLESTR display_name;
612 IBindStatusCallback *previousclb;
613 IUnknown *unk = (IUnknown*)0x00ff00ff;
616 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
617 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
621 hres = RegisterBindStatusCallback(bctx, &bsc, &previousclb, 0);
622 ok(SUCCEEDED(hres), "RegisterBindStatusCallback failed: %08x\n", hres);
623 ok(previousclb == &bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
625 IBindStatusCallback_Release(previousclb);
627 hres = CreateURLMoniker(NULL, urls[test_protocol], &mon);
628 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
630 IBindCtx_Release(bctx);
634 if(test_protocol == FILE_TEST && INDEX_HTML[7] == '/')
635 memmove(INDEX_HTML+7, INDEX_HTML+8, lstrlenW(INDEX_HTML+7)*sizeof(WCHAR));
637 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
638 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
640 IBinding_Release(bind);
642 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
643 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
644 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
646 SET_EXPECT(GetBindInfo);
647 SET_EXPECT(OnStartBinding);
648 if(emulate_protocol) {
650 SET_EXPECT(UnlockRequest);
652 if(test_protocol == HTTP_TEST) {
653 SET_EXPECT(OnProgress_FINDINGRESOURCE);
654 SET_EXPECT(OnProgress_CONNECTING);
656 if(test_protocol == HTTP_TEST || test_protocol == FILE_TEST)
657 SET_EXPECT(OnProgress_SENDINGREQUEST);
658 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
659 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
660 SET_EXPECT(OnDataAvailable);
661 if(test_protocol == HTTP_TEST)
662 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
663 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
664 SET_EXPECT(OnStopBinding);
667 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
668 if (test_protocol == HTTP_TEST && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
670 trace( "Network unreachable, skipping tests\n" );
673 ok(SUCCEEDED(hres), "IMoniker_BindToStorage failed: %08x\n", hres);
674 if (!SUCCEEDED(hres)) return;
676 if(test_protocol == HTTP_TEST) {
678 ok(unk == NULL, "istr should be NULL\n");
681 ok(unk != NULL, "unk == NULL\n");
684 IUnknown_Release(unk);
686 while(!stopped_binding && GetMessage(&msg,NULL,0,0)) {
687 TranslateMessage(&msg);
688 DispatchMessage(&msg);
691 CHECK_CALLED(GetBindInfo);
692 CHECK_CALLED(OnStartBinding);
693 if(emulate_protocol) {
695 CHECK_CALLED(UnlockRequest);
697 if(test_protocol == HTTP_TEST) {
698 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
699 CHECK_CALLED(OnProgress_CONNECTING);
700 CHECK_CALLED(OnProgress_SENDINGREQUEST);
701 todo_wine { CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE); }
703 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
705 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
706 CHECK_CALLED(OnDataAvailable);
707 if(test_protocol == HTTP_TEST)
708 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
709 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
710 CHECK_CALLED(OnStopBinding);
713 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
714 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
717 static void set_file_url(void)
721 static const WCHAR wszFile[] = {'f','i','l','e',':','/','/'};
723 memcpy(INDEX_HTML, wszFile, sizeof(wszFile));
724 len = sizeof(wszFile)/sizeof(WCHAR);
725 INDEX_HTML[len++] = '/';
726 len += GetCurrentDirectoryW(sizeof(INDEX_HTML)/sizeof(WCHAR)-len, INDEX_HTML+len);
727 INDEX_HTML[len++] = '\\';
728 memcpy(INDEX_HTML+len, wszIndexHtml, sizeof(wszIndexHtml));
731 static void create_file(void)
736 static const char html_doc[] = "<HTML></HTML>";
738 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
739 FILE_ATTRIBUTE_NORMAL, NULL);
740 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
741 if(file == INVALID_HANDLE_VALUE)
744 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
750 static void test_BindToStorage_fail(void)
752 IMoniker *mon = NULL;
753 IBindCtx *bctx = NULL;
757 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
758 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
762 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
763 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
765 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
766 ok(hres == MK_E_SYNTAX, "hres=%08x, expected INET_E_SYNTAX\n", hres);
768 IBindCtx_Release(bctx);
770 IMoniker_Release(mon);
776 test_CreateAsyncBindCtx();
777 test_CreateAsyncBindCtxEx();
779 trace("http test...\n");
780 emulate_protocol = FALSE;
781 test_protocol = HTTP_TEST;
782 test_BindToStorage();
784 trace("about test...\n");
785 test_protocol = ABOUT_TEST;
787 test_BindToStorage();
790 trace("emulated about test...\n");
791 emulate_protocol = TRUE;
792 test_protocol = ABOUT_TEST;
793 test_BindToStorage();
795 trace("file test...\n");
797 emulate_protocol = FALSE;
798 test_protocol = FILE_TEST;
799 test_BindToStorage();
800 DeleteFileW(wszIndexHtml);
802 trace("emulated file test...\n");
804 emulate_protocol = TRUE;
805 test_protocol = FILE_TEST;
806 test_BindToStorage();
808 test_BindToStorage_fail();