Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / urlmon / tests / url.c
blobd5b9d125e9edb20b0d1d0f862de8b5b12651b804
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_IBindStatusCallbackEx);
85 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackHolder);
86 DEFINE_EXPECT(QueryInterface_IInternetBindInfo);
87 DEFINE_EXPECT(QueryInterface_IAuthenticate);
88 DEFINE_EXPECT(QueryInterface_IInternetProtocol);
89 DEFINE_EXPECT(QueryInterface_IWindowForBindingUI);
90 DEFINE_EXPECT(QueryService_IAuthenticate);
91 DEFINE_EXPECT(QueryService_IInternetProtocol);
92 DEFINE_EXPECT(QueryService_IInternetBindInfo);
93 DEFINE_EXPECT(QueryService_IWindowForBindingUI);
94 DEFINE_EXPECT(BeginningTransaction);
95 DEFINE_EXPECT(OnResponse);
96 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
97 DEFINE_EXPECT(GetRootSecurityId);
98 DEFINE_EXPECT(GetBindInfo);
99 DEFINE_EXPECT(GetBindInfoEx);
100 DEFINE_EXPECT(OnStartBinding);
101 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
102 DEFINE_EXPECT(OnProgress_CONNECTING);
103 DEFINE_EXPECT(OnProgress_REDIRECTING);
104 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
105 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
106 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
107 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
108 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
109 DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
110 DEFINE_EXPECT(OnStopBinding);
111 DEFINE_EXPECT(OnDataAvailable);
112 DEFINE_EXPECT(OnObjectAvailable);
113 DEFINE_EXPECT(Obj_OnStartBinding);
114 DEFINE_EXPECT(Obj_OnStopBinding);
115 DEFINE_EXPECT(Obj_GetBindInfo);
116 DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
117 DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
118 DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
119 DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
120 DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
121 DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
122 DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
123 DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
124 DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
125 DEFINE_EXPECT(Obj_OnProgress_REDIRECTING);
126 DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
127 DEFINE_EXPECT(Start);
128 DEFINE_EXPECT(Read);
129 DEFINE_EXPECT(LockRequest);
130 DEFINE_EXPECT(Terminate);
131 DEFINE_EXPECT(UnlockRequest);
132 DEFINE_EXPECT(Continue);
133 DEFINE_EXPECT(CreateInstance);
134 DEFINE_EXPECT(Load);
135 DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
136 DEFINE_EXPECT(PutProperty_CLASSIDPROP);
137 DEFINE_EXPECT(SetPriority);
139 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
140 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
142 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
143 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
144 static const WCHAR SHORT_RESPONSE_URL[] =
145 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
146 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
147 'p','o','s','t','t','e','s','t','.','p','h','p',0};
148 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
149 static WCHAR INDEX_HTML[MAX_PATH];
150 static const WCHAR ITS_URL[] =
151 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
152 static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
153 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
154 static const WCHAR https_urlW[] =
155 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',
156 '/','t','e','s','t','.','h','t','m','l',0};
157 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
158 '/','p','u','b','/','o','t','h','e','r','/',
159 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
162 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
164 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
166 static const WCHAR wszWineHQSite[] =
167 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
168 static const WCHAR wszWineHQIP[] =
169 {'2','0','9','.','3','2','.','1','4','1','.','3',0};
170 static const CHAR wszIndexHtmlA[] = "index.html";
171 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
172 static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
173 static const CHAR dwl_htmlA[] = "dwl.html";
174 static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
175 static const WCHAR emptyW[] = {0};
177 static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
178 data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api;
179 static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed;
180 static CHAR mime_type[512];
181 static IInternetProtocolSink *protocol_sink = NULL;
182 static IBinding *current_binding;
183 static HANDLE complete_event, complete_event2;
184 static HRESULT binding_hres;
185 static BOOL have_IHttpNegotiate2, use_bscex;
186 static BOOL test_redirect;
188 static LPCWSTR urls[] = {
189 WINE_ABOUT_URL,
190 ABOUT_BLANK,
191 INDEX_HTML,
192 ITS_URL,
193 MK_URL,
194 https_urlW,
195 ftp_urlW
198 static WCHAR file_url[INTERNET_MAX_URL_LENGTH];
200 static enum {
201 HTTP_TEST,
202 ABOUT_TEST,
203 FILE_TEST,
204 ITS_TEST,
205 MK_TEST,
206 HTTPS_TEST,
207 FTP_TEST
208 } test_protocol;
210 static enum {
211 BEFORE_DOWNLOAD,
212 DOWNLOADING,
213 END_DOWNLOAD
214 } download_state;
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 void test_switch_fail(void)
329 IInternetProtocolSink *binding_sink;
330 PROTOCOLDATA protocoldata;
331 HRESULT hres;
333 static BOOL tested_switch_fail;
335 if(tested_switch_fail)
336 return;
338 tested_switch_fail = TRUE;
340 hres = IBinding_QueryInterface(current_binding, &IID_IInternetProtocolSink, (void**)&binding_sink);
341 ok(hres == S_OK, "Could not get IInternetProtocolSink iface: %08x\n", hres);
342 if(SUCCEEDED(hres)) {
343 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
344 ok(hres == E_FAIL, "Switch failed: %08x, expected E_FAIL\n", hres);
345 IInternetProtocolSink_Release(binding_sink);
349 static DWORD WINAPI thread_proc(PVOID arg)
351 PROTOCOLDATA protocoldata;
352 HRESULT hres;
354 if(bind_to_object)
355 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
356 else
357 SET_EXPECT(OnProgress_FINDINGRESOURCE);
358 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
359 BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
360 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
361 WaitForSingleObject(complete_event, INFINITE);
362 if(bind_to_object)
363 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
364 else
365 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
367 if(bind_to_object)
368 SET_EXPECT(Obj_OnProgress_CONNECTING);
369 else
370 SET_EXPECT(OnProgress_CONNECTING);
371 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
372 BINDSTATUS_CONNECTING, wszWineHQIP);
373 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
374 WaitForSingleObject(complete_event, INFINITE);
375 if(bind_to_object)
376 CHECK_CALLED(Obj_OnProgress_CONNECTING);
377 else
378 CHECK_CALLED(OnProgress_CONNECTING);
380 if(bind_to_object)
381 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
382 else
383 SET_EXPECT(OnProgress_SENDINGREQUEST);
384 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
385 BINDSTATUS_SENDINGREQUEST, NULL);
386 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
387 WaitForSingleObject(complete_event, INFINITE);
388 if(bind_to_object)
389 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
390 else
391 CHECK_CALLED(OnProgress_SENDINGREQUEST);
393 if(test_redirect) {
394 if(bind_to_object)
395 SET_EXPECT(Obj_OnProgress_REDIRECTING);
396 else
397 SET_EXPECT(OnProgress_REDIRECTING);
398 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_REDIRECTING, WINE_ABOUT_URL);
399 ok(hres == S_OK, "ReportProgress(BINDSTATUS_REFIRECTING) failed: %08x\n", hres);
400 WaitForSingleObject(complete_event, INFINITE);
401 if(bind_to_object)
402 CHECK_CALLED(Obj_OnProgress_REDIRECTING);
403 else
404 CHECK_CALLED(OnProgress_REDIRECTING);
407 test_switch_fail();
409 SET_EXPECT(Continue);
410 prot_state = 1;
411 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
412 ok(hres == S_OK, "Switch failed: %08x\n", hres);
413 WaitForSingleObject(complete_event, INFINITE);
415 CHECK_CALLED(Continue);
416 CHECK_CALLED(Read);
417 if(bind_to_object) {
418 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
419 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
420 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
421 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
422 CHECK_CALLED(CreateInstance);
423 CHECK_CALLED(PutProperty_MIMETYPEPROP);
424 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
425 CHECK_CALLED(Load);
426 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
427 CHECK_CALLED(OnObjectAvailable);
428 CHECK_CALLED(Obj_OnStopBinding);
429 }else {
430 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
431 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
432 CHECK_CALLED(LockRequest);
433 CHECK_CALLED(OnDataAvailable);
436 SET_EXPECT(Continue);
437 prot_state = 2;
438 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
439 ok(hres == S_OK, "Switch failed: %08x\n", hres);
440 WaitForSingleObject(complete_event, INFINITE);
441 CHECK_CALLED(Continue);
442 CHECK_CALLED(Read);
443 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
444 CHECK_CALLED(OnDataAvailable);
446 SET_EXPECT(Continue);
447 prot_state = 2;
448 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
449 ok(hres == S_OK, "Switch failed: %08x\n", hres);
450 WaitForSingleObject(complete_event, INFINITE);
451 CHECK_CALLED(Continue);
452 CHECK_CALLED(Read);
453 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
454 CHECK_CALLED(OnDataAvailable);
456 SET_EXPECT(Continue);
457 prot_state = 3;
458 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
459 ok(hres == S_OK, "Switch failed: %08x\n", hres);
460 WaitForSingleObject(complete_event, INFINITE);
461 CHECK_CALLED(Continue);
462 CHECK_CALLED(Read);
463 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
464 CHECK_CALLED(OnDataAvailable);
465 CHECK_CALLED(OnStopBinding);
467 SET_EXPECT(Read);
469 SetEvent(complete_event2);
470 return 0;
473 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
474 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
475 DWORD grfPI, HANDLE_PTR dwReserved)
477 BINDINFO bindinfo;
478 DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
479 HRESULT hres;
481 static const STGMEDIUM stgmed_zero = {0};
482 static const SECURITY_ATTRIBUTES sa_zero = {0};
484 CHECK_EXPECT(Start);
486 read = 0;
488 if(!filedwl_api) /* FIXME */
489 ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", wine_dbgstr_w(szUrl));
490 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
491 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
492 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
493 ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
495 if(!filedwl_api && binding_hres != S_OK) {
496 SET_EXPECT(OnStopBinding);
497 SET_EXPECT(Terminate);
498 hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
499 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
500 CHECK_CALLED(OnStopBinding);
501 CHECK_CALLED(Terminate);
503 return S_OK;
506 memset(&bindinfo, 0, sizeof(bindinfo));
507 bindinfo.cbSize = sizeof(bindinfo);
508 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
509 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
511 if(filedwl_api) {
512 ok(bindf == (BINDF_PULLDATA|BINDF_FROMURLMON|BINDF_NEEDFILE), "bindf=%08x\n", bindf);
513 }else if(tymed == TYMED_ISTREAM && is_urlmon_protocol(test_protocol)) {
514 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
515 |BINDF_FROMURLMON),
516 "bindf=%08x\n", bindf);
517 }else {
518 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
519 |BINDF_FROMURLMON|BINDF_NEEDFILE),
520 "bindf=%08x\n", bindf);
523 ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
524 ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
525 ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
526 ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
527 ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
528 ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
529 ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
530 ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
531 ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
532 ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
533 ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
534 ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
535 ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
536 ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
538 switch(test_protocol) {
539 case MK_TEST:
540 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
541 BINDSTATUS_DIRECTBIND, NULL);
542 ok(hres == S_OK,
543 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
545 case FILE_TEST:
546 case ITS_TEST:
547 if(bind_to_object)
548 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
549 else
550 SET_EXPECT(OnProgress_SENDINGREQUEST);
551 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
552 BINDSTATUS_SENDINGREQUEST, emptyW);
553 ok(hres == S_OK,
554 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
555 if(bind_to_object)
556 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
557 else
558 CHECK_CALLED(OnProgress_SENDINGREQUEST);
559 default:
560 break;
563 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
564 IServiceProvider *service_provider;
565 IHttpNegotiate *http_negotiate;
566 IHttpNegotiate2 *http_negotiate2;
567 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
568 LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
569 BYTE sec_id[100];
570 DWORD fetched = 256, size = 100;
571 DWORD tid;
573 static const WCHAR wszMimes[] = {'*','/','*',0};
575 SET_EXPECT(QueryInterface_IInternetBindInfo);
576 SET_EXPECT(QueryService_IInternetBindInfo);
577 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
578 &ua, 1, &fetched);
579 CLEAR_CALLED(QueryInterface_IInternetBindInfo); /* IE <8 */
580 CLEAR_CALLED(QueryService_IInternetBindInfo); /* IE <8 */
582 ok(hres == E_NOINTERFACE,
583 "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
584 ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
585 ok(ua == (LPWSTR)0xdeadbeef, "ua = %p\n", ua);
587 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
588 accept_mimes, 256, &fetched);
589 ok(hres == S_OK,
590 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
591 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
592 ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
594 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
595 NULL, 256, &fetched);
596 ok(hres == E_INVALIDARG,
597 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
599 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
600 accept_mimes, 256, NULL);
601 ok(hres == E_INVALIDARG,
602 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
604 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
605 (void**)&service_provider);
606 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
608 SET_EXPECT(QueryInterface_IHttpNegotiate);
609 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
610 &IID_IHttpNegotiate, (void**)&http_negotiate);
611 CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
612 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
614 SET_EXPECT(BeginningTransaction);
615 SET_EXPECT(QueryInterface_IHttpNegotiate);
616 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
617 NULL, 0, &additional_headers);
618 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
619 CHECK_CALLED(BeginningTransaction);
620 IHttpNegotiate_Release(http_negotiate);
621 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
622 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
624 SET_EXPECT(QueryInterface_IHttpNegotiate2);
625 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
626 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
627 CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
628 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
630 size = 512;
631 SET_EXPECT(QueryInterface_IHttpNegotiate2);
632 SET_EXPECT(GetRootSecurityId);
633 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
634 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2);
635 CHECK_CALLED(GetRootSecurityId);
636 IHttpNegotiate2_Release(http_negotiate2);
637 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
638 ok(size == 13, "size=%d\n", size);
640 IServiceProvider_Release(service_provider);
642 IInternetProtocolSink_AddRef(pOIProtSink);
643 protocol_sink = pOIProtSink;
644 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
646 return S_OK;
649 if(test_protocol == FILE_TEST) {
650 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
651 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
652 ok(hres == S_OK,
653 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
655 if(bind_to_object)
656 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
657 else
658 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
659 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
660 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
661 ok(hres == S_OK,
662 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
663 if(bind_to_object)
664 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
665 else
666 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
667 }else {
668 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
669 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
670 ok(hres == S_OK,
671 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
674 if(test_protocol == ABOUT_TEST)
675 bscf |= BSCF_DATAFULLYAVAILABLE;
676 if(test_protocol == ITS_TEST)
677 bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
679 SET_EXPECT(Read);
680 if(bind_to_object) {
681 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
682 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
683 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
684 if(test_protocol == FILE_TEST)
685 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
686 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
687 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
688 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
689 SET_EXPECT(CreateInstance);
690 SET_EXPECT(PutProperty_MIMETYPEPROP);
691 SET_EXPECT(PutProperty_CLASSIDPROP);
692 SET_EXPECT(Load);
693 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
694 SET_EXPECT(OnObjectAvailable);
695 SET_EXPECT(Obj_OnStopBinding);
696 }else {
697 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
698 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
699 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
700 if(test_protocol == FILE_TEST)
701 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
702 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
703 SET_EXPECT(LockRequest);
704 if(!filedwl_api)
705 SET_EXPECT(OnDataAvailable);
706 SET_EXPECT(OnStopBinding);
709 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
710 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
712 CHECK_CALLED(Read);
713 if(bind_to_object) {
714 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
715 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
716 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
717 if(test_protocol == FILE_TEST)
718 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
719 CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
720 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
721 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
722 CHECK_CALLED(CreateInstance);
723 CHECK_CALLED(PutProperty_MIMETYPEPROP);
724 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
725 CHECK_CALLED(Load);
726 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
727 CHECK_CALLED(OnObjectAvailable);
728 CHECK_CALLED(Obj_OnStopBinding);
729 }else {
730 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
731 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
732 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
733 if(test_protocol == FILE_TEST)
734 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
735 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
736 CHECK_CALLED(LockRequest);
737 if(!filedwl_api)
738 CHECK_CALLED(OnDataAvailable);
739 CHECK_CALLED(OnStopBinding);
742 if(test_protocol == ITS_TEST) {
743 SET_EXPECT(Read);
744 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
745 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
746 CHECK_CALLED(Read);
749 SET_EXPECT(Terminate);
750 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
751 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
752 CHECK_CALLED(Terminate);
754 return S_OK;
757 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
758 PROTOCOLDATA *pProtocolData)
760 DWORD bscf = 0;
761 HRESULT hres;
763 CHECK_EXPECT(Continue);
765 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
767 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
768 if(!pProtocolData)
769 return S_OK;
771 switch(prot_state) {
772 case 1: {
773 IServiceProvider *service_provider;
774 IHttpNegotiate *http_negotiate;
775 static WCHAR header[] = {'?',0};
777 hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
778 (void**)&service_provider);
779 ok(hres == S_OK, "Could not get IServiceProvicder\n");
781 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
782 &IID_IHttpNegotiate, (void**)&http_negotiate);
783 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
785 SET_EXPECT(QueryInterface_IHttpNegotiate);
786 SET_EXPECT(OnResponse);
787 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
788 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
789 CHECK_CALLED(OnResponse);
790 IHttpNegotiate_Release(http_negotiate);
791 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
793 if(test_protocol == HTTPS_TEST || test_redirect) {
794 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
795 ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
798 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
799 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
800 ok(hres == S_OK,
801 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
803 if(tymed == TYMED_FILE) {
804 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
805 BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_fileW);
806 ok(hres == S_OK,
807 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
810 bscf |= BSCF_FIRSTDATANOTIFICATION;
811 break;
813 case 2:
814 case 3:
815 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
816 break;
819 hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
820 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
822 SET_EXPECT(Read);
823 switch(prot_state) {
824 case 1:
825 if(bind_to_object) {
826 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
827 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
828 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
829 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
830 SET_EXPECT(CreateInstance);
831 SET_EXPECT(PutProperty_MIMETYPEPROP);
832 SET_EXPECT(PutProperty_CLASSIDPROP);
833 SET_EXPECT(Load);
834 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
835 SET_EXPECT(OnObjectAvailable);
836 SET_EXPECT(Obj_OnStopBinding);
837 }else {
838 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
839 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
840 SET_EXPECT(LockRequest);
842 break;
843 case 2:
844 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
845 break;
846 case 3:
847 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
848 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
850 if(!bind_to_object || prot_state >= 2)
851 SET_EXPECT(OnDataAvailable);
852 if(prot_state == 3)
853 SET_EXPECT(OnStopBinding);
855 return S_OK;
858 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
859 DWORD dwOptions)
861 ok(0, "unexpected call\n");
862 return E_NOTIMPL;
865 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
867 CHECK_EXPECT(Terminate);
869 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
871 if(protocol_sink) {
872 IInternetProtocolSink_Release(protocol_sink);
873 protocol_sink = NULL;
876 return S_OK;
879 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
881 ok(0, "unexpected call\n");
882 return E_NOTIMPL;
885 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
887 ok(0, "unexpected call\n");
888 return E_NOTIMPL;
891 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
892 ULONG cb, ULONG *pcbRead)
894 static const char data[] = "<HTML></HTML>";
896 CHECK_EXPECT2(Read);
898 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
899 HRESULT hres;
901 static BOOL pending = TRUE;
903 pending = !pending;
905 switch(prot_state) {
906 case 1:
907 case 2:
908 if(pending) {
909 *pcbRead = 10;
910 memset(pv, '?', 10);
911 return E_PENDING;
912 }else {
913 memset(pv, '?', cb);
914 *pcbRead = cb;
915 read++;
916 return S_OK;
918 case 3:
919 prot_state++;
921 *pcbRead = 0;
923 hres = IInternetProtocolSink_ReportData(protocol_sink,
924 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
925 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
927 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
928 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
930 return S_FALSE;
931 case 4:
932 *pcbRead = 0;
933 return S_FALSE;
937 if(read) {
938 *pcbRead = 0;
939 return S_FALSE;
942 ok(pv != NULL, "pv == NULL\n");
943 ok(cb != 0, "cb == 0\n");
944 ok(pcbRead != NULL, "pcbRead == NULL\n");
945 if(pcbRead) {
946 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
947 read += *pcbRead = sizeof(data)-1;
949 if(pv)
950 memcpy(pv, data, sizeof(data));
952 return S_OK;
955 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
956 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
958 ok(0, "unexpected call\n");
959 return E_NOTIMPL;
962 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
964 CHECK_EXPECT(LockRequest);
965 return S_OK;
968 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
970 CHECK_EXPECT(UnlockRequest);
971 return S_OK;
974 static const IInternetProtocolVtbl ProtocolVtbl = {
975 Protocol_QueryInterface,
976 Protocol_AddRef,
977 Protocol_Release,
978 Protocol_Start,
979 Protocol_Continue,
980 Protocol_Abort,
981 Protocol_Terminate,
982 Protocol_Suspend,
983 Protocol_Resume,
984 Protocol_Read,
985 Protocol_Seek,
986 Protocol_LockRequest,
987 Protocol_UnlockRequest
990 static IInternetProtocol Protocol = { &ProtocolVtbl };
992 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
994 if(IsEqualGUID(&IID_IUnknown, riid)
995 || IsEqualGUID(&IID_IHttpNegotiate, riid)
996 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
997 *ppv = iface;
998 return S_OK;
1001 ok(0, "unexpected call\n");
1002 return E_NOINTERFACE;
1005 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
1007 return 2;
1010 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
1012 return 1;
1015 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
1016 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
1018 CHECK_EXPECT(BeginningTransaction);
1020 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1022 ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
1023 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
1024 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1025 if(pszAdditionalHeaders)
1026 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1028 return S_OK;
1031 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
1032 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
1034 CHECK_EXPECT(OnResponse);
1036 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1038 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
1039 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
1040 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
1041 /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
1042 ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1043 if(pszAdditionalRequestHeaders)
1044 ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1046 return S_OK;
1049 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
1050 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1052 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
1054 CHECK_EXPECT(GetRootSecurityId);
1056 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1058 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
1059 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
1060 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
1062 if(pbSecurityId == (void*)0xdeadbeef)
1063 return E_NOTIMPL;
1065 if(pcbSecurityId) {
1066 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
1067 *pcbSecurityId = sizeof(sec_id);
1070 if(pbSecurityId)
1071 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
1073 return E_FAIL;
1076 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
1077 HttpNegotiate_QueryInterface,
1078 HttpNegotiate_AddRef,
1079 HttpNegotiate_Release,
1080 HttpNegotiate_BeginningTransaction,
1081 HttpNegotiate_OnResponse,
1082 HttpNegotiate_GetRootSecurityId
1085 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
1087 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1089 ok(0, "unexpected call\n");
1090 return E_NOINTERFACE;
1093 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1095 return 2;
1098 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1100 return 1;
1103 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1104 REFGUID guidService, REFIID riid, void **ppv)
1106 if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
1107 CHECK_EXPECT(QueryService_IAuthenticate);
1108 return E_NOTIMPL;
1111 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1112 CHECK_EXPECT2(QueryService_IInternetProtocol);
1113 return E_NOTIMPL;
1116 if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1117 CHECK_EXPECT(QueryService_IInternetBindInfo);
1118 return E_NOTIMPL;
1121 if(IsEqualGUID(&IID_IWindowForBindingUI, guidService)) {
1122 CHECK_EXPECT(QueryService_IWindowForBindingUI);
1123 return E_NOTIMPL;
1126 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
1127 return E_NOINTERFACE;
1130 static IServiceProviderVtbl ServiceProviderVtbl = {
1131 ServiceProvider_QueryInterface,
1132 ServiceProvider_AddRef,
1133 ServiceProvider_Release,
1134 ServiceProvider_QueryService
1137 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1139 static IBindStatusCallbackEx objbsc;
1141 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1143 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1145 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1146 CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1147 if(emulate_protocol) {
1148 *ppv = &Protocol;
1149 return S_OK;
1150 }else {
1151 return E_NOINTERFACE;
1154 else if (IsEqualGUID(&IID_IServiceProvider, riid))
1156 CHECK_EXPECT2(QueryInterface_IServiceProvider);
1157 *ppv = &ServiceProvider;
1158 return S_OK;
1160 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
1162 CHECK_EXPECT2(QueryInterface_IHttpNegotiate);
1163 *ppv = &HttpNegotiate;
1164 return S_OK;
1166 else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
1168 CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1169 *ppv = &HttpNegotiate;
1170 return S_OK;
1172 else if (IsEqualGUID(&IID_IAuthenticate, riid))
1174 CHECK_EXPECT(QueryInterface_IAuthenticate);
1175 return E_NOINTERFACE;
1177 else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
1179 CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1180 *ppv = iface;
1181 return S_OK;
1183 else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
1185 CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1186 return E_NOINTERFACE;
1188 else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid))
1190 CHECK_EXPECT(QueryInterface_IBindStatusCallbackEx);
1191 if(!use_bscex)
1192 return E_NOINTERFACE;
1193 *ppv = iface;
1194 return S_OK;
1196 else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
1198 /* TODO */
1199 CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1201 else if(IsEqualGUID(&IID_IWindowForBindingUI, riid))
1203 CHECK_EXPECT2(QueryInterface_IWindowForBindingUI);
1204 return E_NOINTERFACE;
1206 else
1208 ok(0, "unexpected interface %s\n", debugstr_guid(riid));
1211 return E_NOINTERFACE;
1214 static ULONG WINAPI statusclb_AddRef(IBindStatusCallbackEx *iface)
1216 return 2;
1219 static ULONG WINAPI statusclb_Release(IBindStatusCallbackEx *iface)
1221 return 1;
1224 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved,
1225 IBinding *pib)
1227 IWinInetHttpInfo *http_info;
1228 HRESULT hres;
1229 IMoniker *mon;
1231 if(iface == &objbsc)
1232 CHECK_EXPECT(Obj_OnStartBinding);
1233 else
1234 CHECK_EXPECT(OnStartBinding);
1236 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1238 ok(pib != NULL, "pib should not be NULL\n");
1239 ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1241 if(pib == (void*)0xdeadbeef)
1242 return S_OK;
1244 current_binding = pib;
1246 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1247 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1248 if(SUCCEEDED(hres))
1249 IMoniker_Release(mon);
1251 hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1252 ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1254 return S_OK;
1257 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1259 ok(0, "unexpected call\n");
1260 return E_NOTIMPL;
1263 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1265 ok(0, "unexpected call\n");
1266 return E_NOTIMPL;
1269 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
1270 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1272 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1274 switch(ulStatusCode) {
1275 case BINDSTATUS_FINDINGRESOURCE:
1276 if(iface == &objbsc)
1277 CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1278 else if(test_protocol == FTP_TEST)
1279 todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1280 else
1281 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1282 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1283 SetEvent(complete_event);
1284 break;
1285 case BINDSTATUS_CONNECTING:
1286 if(iface == &objbsc)
1287 CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1288 else if(test_protocol == FTP_TEST)
1289 todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
1290 else
1291 CHECK_EXPECT(OnProgress_CONNECTING);
1292 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1293 SetEvent(complete_event);
1294 break;
1295 case BINDSTATUS_REDIRECTING:
1296 if(iface == &objbsc)
1297 CHECK_EXPECT(Obj_OnProgress_REDIRECTING);
1298 else
1299 CHECK_EXPECT(OnProgress_REDIRECTING);
1300 ok(!lstrcmpW(szStatusText, WINE_ABOUT_URL), "unexpected status text %s\n",
1301 wine_dbgstr_w(szStatusText));
1302 if(!bind_to_object || iface == &objbsc)
1303 SetEvent(complete_event);
1304 break;
1305 case BINDSTATUS_SENDINGREQUEST:
1306 if(iface == &objbsc)
1307 CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1308 else if(test_protocol == FTP_TEST)
1309 CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
1310 else
1311 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1312 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1313 SetEvent(complete_event);
1314 break;
1315 case BINDSTATUS_MIMETYPEAVAILABLE:
1316 if(iface == &objbsc)
1317 CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1318 else
1319 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1320 if(!bind_to_object)
1321 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1322 download_state);
1323 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1324 break;
1325 case BINDSTATUS_BEGINDOWNLOADDATA:
1326 if(iface == &objbsc)
1327 CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1328 else
1329 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1330 ok(szStatusText != NULL, "szStatusText == NULL\n");
1331 if(szStatusText) {
1332 if(filedwl_api) {
1333 /* FIXME */
1334 }else {
1335 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1338 if(!bind_to_object)
1339 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1340 download_state);
1341 download_state = DOWNLOADING;
1342 break;
1343 case BINDSTATUS_DOWNLOADINGDATA:
1344 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1345 ok(iface != &objbsc, "unexpected call\n");
1346 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1347 download_state);
1348 break;
1349 case BINDSTATUS_ENDDOWNLOADDATA:
1350 if(iface == &objbsc)
1351 CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1352 else
1353 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1354 ok(szStatusText != NULL, "szStatusText == NULL\n");
1355 if(szStatusText) {
1356 if(filedwl_api) {
1357 /* FIXME */
1358 }else {
1359 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1362 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1363 download_state);
1364 download_state = END_DOWNLOAD;
1365 break;
1366 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1367 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST) {
1368 if(iface == &objbsc)
1369 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1370 else
1371 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1372 }else { /* FIXME */
1373 CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1374 CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1377 ok(szStatusText != NULL, "szStatusText == NULL\n");
1378 if(szStatusText && test_protocol == FILE_TEST)
1379 ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1380 break;
1381 case BINDSTATUS_CLASSIDAVAILABLE:
1383 CLSID clsid;
1384 HRESULT hr;
1385 if(iface != &objbsc)
1386 ok(0, "unexpected call\n");
1387 else if(1||emulate_protocol)
1388 CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1389 else
1390 todo_wine CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1391 hr = CLSIDFromString((LPOLESTR)szStatusText, &clsid);
1392 ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1393 ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1394 "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1395 break;
1397 case BINDSTATUS_BEGINSYNCOPERATION:
1398 CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1399 if(iface != &objbsc)
1400 ok(0, "unexpected call\n");
1401 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1402 break;
1403 case BINDSTATUS_ENDSYNCOPERATION:
1404 CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1405 if(iface != &objbsc)
1406 ok(0, "unexpected call\n");
1407 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1408 break;
1409 case BINDSTATUS_PROXYDETECTING:
1410 trace("BINDSTATUS_PROXYDETECTING\n");
1411 break;
1412 case BINDSTATUS_COOKIE_SENT:
1413 trace("BINDSTATUS_COOKIE_SENT\n");
1414 break;
1415 default:
1416 ok(0, "unexpected code %d\n", ulStatusCode);
1419 if(current_binding) {
1420 IWinInetHttpInfo *http_info;
1421 HRESULT hres;
1423 hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
1424 if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol))
1425 ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
1426 else
1427 ok(hres == E_NOINTERFACE,
1428 "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
1429 if(SUCCEEDED(hres))
1430 IWinInetHttpInfo_Release(http_info);
1433 return S_OK;
1436 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
1438 if(iface == &objbsc) {
1439 CHECK_EXPECT(Obj_OnStopBinding);
1440 stopped_obj_binding = TRUE;
1441 }else {
1442 CHECK_EXPECT(OnStopBinding);
1443 stopped_binding = TRUE;
1446 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1448 /* ignore DNS failure */
1449 if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1450 return S_OK;
1452 if(filedwl_api)
1453 ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1454 else
1455 ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1456 ok(szError == NULL, "szError should be NULL\n");
1458 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) && emulate_protocol) {
1459 SetEvent(complete_event);
1460 if(iface != &objbsc)
1461 WaitForSingleObject(complete_event2, INFINITE);
1464 return S_OK;
1467 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1469 DWORD cbSize;
1471 if(iface == &objbsc)
1472 CHECK_EXPECT(Obj_GetBindInfo);
1473 else
1474 CHECK_EXPECT(GetBindInfo);
1476 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1478 *grfBINDF = bindf;
1479 cbSize = pbindinfo->cbSize;
1480 memset(pbindinfo, 0, cbSize);
1481 pbindinfo->cbSize = cbSize;
1483 return S_OK;
1486 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
1487 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1489 HRESULT hres;
1490 DWORD readed;
1491 BYTE buf[512];
1492 CHAR clipfmt[512];
1494 if(iface == &objbsc)
1495 ok(0, "unexpected call\n");
1497 CHECK_EXPECT2(OnDataAvailable);
1499 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1501 ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
1502 "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
1503 download_state);
1504 data_available = TRUE;
1506 ok(pformatetc != NULL, "pformatetx == NULL\n");
1507 if(pformatetc) {
1508 if (mime_type[0]) {
1509 clipfmt[0] = 0;
1510 ok(GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1),
1511 "GetClipboardFormatName failed, error %d\n", GetLastError());
1512 ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
1513 pformatetc->cfFormat, clipfmt, mime_type);
1514 } else {
1515 ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
1517 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1518 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
1519 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
1520 ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1523 ok(pstgmed != NULL, "stgmeg == NULL\n");
1524 ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1525 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1527 switch(pstgmed->tymed) {
1528 case TYMED_ISTREAM:
1529 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
1530 hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
1531 ok(hres == STG_E_ACCESSDENIED,
1532 "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1534 hres = IStream_Commit(U(*pstgmed).pstm, 0);
1535 ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1537 hres = IStream_Revert(U(*pstgmed).pstm);
1538 ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
1541 ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
1542 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
1543 while(hres == S_OK);
1544 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
1545 break;
1547 case TYMED_FILE:
1548 if(test_protocol == FILE_TEST)
1549 ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1550 "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
1551 else if(emulate_protocol)
1552 ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1553 "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
1554 else
1555 ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1558 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1559 && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1560 SetEvent(complete_event);
1562 return S_OK;
1565 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
1567 CHECK_EXPECT(OnObjectAvailable);
1569 if(iface != &objbsc)
1570 ok(0, "unexpected call\n");
1572 ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
1573 ok(punk != NULL, "punk == NULL\n");
1575 return S_OK;
1578 static HRESULT WINAPI statusclb_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo,
1579 DWORD *grfBINDF2, DWORD *pdwReserved)
1581 CHECK_EXPECT(GetBindInfoEx);
1583 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1584 ok(grfBINDF2 != NULL, "grfBINDF2 == NULL\n");
1585 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1586 ok(pdwReserved != NULL, "dwReserved == NULL\n");
1588 return S_OK;
1591 static const IBindStatusCallbackExVtbl BindStatusCallbackVtbl = {
1592 statusclb_QueryInterface,
1593 statusclb_AddRef,
1594 statusclb_Release,
1595 statusclb_OnStartBinding,
1596 statusclb_GetPriority,
1597 statusclb_OnLowResource,
1598 statusclb_OnProgress,
1599 statusclb_OnStopBinding,
1600 statusclb_GetBindInfo,
1601 statusclb_OnDataAvailable,
1602 statusclb_OnObjectAvailable,
1603 statusclb_GetBindInfoEx
1606 static IBindStatusCallbackEx bsc = { &BindStatusCallbackVtbl };
1607 static IBindStatusCallbackEx objbsc = { &BindStatusCallbackVtbl };
1609 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
1611 *ppv = NULL;
1612 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1613 return E_NOINTERFACE;
1616 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
1618 return 2;
1621 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
1623 return 1;
1626 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
1628 switch(mkp) {
1629 case MIMETYPEPROP:
1630 CHECK_EXPECT(PutProperty_MIMETYPEPROP);
1631 ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", wine_dbgstr_w(val));
1632 break;
1633 case CLASSIDPROP:
1634 CHECK_EXPECT(PutProperty_CLASSIDPROP);
1635 break;
1636 default:
1637 break;
1640 return S_OK;
1643 static const IMonikerPropVtbl MonikerPropVtbl = {
1644 MonikerProp_QueryInterface,
1645 MonikerProp_AddRef,
1646 MonikerProp_Release,
1647 MonikerProp_PutProperty
1650 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
1652 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
1654 *ppv = NULL;
1656 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
1657 *ppv = iface;
1658 else if(IsEqualGUID(&IID_IMonikerProp, riid))
1659 *ppv = &MonikerProp;
1661 if(*ppv)
1662 return S_OK;
1664 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1665 return E_NOINTERFACE;
1668 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
1670 return 2;
1673 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
1675 return 1;
1678 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
1680 ok(0, "unexpected call\n");
1681 return E_NOTIMPL;
1684 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
1686 ok(0, "unexpected call\n");
1687 return E_NOTIMPL;
1690 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
1691 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
1693 IUnknown *unk;
1694 HRESULT hres;
1696 static WCHAR cbinding_contextW[] =
1697 {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
1699 CHECK_EXPECT(Load);
1700 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1702 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1703 ok(!fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1704 else
1705 ok(fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1706 ok(pimkName != NULL, "pimkName == NULL\n");
1707 ok(pibc != NULL, "pibc == NULL\n");
1708 ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
1710 hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
1711 ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
1712 if(SUCCEEDED(hres)) {
1713 IBinding *binding;
1715 hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
1716 ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
1718 IBinding_Release(binding);
1719 IUnknown_Release(unk);
1722 SET_EXPECT(QueryInterface_IServiceProvider);
1723 hres = RegisterBindStatusCallback(pibc, (IBindStatusCallback*)&bsc, NULL, 0);
1724 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
1725 CHECK_CALLED(QueryInterface_IServiceProvider);
1727 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1728 SET_EXPECT(GetBindInfo);
1729 SET_EXPECT(OnStartBinding);
1730 if(test_redirect)
1731 SET_EXPECT(OnProgress_REDIRECTING);
1732 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1733 if(test_protocol == FILE_TEST)
1734 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1735 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1736 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1737 SET_EXPECT(LockRequest);
1738 SET_EXPECT(OnDataAvailable);
1739 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1740 SET_EXPECT(OnStopBinding);
1742 hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
1743 ok(hres == S_OK, "Load failed: %08x\n", hres);
1745 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
1746 CHECK_CALLED(GetBindInfo);
1747 CHECK_CALLED(OnStartBinding);
1748 if(test_redirect)
1749 CHECK_CALLED(OnProgress_REDIRECTING);
1750 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
1751 if(test_protocol == FILE_TEST)
1752 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1753 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1754 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
1755 CHECK_CALLED(LockRequest);
1756 CHECK_CALLED(OnDataAvailable);
1757 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1758 CHECK_CALLED(OnStopBinding);
1760 if(unk)
1761 IUnknown_Release(unk);
1763 return S_OK;
1766 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
1768 ok(0, "unexpected call\n");
1769 return E_NOTIMPL;
1772 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
1774 ok(0, "unexpected call\n");
1775 return E_NOTIMPL;
1778 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
1780 ok(0, "unexpected call\n");
1781 return E_NOTIMPL;
1784 static const IPersistMonikerVtbl PersistMonikerVtbl = {
1785 PersistMoniker_QueryInterface,
1786 PersistMoniker_AddRef,
1787 PersistMoniker_Release,
1788 PersistMoniker_GetClassID,
1789 PersistMoniker_IsDirty,
1790 PersistMoniker_Load,
1791 PersistMoniker_Save,
1792 PersistMoniker_SaveCompleted,
1793 PersistMoniker_GetCurMoniker
1796 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
1798 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1800 *ppv = NULL;
1802 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1803 *ppv = iface;
1804 return S_OK;
1807 if(IsEqualGUID(&IID_IMarshal, riid))
1808 return E_NOINTERFACE;
1809 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1810 return E_NOINTERFACE;
1812 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1813 return E_NOTIMPL;
1816 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1818 return 2;
1821 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1823 return 1;
1826 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1828 CHECK_EXPECT(CreateInstance);
1829 ok(!outer, "outer = %p\n", outer);
1830 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1831 *ppv = &PersistMoniker;
1832 return S_OK;
1835 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1837 ok(0, "unexpected call\n");
1838 return S_OK;
1841 static const IClassFactoryVtbl ClassFactoryVtbl = {
1842 ClassFactory_QueryInterface,
1843 ClassFactory_AddRef,
1844 ClassFactory_Release,
1845 ClassFactory_CreateInstance,
1846 ClassFactory_LockServer
1849 static IClassFactory mime_cf = { &ClassFactoryVtbl };
1851 static void test_CreateAsyncBindCtx(void)
1853 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
1854 IUnknown *unk;
1855 HRESULT hres;
1856 ULONG ref;
1857 BIND_OPTS bindopts;
1859 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
1860 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1861 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
1863 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
1864 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1866 SET_EXPECT(QueryInterface_IServiceProvider);
1867 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
1868 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
1869 CHECK_CALLED(QueryInterface_IServiceProvider);
1871 bindopts.cbStruct = sizeof(bindopts);
1872 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1873 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1874 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1875 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1876 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1877 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1878 bindopts.grfMode);
1879 ok(bindopts.dwTickCountDeadline == 0,
1880 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1882 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1883 ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
1884 if(SUCCEEDED(hres))
1885 IUnknown_Release(unk);
1887 ref = IBindCtx_Release(bctx);
1888 ok(ref == 0, "bctx should be destroyed here\n");
1891 static void test_CreateAsyncBindCtxEx(void)
1893 IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
1894 IUnknown *unk;
1895 BIND_OPTS bindopts;
1896 HRESULT hres;
1898 static WCHAR testW[] = {'t','e','s','t',0};
1900 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
1901 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
1903 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1904 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1906 if(SUCCEEDED(hres)) {
1907 bindopts.cbStruct = sizeof(bindopts);
1908 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1909 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1910 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1911 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1912 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1913 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1914 bindopts.grfMode);
1915 ok(bindopts.dwTickCountDeadline == 0,
1916 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1918 IBindCtx_Release(bctx);
1921 CreateBindCtx(0, &bctx_arg);
1922 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1923 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1925 if(SUCCEEDED(hres)) {
1926 bindopts.cbStruct = sizeof(bindopts);
1927 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1928 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1929 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1930 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1931 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1932 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1933 bindopts.grfMode);
1934 ok(bindopts.dwTickCountDeadline == 0,
1935 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1937 IBindCtx_Release(bctx);
1940 IBindCtx_Release(bctx_arg);
1942 SET_EXPECT(QueryInterface_IServiceProvider);
1943 hres = CreateAsyncBindCtxEx(NULL, 0, (IBindStatusCallback*)&bsc, NULL, &bctx, 0);
1944 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1945 CHECK_CALLED(QueryInterface_IServiceProvider);
1947 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1948 ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
1949 if(SUCCEEDED(hres))
1950 IUnknown_Release(unk);
1952 IBindCtx_Release(bctx);
1954 hres = CreateBindCtx(0, &bctx2);
1955 ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
1957 hres = CreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
1958 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1960 hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
1961 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
1963 hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
1964 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1965 ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
1967 IBindCtx_Release(bctx);
1968 IBindCtx_Release(bctx2);
1971 static void test_GetBindInfoEx(IBindStatusCallback *holder)
1973 IBindStatusCallbackEx *bscex;
1974 BINDINFO bindinfo = {sizeof(bindinfo)};
1975 DWORD bindf, bindf2, dw;
1976 HRESULT hres;
1978 hres = IBindStatusCallback_QueryInterface(holder, &IID_IBindStatusCallbackEx, (void**)&bscex);
1979 if(FAILED(hres)) {
1980 win_skip("IBindStatusCallbackEx not supported\n");
1981 return;
1984 use_bscex = TRUE;
1986 bindf = 0;
1987 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1988 SET_EXPECT(GetBindInfoEx);
1989 hres = IBindStatusCallback_GetBindInfo(holder, &bindf, &bindinfo);
1990 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1991 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1992 CHECK_CALLED(GetBindInfoEx);
1994 bindf = bindf2 = dw = 0;
1995 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1996 SET_EXPECT(GetBindInfoEx);
1997 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
1998 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1999 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2000 CHECK_CALLED(GetBindInfoEx);
2002 use_bscex = FALSE;
2004 bindf = bindf2 = dw = 0xdeadbeef;
2005 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2006 SET_EXPECT(GetBindInfo);
2007 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
2008 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2009 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2010 CHECK_CALLED(GetBindInfo);
2011 ok(bindf2 == 0xdeadbeef, "bindf2 = %x\n", bindf2);
2012 ok(dw == 0xdeadbeef, "dw = %x\n", dw);
2014 IBindStatusCallbackEx_Release(bscex);
2017 static BOOL test_bscholder(IBindStatusCallback *holder)
2019 IServiceProvider *serv_prov;
2020 IHttpNegotiate *http_negotiate, *http_negotiate_serv;
2021 IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
2022 IAuthenticate *authenticate, *authenticate_serv;
2023 IInternetProtocol *protocol;
2024 BINDINFO bindinfo = {sizeof(bindinfo)};
2025 BOOL ret = TRUE;
2026 LPWSTR wstr;
2027 DWORD dw;
2028 HRESULT hres;
2030 hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
2031 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2033 dw = 0xdeadbeef;
2034 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2035 SET_EXPECT(GetBindInfo);
2036 hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
2037 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2038 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2039 CHECK_CALLED(GetBindInfo);
2041 test_GetBindInfoEx(holder);
2043 SET_EXPECT(OnStartBinding);
2044 hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
2045 ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
2046 CHECK_CALLED(OnStartBinding);
2048 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
2049 ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
2051 SET_EXPECT(QueryInterface_IHttpNegotiate);
2052 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2053 (void**)&http_negotiate_serv);
2054 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2055 CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
2057 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2059 wstr = (void*)0xdeadbeef;
2060 SET_EXPECT(QueryInterface_IHttpNegotiate);
2061 SET_EXPECT(BeginningTransaction);
2062 hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
2063 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2064 CHECK_CALLED(BeginningTransaction);
2065 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
2066 ok(wstr == NULL, "wstr = %p\n", wstr);
2068 IHttpNegotiate_Release(http_negotiate_serv);
2070 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2071 (void**)&http_negotiate_serv);
2072 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2073 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2074 IHttpNegotiate_Release(http_negotiate_serv);
2076 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
2077 if(SUCCEEDED(hres)) {
2078 have_IHttpNegotiate2 = TRUE;
2080 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2081 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
2082 (void**)&http_negotiate2_serv);
2083 ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
2084 CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
2085 ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
2087 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2088 SET_EXPECT(GetRootSecurityId);
2089 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
2090 ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
2091 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2); /* IE8 */
2092 CHECK_CALLED(GetRootSecurityId);
2094 IHttpNegotiate_Release(http_negotiate2_serv);
2095 IHttpNegotiate_Release(http_negotiate2);
2096 }else {
2097 skip("Could not get IHttpNegotiate2\n");
2098 ret = FALSE;
2101 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2102 hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
2103 ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
2104 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2106 SET_EXPECT(QueryInterface_IHttpNegotiate);
2107 SET_EXPECT(OnResponse);
2108 wstr = (void*)0xdeadbeef;
2109 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
2110 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2111 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2112 CHECK_CALLED(OnResponse);
2114 IHttpNegotiate_Release(http_negotiate);
2116 hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
2117 ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
2119 SET_EXPECT(QueryInterface_IAuthenticate);
2120 SET_EXPECT(QueryService_IAuthenticate);
2121 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2122 (void**)&authenticate_serv);
2123 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2124 CLEAR_CALLED(QueryInterface_IAuthenticate); /* IE <8 */
2125 CLEAR_CALLED(QueryService_IAuthenticate); /* IE <8 */
2126 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2127 IAuthenticate_Release(authenticate_serv);
2129 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2130 (void**)&authenticate_serv);
2131 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2132 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2134 IAuthenticate_Release(authenticate);
2135 IAuthenticate_Release(authenticate_serv);
2137 SET_EXPECT(OnStopBinding);
2138 hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
2139 ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
2140 CHECK_CALLED(OnStopBinding);
2142 SET_EXPECT(QueryInterface_IInternetProtocol);
2143 SET_EXPECT(QueryService_IInternetProtocol);
2144 hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
2145 (void**)&protocol);
2146 ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
2147 CHECK_CALLED(QueryInterface_IInternetProtocol);
2148 CHECK_CALLED(QueryService_IInternetProtocol);
2150 IServiceProvider_Release(serv_prov);
2151 return ret;
2154 static BOOL test_RegisterBindStatusCallback(void)
2156 IBindStatusCallback *prevbsc, *clb;
2157 IBindCtx *bindctx;
2158 BOOL ret = TRUE;
2159 IUnknown *unk;
2160 HRESULT hres;
2162 hres = CreateBindCtx(0, &bindctx);
2163 ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
2165 SET_EXPECT(QueryInterface_IServiceProvider);
2167 hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
2168 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2170 SET_EXPECT(QueryInterface_IBindStatusCallback);
2171 SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
2172 prevbsc = (void*)0xdeadbeef;
2173 hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2174 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2175 ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc=%p\n", prevbsc);
2176 CHECK_CALLED(QueryInterface_IBindStatusCallback);
2177 CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
2179 CHECK_CALLED(QueryInterface_IServiceProvider);
2181 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2182 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2184 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2185 IUnknown_Release(unk);
2186 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2187 ok(clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2189 if(!test_bscholder(clb))
2190 ret = FALSE;
2192 IBindStatusCallback_Release(clb);
2194 hres = RevokeBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc);
2195 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2197 unk = (void*)0xdeadbeef;
2198 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2199 ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
2200 ok(unk == NULL, "unk != NULL\n");
2202 if(unk)
2203 IUnknown_Release(unk);
2205 hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
2206 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2208 hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
2209 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2211 hres = RevokeBindStatusCallback(bindctx, NULL);
2212 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2214 IBindCtx_Release(bindctx);
2215 return ret;
2218 #define BINDTEST_EMULATE 0x0001
2219 #define BINDTEST_TOOBJECT 0x0002
2220 #define BINDTEST_FILEDWLAPI 0x0004
2221 #define BINDTEST_HTTPRESPONSE 0x0008
2222 #define BINDTEST_REDIRECT 0x0010
2224 static void init_bind_test(int protocol, DWORD flags, DWORD t)
2226 test_protocol = protocol;
2227 emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
2228 download_state = BEFORE_DOWNLOAD;
2229 stopped_binding = FALSE;
2230 stopped_obj_binding = FALSE;
2231 data_available = FALSE;
2232 mime_type[0] = 0;
2233 binding_hres = S_OK;
2234 bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
2235 tymed = t;
2236 filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
2237 if(flags & BINDTEST_HTTPRESPONSE)
2238 urls[HTTP_TEST] = SHORT_RESPONSE_URL;
2239 else
2240 urls[HTTP_TEST] = WINE_ABOUT_URL;
2241 test_redirect = (flags & BINDTEST_REDIRECT) != 0;
2244 static void test_BindToStorage(int protocol, DWORD flags, DWORD t)
2246 IMoniker *mon;
2247 HRESULT hres;
2248 LPOLESTR display_name;
2249 IBindCtx *bctx;
2250 MSG msg;
2251 IBindStatusCallback *previousclb;
2252 IUnknown *unk = (IUnknown*)0x00ff00ff;
2253 IBinding *bind;
2255 init_bind_test(protocol, flags, t);
2257 SET_EXPECT(QueryInterface_IServiceProvider);
2258 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2259 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2260 CHECK_CALLED(QueryInterface_IServiceProvider);
2261 if(FAILED(hres))
2262 return;
2264 SET_EXPECT(QueryInterface_IServiceProvider);
2265 hres = RegisterBindStatusCallback(bctx, (IBindStatusCallback*)&bsc, &previousclb, 0);
2266 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2267 ok(previousclb == (IBindStatusCallback*)&bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2268 CHECK_CALLED(QueryInterface_IServiceProvider);
2269 if(previousclb)
2270 IBindStatusCallback_Release(previousclb);
2272 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2273 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2274 if(FAILED(hres)) {
2275 IBindCtx_Release(bctx);
2276 return;
2279 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2280 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2281 if(SUCCEEDED(hres))
2282 IBinding_Release(bind);
2284 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2285 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2286 ok(!lstrcmpW(display_name, urls[test_protocol]),
2287 "GetDisplayName got wrong name %s\n", wine_dbgstr_w(display_name));
2288 CoTaskMemFree(display_name);
2290 if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
2291 binding_hres = INET_E_DATA_NOT_AVAILABLE;
2293 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2294 SET_EXPECT(GetBindInfo);
2295 SET_EXPECT(QueryInterface_IInternetProtocol);
2296 if(!emulate_protocol)
2297 SET_EXPECT(QueryService_IInternetProtocol);
2298 SET_EXPECT(OnStartBinding);
2299 if(emulate_protocol) {
2300 if(is_urlmon_protocol(test_protocol))
2301 SET_EXPECT(SetPriority);
2302 SET_EXPECT(Start);
2303 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2304 SET_EXPECT(Terminate);
2305 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2306 SET_EXPECT(UnlockRequest);
2307 }else {
2308 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2309 SET_EXPECT(QueryInterface_IInternetBindInfo);
2310 SET_EXPECT(QueryService_IInternetBindInfo);
2311 SET_EXPECT(QueryInterface_IHttpNegotiate);
2312 SET_EXPECT(QueryInterface_IWindowForBindingUI);
2313 SET_EXPECT(QueryService_IWindowForBindingUI);
2314 SET_EXPECT(BeginningTransaction);
2315 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2316 SET_EXPECT(GetRootSecurityId);
2317 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2318 SET_EXPECT(OnProgress_CONNECTING);
2320 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST
2321 || test_protocol == FILE_TEST)
2322 SET_EXPECT(OnProgress_SENDINGREQUEST);
2323 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2324 SET_EXPECT(QueryInterface_IHttpNegotiate);
2325 SET_EXPECT(OnResponse);
2327 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2328 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2329 if(test_protocol == FILE_TEST)
2330 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2331 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2332 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2333 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2334 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2335 SET_EXPECT(OnDataAvailable);
2336 SET_EXPECT(OnStopBinding);
2339 hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2340 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2341 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2343 skip("Network unreachable, skipping tests\n");
2344 return;
2347 if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
2348 || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2349 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2350 ok(unk == NULL, "istr should be NULL\n");
2351 }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
2352 ok(hres == INET_E_DATA_NOT_AVAILABLE,
2353 "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
2354 ok(unk == NULL, "istr should be NULL\n");
2355 }else {
2356 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2357 ok(unk != NULL, "unk == NULL\n");
2359 if(unk)
2360 IUnknown_Release(unk);
2362 if(FAILED(hres))
2363 return;
2365 while((bindf & BINDF_ASYNCHRONOUS) &&
2366 !stopped_binding && GetMessage(&msg,NULL,0,0)) {
2367 TranslateMessage(&msg);
2368 DispatchMessage(&msg);
2371 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2372 CHECK_CALLED(GetBindInfo);
2373 CHECK_CALLED(QueryInterface_IInternetProtocol);
2374 if(!emulate_protocol)
2375 CHECK_CALLED(QueryService_IInternetProtocol);
2376 CHECK_CALLED(OnStartBinding);
2377 if(emulate_protocol) {
2378 if(is_urlmon_protocol(test_protocol))
2379 CHECK_CALLED(SetPriority);
2380 CHECK_CALLED(Start);
2381 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2382 if(tymed == TYMED_FILE)
2383 CLEAR_CALLED(Read);
2384 CHECK_CALLED(Terminate);
2386 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2387 CHECK_CALLED(UnlockRequest);
2388 }else {
2389 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2390 CLEAR_CALLED(QueryInterface_IInternetBindInfo);
2391 CLEAR_CALLED(QueryService_IInternetBindInfo);
2392 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2393 CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
2394 CLEAR_CALLED(QueryService_IWindowForBindingUI);
2395 CHECK_CALLED(BeginningTransaction);
2396 if (have_IHttpNegotiate2)
2398 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2399 CHECK_CALLED(GetRootSecurityId);
2401 if(http_is_first || test_protocol == HTTPS_TEST) {
2402 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2403 CHECK_CALLED(OnProgress_CONNECTING);
2404 }else todo_wine {
2405 CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
2406 /* IE7 does call this */
2407 CLEAR_CALLED(OnProgress_CONNECTING);
2410 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2411 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2412 else if(test_protocol == FTP_TEST)
2413 todo_wine CHECK_CALLED(OnProgress_SENDINGREQUEST);
2414 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2415 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2416 CHECK_CALLED(OnResponse);
2418 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2419 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2420 if(test_protocol == FILE_TEST)
2421 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2422 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2423 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2424 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2425 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2426 CHECK_CALLED(OnDataAvailable);
2427 CHECK_CALLED(OnStopBinding);
2430 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2431 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2433 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2434 http_is_first = FALSE;
2437 static void test_BindToObject(int protocol, DWORD flags)
2439 IMoniker *mon;
2440 HRESULT hres;
2441 LPOLESTR display_name;
2442 IBindCtx *bctx;
2443 DWORD regid;
2444 MSG msg;
2445 IUnknown *unk = (IUnknown*)0x00ff00ff;
2446 IBinding *bind;
2448 init_bind_test(protocol, BINDTEST_TOOBJECT|flags, TYMED_ISTREAM);
2450 if(emulate_protocol)
2451 CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
2452 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2454 SET_EXPECT(QueryInterface_IServiceProvider);
2455 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&objbsc, NULL, &bctx);
2456 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
2457 CHECK_CALLED(QueryInterface_IServiceProvider);
2458 if(FAILED(hres))
2459 return;
2461 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2462 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2463 if(FAILED(hres)) {
2464 IBindCtx_Release(bctx);
2465 return;
2468 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2469 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2470 if(SUCCEEDED(hres))
2471 IBinding_Release(bind);
2473 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2474 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2475 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
2477 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2478 SET_EXPECT(Obj_GetBindInfo);
2479 SET_EXPECT(QueryInterface_IInternetProtocol);
2480 if(!emulate_protocol)
2481 SET_EXPECT(QueryService_IInternetProtocol);
2482 SET_EXPECT(Obj_OnStartBinding);
2483 if(emulate_protocol) {
2484 if(is_urlmon_protocol(test_protocol))
2485 SET_EXPECT(SetPriority);
2486 SET_EXPECT(Start);
2487 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2488 SET_EXPECT(Terminate);
2489 if(test_protocol == FILE_TEST)
2490 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2491 SET_EXPECT(UnlockRequest);
2492 }else {
2493 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2494 SET_EXPECT(QueryInterface_IHttpNegotiate);
2495 SET_EXPECT(BeginningTransaction);
2496 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2497 SET_EXPECT(GetRootSecurityId);
2498 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
2499 SET_EXPECT(Obj_OnProgress_CONNECTING);
2500 SET_EXPECT(QueryInterface_IWindowForBindingUI);
2501 SET_EXPECT(QueryService_IWindowForBindingUI);
2503 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2504 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
2505 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2506 SET_EXPECT(QueryInterface_IHttpNegotiate);
2507 SET_EXPECT(OnResponse);
2509 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
2510 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
2511 if(test_protocol == FILE_TEST)
2512 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2513 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2514 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2515 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
2516 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
2517 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
2518 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
2519 SET_EXPECT(OnObjectAvailable);
2520 SET_EXPECT(Obj_OnStopBinding);
2523 hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
2525 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2526 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2528 skip( "Network unreachable, skipping tests\n" );
2529 return;
2532 /* no point testing the calls if binding didn't even work */
2533 if (FAILED(hres)) return;
2535 if(bindf & BINDF_ASYNCHRONOUS) {
2536 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
2537 ok(unk == NULL, "istr should be NULL\n");
2538 }else {
2539 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2540 ok(unk != NULL, "unk == NULL\n");
2541 if(emulate_protocol)
2542 ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
2544 if(unk)
2545 IUnknown_Release(unk);
2547 while((bindf & BINDF_ASYNCHRONOUS) &&
2548 !((!emulate_protocol || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
2549 TranslateMessage(&msg);
2550 DispatchMessage(&msg);
2553 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx);
2554 CHECK_CALLED(Obj_GetBindInfo);
2555 CHECK_CALLED(QueryInterface_IInternetProtocol);
2556 if(!emulate_protocol)
2557 CHECK_CALLED(QueryService_IInternetProtocol);
2558 CHECK_CALLED(Obj_OnStartBinding);
2559 if(emulate_protocol) {
2560 if(is_urlmon_protocol(test_protocol))
2561 CHECK_CALLED(SetPriority);
2562 CHECK_CALLED(Start);
2563 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2564 CHECK_CALLED(Terminate);
2565 if(test_protocol == FILE_TEST)
2566 CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
2567 CHECK_CALLED(UnlockRequest);
2568 }else {
2569 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2570 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2571 CHECK_CALLED(BeginningTransaction);
2572 if (have_IHttpNegotiate2)
2574 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2575 CHECK_CALLED(GetRootSecurityId);
2577 if(http_is_first) {
2578 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2579 CHECK_CALLED(Obj_OnProgress_CONNECTING);
2580 }else todo_wine {
2581 CHECK_NOT_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2582 /* IE7 does call this */
2583 CLEAR_CALLED(Obj_OnProgress_CONNECTING);
2585 CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
2586 CLEAR_CALLED(QueryService_IWindowForBindingUI);
2588 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
2589 if(urls[test_protocol] == SHORT_RESPONSE_URL)
2590 CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
2591 else
2592 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
2594 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2595 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2596 CHECK_CALLED(OnResponse);
2598 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
2599 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
2600 if(test_protocol == FILE_TEST)
2601 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2602 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2603 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2604 CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
2605 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
2606 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
2607 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
2608 CHECK_CALLED(OnObjectAvailable);
2609 CHECK_CALLED(Obj_OnStopBinding);
2612 if(test_protocol != HTTP_TEST || emulate_protocol || !(bindf & BINDF_ASYNCHRONOUS)) {
2613 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2614 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2615 }else {
2616 todo_wine ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2617 IBindCtx_Release(bctx);
2620 if(emulate_protocol)
2621 CoRevokeClassObject(regid);
2623 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2624 http_is_first = FALSE;
2627 static void test_URLDownloadToFile(DWORD prot, BOOL emul)
2629 BOOL res;
2630 HRESULT hres;
2632 init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);
2634 SET_EXPECT(GetBindInfo);
2635 SET_EXPECT(QueryInterface_IInternetProtocol);
2636 if(!emulate_protocol) {
2637 SET_EXPECT(QueryInterface_IServiceProvider);
2638 SET_EXPECT(QueryService_IInternetProtocol);
2640 SET_EXPECT(OnStartBinding);
2641 if(emulate_protocol) {
2642 if(is_urlmon_protocol(test_protocol))
2643 SET_EXPECT(SetPriority);
2644 SET_EXPECT(Start);
2645 SET_EXPECT(UnlockRequest);
2646 }else {
2647 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2648 SET_EXPECT(QueryInterface_IHttpNegotiate);
2649 SET_EXPECT(BeginningTransaction);
2650 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2651 SET_EXPECT(GetRootSecurityId);
2652 SET_EXPECT(QueryInterface_IWindowForBindingUI);
2653 SET_EXPECT(OnProgress_CONNECTING);
2655 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2656 SET_EXPECT(OnProgress_SENDINGREQUEST);
2657 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2658 SET_EXPECT(QueryInterface_IHttpNegotiate);
2659 SET_EXPECT(OnResponse);
2661 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2662 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2663 if(test_protocol == FILE_TEST)
2664 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2665 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2666 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2667 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2668 SET_EXPECT(OnStopBinding);
2671 hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol],
2672 dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
2673 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2675 CHECK_CALLED(GetBindInfo);
2676 CHECK_CALLED(QueryInterface_IInternetProtocol);
2677 if(!emulate_protocol) {
2678 CHECK_CALLED(QueryInterface_IServiceProvider);
2679 CHECK_CALLED(QueryService_IInternetProtocol);
2681 CHECK_CALLED(OnStartBinding);
2682 if(emulate_protocol) {
2683 if(is_urlmon_protocol(test_protocol))
2684 CHECK_CALLED(SetPriority);
2685 CHECK_CALLED(Start);
2686 CHECK_CALLED(UnlockRequest);
2687 }else {
2688 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2689 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2690 CHECK_CALLED(BeginningTransaction);
2691 if (have_IHttpNegotiate2)
2693 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2694 CHECK_CALLED(GetRootSecurityId);
2696 CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
2697 CLEAR_CALLED(OnProgress_CONNECTING);
2699 if(test_protocol == FILE_TEST)
2700 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2701 else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2702 CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
2703 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2704 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2705 CHECK_CALLED(OnResponse);
2707 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2708 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2709 if(test_protocol == FILE_TEST)
2710 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2711 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2712 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2713 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2714 CHECK_CALLED(OnStopBinding);
2717 res = DeleteFileA(dwl_htmlA);
2718 ok(res, "DeleteFile failed: %u\n", GetLastError());
2720 if(prot != FILE_TEST || emul)
2721 return;
2723 hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
2724 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2726 res = DeleteFileA(dwl_htmlA);
2727 ok(res, "DeleteFile failed: %u\n", GetLastError());
2730 static void set_file_url(char *path)
2732 CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
2733 CHAR INDEX_HTMLA[MAX_PATH];
2735 lstrcpyA(file_urlA, "file:///");
2736 lstrcatA(file_urlA, path);
2737 MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
2739 lstrcpyA(INDEX_HTMLA, "file://");
2740 lstrcatA(INDEX_HTMLA, path);
2741 MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
2744 static void create_file(void)
2746 HANDLE file;
2747 DWORD size;
2748 CHAR path[MAX_PATH];
2750 static const char html_doc[] = "<HTML></HTML>";
2752 file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2753 FILE_ATTRIBUTE_NORMAL, NULL);
2754 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2755 if(file == INVALID_HANDLE_VALUE)
2756 return;
2758 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2759 CloseHandle(file);
2761 GetCurrentDirectoryA(MAX_PATH, path);
2762 lstrcatA(path, "\\");
2763 lstrcatA(path, wszIndexHtmlA);
2764 set_file_url(path);
2767 static void test_ReportResult(HRESULT exhres)
2769 IMoniker *mon = NULL;
2770 IBindCtx *bctx = NULL;
2771 IUnknown *unk = (void*)0xdeadbeef;
2772 HRESULT hres;
2774 init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2775 binding_hres = exhres;
2777 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2778 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2780 SET_EXPECT(QueryInterface_IServiceProvider);
2781 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2782 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2783 CHECK_CALLED(QueryInterface_IServiceProvider);
2785 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2786 SET_EXPECT(GetBindInfo);
2787 SET_EXPECT(QueryInterface_IInternetProtocol);
2788 SET_EXPECT(OnStartBinding);
2789 if(is_urlmon_protocol(test_protocol))
2790 SET_EXPECT(SetPriority);
2791 SET_EXPECT(Start);
2793 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2794 if(SUCCEEDED(exhres))
2795 ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
2796 else
2797 ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
2798 "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
2800 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2801 CHECK_CALLED(GetBindInfo);
2802 CHECK_CALLED(QueryInterface_IInternetProtocol);
2803 CHECK_CALLED(OnStartBinding);
2804 if(is_urlmon_protocol(test_protocol))
2805 CHECK_CALLED(SetPriority);
2806 CHECK_CALLED(Start);
2808 ok(unk == NULL, "unk=%p\n", unk);
2810 IBindCtx_Release(bctx);
2811 IMoniker_Release(mon);
2814 static void test_BindToStorage_fail(void)
2816 IMoniker *mon = NULL;
2817 IBindCtx *bctx = NULL;
2818 IUnknown *unk;
2819 HRESULT hres;
2821 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2822 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2823 if(FAILED(hres))
2824 return;
2826 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2827 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2829 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2830 ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
2831 "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
2833 IBindCtx_Release(bctx);
2835 IMoniker_Release(mon);
2837 test_ReportResult(E_NOTIMPL);
2838 test_ReportResult(S_FALSE);
2841 static void test_StdURLMoniker(void)
2843 IMoniker *mon, *async_mon;
2844 LPOLESTR display_name;
2845 HRESULT hres;
2847 hres = CoCreateInstance(&IID_IInternet, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2848 &IID_IMoniker, (void**)&mon);
2849 ok(hres == S_OK, "Could not create IInternet instance: %08x\n", hres);
2850 if(FAILED(hres))
2851 return;
2853 hres = IMoniker_QueryInterface(mon, &IID_IAsyncMoniker, (void**)&async_mon);
2854 ok(hres == S_OK, "Could not get IAsyncMoniker iface: %08x\n", hres);
2855 ok(mon == async_mon, "mon != async_mon\n");
2856 IMoniker_Release(async_mon);
2858 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &display_name);
2859 ok(hres == E_OUTOFMEMORY, "GetDisplayName failed: %08x, expected E_OUTOFMEMORY\n", hres);
2861 IMoniker_Release(mon);
2864 START_TEST(url)
2866 complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2867 complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2868 thread_id = GetCurrentThreadId();
2869 create_file();
2871 test_create();
2873 trace("test CreateAsyncBindCtx...\n");
2874 test_CreateAsyncBindCtx();
2876 trace("test CreateAsyncBindCtxEx...\n");
2877 test_CreateAsyncBindCtxEx();
2879 trace("test RegisterBindStatusCallback...\n");
2880 if(test_RegisterBindStatusCallback()) {
2881 trace("test BindToStorage failures...\n");
2882 test_BindToStorage_fail();
2884 trace("synchronous http test (COM not initialised)...\n");
2885 test_BindToStorage(HTTP_TEST, 0, TYMED_ISTREAM);
2887 CoInitialize(NULL);
2889 trace("test StdURLMoniker...\n");
2890 test_StdURLMoniker();
2892 trace("synchronous http test...\n");
2893 test_BindToStorage(HTTP_TEST, 0, TYMED_ISTREAM);
2895 trace("synchronous http test (to object)...\n");
2896 test_BindToObject(HTTP_TEST, 0);
2898 trace("synchronous file test...\n");
2899 test_BindToStorage(FILE_TEST, 0, TYMED_ISTREAM);
2901 trace("synchronous file test (to object)...\n");
2902 test_BindToObject(FILE_TEST, 0);
2904 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2906 trace("http test...\n");
2907 test_BindToStorage(HTTP_TEST, 0, TYMED_ISTREAM);
2909 trace("http test (to file)...\n");
2910 test_BindToStorage(HTTP_TEST, 0, TYMED_FILE);
2912 trace("http test (to object)...\n");
2913 test_BindToObject(HTTP_TEST, 0);
2915 trace("http test (short response)...\n");
2916 http_is_first = TRUE;
2917 test_BindToStorage(HTTP_TEST, BINDTEST_HTTPRESPONSE, TYMED_ISTREAM);
2919 trace("http test (short response, to object)...\n");
2920 test_BindToObject(HTTP_TEST, 0);
2922 trace("emulated http test...\n");
2923 test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2925 trace("emulated http test (to object)...\n");
2926 test_BindToObject(HTTP_TEST, BINDTEST_EMULATE);
2928 trace("emulated http test (to object, redirect)...\n");
2929 test_BindToObject(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_REDIRECT);
2931 trace("emulated http test (to file)...\n");
2932 test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE, TYMED_FILE);
2934 trace("emulated http test (redirect)...\n");
2935 test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_REDIRECT, TYMED_ISTREAM);
2937 trace("asynchronous https test...\n");
2938 test_BindToStorage(HTTPS_TEST, 0, TYMED_ISTREAM);
2940 trace("emulated https test...\n");
2941 test_BindToStorage(HTTPS_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2943 trace("about test...\n");
2944 test_BindToStorage(ABOUT_TEST, 0, TYMED_ISTREAM);
2946 trace("about test (to file)...\n");
2947 test_BindToStorage(ABOUT_TEST, 0, TYMED_FILE);
2949 trace("about test (to object)...\n");
2950 test_BindToObject(ABOUT_TEST, 0);
2952 trace("emulated about test...\n");
2953 test_BindToStorage(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2955 trace("emulated about test (to file)...\n");
2956 test_BindToStorage(ABOUT_TEST, BINDTEST_EMULATE, TYMED_FILE);
2958 trace("emulated about test (to object)...\n");
2959 test_BindToObject(ABOUT_TEST, BINDTEST_EMULATE);
2961 trace("file test...\n");
2962 test_BindToStorage(FILE_TEST, 0, TYMED_ISTREAM);
2964 trace("file test (to file)...\n");
2965 test_BindToStorage(FILE_TEST, 0, TYMED_FILE);
2967 trace("file test (to object)...\n");
2968 test_BindToObject(FILE_TEST, 0);
2970 trace("emulated file test...\n");
2971 test_BindToStorage(FILE_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2973 trace("emulated file test (to file)...\n");
2974 test_BindToStorage(FILE_TEST, BINDTEST_EMULATE, TYMED_FILE);
2976 trace("emulated file test (to object)...\n");
2977 test_BindToObject(FILE_TEST, BINDTEST_EMULATE);
2979 trace("emulated its test...\n");
2980 test_BindToStorage(ITS_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2982 trace("emulated its test (to file)...\n");
2983 test_BindToStorage(ITS_TEST, BINDTEST_EMULATE, TYMED_FILE);
2985 trace("emulated mk test...\n");
2986 test_BindToStorage(MK_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2988 trace("test URLDownloadToFile for file protocol...\n");
2989 test_URLDownloadToFile(FILE_TEST, FALSE);
2991 trace("test URLDownloadToFile for emulated file protocol...\n");
2992 test_URLDownloadToFile(FILE_TEST, TRUE);
2994 trace("test URLDownloadToFile for http protocol...\n");
2995 test_URLDownloadToFile(HTTP_TEST, FALSE);
2997 bindf |= BINDF_NOWRITECACHE;
2999 trace("ftp test...\n");
3000 test_BindToStorage(FTP_TEST, 0, TYMED_ISTREAM);
3002 trace("test failures...\n");
3003 test_BindToStorage_fail();
3006 DeleteFileA(wszIndexHtmlA);
3007 CloseHandle(complete_event);
3008 CloseHandle(complete_event2);
3009 CoUninitialize();