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);
471 /* FIXME: Uncomment after removing BindToStorage hack. */
472 ok(pformatetc != NULL, "pformatetx == NULL\n");
474 ok(pformatetc->cfFormat == 0xc02d, "clipformat=%x\n", pformatetc->cfFormat);
475 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
476 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
477 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
478 ok(pformatetc->tymed == TYMED_ISTREAM, "tymed=%u\n", pformatetc->tymed);
481 ok(pstgmed != NULL, "stgmeg == NULL\n");
483 ok(pstgmed->tymed == TYMED_ISTREAM, "tymed=%u\n", pstgmed->tymed);
484 ok(U(*pstgmed).pstm != NULL, "pstm == NULL\n");
485 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
489 if(U(*pstgmed).pstm) {
490 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
492 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
498 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
500 ok(0, "unexpected call\n");
504 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
505 statusclb_QueryInterface,
508 statusclb_OnStartBinding,
509 statusclb_GetPriority,
510 statusclb_OnLowResource,
511 statusclb_OnProgress,
512 statusclb_OnStopBinding,
513 statusclb_GetBindInfo,
514 statusclb_OnDataAvailable,
515 statusclb_OnObjectAvailable
518 static IBindStatusCallback bsc = { &BindStatusCallbackVtbl };
520 static void test_CreateAsyncBindCtx(void)
522 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
527 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
528 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
529 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
531 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
532 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
534 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
535 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n", hres);
537 bindopts.cbStruct = sizeof(bindopts);
538 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
539 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
540 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
541 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
542 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
543 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
545 ok(bindopts.dwTickCountDeadline == 0,
546 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
548 ref = IBindCtx_Release(bctx);
549 ok(ref == 0, "bctx should be destroyed here\n");
552 static void test_CreateAsyncBindCtxEx(void)
554 IBindCtx *bctx = NULL, *bctx_arg = NULL;
558 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
559 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
561 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
562 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
564 if(SUCCEEDED(hres)) {
565 bindopts.cbStruct = sizeof(bindopts);
566 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
567 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
568 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
569 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
570 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
571 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
573 ok(bindopts.dwTickCountDeadline == 0,
574 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
576 IBindCtx_Release(bctx);
579 CreateBindCtx(0, &bctx_arg);
580 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
581 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
583 if(SUCCEEDED(hres)) {
584 bindopts.cbStruct = sizeof(bindopts);
585 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
586 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
587 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
588 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
589 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
590 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
592 ok(bindopts.dwTickCountDeadline == 0,
593 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
595 IBindCtx_Release(bctx);
598 IBindCtx_Release(bctx_arg);
600 hres = CreateAsyncBindCtxEx(NULL, 0, &bsc, NULL, &bctx, 0);
601 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
604 IBindCtx_Release(bctx);
607 static void test_BindToStorage(int protocol, BOOL emul)
611 LPOLESTR display_name;
614 IBindStatusCallback *previousclb;
615 IUnknown *unk = (IUnknown*)0x00ff00ff;
618 test_protocol = protocol;
619 emulate_protocol = emul;
621 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
622 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
626 hres = RegisterBindStatusCallback(bctx, &bsc, &previousclb, 0);
627 ok(SUCCEEDED(hres), "RegisterBindStatusCallback failed: %08x\n", hres);
628 ok(previousclb == &bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
630 IBindStatusCallback_Release(previousclb);
632 hres = CreateURLMoniker(NULL, urls[test_protocol], &mon);
633 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
635 IBindCtx_Release(bctx);
639 if(test_protocol == FILE_TEST && INDEX_HTML[7] == '/')
640 memmove(INDEX_HTML+7, INDEX_HTML+8, lstrlenW(INDEX_HTML+7)*sizeof(WCHAR));
642 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
643 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
645 IBinding_Release(bind);
647 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
648 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
649 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
651 SET_EXPECT(GetBindInfo);
652 SET_EXPECT(OnStartBinding);
653 if(emulate_protocol) {
655 SET_EXPECT(UnlockRequest);
657 if(test_protocol == HTTP_TEST) {
658 SET_EXPECT(OnProgress_FINDINGRESOURCE);
659 SET_EXPECT(OnProgress_CONNECTING);
661 if(test_protocol == HTTP_TEST || test_protocol == FILE_TEST)
662 SET_EXPECT(OnProgress_SENDINGREQUEST);
663 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
664 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
665 SET_EXPECT(OnDataAvailable);
666 if(test_protocol == HTTP_TEST)
667 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
668 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
669 SET_EXPECT(OnStopBinding);
672 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
673 if (test_protocol == HTTP_TEST && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
675 trace( "Network unreachable, skipping tests\n" );
678 ok(SUCCEEDED(hres), "IMoniker_BindToStorage failed: %08x\n", hres);
679 if (!SUCCEEDED(hres)) return;
681 if(test_protocol == HTTP_TEST) {
683 ok(unk == NULL, "istr should be NULL\n");
686 ok(unk != NULL, "unk == NULL\n");
689 IUnknown_Release(unk);
691 while(!stopped_binding && GetMessage(&msg,NULL,0,0)) {
692 TranslateMessage(&msg);
693 DispatchMessage(&msg);
696 CHECK_CALLED(GetBindInfo);
697 CHECK_CALLED(OnStartBinding);
698 if(emulate_protocol) {
700 CHECK_CALLED(UnlockRequest);
702 if(test_protocol == HTTP_TEST) {
703 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
704 CHECK_CALLED(OnProgress_CONNECTING);
705 CHECK_CALLED(OnProgress_SENDINGREQUEST);
706 todo_wine { CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE); }
708 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
710 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
711 CHECK_CALLED(OnDataAvailable);
712 if(test_protocol == HTTP_TEST)
713 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
714 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
715 CHECK_CALLED(OnStopBinding);
718 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
719 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
722 static void set_file_url(void)
726 static const WCHAR wszFile[] = {'f','i','l','e',':','/','/'};
728 memcpy(INDEX_HTML, wszFile, sizeof(wszFile));
729 len = sizeof(wszFile)/sizeof(WCHAR);
730 INDEX_HTML[len++] = '/';
731 len += GetCurrentDirectoryW(sizeof(INDEX_HTML)/sizeof(WCHAR)-len, INDEX_HTML+len);
732 INDEX_HTML[len++] = '\\';
733 memcpy(INDEX_HTML+len, wszIndexHtml, sizeof(wszIndexHtml));
736 static void create_file(void)
741 static const char html_doc[] = "<HTML></HTML>";
743 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
744 FILE_ATTRIBUTE_NORMAL, NULL);
745 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
746 if(file == INVALID_HANDLE_VALUE)
749 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
755 static void test_BindToStorage_fail(void)
757 IMoniker *mon = NULL;
758 IBindCtx *bctx = NULL;
762 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
763 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
767 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
768 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
770 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
771 ok(hres == MK_E_SYNTAX, "hres=%08x, expected INET_E_SYNTAX\n", hres);
773 IBindCtx_Release(bctx);
775 IMoniker_Release(mon);
781 test_CreateAsyncBindCtx();
782 test_CreateAsyncBindCtxEx();
784 trace("http test...\n");
785 test_BindToStorage(HTTP_TEST, FALSE);
787 trace("about test...\n");
789 test_BindToStorage(ABOUT_TEST, FALSE);
792 trace("emulated about test...\n");
793 test_BindToStorage(ABOUT_TEST, TRUE);
795 trace("file test...\n");
797 test_BindToStorage(FILE_TEST, FALSE);
798 DeleteFileW(wszIndexHtml);
800 trace("emulated file test...\n");
802 test_BindToStorage(FILE_TEST, TRUE);
804 test_BindToStorage_fail();