push d2ed94b6221baa59db3b40852d651a773c374f7d
[wine/hacks.git] / dlls / urlmon / tests / url.c
blob9d10a5933e9b9700b7483621984e2d3cb28ee045
1 /*
2 * UrlMon URL tests
4 * Copyright 2004 Kevin Koltzau
5 * Copyright 2004-2007 Jacek Caban for CodeWeavers
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
22 #include <stdarg.h>
23 #include <stdio.h>
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define CONST_VTABLE
29 #include "windef.h"
30 #include "winbase.h"
31 #include "initguid.h"
32 #include "urlmon.h"
33 #include "wininet.h"
34 #include "mshtml.h"
36 #include "wine/test.h"
38 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
39 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
40 DEFINE_GUID(IID_IBindStatusCallbackHolder,0x79eac9cc,0xbaf9,0x11ce,0x8c,0x82,0x00,0xaa,0x00,0x4b,0xa9,0x0b);
42 #define DEFINE_EXPECT(func) \
43 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
45 #define SET_EXPECT(func) \
46 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
48 #define CHECK_EXPECT2(func) \
49 do { \
50 ok(expect_ ##func, "unexpected call " #func "\n"); \
51 called_ ## func = TRUE; \
52 }while(0)
54 #define CHECK_EXPECT(func) \
55 do { \
56 CHECK_EXPECT2(func); \
57 expect_ ## func = FALSE; \
58 }while(0)
60 #define CHECK_CALLED(func) \
61 do { \
62 ok(called_ ## func, "expected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
64 }while(0)
66 #define CHECK_NOT_CALLED(func) \
67 do { \
68 ok(!called_ ## func, "unexpected " #func "\n"); \
69 expect_ ## func = called_ ## func = FALSE; \
70 }while(0)
72 #define CHECK_CALLED_BROKEN(func) \
73 do { \
74 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
75 expect_ ## func = called_ ## func = FALSE; \
76 }while(0)
78 #define CLEAR_CALLED(func) \
79 expect_ ## func = called_ ## func = FALSE
81 DEFINE_EXPECT(QueryInterface_IServiceProvider);
82 DEFINE_EXPECT(QueryInterface_IHttpNegotiate);
83 DEFINE_EXPECT(QueryInterface_IBindStatusCallback);
84 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackHolder);
85 DEFINE_EXPECT(QueryInterface_IInternetBindInfo);
86 DEFINE_EXPECT(QueryInterface_IAuthenticate);
87 DEFINE_EXPECT(QueryInterface_IInternetProtocol);
88 DEFINE_EXPECT(QueryService_IAuthenticate);
89 DEFINE_EXPECT(QueryService_IInternetProtocol);
90 DEFINE_EXPECT(QueryService_IInternetBindInfo);
91 DEFINE_EXPECT(BeginningTransaction);
92 DEFINE_EXPECT(OnResponse);
93 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
94 DEFINE_EXPECT(GetRootSecurityId);
95 DEFINE_EXPECT(GetBindInfo);
96 DEFINE_EXPECT(OnStartBinding);
97 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
98 DEFINE_EXPECT(OnProgress_CONNECTING);
99 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
100 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
101 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
102 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
103 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
104 DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
105 DEFINE_EXPECT(OnStopBinding);
106 DEFINE_EXPECT(OnDataAvailable);
107 DEFINE_EXPECT(OnObjectAvailable);
108 DEFINE_EXPECT(Obj_OnStartBinding);
109 DEFINE_EXPECT(Obj_OnStopBinding);
110 DEFINE_EXPECT(Obj_GetBindInfo);
111 DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
112 DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
113 DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
114 DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
115 DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
116 DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
117 DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
118 DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
119 DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
120 DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
121 DEFINE_EXPECT(Start);
122 DEFINE_EXPECT(Read);
123 DEFINE_EXPECT(LockRequest);
124 DEFINE_EXPECT(Terminate);
125 DEFINE_EXPECT(UnlockRequest);
126 DEFINE_EXPECT(Continue);
127 DEFINE_EXPECT(CreateInstance);
128 DEFINE_EXPECT(Load);
129 DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
130 DEFINE_EXPECT(PutProperty_CLASSIDPROP);
131 DEFINE_EXPECT(SetPriority);
133 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
134 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
136 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
137 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
138 static const WCHAR SHORT_RESPONSE_URL[] =
139 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
140 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
141 'p','o','s','t','t','e','s','t','.','p','h','p',0};
142 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
143 static WCHAR INDEX_HTML[MAX_PATH];
144 static const WCHAR ITS_URL[] =
145 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
146 static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
147 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
148 static const WCHAR https_urlW[] =
149 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',
150 '/','t','e','s','t','.','h','t','m','l',0};
151 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
152 '/','p','u','b','/','o','t','h','e','r','/',
153 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
156 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
158 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
160 static const WCHAR wszWineHQSite[] =
161 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
162 static const WCHAR wszWineHQIP[] =
163 {'2','0','9','.','3','2','.','1','4','1','.','3',0};
164 static const CHAR wszIndexHtmlA[] = "index.html";
165 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
166 static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
167 static const CHAR dwl_htmlA[] = "dwl.html";
168 static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
169 static const WCHAR emptyW[] = {0};
171 static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
172 data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api;
173 static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed;
174 static CHAR mime_type[512];
175 static IInternetProtocolSink *protocol_sink = NULL;
176 static IBinding *current_binding;
177 static HANDLE complete_event, complete_event2;
178 static HRESULT binding_hres;
179 static BOOL have_IHttpNegotiate2;
181 static LPCWSTR urls[] = {
182 WINE_ABOUT_URL,
183 ABOUT_BLANK,
184 INDEX_HTML,
185 ITS_URL,
186 MK_URL,
187 https_urlW,
188 ftp_urlW
191 static WCHAR file_url[INTERNET_MAX_URL_LENGTH];
193 static enum {
194 HTTP_TEST,
195 ABOUT_TEST,
196 FILE_TEST,
197 ITS_TEST,
198 MK_TEST,
199 HTTPS_TEST,
200 FTP_TEST
201 } test_protocol;
203 static enum {
204 BEFORE_DOWNLOAD,
205 DOWNLOADING,
206 END_DOWNLOAD
207 } download_state;
209 static const char *debugstr_w(LPCWSTR str)
211 static char buf[1024];
212 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
213 return buf;
216 static const char *debugstr_guid(REFIID riid)
218 static char buf[50];
220 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
221 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
222 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
223 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
225 return buf;
228 static BOOL is_urlmon_protocol(int prot)
230 return prot == FILE_TEST || prot == HTTP_TEST || prot == HTTPS_TEST || prot == FTP_TEST || prot == MK_TEST;
233 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
235 HRESULT hr;
236 IMoniker *mon1 = NULL;
237 IMoniker *mon2 = NULL;
239 hr = CreateURLMoniker(NULL, url1, &mon1);
240 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
241 if(SUCCEEDED(hr)) {
242 hr = CreateURLMoniker(mon1, url2, &mon2);
243 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
245 if(mon1) IMoniker_Release(mon1);
246 if(mon2) IMoniker_Release(mon2);
249 static void test_create(void)
251 test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
254 static HRESULT WINAPI Priority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
256 ok(0, "unexpected call\n");
257 return E_NOINTERFACE;
260 static ULONG WINAPI Priority_AddRef(IInternetPriority *iface)
262 return 2;
265 static ULONG WINAPI Priority_Release(IInternetPriority *iface)
267 return 1;
270 static HRESULT WINAPI Priority_SetPriority(IInternetPriority *iface, LONG nPriority)
272 CHECK_EXPECT(SetPriority);
273 ok(!nPriority, "nPriority = %d\n", nPriority);
274 return S_OK;
277 static HRESULT WINAPI Priority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
279 ok(0, "unexpected call\n");
280 return S_OK;
283 static const IInternetPriorityVtbl InternetPriorityVtbl = {
284 Priority_QueryInterface,
285 Priority_AddRef,
286 Priority_Release,
287 Priority_SetPriority,
288 Priority_GetPriority
291 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
293 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
295 *ppv = NULL;
297 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
298 *ppv = iface;
299 return S_OK;
302 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
303 if(!is_urlmon_protocol(test_protocol))
304 return E_NOINTERFACE;
306 *ppv = &InternetPriority;
307 return S_OK;
310 if(IsEqualGUID(&IID_IInternetProtocolEx, riid))
311 return E_NOINTERFACE; /* TODO */
313 ok(0, "unexpected call %s\n", debugstr_guid(riid));
314 return E_NOINTERFACE;
317 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
319 return 2;
322 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
324 return 1;
327 static DWORD WINAPI thread_proc(PVOID arg)
329 PROTOCOLDATA protocoldata;
330 HRESULT hres;
332 if(bind_to_object)
333 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
334 else
335 SET_EXPECT(OnProgress_FINDINGRESOURCE);
336 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
337 BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
338 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
339 WaitForSingleObject(complete_event, INFINITE);
340 if(bind_to_object)
341 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
342 else
343 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
345 if(bind_to_object)
346 SET_EXPECT(Obj_OnProgress_CONNECTING);
347 else
348 SET_EXPECT(OnProgress_CONNECTING);
349 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
350 BINDSTATUS_CONNECTING, wszWineHQIP);
351 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
352 WaitForSingleObject(complete_event, INFINITE);
353 if(bind_to_object)
354 CHECK_CALLED(Obj_OnProgress_CONNECTING);
355 else
356 CHECK_CALLED(OnProgress_CONNECTING);
358 if(bind_to_object)
359 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
360 else
361 SET_EXPECT(OnProgress_SENDINGREQUEST);
362 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
363 BINDSTATUS_SENDINGREQUEST, NULL);
364 ok(hres == S_OK, "ReportProxgress failed: %08x\n", hres);
365 WaitForSingleObject(complete_event, INFINITE);
366 if(bind_to_object)
367 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
368 else
369 CHECK_CALLED(OnProgress_SENDINGREQUEST);
371 SET_EXPECT(Continue);
372 prot_state = 1;
373 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
374 ok(hres == S_OK, "Switch failed: %08x\n", hres);
375 WaitForSingleObject(complete_event, INFINITE);
377 CHECK_CALLED(Continue);
378 CHECK_CALLED(Read);
379 if(bind_to_object) {
380 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
381 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
382 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
383 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
384 CHECK_CALLED(CreateInstance);
385 CHECK_CALLED(PutProperty_MIMETYPEPROP);
386 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
387 CHECK_CALLED(Load);
388 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
389 CHECK_CALLED(OnObjectAvailable);
390 CHECK_CALLED(Obj_OnStopBinding);
391 }else {
392 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
393 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
394 CHECK_CALLED(LockRequest);
395 CHECK_CALLED(OnDataAvailable);
398 SET_EXPECT(Continue);
399 prot_state = 2;
400 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
401 ok(hres == S_OK, "Switch failed: %08x\n", hres);
402 WaitForSingleObject(complete_event, INFINITE);
403 CHECK_CALLED(Continue);
404 CHECK_CALLED(Read);
405 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
406 CHECK_CALLED(OnDataAvailable);
408 SET_EXPECT(Continue);
409 prot_state = 2;
410 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
411 ok(hres == S_OK, "Switch failed: %08x\n", hres);
412 WaitForSingleObject(complete_event, INFINITE);
413 CHECK_CALLED(Continue);
414 CHECK_CALLED(Read);
415 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
416 CHECK_CALLED(OnDataAvailable);
418 SET_EXPECT(Continue);
419 prot_state = 3;
420 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
421 ok(hres == S_OK, "Switch failed: %08x\n", hres);
422 WaitForSingleObject(complete_event, INFINITE);
423 CHECK_CALLED(Continue);
424 CHECK_CALLED(Read);
425 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
426 CHECK_CALLED(OnDataAvailable);
427 CHECK_CALLED(OnStopBinding);
429 SET_EXPECT(Read);
431 SetEvent(complete_event2);
432 return 0;
435 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
436 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
437 DWORD grfPI, HANDLE_PTR dwReserved)
439 BINDINFO bindinfo;
440 DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
441 HRESULT hres;
443 static const STGMEDIUM stgmed_zero = {0};
444 static const SECURITY_ATTRIBUTES sa_zero = {0};
446 CHECK_EXPECT(Start);
448 read = 0;
450 if(!filedwl_api) /* FIXME */
451 ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", debugstr_w(szUrl));
452 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
453 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
454 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
455 ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
457 if(!filedwl_api && binding_hres != S_OK) {
458 SET_EXPECT(OnStopBinding);
459 SET_EXPECT(Terminate);
460 hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
461 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
462 CHECK_CALLED(OnStopBinding);
463 CHECK_CALLED(Terminate);
465 return S_OK;
468 memset(&bindinfo, 0, sizeof(bindinfo));
469 bindinfo.cbSize = sizeof(bindinfo);
470 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
471 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
473 if(filedwl_api) {
474 ok(bindf == (BINDF_PULLDATA|BINDF_FROMURLMON|BINDF_NEEDFILE), "bindf=%08x\n", bindf);
475 }else if(tymed == TYMED_ISTREAM && is_urlmon_protocol(test_protocol)) {
476 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
477 |BINDF_FROMURLMON),
478 "bindf=%08x\n", bindf);
479 }else {
480 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
481 |BINDF_FROMURLMON|BINDF_NEEDFILE),
482 "bindf=%08x\n", bindf);
485 ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
486 ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
487 ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
488 ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
489 ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
490 ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
491 ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
492 ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
493 ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
494 ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
495 ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
496 ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
497 ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
498 ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
500 switch(test_protocol) {
501 case MK_TEST:
502 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
503 BINDSTATUS_DIRECTBIND, NULL);
504 ok(hres == S_OK,
505 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
507 case FILE_TEST:
508 case ITS_TEST:
509 if(bind_to_object)
510 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
511 else
512 SET_EXPECT(OnProgress_SENDINGREQUEST);
513 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
514 BINDSTATUS_SENDINGREQUEST, emptyW);
515 ok(hres == S_OK,
516 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
517 if(bind_to_object)
518 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
519 else
520 CHECK_CALLED(OnProgress_SENDINGREQUEST);
521 default:
522 break;
525 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
526 IServiceProvider *service_provider;
527 IHttpNegotiate *http_negotiate;
528 IHttpNegotiate2 *http_negotiate2;
529 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
530 LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
531 BYTE sec_id[100];
532 DWORD fetched = 256, size = 100;
533 DWORD tid;
535 static const WCHAR wszMimes[] = {'*','/','*',0};
537 SET_EXPECT(QueryInterface_IInternetBindInfo);
538 SET_EXPECT(QueryService_IInternetBindInfo);
539 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
540 &ua, 1, &fetched);
541 todo_wine {
542 CHECK_CALLED(QueryInterface_IInternetBindInfo);
543 CHECK_CALLED(QueryService_IInternetBindInfo);
545 ok(hres == E_NOINTERFACE,
546 "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
547 ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
548 ok(ua == (LPWSTR)0xdeadbeef, "ua = %p\n", ua);
550 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
551 accept_mimes, 256, &fetched);
552 ok(hres == S_OK,
553 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
554 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
555 ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
557 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
558 NULL, 256, &fetched);
559 ok(hres == E_INVALIDARG,
560 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
562 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
563 accept_mimes, 256, NULL);
564 ok(hres == E_INVALIDARG,
565 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
567 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
568 (void**)&service_provider);
569 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
571 SET_EXPECT(QueryInterface_IHttpNegotiate);
572 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
573 &IID_IHttpNegotiate, (void**)&http_negotiate);
574 CHECK_CALLED(QueryInterface_IHttpNegotiate);
575 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
577 SET_EXPECT(BeginningTransaction);
578 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
579 NULL, 0, &additional_headers);
580 CHECK_CALLED(BeginningTransaction);
581 IHttpNegotiate_Release(http_negotiate);
582 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
583 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
585 SET_EXPECT(QueryInterface_IHttpNegotiate2);
586 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
587 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
588 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
589 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
591 size = 512;
592 SET_EXPECT(GetRootSecurityId);
593 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
594 CHECK_CALLED(GetRootSecurityId);
595 IHttpNegotiate2_Release(http_negotiate2);
596 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
597 ok(size == 13, "size=%d\n", size);
599 IServiceProvider_Release(service_provider);
601 IInternetProtocolSink_AddRef(pOIProtSink);
602 protocol_sink = pOIProtSink;
603 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
605 return S_OK;
608 if(test_protocol == FILE_TEST) {
609 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
610 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
611 ok(hres == S_OK,
612 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
614 if(bind_to_object)
615 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
616 else
617 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
618 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
619 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
620 ok(hres == S_OK,
621 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
622 if(bind_to_object)
623 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
624 else
625 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
626 }else {
627 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
628 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
629 ok(hres == S_OK,
630 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
633 if(test_protocol == ABOUT_TEST)
634 bscf |= BSCF_DATAFULLYAVAILABLE;
635 if(test_protocol == ITS_TEST)
636 bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
638 SET_EXPECT(Read);
639 if(bind_to_object) {
640 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
641 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
642 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
643 if(test_protocol == FILE_TEST)
644 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
645 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
646 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
647 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
648 SET_EXPECT(CreateInstance);
649 SET_EXPECT(PutProperty_MIMETYPEPROP);
650 SET_EXPECT(PutProperty_CLASSIDPROP);
651 SET_EXPECT(Load);
652 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
653 SET_EXPECT(OnObjectAvailable);
654 SET_EXPECT(Obj_OnStopBinding);
655 }else {
656 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
657 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
658 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
659 if(test_protocol == FILE_TEST)
660 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
661 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
662 SET_EXPECT(LockRequest);
663 if(!filedwl_api)
664 SET_EXPECT(OnDataAvailable);
665 SET_EXPECT(OnStopBinding);
668 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
669 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
671 CHECK_CALLED(Read);
672 if(bind_to_object) {
673 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
674 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
675 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
676 if(test_protocol == FILE_TEST)
677 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
678 CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
679 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
680 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
681 CHECK_CALLED(CreateInstance);
682 CHECK_CALLED(PutProperty_MIMETYPEPROP);
683 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
684 CHECK_CALLED(Load);
685 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
686 CHECK_CALLED(OnObjectAvailable);
687 CHECK_CALLED(Obj_OnStopBinding);
688 }else {
689 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
690 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
691 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
692 if(test_protocol == FILE_TEST)
693 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
694 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
695 CHECK_CALLED(LockRequest);
696 if(!filedwl_api)
697 CHECK_CALLED(OnDataAvailable);
698 CHECK_CALLED(OnStopBinding);
701 if(test_protocol == ITS_TEST) {
702 SET_EXPECT(Read);
703 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
704 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
705 CHECK_CALLED(Read);
708 SET_EXPECT(Terminate);
709 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
710 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
711 CHECK_CALLED(Terminate);
713 return S_OK;
716 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
717 PROTOCOLDATA *pProtocolData)
719 DWORD bscf = 0;
720 HRESULT hres;
722 CHECK_EXPECT(Continue);
724 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
726 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
727 if(!pProtocolData)
728 return S_OK;
730 switch(prot_state) {
731 case 1: {
732 IServiceProvider *service_provider;
733 IHttpNegotiate *http_negotiate;
734 static WCHAR header[] = {'?',0};
736 hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
737 (void**)&service_provider);
738 ok(hres == S_OK, "Could not get IServiceProvicder\n");
740 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
741 &IID_IHttpNegotiate, (void**)&http_negotiate);
742 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
744 SET_EXPECT(OnResponse);
745 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
746 CHECK_CALLED(OnResponse);
747 IHttpNegotiate_Release(http_negotiate);
748 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
750 if(test_protocol == HTTPS_TEST) {
751 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
752 ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
755 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
756 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
757 ok(hres == S_OK,
758 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
760 if(tymed == TYMED_FILE) {
761 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
762 BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_fileW);
763 ok(hres == S_OK,
764 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
767 bscf |= BSCF_FIRSTDATANOTIFICATION;
768 break;
770 case 2:
771 case 3:
772 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
773 break;
776 hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
777 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
779 SET_EXPECT(Read);
780 switch(prot_state) {
781 case 1:
782 if(bind_to_object) {
783 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
784 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
785 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
786 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
787 SET_EXPECT(CreateInstance);
788 SET_EXPECT(PutProperty_MIMETYPEPROP);
789 SET_EXPECT(PutProperty_CLASSIDPROP);
790 SET_EXPECT(Load);
791 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
792 SET_EXPECT(OnObjectAvailable);
793 SET_EXPECT(Obj_OnStopBinding);
794 }else {
795 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
796 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
797 SET_EXPECT(LockRequest);
799 break;
800 case 2:
801 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
802 break;
803 case 3:
804 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
805 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
807 if(!bind_to_object || prot_state >= 2)
808 SET_EXPECT(OnDataAvailable);
809 if(prot_state == 3)
810 SET_EXPECT(OnStopBinding);
812 return S_OK;
815 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
816 DWORD dwOptions)
818 ok(0, "unexpected call\n");
819 return E_NOTIMPL;
822 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
824 CHECK_EXPECT(Terminate);
826 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
828 if(protocol_sink) {
829 IInternetProtocolSink_Release(protocol_sink);
830 protocol_sink = NULL;
833 return S_OK;
836 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
838 ok(0, "unexpected call\n");
839 return E_NOTIMPL;
842 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
844 ok(0, "unexpected call\n");
845 return E_NOTIMPL;
848 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
849 ULONG cb, ULONG *pcbRead)
851 static const char data[] = "<HTML></HTML>";
853 CHECK_EXPECT2(Read);
855 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
856 HRESULT hres;
858 static BOOL pending = TRUE;
860 pending = !pending;
862 switch(prot_state) {
863 case 1:
864 case 2:
865 if(pending) {
866 *pcbRead = 10;
867 memset(pv, '?', 10);
868 return E_PENDING;
869 }else {
870 memset(pv, '?', cb);
871 *pcbRead = cb;
872 read++;
873 return S_OK;
875 case 3:
876 prot_state++;
878 *pcbRead = 0;
880 hres = IInternetProtocolSink_ReportData(protocol_sink,
881 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
882 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
884 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
885 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
887 return S_FALSE;
888 case 4:
889 *pcbRead = 0;
890 return S_FALSE;
894 if(read) {
895 *pcbRead = 0;
896 return S_FALSE;
899 ok(pv != NULL, "pv == NULL\n");
900 ok(cb != 0, "cb == 0\n");
901 ok(pcbRead != NULL, "pcbRead == NULL\n");
902 if(pcbRead) {
903 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
904 read += *pcbRead = sizeof(data)-1;
906 if(pv)
907 memcpy(pv, data, sizeof(data));
909 return S_OK;
912 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
913 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
915 ok(0, "unexpected call\n");
916 return E_NOTIMPL;
919 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
921 CHECK_EXPECT(LockRequest);
922 return S_OK;
925 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
927 CHECK_EXPECT(UnlockRequest);
928 return S_OK;
931 static const IInternetProtocolVtbl ProtocolVtbl = {
932 Protocol_QueryInterface,
933 Protocol_AddRef,
934 Protocol_Release,
935 Protocol_Start,
936 Protocol_Continue,
937 Protocol_Abort,
938 Protocol_Terminate,
939 Protocol_Suspend,
940 Protocol_Resume,
941 Protocol_Read,
942 Protocol_Seek,
943 Protocol_LockRequest,
944 Protocol_UnlockRequest
947 static IInternetProtocol Protocol = { &ProtocolVtbl };
949 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
951 if(IsEqualGUID(&IID_IUnknown, riid)
952 || IsEqualGUID(&IID_IHttpNegotiate, riid)
953 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
954 *ppv = iface;
955 return S_OK;
958 ok(0, "unexpected call\n");
959 return E_NOINTERFACE;
962 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
964 return 2;
967 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
969 return 1;
972 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
973 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
975 CHECK_EXPECT(BeginningTransaction);
977 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
979 ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
980 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
981 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
982 if(pszAdditionalHeaders)
983 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
985 return S_OK;
988 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
989 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
991 CHECK_EXPECT(OnResponse);
993 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
995 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
996 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
997 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
998 /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
999 ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1000 if(pszAdditionalRequestHeaders)
1001 ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1003 return S_OK;
1006 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
1007 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1009 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
1011 CHECK_EXPECT(GetRootSecurityId);
1013 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1015 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
1016 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
1017 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
1019 if(pbSecurityId == (void*)0xdeadbeef)
1020 return E_NOTIMPL;
1022 if(pcbSecurityId) {
1023 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
1024 *pcbSecurityId = sizeof(sec_id);
1027 if(pbSecurityId)
1028 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
1030 return E_FAIL;
1033 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
1034 HttpNegotiate_QueryInterface,
1035 HttpNegotiate_AddRef,
1036 HttpNegotiate_Release,
1037 HttpNegotiate_BeginningTransaction,
1038 HttpNegotiate_OnResponse,
1039 HttpNegotiate_GetRootSecurityId
1042 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
1044 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1046 ok(0, "unexpected call\n");
1047 return E_NOINTERFACE;
1050 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1052 return 2;
1055 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1057 return 1;
1060 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1061 REFGUID guidService, REFIID riid, void **ppv)
1063 if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
1064 CHECK_EXPECT(QueryService_IAuthenticate);
1065 return E_NOTIMPL;
1068 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1069 CHECK_EXPECT2(QueryService_IInternetProtocol);
1070 return E_NOTIMPL;
1073 if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1074 CHECK_EXPECT(QueryService_IInternetBindInfo);
1075 return E_NOTIMPL;
1078 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
1079 return E_NOINTERFACE;
1082 static IServiceProviderVtbl ServiceProviderVtbl = {
1083 ServiceProvider_QueryInterface,
1084 ServiceProvider_AddRef,
1085 ServiceProvider_Release,
1086 ServiceProvider_QueryService
1089 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1091 static IBindStatusCallback objbsc;
1093 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallback *iface, REFIID riid, void **ppv)
1095 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1097 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1098 CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1099 if(emulate_protocol) {
1100 *ppv = &Protocol;
1101 return S_OK;
1102 }else {
1103 return E_NOINTERFACE;
1106 else if (IsEqualGUID(&IID_IServiceProvider, riid))
1108 CHECK_EXPECT2(QueryInterface_IServiceProvider);
1109 *ppv = &ServiceProvider;
1110 return S_OK;
1112 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
1114 CHECK_EXPECT(QueryInterface_IHttpNegotiate);
1115 *ppv = &HttpNegotiate;
1116 return S_OK;
1118 else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
1120 CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1121 *ppv = &HttpNegotiate;
1122 return S_OK;
1124 else if (IsEqualGUID(&IID_IAuthenticate, riid))
1126 CHECK_EXPECT(QueryInterface_IAuthenticate);
1127 return E_NOINTERFACE;
1129 else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
1131 CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1132 *ppv = iface;
1133 return S_OK;
1135 else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
1137 CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1138 return E_NOINTERFACE;
1140 else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
1142 /* TODO */
1143 CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1145 else
1147 ok(0, "unexpected interface %s\n", debugstr_guid(riid));
1150 return E_NOINTERFACE;
1153 static ULONG WINAPI statusclb_AddRef(IBindStatusCallback *iface)
1155 return 2;
1158 static ULONG WINAPI statusclb_Release(IBindStatusCallback *iface)
1160 return 1;
1163 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallback *iface, DWORD dwReserved,
1164 IBinding *pib)
1166 IWinInetHttpInfo *http_info;
1167 HRESULT hres;
1168 IMoniker *mon;
1170 if(iface == &objbsc)
1171 CHECK_EXPECT(Obj_OnStartBinding);
1172 else
1173 CHECK_EXPECT(OnStartBinding);
1175 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1177 ok(pib != NULL, "pib should not be NULL\n");
1178 ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1180 if(pib == (void*)0xdeadbeef)
1181 return S_OK;
1183 current_binding = pib;
1185 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1186 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1187 if(SUCCEEDED(hres))
1188 IMoniker_Release(mon);
1190 hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1191 ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1193 return S_OK;
1196 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
1198 ok(0, "unexpected call\n");
1199 return E_NOTIMPL;
1202 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
1204 ok(0, "unexpected call\n");
1205 return E_NOTIMPL;
1208 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
1209 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1211 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1213 switch(ulStatusCode) {
1214 case BINDSTATUS_FINDINGRESOURCE:
1215 if(iface == &objbsc)
1216 CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1217 else if(test_protocol == FTP_TEST)
1218 todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1219 else
1220 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1221 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1222 SetEvent(complete_event);
1223 break;
1224 case BINDSTATUS_CONNECTING:
1225 if(iface == &objbsc)
1226 CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1227 else if(test_protocol == FTP_TEST)
1228 todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
1229 else
1230 CHECK_EXPECT(OnProgress_CONNECTING);
1231 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1232 SetEvent(complete_event);
1233 break;
1234 case BINDSTATUS_SENDINGREQUEST:
1235 if(iface == &objbsc)
1236 CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1237 else if(test_protocol == FTP_TEST)
1238 CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
1239 else
1240 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1241 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1242 SetEvent(complete_event);
1243 break;
1244 case BINDSTATUS_MIMETYPEAVAILABLE:
1245 if(iface == &objbsc)
1246 CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1247 else
1248 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1249 if(!bind_to_object)
1250 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1251 download_state);
1252 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1253 break;
1254 case BINDSTATUS_BEGINDOWNLOADDATA:
1255 if(iface == &objbsc)
1256 CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1257 else
1258 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1259 ok(szStatusText != NULL, "szStatusText == NULL\n");
1260 if(szStatusText) {
1261 if(filedwl_api) {
1262 /* FIXME */
1263 }else {
1264 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1267 if(!bind_to_object)
1268 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1269 download_state);
1270 download_state = DOWNLOADING;
1271 break;
1272 case BINDSTATUS_DOWNLOADINGDATA:
1273 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1274 ok(iface != &objbsc, "unexpected call\n");
1275 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1276 download_state);
1277 break;
1278 case BINDSTATUS_ENDDOWNLOADDATA:
1279 if(iface == &objbsc)
1280 CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1281 else
1282 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1283 ok(szStatusText != NULL, "szStatusText == NULL\n");
1284 if(szStatusText) {
1285 if(filedwl_api) {
1286 /* FIXME */
1287 }else {
1288 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1291 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1292 download_state);
1293 download_state = END_DOWNLOAD;
1294 break;
1295 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1296 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST) {
1297 if(iface == &objbsc)
1298 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1299 else
1300 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1301 }else { /* FIXME */
1302 CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1303 CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1306 ok(szStatusText != NULL, "szStatusText == NULL\n");
1307 if(szStatusText && test_protocol == FILE_TEST)
1308 ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1309 break;
1310 case BINDSTATUS_CLASSIDAVAILABLE:
1312 CLSID clsid;
1313 HRESULT hr;
1314 if(iface != &objbsc)
1315 ok(0, "unexpected call\n");
1316 else if(1||emulate_protocol)
1317 CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1318 else
1319 todo_wine CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1320 hr = CLSIDFromString((LPOLESTR)szStatusText, &clsid);
1321 ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1322 ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1323 "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1324 break;
1326 case BINDSTATUS_BEGINSYNCOPERATION:
1327 CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1328 if(iface != &objbsc)
1329 ok(0, "unexpected call\n");
1330 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1331 break;
1332 case BINDSTATUS_ENDSYNCOPERATION:
1333 CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1334 if(iface != &objbsc)
1335 ok(0, "unexpected call\n");
1336 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1337 break;
1338 case BINDSTATUS_PROXYDETECTING:
1339 trace("BINDSTATUS_PROXYDETECTING\n");
1340 break;
1341 default:
1342 ok(0, "unexpected code %d\n", ulStatusCode);
1345 if(current_binding) {
1346 IWinInetHttpInfo *http_info;
1347 HRESULT hres;
1349 hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
1350 if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol))
1351 ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
1352 else
1353 ok(hres == E_NOINTERFACE,
1354 "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
1355 if(SUCCEEDED(hres))
1356 IWinInetHttpInfo_Release(http_info);
1359 return S_OK;
1362 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
1364 if(iface == &objbsc) {
1365 CHECK_EXPECT(Obj_OnStopBinding);
1366 stopped_obj_binding = TRUE;
1367 }else {
1368 CHECK_EXPECT(OnStopBinding);
1369 stopped_binding = TRUE;
1372 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1374 /* ignore DNS failure */
1375 if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1376 return S_OK;
1378 if(filedwl_api)
1379 ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1380 else
1381 ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1382 ok(szError == NULL, "szError should be NULL\n");
1384 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) && emulate_protocol) {
1385 SetEvent(complete_event);
1386 if(iface != &objbsc)
1387 WaitForSingleObject(complete_event2, INFINITE);
1390 return S_OK;
1393 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1395 DWORD cbSize;
1397 if(iface == &objbsc)
1398 CHECK_EXPECT(Obj_GetBindInfo);
1399 else
1400 CHECK_EXPECT(GetBindInfo);
1402 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1404 *grfBINDF = bindf;
1405 cbSize = pbindinfo->cbSize;
1406 memset(pbindinfo, 0, cbSize);
1407 pbindinfo->cbSize = cbSize;
1409 return S_OK;
1412 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
1413 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1415 HRESULT hres;
1416 DWORD readed;
1417 BYTE buf[512];
1418 CHAR clipfmt[512];
1420 if(iface == &objbsc)
1421 ok(0, "unexpected call\n");
1423 CHECK_EXPECT2(OnDataAvailable);
1425 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1427 ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
1428 "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
1429 download_state);
1430 data_available = TRUE;
1432 ok(pformatetc != NULL, "pformatetx == NULL\n");
1433 if(pformatetc) {
1434 if (mime_type[0]) {
1435 clipfmt[0] = 0;
1436 ok(GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1),
1437 "GetClipboardFormatName failed, error %d\n", GetLastError());
1438 ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
1439 pformatetc->cfFormat, clipfmt, mime_type);
1440 } else {
1441 ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
1443 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1444 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
1445 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
1446 ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1449 ok(pstgmed != NULL, "stgmeg == NULL\n");
1450 ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1451 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1453 switch(pstgmed->tymed) {
1454 case TYMED_ISTREAM:
1455 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
1456 hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
1457 ok(hres == STG_E_ACCESSDENIED,
1458 "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1460 hres = IStream_Commit(U(*pstgmed).pstm, 0);
1461 ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1463 hres = IStream_Revert(U(*pstgmed).pstm);
1464 ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
1467 ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
1468 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
1469 while(hres == S_OK);
1470 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
1471 break;
1473 case TYMED_FILE:
1474 if(test_protocol == FILE_TEST)
1475 ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1476 "unexpected file name %s\n", debugstr_w(pstgmed->u.lpszFileName));
1477 else if(emulate_protocol)
1478 ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1479 "unexpected file name %s\n", debugstr_w(pstgmed->u.lpszFileName));
1480 else
1481 ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1484 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1485 && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1486 SetEvent(complete_event);
1488 return S_OK;
1491 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
1493 CHECK_EXPECT(OnObjectAvailable);
1495 if(iface != &objbsc)
1496 ok(0, "unexpected call\n");
1498 ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
1499 ok(punk != NULL, "punk == NULL\n");
1501 return S_OK;
1504 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
1505 statusclb_QueryInterface,
1506 statusclb_AddRef,
1507 statusclb_Release,
1508 statusclb_OnStartBinding,
1509 statusclb_GetPriority,
1510 statusclb_OnLowResource,
1511 statusclb_OnProgress,
1512 statusclb_OnStopBinding,
1513 statusclb_GetBindInfo,
1514 statusclb_OnDataAvailable,
1515 statusclb_OnObjectAvailable
1518 static IBindStatusCallback bsc = { &BindStatusCallbackVtbl };
1519 static IBindStatusCallback objbsc = { &BindStatusCallbackVtbl };
1521 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
1523 *ppv = NULL;
1524 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1525 return E_NOINTERFACE;
1528 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
1530 return 2;
1533 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
1535 return 1;
1538 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
1540 switch(mkp) {
1541 case MIMETYPEPROP:
1542 CHECK_EXPECT(PutProperty_MIMETYPEPROP);
1543 ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", debugstr_w(val));
1544 break;
1545 case CLASSIDPROP:
1546 CHECK_EXPECT(PutProperty_CLASSIDPROP);
1547 break;
1548 default:
1549 break;
1552 return S_OK;
1555 static const IMonikerPropVtbl MonikerPropVtbl = {
1556 MonikerProp_QueryInterface,
1557 MonikerProp_AddRef,
1558 MonikerProp_Release,
1559 MonikerProp_PutProperty
1562 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
1564 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
1566 *ppv = NULL;
1568 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
1569 *ppv = iface;
1570 else if(IsEqualGUID(&IID_IMonikerProp, riid))
1571 *ppv = &MonikerProp;
1573 if(*ppv)
1574 return S_OK;
1576 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1577 return E_NOINTERFACE;
1580 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
1582 return 2;
1585 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
1587 return 1;
1590 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
1592 ok(0, "unexpected call\n");
1593 return E_NOTIMPL;
1596 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
1598 ok(0, "unexpected call\n");
1599 return E_NOTIMPL;
1602 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
1603 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
1605 IUnknown *unk;
1606 HRESULT hres;
1608 static WCHAR cbinding_contextW[] =
1609 {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
1611 CHECK_EXPECT(Load);
1612 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1614 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1615 ok(!fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1616 else
1617 ok(fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1618 ok(pimkName != NULL, "pimkName == NULL\n");
1619 ok(pibc != NULL, "pibc == NULL\n");
1620 ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
1622 hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
1623 ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
1624 if(SUCCEEDED(hres)) {
1625 IBinding *binding;
1627 hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
1628 ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
1630 IBinding_Release(binding);
1631 IUnknown_Release(unk);
1634 SET_EXPECT(QueryInterface_IServiceProvider);
1635 hres = RegisterBindStatusCallback(pibc, &bsc, NULL, 0);
1636 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
1637 CHECK_CALLED(QueryInterface_IServiceProvider);
1639 SET_EXPECT(GetBindInfo);
1640 SET_EXPECT(OnStartBinding);
1641 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1642 if(test_protocol == FILE_TEST)
1643 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1644 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1645 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1646 SET_EXPECT(LockRequest);
1647 SET_EXPECT(OnDataAvailable);
1648 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1649 SET_EXPECT(OnStopBinding);
1651 hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
1652 ok(hres == S_OK, "Load failed: %08x\n", hres);
1654 CHECK_CALLED(GetBindInfo);
1655 CHECK_CALLED(OnStartBinding);
1656 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
1657 if(test_protocol == FILE_TEST)
1658 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1659 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1660 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
1661 CHECK_CALLED(LockRequest);
1662 CHECK_CALLED(OnDataAvailable);
1663 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1664 CHECK_CALLED(OnStopBinding);
1666 if(unk)
1667 IUnknown_Release(unk);
1669 return S_OK;
1672 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
1674 ok(0, "unexpected call\n");
1675 return E_NOTIMPL;
1678 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
1680 ok(0, "unexpected call\n");
1681 return E_NOTIMPL;
1684 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
1686 ok(0, "unexpected call\n");
1687 return E_NOTIMPL;
1690 static const IPersistMonikerVtbl PersistMonikerVtbl = {
1691 PersistMoniker_QueryInterface,
1692 PersistMoniker_AddRef,
1693 PersistMoniker_Release,
1694 PersistMoniker_GetClassID,
1695 PersistMoniker_IsDirty,
1696 PersistMoniker_Load,
1697 PersistMoniker_Save,
1698 PersistMoniker_SaveCompleted,
1699 PersistMoniker_GetCurMoniker
1702 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
1704 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1706 *ppv = NULL;
1708 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1709 *ppv = iface;
1710 return S_OK;
1713 if(IsEqualGUID(&IID_IMarshal, riid))
1714 return E_NOINTERFACE;
1715 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1716 return E_NOINTERFACE;
1718 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1719 return E_NOTIMPL;
1722 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1724 return 2;
1727 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1729 return 1;
1732 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1734 CHECK_EXPECT(CreateInstance);
1735 ok(!outer, "outer = %p\n", outer);
1736 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1737 *ppv = &PersistMoniker;
1738 return S_OK;
1741 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1743 ok(0, "unexpected call\n");
1744 return S_OK;
1747 static const IClassFactoryVtbl ClassFactoryVtbl = {
1748 ClassFactory_QueryInterface,
1749 ClassFactory_AddRef,
1750 ClassFactory_Release,
1751 ClassFactory_CreateInstance,
1752 ClassFactory_LockServer
1755 static IClassFactory mime_cf = { &ClassFactoryVtbl };
1757 static void test_CreateAsyncBindCtx(void)
1759 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
1760 IUnknown *unk;
1761 HRESULT hres;
1762 ULONG ref;
1763 BIND_OPTS bindopts;
1765 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
1766 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1767 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
1769 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
1770 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1772 SET_EXPECT(QueryInterface_IServiceProvider);
1773 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
1774 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
1775 CHECK_CALLED(QueryInterface_IServiceProvider);
1777 bindopts.cbStruct = sizeof(bindopts);
1778 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1779 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1780 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1781 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1782 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1783 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1784 bindopts.grfMode);
1785 ok(bindopts.dwTickCountDeadline == 0,
1786 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1788 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1789 ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
1790 if(SUCCEEDED(hres))
1791 IUnknown_Release(unk);
1793 ref = IBindCtx_Release(bctx);
1794 ok(ref == 0, "bctx should be destroyed here\n");
1797 static void test_CreateAsyncBindCtxEx(void)
1799 IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
1800 IUnknown *unk;
1801 BIND_OPTS bindopts;
1802 HRESULT hres;
1804 static WCHAR testW[] = {'t','e','s','t',0};
1806 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
1807 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
1809 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1810 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1812 if(SUCCEEDED(hres)) {
1813 bindopts.cbStruct = sizeof(bindopts);
1814 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1815 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1816 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1817 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1818 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1819 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1820 bindopts.grfMode);
1821 ok(bindopts.dwTickCountDeadline == 0,
1822 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1824 IBindCtx_Release(bctx);
1827 CreateBindCtx(0, &bctx_arg);
1828 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1829 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1831 if(SUCCEEDED(hres)) {
1832 bindopts.cbStruct = sizeof(bindopts);
1833 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1834 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1835 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1836 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1837 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1838 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1839 bindopts.grfMode);
1840 ok(bindopts.dwTickCountDeadline == 0,
1841 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1843 IBindCtx_Release(bctx);
1846 IBindCtx_Release(bctx_arg);
1848 SET_EXPECT(QueryInterface_IServiceProvider);
1849 hres = CreateAsyncBindCtxEx(NULL, 0, &bsc, NULL, &bctx, 0);
1850 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1851 CHECK_CALLED(QueryInterface_IServiceProvider);
1853 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1854 ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
1855 if(SUCCEEDED(hres))
1856 IUnknown_Release(unk);
1858 IBindCtx_Release(bctx);
1860 hres = CreateBindCtx(0, &bctx2);
1861 ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
1863 hres = CreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
1864 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1866 hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
1867 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
1869 hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
1870 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1871 ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
1873 IBindCtx_Release(bctx);
1874 IBindCtx_Release(bctx2);
1877 static BOOL test_bscholder(IBindStatusCallback *holder)
1879 IServiceProvider *serv_prov;
1880 IHttpNegotiate *http_negotiate, *http_negotiate_serv;
1881 IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
1882 IAuthenticate *authenticate, *authenticate_serv;
1883 IInternetProtocol *protocol;
1884 BINDINFO bindinfo = {sizeof(bindinfo)};
1885 BOOL ret = TRUE;
1886 LPWSTR wstr;
1887 DWORD dw;
1888 HRESULT hres;
1890 hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
1891 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
1893 dw = 0xdeadbeef;
1894 SET_EXPECT(GetBindInfo);
1895 hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
1896 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1897 CHECK_CALLED(GetBindInfo);
1899 SET_EXPECT(OnStartBinding);
1900 hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
1901 ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
1902 CHECK_CALLED(OnStartBinding);
1904 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
1905 ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
1907 wstr = (void*)0xdeadbeef;
1908 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol], (void*)0xdeadbeef, 0xff, &wstr);
1909 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
1910 ok(wstr == NULL, "wstr = %p\n", wstr);
1912 SET_EXPECT(QueryInterface_IHttpNegotiate);
1913 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
1914 (void**)&http_negotiate_serv);
1915 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
1916 CHECK_CALLED(QueryInterface_IHttpNegotiate);
1918 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
1920 wstr = (void*)0xdeadbeef;
1921 SET_EXPECT(BeginningTransaction);
1922 hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
1923 CHECK_CALLED(BeginningTransaction);
1924 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
1925 ok(wstr == NULL, "wstr = %p\n", wstr);
1927 IHttpNegotiate_Release(http_negotiate_serv);
1929 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
1930 (void**)&http_negotiate_serv);
1931 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
1932 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
1933 IHttpNegotiate_Release(http_negotiate_serv);
1935 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1936 if(SUCCEEDED(hres)) {
1937 have_IHttpNegotiate2 = TRUE;
1938 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
1939 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x\n", hres);
1941 SET_EXPECT(QueryInterface_IHttpNegotiate2);
1942 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
1943 (void**)&http_negotiate2_serv);
1944 ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
1945 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
1946 ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
1948 SET_EXPECT(GetRootSecurityId);
1949 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
1950 ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
1951 CHECK_CALLED(GetRootSecurityId);
1953 IHttpNegotiate_Release(http_negotiate2_serv);
1954 IHttpNegotiate_Release(http_negotiate2);
1955 }else {
1956 skip("Could not get IHttpNegotiate2\n");
1957 ret = FALSE;
1960 SET_EXPECT(OnProgress_FINDINGRESOURCE);
1961 hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
1962 ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
1963 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
1965 SET_EXPECT(OnResponse);
1966 wstr = (void*)0xdeadbeef;
1967 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
1968 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1969 CHECK_CALLED(OnResponse);
1971 IHttpNegotiate_Release(http_negotiate);
1973 hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
1974 ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
1976 SET_EXPECT(QueryInterface_IAuthenticate);
1977 SET_EXPECT(QueryService_IAuthenticate);
1978 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
1979 (void**)&authenticate_serv);
1980 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
1981 CHECK_CALLED(QueryInterface_IAuthenticate);
1982 CHECK_CALLED(QueryService_IAuthenticate);
1983 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
1984 IAuthenticate_Release(authenticate_serv);
1986 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
1987 (void**)&authenticate_serv);
1988 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
1989 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
1991 IAuthenticate_Release(authenticate);
1992 IAuthenticate_Release(authenticate_serv);
1994 SET_EXPECT(OnStopBinding);
1995 hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
1996 ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
1997 CHECK_CALLED(OnStopBinding);
1999 SET_EXPECT(QueryInterface_IInternetProtocol);
2000 SET_EXPECT(QueryService_IInternetProtocol);
2001 hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
2002 (void**)&protocol);
2003 ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
2004 CHECK_CALLED(QueryInterface_IInternetProtocol);
2005 CHECK_CALLED(QueryService_IInternetProtocol);
2007 IServiceProvider_Release(serv_prov);
2008 return ret;
2011 static BOOL test_RegisterBindStatusCallback(void)
2013 IBindStatusCallback *prevbsc, *clb;
2014 IBindCtx *bindctx;
2015 BOOL ret = TRUE;
2016 IUnknown *unk;
2017 HRESULT hres;
2019 hres = CreateBindCtx(0, &bindctx);
2020 ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
2022 SET_EXPECT(QueryInterface_IServiceProvider);
2024 hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
2025 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2027 SET_EXPECT(QueryInterface_IBindStatusCallback);
2028 SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
2029 prevbsc = (void*)0xdeadbeef;
2030 hres = RegisterBindStatusCallback(bindctx, &bsc, &prevbsc, 0);
2031 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2032 ok(prevbsc == &bsc, "prevbsc=%p\n", prevbsc);
2033 CHECK_CALLED(QueryInterface_IBindStatusCallback);
2034 CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
2036 CHECK_CALLED(QueryInterface_IServiceProvider);
2038 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2039 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2041 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2042 IUnknown_Release(unk);
2043 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2044 ok(clb != &bsc, "bsc == clb\n");
2046 if(!test_bscholder(clb))
2047 ret = FALSE;
2049 IBindStatusCallback_Release(clb);
2051 hres = RevokeBindStatusCallback(bindctx, &bsc);
2052 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2054 unk = (void*)0xdeadbeef;
2055 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2056 ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
2057 ok(unk == NULL, "unk != NULL\n");
2059 if(unk)
2060 IUnknown_Release(unk);
2062 hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
2063 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2065 hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
2066 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2068 hres = RevokeBindStatusCallback(bindctx, NULL);
2069 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2071 IBindCtx_Release(bindctx);
2072 return ret;
2075 #define BINDTEST_EMULATE 1
2076 #define BINDTEST_TOOBJECT 2
2077 #define BINDTEST_FILEDWLAPI 4
2079 static void init_bind_test(int protocol, DWORD flags, DWORD t)
2081 test_protocol = protocol;
2082 emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
2083 download_state = BEFORE_DOWNLOAD;
2084 stopped_binding = FALSE;
2085 stopped_obj_binding = FALSE;
2086 data_available = FALSE;
2087 mime_type[0] = 0;
2088 binding_hres = S_OK;
2089 bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
2090 tymed = t;
2091 filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
2094 static void test_BindToStorage(int protocol, BOOL emul, DWORD t)
2096 IMoniker *mon;
2097 HRESULT hres;
2098 LPOLESTR display_name;
2099 IBindCtx *bctx;
2100 MSG msg;
2101 IBindStatusCallback *previousclb;
2102 IUnknown *unk = (IUnknown*)0x00ff00ff;
2103 IBinding *bind;
2105 init_bind_test(protocol, emul ? BINDTEST_EMULATE : 0, t);
2107 SET_EXPECT(QueryInterface_IServiceProvider);
2108 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
2109 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2110 CHECK_CALLED(QueryInterface_IServiceProvider);
2111 if(FAILED(hres))
2112 return;
2114 SET_EXPECT(QueryInterface_IServiceProvider);
2115 hres = RegisterBindStatusCallback(bctx, &bsc, &previousclb, 0);
2116 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2117 ok(previousclb == &bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2118 CHECK_CALLED(QueryInterface_IServiceProvider);
2119 if(previousclb)
2120 IBindStatusCallback_Release(previousclb);
2122 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2123 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2124 if(FAILED(hres)) {
2125 IBindCtx_Release(bctx);
2126 return;
2129 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2130 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2131 if(SUCCEEDED(hres))
2132 IBinding_Release(bind);
2134 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2135 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2136 ok(!lstrcmpW(display_name, urls[test_protocol]),
2137 "GetDisplayName got wrong name %s\n", debugstr_w(display_name));
2138 CoTaskMemFree(display_name);
2140 if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
2141 binding_hres = INET_E_DATA_NOT_AVAILABLE;
2143 SET_EXPECT(GetBindInfo);
2144 SET_EXPECT(QueryInterface_IInternetProtocol);
2145 if(!emulate_protocol)
2146 SET_EXPECT(QueryService_IInternetProtocol);
2147 SET_EXPECT(OnStartBinding);
2148 if(emulate_protocol) {
2149 if(is_urlmon_protocol(test_protocol))
2150 SET_EXPECT(SetPriority);
2151 SET_EXPECT(Start);
2152 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2153 SET_EXPECT(Terminate);
2154 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2155 SET_EXPECT(UnlockRequest);
2156 }else {
2157 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2158 SET_EXPECT(QueryInterface_IInternetBindInfo);
2159 SET_EXPECT(QueryService_IInternetBindInfo);
2160 SET_EXPECT(QueryInterface_IHttpNegotiate);
2161 SET_EXPECT(BeginningTransaction);
2162 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2163 SET_EXPECT(GetRootSecurityId);
2164 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2165 SET_EXPECT(OnProgress_CONNECTING);
2167 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST
2168 || test_protocol == FILE_TEST)
2169 SET_EXPECT(OnProgress_SENDINGREQUEST);
2170 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2171 SET_EXPECT(OnResponse);
2172 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2173 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2174 if(test_protocol == FILE_TEST)
2175 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2176 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2177 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2178 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2179 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2180 SET_EXPECT(OnDataAvailable);
2181 SET_EXPECT(OnStopBinding);
2184 hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2185 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2186 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2188 skip("Network unreachable, skipping tests\n");
2189 return;
2192 if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
2193 || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2194 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2195 ok(unk == NULL, "istr should be NULL\n");
2196 }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
2197 ok(hres == INET_E_DATA_NOT_AVAILABLE,
2198 "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
2199 ok(unk == NULL, "istr should be NULL\n");
2200 }else {
2201 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2202 ok(unk != NULL, "unk == NULL\n");
2204 if(unk)
2205 IUnknown_Release(unk);
2207 if(FAILED(hres))
2208 return;
2210 while((bindf & BINDF_ASYNCHRONOUS) &&
2211 !stopped_binding && GetMessage(&msg,NULL,0,0)) {
2212 TranslateMessage(&msg);
2213 DispatchMessage(&msg);
2216 CHECK_CALLED(GetBindInfo);
2217 CHECK_CALLED(QueryInterface_IInternetProtocol);
2218 if(!emulate_protocol)
2219 CHECK_CALLED(QueryService_IInternetProtocol);
2220 CHECK_CALLED(OnStartBinding);
2221 if(emulate_protocol) {
2222 if(is_urlmon_protocol(test_protocol))
2223 CHECK_CALLED(SetPriority);
2224 CHECK_CALLED(Start);
2225 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2226 if(tymed == TYMED_FILE)
2227 CLEAR_CALLED(Read);
2228 CHECK_CALLED(Terminate);
2230 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2231 CHECK_CALLED(UnlockRequest);
2232 }else {
2233 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2234 CLEAR_CALLED(QueryInterface_IInternetBindInfo);
2235 CLEAR_CALLED(QueryService_IInternetBindInfo);
2236 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2237 CHECK_CALLED(BeginningTransaction);
2238 if (have_IHttpNegotiate2)
2240 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2241 CHECK_CALLED(GetRootSecurityId);
2243 if(http_is_first || test_protocol == HTTPS_TEST) {
2244 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2245 CHECK_CALLED(OnProgress_CONNECTING);
2246 }else todo_wine {
2247 CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
2248 /* IE7 does call this */
2249 CLEAR_CALLED(OnProgress_CONNECTING);
2252 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2253 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2254 else if(test_protocol == FTP_TEST)
2255 todo_wine CHECK_CALLED(OnProgress_SENDINGREQUEST);
2256 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2257 CHECK_CALLED(OnResponse);
2258 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2259 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2260 if(test_protocol == FILE_TEST)
2261 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2262 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2263 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2264 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2265 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2266 CHECK_CALLED(OnDataAvailable);
2267 CHECK_CALLED(OnStopBinding);
2270 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2271 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2273 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2274 http_is_first = FALSE;
2277 static void test_BindToObject(int protocol, BOOL emul)
2279 IMoniker *mon;
2280 HRESULT hres;
2281 LPOLESTR display_name;
2282 IBindCtx *bctx;
2283 DWORD regid;
2284 MSG msg;
2285 IUnknown *unk = (IUnknown*)0x00ff00ff;
2286 IBinding *bind;
2288 init_bind_test(protocol, BINDTEST_TOOBJECT | (emul ? BINDTEST_EMULATE : 0), TYMED_ISTREAM);
2290 if(emul)
2291 CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
2292 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2294 SET_EXPECT(QueryInterface_IServiceProvider);
2295 hres = CreateAsyncBindCtx(0, &objbsc, NULL, &bctx);
2296 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
2297 CHECK_CALLED(QueryInterface_IServiceProvider);
2298 if(FAILED(hres))
2299 return;
2301 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2302 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2303 if(FAILED(hres)) {
2304 IBindCtx_Release(bctx);
2305 return;
2308 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2309 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2310 if(SUCCEEDED(hres))
2311 IBinding_Release(bind);
2313 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2314 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2315 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
2317 SET_EXPECT(Obj_GetBindInfo);
2318 SET_EXPECT(QueryInterface_IInternetProtocol);
2319 if(!emulate_protocol)
2320 SET_EXPECT(QueryService_IInternetProtocol);
2321 SET_EXPECT(Obj_OnStartBinding);
2322 if(emulate_protocol) {
2323 if(is_urlmon_protocol(test_protocol))
2324 SET_EXPECT(SetPriority);
2325 SET_EXPECT(Start);
2326 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2327 SET_EXPECT(Terminate);
2328 if(test_protocol == FILE_TEST)
2329 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2330 SET_EXPECT(UnlockRequest);
2331 }else {
2332 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2333 SET_EXPECT(QueryInterface_IHttpNegotiate);
2334 SET_EXPECT(BeginningTransaction);
2335 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2336 SET_EXPECT(GetRootSecurityId);
2337 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
2338 SET_EXPECT(Obj_OnProgress_CONNECTING);
2340 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2341 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
2342 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2343 SET_EXPECT(OnResponse);
2344 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
2345 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
2346 if(test_protocol == FILE_TEST)
2347 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2348 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2349 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2350 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
2351 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
2352 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
2353 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
2354 SET_EXPECT(OnObjectAvailable);
2355 SET_EXPECT(Obj_OnStopBinding);
2358 hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
2360 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2361 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2363 skip( "Network unreachable, skipping tests\n" );
2364 return;
2367 /* no point testing the calls if binding didn't even work */
2368 if (FAILED(hres)) return;
2370 if(bindf & BINDF_ASYNCHRONOUS) {
2371 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
2372 ok(unk == NULL, "istr should be NULL\n");
2373 }else {
2374 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2375 ok(unk != NULL, "unk == NULL\n");
2376 if(emul)
2377 ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
2379 if(unk)
2380 IUnknown_Release(unk);
2382 while((bindf & BINDF_ASYNCHRONOUS) &&
2383 !((!emul || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
2384 TranslateMessage(&msg);
2385 DispatchMessage(&msg);
2388 CHECK_CALLED(Obj_GetBindInfo);
2389 CHECK_CALLED(QueryInterface_IInternetProtocol);
2390 if(!emulate_protocol)
2391 CHECK_CALLED(QueryService_IInternetProtocol);
2392 CHECK_CALLED(Obj_OnStartBinding);
2393 if(emulate_protocol) {
2394 if(is_urlmon_protocol(test_protocol))
2395 CHECK_CALLED(SetPriority);
2396 CHECK_CALLED(Start);
2397 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2398 CHECK_CALLED(Terminate);
2399 if(test_protocol == FILE_TEST)
2400 CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
2401 CHECK_CALLED(UnlockRequest);
2402 }else {
2403 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2404 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2405 CHECK_CALLED(BeginningTransaction);
2406 if (have_IHttpNegotiate2)
2408 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2409 CHECK_CALLED(GetRootSecurityId);
2411 if(http_is_first) {
2412 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2413 CHECK_CALLED(Obj_OnProgress_CONNECTING);
2414 }else todo_wine {
2415 CHECK_NOT_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2416 /* IE7 does call this */
2417 CLEAR_CALLED(Obj_OnProgress_CONNECTING);
2420 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
2421 if(urls[test_protocol] == SHORT_RESPONSE_URL)
2422 CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
2423 else
2424 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
2426 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2427 CHECK_CALLED(OnResponse);
2428 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
2429 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
2430 if(test_protocol == FILE_TEST)
2431 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2432 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2433 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2434 CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
2435 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
2436 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
2437 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
2438 CHECK_CALLED(OnObjectAvailable);
2439 CHECK_CALLED(Obj_OnStopBinding);
2442 if(test_protocol != HTTP_TEST || test_protocol == HTTPS_TEST || emul || urls[test_protocol] == SHORT_RESPONSE_URL) {
2443 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2444 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2445 }else {
2446 todo_wine ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2448 if(bindf & BINDF_ASYNCHRONOUS)
2449 IBindCtx_Release(bctx);
2450 else
2451 todo_wine ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2454 if(emul)
2455 CoRevokeClassObject(regid);
2457 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2458 http_is_first = FALSE;
2461 static void test_URLDownloadToFile(DWORD prot, BOOL emul)
2463 BOOL res;
2464 HRESULT hres;
2466 init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);
2468 SET_EXPECT(GetBindInfo);
2469 SET_EXPECT(QueryInterface_IInternetProtocol);
2470 if(!emulate_protocol) {
2471 SET_EXPECT(QueryInterface_IServiceProvider);
2472 SET_EXPECT(QueryService_IInternetProtocol);
2474 SET_EXPECT(OnStartBinding);
2475 if(emulate_protocol) {
2476 if(is_urlmon_protocol(test_protocol))
2477 SET_EXPECT(SetPriority);
2478 SET_EXPECT(Start);
2479 SET_EXPECT(UnlockRequest);
2480 }else {
2481 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2482 SET_EXPECT(QueryInterface_IHttpNegotiate);
2483 SET_EXPECT(BeginningTransaction);
2484 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2485 SET_EXPECT(GetRootSecurityId);
2487 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2488 SET_EXPECT(OnProgress_SENDINGREQUEST);
2489 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2490 SET_EXPECT(OnResponse);
2491 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2492 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2493 if(test_protocol == FILE_TEST)
2494 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2495 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2496 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2497 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2498 SET_EXPECT(OnStopBinding);
2501 hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], dwl_htmlW, 0, &bsc);
2502 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2504 CHECK_CALLED(GetBindInfo);
2505 CHECK_CALLED(QueryInterface_IInternetProtocol);
2506 if(!emulate_protocol) {
2507 CHECK_CALLED(QueryInterface_IServiceProvider);
2508 CHECK_CALLED(QueryService_IInternetProtocol);
2510 CHECK_CALLED(OnStartBinding);
2511 if(emulate_protocol) {
2512 if(is_urlmon_protocol(test_protocol))
2513 CHECK_CALLED(SetPriority);
2514 CHECK_CALLED(Start);
2515 CHECK_CALLED(UnlockRequest);
2516 }else {
2517 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2518 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2519 CHECK_CALLED(BeginningTransaction);
2520 if (have_IHttpNegotiate2)
2522 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2523 CHECK_CALLED(GetRootSecurityId);
2526 if(test_protocol == FILE_TEST)
2527 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2528 else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2529 CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
2530 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2531 CHECK_CALLED(OnResponse);
2532 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2533 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2534 if(test_protocol == FILE_TEST)
2535 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2536 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2537 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2538 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2539 CHECK_CALLED(OnStopBinding);
2542 res = DeleteFileA(dwl_htmlA);
2543 ok(res, "DeleteFile failed: %u\n", GetLastError());
2545 if(prot != FILE_TEST || emul)
2546 return;
2548 hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
2549 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2551 res = DeleteFileA(dwl_htmlA);
2552 ok(res, "DeleteFile failed: %u\n", GetLastError());
2555 static void set_file_url(char *path)
2557 CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
2558 CHAR INDEX_HTMLA[MAX_PATH];
2560 lstrcpyA(file_urlA, "file:///");
2561 lstrcatA(file_urlA, path);
2562 MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
2564 lstrcpyA(INDEX_HTMLA, "file://");
2565 lstrcatA(INDEX_HTMLA, path);
2566 MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
2569 static void create_file(void)
2571 HANDLE file;
2572 DWORD size;
2573 CHAR path[MAX_PATH];
2575 static const char html_doc[] = "<HTML></HTML>";
2577 file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2578 FILE_ATTRIBUTE_NORMAL, NULL);
2579 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2580 if(file == INVALID_HANDLE_VALUE)
2581 return;
2583 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2584 CloseHandle(file);
2586 GetCurrentDirectoryA(MAX_PATH, path);
2587 lstrcatA(path, "\\");
2588 lstrcatA(path, wszIndexHtmlA);
2589 set_file_url(path);
2592 static void test_ReportResult(HRESULT exhres)
2594 IMoniker *mon = NULL;
2595 IBindCtx *bctx = NULL;
2596 IUnknown *unk = (void*)0xdeadbeef;
2597 HRESULT hres;
2599 init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2600 binding_hres = exhres;
2602 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2603 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2605 SET_EXPECT(QueryInterface_IServiceProvider);
2606 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
2607 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2608 CHECK_CALLED(QueryInterface_IServiceProvider);
2610 SET_EXPECT(GetBindInfo);
2611 SET_EXPECT(QueryInterface_IInternetProtocol);
2612 SET_EXPECT(OnStartBinding);
2613 if(is_urlmon_protocol(test_protocol))
2614 SET_EXPECT(SetPriority);
2615 SET_EXPECT(Start);
2617 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2618 if(SUCCEEDED(exhres))
2619 ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
2620 else
2621 ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
2622 "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
2624 CHECK_CALLED(GetBindInfo);
2625 CHECK_CALLED(QueryInterface_IInternetProtocol);
2626 CHECK_CALLED(OnStartBinding);
2627 if(is_urlmon_protocol(test_protocol))
2628 CHECK_CALLED(SetPriority);
2629 CHECK_CALLED(Start);
2631 ok(unk == NULL, "unk=%p\n", unk);
2633 IBindCtx_Release(bctx);
2634 IMoniker_Release(mon);
2637 static void test_BindToStorage_fail(void)
2639 IMoniker *mon = NULL;
2640 IBindCtx *bctx = NULL;
2641 IUnknown *unk;
2642 HRESULT hres;
2644 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2645 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2646 if(FAILED(hres))
2647 return;
2649 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2650 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2652 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2653 ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
2654 "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
2656 IBindCtx_Release(bctx);
2658 IMoniker_Release(mon);
2660 test_ReportResult(E_NOTIMPL);
2661 test_ReportResult(S_FALSE);
2664 static void test_StdURLMoniker(void)
2666 IMoniker *mon, *async_mon;
2667 LPOLESTR display_name;
2668 HRESULT hres;
2670 hres = CoCreateInstance(&IID_IInternet, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2671 &IID_IMoniker, (void**)&mon);
2672 ok(hres == S_OK, "Could not create IInternet instance: %08x\n", hres);
2673 if(FAILED(hres))
2674 return;
2676 hres = IMoniker_QueryInterface(mon, &IID_IAsyncMoniker, (void**)&async_mon);
2677 ok(hres == S_OK, "Could not get IAsyncMoniker iface: %08x\n", hres);
2678 ok(mon == async_mon, "mon != async_mon\n");
2679 IMoniker_Release(async_mon);
2681 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &display_name);
2682 ok(hres == E_OUTOFMEMORY, "GetDisplayName failed: %08x, expected E_OUTOFMEMORY\n", hres);
2684 IMoniker_Release(mon);
2687 static void gecko_installer_workaround(BOOL disable)
2689 HKEY hkey;
2690 DWORD res;
2692 static BOOL has_url = FALSE;
2693 static char url[2048];
2695 if(!disable && !has_url)
2696 return;
2698 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2699 if(res != ERROR_SUCCESS)
2700 return;
2702 if(disable) {
2703 DWORD type, size = sizeof(url);
2705 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2706 if(res == ERROR_SUCCESS && type == REG_SZ)
2707 has_url = TRUE;
2709 RegDeleteValue(hkey, "GeckoUrl");
2710 }else {
2711 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2714 RegCloseKey(hkey);
2717 START_TEST(url)
2719 gecko_installer_workaround(TRUE);
2721 complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2722 complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2723 thread_id = GetCurrentThreadId();
2724 create_file();
2726 test_create();
2727 test_CreateAsyncBindCtx();
2728 test_CreateAsyncBindCtxEx();
2730 if(test_RegisterBindStatusCallback()) {
2731 test_BindToStorage_fail();
2733 trace("synchronous http test (COM not initialised)...\n");
2734 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2736 CoInitialize(NULL);
2738 trace("test StdURLMoniker...\n");
2739 test_StdURLMoniker();
2741 trace("synchronous http test...\n");
2742 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2744 trace("synchronous http test (to object)...\n");
2745 test_BindToObject(HTTP_TEST, FALSE);
2747 trace("synchronous file test...\n");
2748 test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2750 trace("synchronous file test (to object)...\n");
2751 test_BindToObject(FILE_TEST, FALSE);
2753 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2755 trace("http test...\n");
2756 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2758 trace("http test (to file)...\n");
2759 test_BindToStorage(HTTP_TEST, FALSE, TYMED_FILE);
2761 trace("http test (to object)...\n");
2762 test_BindToObject(HTTP_TEST, FALSE);
2764 trace("http test (short response)...\n");
2765 http_is_first = TRUE;
2766 urls[HTTP_TEST] = SHORT_RESPONSE_URL;
2767 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2769 trace("http test (short response, to object)...\n");
2770 test_BindToObject(HTTP_TEST, FALSE);
2772 trace("emulated http test...\n");
2773 test_BindToStorage(HTTP_TEST, TRUE, TYMED_ISTREAM);
2775 trace("emulated http test (to object)...\n");
2776 test_BindToObject(HTTP_TEST, TRUE);
2778 trace("emulated http test (to file)...\n");
2779 test_BindToStorage(HTTP_TEST, TRUE, TYMED_FILE);
2781 trace("asynchronous https test...\n");
2782 test_BindToStorage(HTTPS_TEST, FALSE, TYMED_ISTREAM);
2784 trace("emulated https test...\n");
2785 test_BindToStorage(HTTPS_TEST, TRUE, TYMED_ISTREAM);
2787 trace("about test...\n");
2788 test_BindToStorage(ABOUT_TEST, FALSE, TYMED_ISTREAM);
2790 trace("about test (to file)...\n");
2791 test_BindToStorage(ABOUT_TEST, FALSE, TYMED_FILE);
2793 trace("about test (to object)...\n");
2794 test_BindToObject(ABOUT_TEST, FALSE);
2796 trace("emulated about test...\n");
2797 test_BindToStorage(ABOUT_TEST, TRUE, TYMED_ISTREAM);
2799 trace("emulated about test (to file)...\n");
2800 test_BindToStorage(ABOUT_TEST, TRUE, TYMED_FILE);
2802 trace("emulated about test (to object)...\n");
2803 test_BindToObject(ABOUT_TEST, TRUE);
2805 trace("file test...\n");
2806 test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2808 trace("file test (to file)...\n");
2809 test_BindToStorage(FILE_TEST, FALSE, TYMED_FILE);
2811 trace("file test (to object)...\n");
2812 test_BindToObject(FILE_TEST, FALSE);
2814 trace("emulated file test...\n");
2815 test_BindToStorage(FILE_TEST, TRUE, TYMED_ISTREAM);
2817 trace("emulated file test (to file)...\n");
2818 test_BindToStorage(FILE_TEST, TRUE, TYMED_FILE);
2820 trace("emulated file test (to object)...\n");
2821 test_BindToObject(FILE_TEST, TRUE);
2823 trace("emulated its test...\n");
2824 test_BindToStorage(ITS_TEST, TRUE, TYMED_ISTREAM);
2826 trace("emulated its test (to file)...\n");
2827 test_BindToStorage(ITS_TEST, TRUE, TYMED_FILE);
2829 trace("emulated mk test...\n");
2830 test_BindToStorage(MK_TEST, TRUE, TYMED_ISTREAM);
2832 trace("test URLDownloadToFile for file protocol...\n");
2833 test_URLDownloadToFile(FILE_TEST, FALSE);
2835 trace("test URLDownloadToFile for emulated file protocol...\n");
2836 test_URLDownloadToFile(FILE_TEST, TRUE);
2838 trace("test URLDownloadToFile for http protocol...\n");
2839 test_URLDownloadToFile(HTTP_TEST, FALSE);
2841 bindf |= BINDF_NOWRITECACHE;
2843 trace("ftp test...\n");
2844 test_BindToStorage(FTP_TEST, FALSE, TYMED_ISTREAM);
2846 trace("test failures...\n");
2847 test_BindToStorage_fail();
2850 DeleteFileA(wszIndexHtmlA);
2851 CloseHandle(complete_event);
2852 CloseHandle(complete_event2);
2853 CoUninitialize();
2855 gecko_installer_workaround(FALSE);