push ca931951dc5f3f050707cce013d2412130f45f11
[wine/hacks.git] / dlls / urlmon / tests / url.c
blobb5bf79c03fc6ac3740a06dc4504dcb59ffde67e9
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(QueryService_IAuthenticate);
90 DEFINE_EXPECT(QueryService_IInternetProtocol);
91 DEFINE_EXPECT(QueryService_IInternetBindInfo);
92 DEFINE_EXPECT(BeginningTransaction);
93 DEFINE_EXPECT(OnResponse);
94 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
95 DEFINE_EXPECT(GetRootSecurityId);
96 DEFINE_EXPECT(GetBindInfo);
97 DEFINE_EXPECT(GetBindInfoEx);
98 DEFINE_EXPECT(OnStartBinding);
99 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
100 DEFINE_EXPECT(OnProgress_CONNECTING);
101 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
102 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
103 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
104 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
105 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
106 DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
107 DEFINE_EXPECT(OnStopBinding);
108 DEFINE_EXPECT(OnDataAvailable);
109 DEFINE_EXPECT(OnObjectAvailable);
110 DEFINE_EXPECT(Obj_OnStartBinding);
111 DEFINE_EXPECT(Obj_OnStopBinding);
112 DEFINE_EXPECT(Obj_GetBindInfo);
113 DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
114 DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
115 DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
116 DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
117 DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
118 DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
119 DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
120 DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
121 DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
122 DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
123 DEFINE_EXPECT(Start);
124 DEFINE_EXPECT(Read);
125 DEFINE_EXPECT(LockRequest);
126 DEFINE_EXPECT(Terminate);
127 DEFINE_EXPECT(UnlockRequest);
128 DEFINE_EXPECT(Continue);
129 DEFINE_EXPECT(CreateInstance);
130 DEFINE_EXPECT(Load);
131 DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
132 DEFINE_EXPECT(PutProperty_CLASSIDPROP);
133 DEFINE_EXPECT(SetPriority);
135 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
136 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
138 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
139 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
140 static const WCHAR SHORT_RESPONSE_URL[] =
141 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
142 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
143 'p','o','s','t','t','e','s','t','.','p','h','p',0};
144 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
145 static WCHAR INDEX_HTML[MAX_PATH];
146 static const WCHAR ITS_URL[] =
147 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
148 static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
149 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
150 static const WCHAR https_urlW[] =
151 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',
152 '/','t','e','s','t','.','h','t','m','l',0};
153 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
154 '/','p','u','b','/','o','t','h','e','r','/',
155 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
158 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
160 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
162 static const WCHAR wszWineHQSite[] =
163 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
164 static const WCHAR wszWineHQIP[] =
165 {'2','0','9','.','3','2','.','1','4','1','.','3',0};
166 static const CHAR wszIndexHtmlA[] = "index.html";
167 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
168 static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
169 static const CHAR dwl_htmlA[] = "dwl.html";
170 static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
171 static const WCHAR emptyW[] = {0};
173 static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
174 data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api;
175 static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed;
176 static CHAR mime_type[512];
177 static IInternetProtocolSink *protocol_sink = NULL;
178 static IBinding *current_binding;
179 static HANDLE complete_event, complete_event2;
180 static HRESULT binding_hres;
181 static BOOL have_IHttpNegotiate2, use_bscex;
183 static LPCWSTR urls[] = {
184 WINE_ABOUT_URL,
185 ABOUT_BLANK,
186 INDEX_HTML,
187 ITS_URL,
188 MK_URL,
189 https_urlW,
190 ftp_urlW
193 static WCHAR file_url[INTERNET_MAX_URL_LENGTH];
195 static enum {
196 HTTP_TEST,
197 ABOUT_TEST,
198 FILE_TEST,
199 ITS_TEST,
200 MK_TEST,
201 HTTPS_TEST,
202 FTP_TEST
203 } test_protocol;
205 static enum {
206 BEFORE_DOWNLOAD,
207 DOWNLOADING,
208 END_DOWNLOAD
209 } download_state;
211 static const char *debugstr_w(LPCWSTR str)
213 static char buf[1024];
214 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
215 return buf;
218 static const char *debugstr_guid(REFIID riid)
220 static char buf[50];
222 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
223 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
224 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
225 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
227 return buf;
230 static BOOL is_urlmon_protocol(int prot)
232 return prot == FILE_TEST || prot == HTTP_TEST || prot == HTTPS_TEST || prot == FTP_TEST || prot == MK_TEST;
235 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
237 HRESULT hr;
238 IMoniker *mon1 = NULL;
239 IMoniker *mon2 = NULL;
241 hr = CreateURLMoniker(NULL, url1, &mon1);
242 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
243 if(SUCCEEDED(hr)) {
244 hr = CreateURLMoniker(mon1, url2, &mon2);
245 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
247 if(mon1) IMoniker_Release(mon1);
248 if(mon2) IMoniker_Release(mon2);
251 static void test_create(void)
253 test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
256 static HRESULT WINAPI Priority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
258 ok(0, "unexpected call\n");
259 return E_NOINTERFACE;
262 static ULONG WINAPI Priority_AddRef(IInternetPriority *iface)
264 return 2;
267 static ULONG WINAPI Priority_Release(IInternetPriority *iface)
269 return 1;
272 static HRESULT WINAPI Priority_SetPriority(IInternetPriority *iface, LONG nPriority)
274 CHECK_EXPECT(SetPriority);
275 ok(!nPriority, "nPriority = %d\n", nPriority);
276 return S_OK;
279 static HRESULT WINAPI Priority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
281 ok(0, "unexpected call\n");
282 return S_OK;
285 static const IInternetPriorityVtbl InternetPriorityVtbl = {
286 Priority_QueryInterface,
287 Priority_AddRef,
288 Priority_Release,
289 Priority_SetPriority,
290 Priority_GetPriority
293 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
295 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
297 *ppv = NULL;
299 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
300 *ppv = iface;
301 return S_OK;
304 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
305 if(!is_urlmon_protocol(test_protocol))
306 return E_NOINTERFACE;
308 *ppv = &InternetPriority;
309 return S_OK;
312 if(IsEqualGUID(&IID_IInternetProtocolEx, riid))
313 return E_NOINTERFACE; /* TODO */
315 ok(0, "unexpected call %s\n", debugstr_guid(riid));
316 return E_NOINTERFACE;
319 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
321 return 2;
324 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
326 return 1;
329 static void test_switch_fail(void)
331 IInternetProtocolSink *binding_sink;
332 PROTOCOLDATA protocoldata;
333 HRESULT hres;
335 static BOOL tested_switch_fail;
337 if(tested_switch_fail)
338 return;
340 tested_switch_fail = TRUE;
342 hres = IBinding_QueryInterface(current_binding, &IID_IInternetProtocolSink, (void**)&binding_sink);
343 ok(hres == S_OK, "Could not get IInternetProtocolSink iface: %08x\n", hres);
344 if(SUCCEEDED(hres)) {
345 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
346 ok(hres == E_FAIL, "Switch failed: %08x, expected E_FAIL\n", hres);
347 IInternetProtocolSink_Release(binding_sink);
351 static DWORD WINAPI thread_proc(PVOID arg)
353 PROTOCOLDATA protocoldata;
354 HRESULT hres;
356 if(bind_to_object)
357 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
358 else
359 SET_EXPECT(OnProgress_FINDINGRESOURCE);
360 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
361 BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
362 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
363 WaitForSingleObject(complete_event, INFINITE);
364 if(bind_to_object)
365 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
366 else
367 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
369 if(bind_to_object)
370 SET_EXPECT(Obj_OnProgress_CONNECTING);
371 else
372 SET_EXPECT(OnProgress_CONNECTING);
373 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
374 BINDSTATUS_CONNECTING, wszWineHQIP);
375 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
376 WaitForSingleObject(complete_event, INFINITE);
377 if(bind_to_object)
378 CHECK_CALLED(Obj_OnProgress_CONNECTING);
379 else
380 CHECK_CALLED(OnProgress_CONNECTING);
382 if(bind_to_object)
383 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
384 else
385 SET_EXPECT(OnProgress_SENDINGREQUEST);
386 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
387 BINDSTATUS_SENDINGREQUEST, NULL);
388 ok(hres == S_OK, "ReportProxgress failed: %08x\n", hres);
389 WaitForSingleObject(complete_event, INFINITE);
390 if(bind_to_object)
391 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
392 else
393 CHECK_CALLED(OnProgress_SENDINGREQUEST);
395 test_switch_fail();
397 SET_EXPECT(Continue);
398 prot_state = 1;
399 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
400 ok(hres == S_OK, "Switch failed: %08x\n", hres);
401 WaitForSingleObject(complete_event, INFINITE);
403 CHECK_CALLED(Continue);
404 CHECK_CALLED(Read);
405 if(bind_to_object) {
406 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
407 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
408 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
409 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
410 CHECK_CALLED(CreateInstance);
411 CHECK_CALLED(PutProperty_MIMETYPEPROP);
412 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
413 CHECK_CALLED(Load);
414 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
415 CHECK_CALLED(OnObjectAvailable);
416 CHECK_CALLED(Obj_OnStopBinding);
417 }else {
418 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
419 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
420 CHECK_CALLED(LockRequest);
421 CHECK_CALLED(OnDataAvailable);
424 SET_EXPECT(Continue);
425 prot_state = 2;
426 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
427 ok(hres == S_OK, "Switch failed: %08x\n", hres);
428 WaitForSingleObject(complete_event, INFINITE);
429 CHECK_CALLED(Continue);
430 CHECK_CALLED(Read);
431 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
432 CHECK_CALLED(OnDataAvailable);
434 SET_EXPECT(Continue);
435 prot_state = 2;
436 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
437 ok(hres == S_OK, "Switch failed: %08x\n", hres);
438 WaitForSingleObject(complete_event, INFINITE);
439 CHECK_CALLED(Continue);
440 CHECK_CALLED(Read);
441 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
442 CHECK_CALLED(OnDataAvailable);
444 SET_EXPECT(Continue);
445 prot_state = 3;
446 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
447 ok(hres == S_OK, "Switch failed: %08x\n", hres);
448 WaitForSingleObject(complete_event, INFINITE);
449 CHECK_CALLED(Continue);
450 CHECK_CALLED(Read);
451 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
452 CHECK_CALLED(OnDataAvailable);
453 CHECK_CALLED(OnStopBinding);
455 SET_EXPECT(Read);
457 SetEvent(complete_event2);
458 return 0;
461 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
462 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
463 DWORD grfPI, HANDLE_PTR dwReserved)
465 BINDINFO bindinfo;
466 DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
467 HRESULT hres;
469 static const STGMEDIUM stgmed_zero = {0};
470 static const SECURITY_ATTRIBUTES sa_zero = {0};
472 CHECK_EXPECT(Start);
474 read = 0;
476 if(!filedwl_api) /* FIXME */
477 ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", debugstr_w(szUrl));
478 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
479 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
480 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
481 ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
483 if(!filedwl_api && binding_hres != S_OK) {
484 SET_EXPECT(OnStopBinding);
485 SET_EXPECT(Terminate);
486 hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
487 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
488 CHECK_CALLED(OnStopBinding);
489 CHECK_CALLED(Terminate);
491 return S_OK;
494 memset(&bindinfo, 0, sizeof(bindinfo));
495 bindinfo.cbSize = sizeof(bindinfo);
496 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
497 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
499 if(filedwl_api) {
500 ok(bindf == (BINDF_PULLDATA|BINDF_FROMURLMON|BINDF_NEEDFILE), "bindf=%08x\n", bindf);
501 }else if(tymed == TYMED_ISTREAM && is_urlmon_protocol(test_protocol)) {
502 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
503 |BINDF_FROMURLMON),
504 "bindf=%08x\n", bindf);
505 }else {
506 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
507 |BINDF_FROMURLMON|BINDF_NEEDFILE),
508 "bindf=%08x\n", bindf);
511 ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
512 ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
513 ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
514 ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
515 ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
516 ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
517 ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
518 ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
519 ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
520 ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
521 ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
522 ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
523 ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
524 ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
526 switch(test_protocol) {
527 case MK_TEST:
528 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
529 BINDSTATUS_DIRECTBIND, NULL);
530 ok(hres == S_OK,
531 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
533 case FILE_TEST:
534 case ITS_TEST:
535 if(bind_to_object)
536 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
537 else
538 SET_EXPECT(OnProgress_SENDINGREQUEST);
539 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
540 BINDSTATUS_SENDINGREQUEST, emptyW);
541 ok(hres == S_OK,
542 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
543 if(bind_to_object)
544 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
545 else
546 CHECK_CALLED(OnProgress_SENDINGREQUEST);
547 default:
548 break;
551 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
552 IServiceProvider *service_provider;
553 IHttpNegotiate *http_negotiate;
554 IHttpNegotiate2 *http_negotiate2;
555 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
556 LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
557 BYTE sec_id[100];
558 DWORD fetched = 256, size = 100;
559 DWORD tid;
561 static const WCHAR wszMimes[] = {'*','/','*',0};
563 SET_EXPECT(QueryInterface_IInternetBindInfo);
564 SET_EXPECT(QueryService_IInternetBindInfo);
565 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
566 &ua, 1, &fetched);
567 CLEAR_CALLED(QueryInterface_IInternetBindInfo); /* IE <8 */
568 CLEAR_CALLED(QueryService_IInternetBindInfo); /* IE <8 */
570 ok(hres == E_NOINTERFACE,
571 "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
572 ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
573 ok(ua == (LPWSTR)0xdeadbeef, "ua = %p\n", ua);
575 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
576 accept_mimes, 256, &fetched);
577 ok(hres == S_OK,
578 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
579 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
580 ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
582 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
583 NULL, 256, &fetched);
584 ok(hres == E_INVALIDARG,
585 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
587 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
588 accept_mimes, 256, NULL);
589 ok(hres == E_INVALIDARG,
590 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
592 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
593 (void**)&service_provider);
594 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
596 SET_EXPECT(QueryInterface_IHttpNegotiate);
597 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
598 &IID_IHttpNegotiate, (void**)&http_negotiate);
599 CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
600 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
602 SET_EXPECT(BeginningTransaction);
603 SET_EXPECT(QueryInterface_IHttpNegotiate);
604 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
605 NULL, 0, &additional_headers);
606 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
607 CHECK_CALLED(BeginningTransaction);
608 IHttpNegotiate_Release(http_negotiate);
609 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
610 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
612 SET_EXPECT(QueryInterface_IHttpNegotiate2);
613 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
614 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
615 CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
616 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
618 size = 512;
619 SET_EXPECT(QueryInterface_IHttpNegotiate2);
620 SET_EXPECT(GetRootSecurityId);
621 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
622 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2);
623 CHECK_CALLED(GetRootSecurityId);
624 IHttpNegotiate2_Release(http_negotiate2);
625 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
626 ok(size == 13, "size=%d\n", size);
628 IServiceProvider_Release(service_provider);
630 IInternetProtocolSink_AddRef(pOIProtSink);
631 protocol_sink = pOIProtSink;
632 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
634 return S_OK;
637 if(test_protocol == FILE_TEST) {
638 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
639 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
640 ok(hres == S_OK,
641 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
643 if(bind_to_object)
644 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
645 else
646 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
647 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
648 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
649 ok(hres == S_OK,
650 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
651 if(bind_to_object)
652 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
653 else
654 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
655 }else {
656 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
657 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
658 ok(hres == S_OK,
659 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
662 if(test_protocol == ABOUT_TEST)
663 bscf |= BSCF_DATAFULLYAVAILABLE;
664 if(test_protocol == ITS_TEST)
665 bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
667 SET_EXPECT(Read);
668 if(bind_to_object) {
669 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
670 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
671 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
672 if(test_protocol == FILE_TEST)
673 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
674 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
675 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
676 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
677 SET_EXPECT(CreateInstance);
678 SET_EXPECT(PutProperty_MIMETYPEPROP);
679 SET_EXPECT(PutProperty_CLASSIDPROP);
680 SET_EXPECT(Load);
681 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
682 SET_EXPECT(OnObjectAvailable);
683 SET_EXPECT(Obj_OnStopBinding);
684 }else {
685 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
686 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
687 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
688 if(test_protocol == FILE_TEST)
689 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
690 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
691 SET_EXPECT(LockRequest);
692 if(!filedwl_api)
693 SET_EXPECT(OnDataAvailable);
694 SET_EXPECT(OnStopBinding);
697 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
698 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
700 CHECK_CALLED(Read);
701 if(bind_to_object) {
702 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
703 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
704 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
705 if(test_protocol == FILE_TEST)
706 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
707 CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
708 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
709 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
710 CHECK_CALLED(CreateInstance);
711 CHECK_CALLED(PutProperty_MIMETYPEPROP);
712 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
713 CHECK_CALLED(Load);
714 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
715 CHECK_CALLED(OnObjectAvailable);
716 CHECK_CALLED(Obj_OnStopBinding);
717 }else {
718 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
719 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
720 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
721 if(test_protocol == FILE_TEST)
722 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
723 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
724 CHECK_CALLED(LockRequest);
725 if(!filedwl_api)
726 CHECK_CALLED(OnDataAvailable);
727 CHECK_CALLED(OnStopBinding);
730 if(test_protocol == ITS_TEST) {
731 SET_EXPECT(Read);
732 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
733 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
734 CHECK_CALLED(Read);
737 SET_EXPECT(Terminate);
738 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
739 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
740 CHECK_CALLED(Terminate);
742 return S_OK;
745 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
746 PROTOCOLDATA *pProtocolData)
748 DWORD bscf = 0;
749 HRESULT hres;
751 CHECK_EXPECT(Continue);
753 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
755 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
756 if(!pProtocolData)
757 return S_OK;
759 switch(prot_state) {
760 case 1: {
761 IServiceProvider *service_provider;
762 IHttpNegotiate *http_negotiate;
763 static WCHAR header[] = {'?',0};
765 hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
766 (void**)&service_provider);
767 ok(hres == S_OK, "Could not get IServiceProvicder\n");
769 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
770 &IID_IHttpNegotiate, (void**)&http_negotiate);
771 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
773 SET_EXPECT(QueryInterface_IHttpNegotiate);
774 SET_EXPECT(OnResponse);
775 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
776 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
777 CHECK_CALLED(OnResponse);
778 IHttpNegotiate_Release(http_negotiate);
779 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
781 if(test_protocol == HTTPS_TEST) {
782 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
783 ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
786 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
787 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
788 ok(hres == S_OK,
789 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
791 if(tymed == TYMED_FILE) {
792 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
793 BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_fileW);
794 ok(hres == S_OK,
795 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
798 bscf |= BSCF_FIRSTDATANOTIFICATION;
799 break;
801 case 2:
802 case 3:
803 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
804 break;
807 hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
808 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
810 SET_EXPECT(Read);
811 switch(prot_state) {
812 case 1:
813 if(bind_to_object) {
814 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
815 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
816 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
817 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
818 SET_EXPECT(CreateInstance);
819 SET_EXPECT(PutProperty_MIMETYPEPROP);
820 SET_EXPECT(PutProperty_CLASSIDPROP);
821 SET_EXPECT(Load);
822 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
823 SET_EXPECT(OnObjectAvailable);
824 SET_EXPECT(Obj_OnStopBinding);
825 }else {
826 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
827 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
828 SET_EXPECT(LockRequest);
830 break;
831 case 2:
832 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
833 break;
834 case 3:
835 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
836 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
838 if(!bind_to_object || prot_state >= 2)
839 SET_EXPECT(OnDataAvailable);
840 if(prot_state == 3)
841 SET_EXPECT(OnStopBinding);
843 return S_OK;
846 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
847 DWORD dwOptions)
849 ok(0, "unexpected call\n");
850 return E_NOTIMPL;
853 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
855 CHECK_EXPECT(Terminate);
857 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
859 if(protocol_sink) {
860 IInternetProtocolSink_Release(protocol_sink);
861 protocol_sink = NULL;
864 return S_OK;
867 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
869 ok(0, "unexpected call\n");
870 return E_NOTIMPL;
873 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
875 ok(0, "unexpected call\n");
876 return E_NOTIMPL;
879 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
880 ULONG cb, ULONG *pcbRead)
882 static const char data[] = "<HTML></HTML>";
884 CHECK_EXPECT2(Read);
886 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
887 HRESULT hres;
889 static BOOL pending = TRUE;
891 pending = !pending;
893 switch(prot_state) {
894 case 1:
895 case 2:
896 if(pending) {
897 *pcbRead = 10;
898 memset(pv, '?', 10);
899 return E_PENDING;
900 }else {
901 memset(pv, '?', cb);
902 *pcbRead = cb;
903 read++;
904 return S_OK;
906 case 3:
907 prot_state++;
909 *pcbRead = 0;
911 hres = IInternetProtocolSink_ReportData(protocol_sink,
912 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
913 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
915 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
916 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
918 return S_FALSE;
919 case 4:
920 *pcbRead = 0;
921 return S_FALSE;
925 if(read) {
926 *pcbRead = 0;
927 return S_FALSE;
930 ok(pv != NULL, "pv == NULL\n");
931 ok(cb != 0, "cb == 0\n");
932 ok(pcbRead != NULL, "pcbRead == NULL\n");
933 if(pcbRead) {
934 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
935 read += *pcbRead = sizeof(data)-1;
937 if(pv)
938 memcpy(pv, data, sizeof(data));
940 return S_OK;
943 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
944 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
946 ok(0, "unexpected call\n");
947 return E_NOTIMPL;
950 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
952 CHECK_EXPECT(LockRequest);
953 return S_OK;
956 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
958 CHECK_EXPECT(UnlockRequest);
959 return S_OK;
962 static const IInternetProtocolVtbl ProtocolVtbl = {
963 Protocol_QueryInterface,
964 Protocol_AddRef,
965 Protocol_Release,
966 Protocol_Start,
967 Protocol_Continue,
968 Protocol_Abort,
969 Protocol_Terminate,
970 Protocol_Suspend,
971 Protocol_Resume,
972 Protocol_Read,
973 Protocol_Seek,
974 Protocol_LockRequest,
975 Protocol_UnlockRequest
978 static IInternetProtocol Protocol = { &ProtocolVtbl };
980 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
982 if(IsEqualGUID(&IID_IUnknown, riid)
983 || IsEqualGUID(&IID_IHttpNegotiate, riid)
984 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
985 *ppv = iface;
986 return S_OK;
989 ok(0, "unexpected call\n");
990 return E_NOINTERFACE;
993 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
995 return 2;
998 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
1000 return 1;
1003 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
1004 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
1006 CHECK_EXPECT(BeginningTransaction);
1008 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1010 ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
1011 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
1012 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1013 if(pszAdditionalHeaders)
1014 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1016 return S_OK;
1019 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
1020 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
1022 CHECK_EXPECT(OnResponse);
1024 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1026 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
1027 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
1028 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
1029 /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
1030 ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1031 if(pszAdditionalRequestHeaders)
1032 ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1034 return S_OK;
1037 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
1038 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1040 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
1042 CHECK_EXPECT(GetRootSecurityId);
1044 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1046 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
1047 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
1048 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
1050 if(pbSecurityId == (void*)0xdeadbeef)
1051 return E_NOTIMPL;
1053 if(pcbSecurityId) {
1054 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
1055 *pcbSecurityId = sizeof(sec_id);
1058 if(pbSecurityId)
1059 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
1061 return E_FAIL;
1064 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
1065 HttpNegotiate_QueryInterface,
1066 HttpNegotiate_AddRef,
1067 HttpNegotiate_Release,
1068 HttpNegotiate_BeginningTransaction,
1069 HttpNegotiate_OnResponse,
1070 HttpNegotiate_GetRootSecurityId
1073 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
1075 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1077 ok(0, "unexpected call\n");
1078 return E_NOINTERFACE;
1081 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1083 return 2;
1086 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1088 return 1;
1091 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1092 REFGUID guidService, REFIID riid, void **ppv)
1094 if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
1095 CHECK_EXPECT(QueryService_IAuthenticate);
1096 return E_NOTIMPL;
1099 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1100 CHECK_EXPECT2(QueryService_IInternetProtocol);
1101 return E_NOTIMPL;
1104 if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1105 CHECK_EXPECT(QueryService_IInternetBindInfo);
1106 return E_NOTIMPL;
1109 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
1110 return E_NOINTERFACE;
1113 static IServiceProviderVtbl ServiceProviderVtbl = {
1114 ServiceProvider_QueryInterface,
1115 ServiceProvider_AddRef,
1116 ServiceProvider_Release,
1117 ServiceProvider_QueryService
1120 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1122 static IBindStatusCallbackEx objbsc;
1124 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1126 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1128 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1129 CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1130 if(emulate_protocol) {
1131 *ppv = &Protocol;
1132 return S_OK;
1133 }else {
1134 return E_NOINTERFACE;
1137 else if (IsEqualGUID(&IID_IServiceProvider, riid))
1139 CHECK_EXPECT2(QueryInterface_IServiceProvider);
1140 *ppv = &ServiceProvider;
1141 return S_OK;
1143 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
1145 CHECK_EXPECT2(QueryInterface_IHttpNegotiate);
1146 *ppv = &HttpNegotiate;
1147 return S_OK;
1149 else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
1151 CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1152 *ppv = &HttpNegotiate;
1153 return S_OK;
1155 else if (IsEqualGUID(&IID_IAuthenticate, riid))
1157 CHECK_EXPECT(QueryInterface_IAuthenticate);
1158 return E_NOINTERFACE;
1160 else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
1162 CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1163 *ppv = iface;
1164 return S_OK;
1166 else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
1168 CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1169 return E_NOINTERFACE;
1171 else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid))
1173 CHECK_EXPECT(QueryInterface_IBindStatusCallbackEx);
1174 if(!use_bscex)
1175 return E_NOINTERFACE;
1176 *ppv = iface;
1177 return S_OK;
1179 else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
1181 /* TODO */
1182 CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1184 else
1186 ok(0, "unexpected interface %s\n", debugstr_guid(riid));
1189 return E_NOINTERFACE;
1192 static ULONG WINAPI statusclb_AddRef(IBindStatusCallbackEx *iface)
1194 return 2;
1197 static ULONG WINAPI statusclb_Release(IBindStatusCallbackEx *iface)
1199 return 1;
1202 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved,
1203 IBinding *pib)
1205 IWinInetHttpInfo *http_info;
1206 HRESULT hres;
1207 IMoniker *mon;
1209 if(iface == &objbsc)
1210 CHECK_EXPECT(Obj_OnStartBinding);
1211 else
1212 CHECK_EXPECT(OnStartBinding);
1214 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1216 ok(pib != NULL, "pib should not be NULL\n");
1217 ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1219 if(pib == (void*)0xdeadbeef)
1220 return S_OK;
1222 current_binding = pib;
1224 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1225 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1226 if(SUCCEEDED(hres))
1227 IMoniker_Release(mon);
1229 hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1230 ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1232 return S_OK;
1235 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1237 ok(0, "unexpected call\n");
1238 return E_NOTIMPL;
1241 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1243 ok(0, "unexpected call\n");
1244 return E_NOTIMPL;
1247 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
1248 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1250 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1252 switch(ulStatusCode) {
1253 case BINDSTATUS_FINDINGRESOURCE:
1254 if(iface == &objbsc)
1255 CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1256 else if(test_protocol == FTP_TEST)
1257 todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1258 else
1259 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1260 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1261 SetEvent(complete_event);
1262 break;
1263 case BINDSTATUS_CONNECTING:
1264 if(iface == &objbsc)
1265 CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1266 else if(test_protocol == FTP_TEST)
1267 todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
1268 else
1269 CHECK_EXPECT(OnProgress_CONNECTING);
1270 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1271 SetEvent(complete_event);
1272 break;
1273 case BINDSTATUS_SENDINGREQUEST:
1274 if(iface == &objbsc)
1275 CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1276 else if(test_protocol == FTP_TEST)
1277 CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
1278 else
1279 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1280 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1281 SetEvent(complete_event);
1282 break;
1283 case BINDSTATUS_MIMETYPEAVAILABLE:
1284 if(iface == &objbsc)
1285 CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1286 else
1287 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1288 if(!bind_to_object)
1289 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1290 download_state);
1291 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1292 break;
1293 case BINDSTATUS_BEGINDOWNLOADDATA:
1294 if(iface == &objbsc)
1295 CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1296 else
1297 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1298 ok(szStatusText != NULL, "szStatusText == NULL\n");
1299 if(szStatusText) {
1300 if(filedwl_api) {
1301 /* FIXME */
1302 }else {
1303 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1306 if(!bind_to_object)
1307 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1308 download_state);
1309 download_state = DOWNLOADING;
1310 break;
1311 case BINDSTATUS_DOWNLOADINGDATA:
1312 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1313 ok(iface != &objbsc, "unexpected call\n");
1314 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1315 download_state);
1316 break;
1317 case BINDSTATUS_ENDDOWNLOADDATA:
1318 if(iface == &objbsc)
1319 CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1320 else
1321 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1322 ok(szStatusText != NULL, "szStatusText == NULL\n");
1323 if(szStatusText) {
1324 if(filedwl_api) {
1325 /* FIXME */
1326 }else {
1327 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1330 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1331 download_state);
1332 download_state = END_DOWNLOAD;
1333 break;
1334 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1335 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST) {
1336 if(iface == &objbsc)
1337 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1338 else
1339 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1340 }else { /* FIXME */
1341 CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1342 CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1345 ok(szStatusText != NULL, "szStatusText == NULL\n");
1346 if(szStatusText && test_protocol == FILE_TEST)
1347 ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1348 break;
1349 case BINDSTATUS_CLASSIDAVAILABLE:
1351 CLSID clsid;
1352 HRESULT hr;
1353 if(iface != &objbsc)
1354 ok(0, "unexpected call\n");
1355 else if(1||emulate_protocol)
1356 CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1357 else
1358 todo_wine CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1359 hr = CLSIDFromString((LPOLESTR)szStatusText, &clsid);
1360 ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1361 ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1362 "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1363 break;
1365 case BINDSTATUS_BEGINSYNCOPERATION:
1366 CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1367 if(iface != &objbsc)
1368 ok(0, "unexpected call\n");
1369 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1370 break;
1371 case BINDSTATUS_ENDSYNCOPERATION:
1372 CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1373 if(iface != &objbsc)
1374 ok(0, "unexpected call\n");
1375 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1376 break;
1377 case BINDSTATUS_PROXYDETECTING:
1378 trace("BINDSTATUS_PROXYDETECTING\n");
1379 break;
1380 case BINDSTATUS_COOKIE_SENT:
1381 trace("BINDSTATUS_COOKIE_SENT\n");
1382 break;
1383 default:
1384 ok(0, "unexpected code %d\n", ulStatusCode);
1387 if(current_binding) {
1388 IWinInetHttpInfo *http_info;
1389 HRESULT hres;
1391 hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
1392 if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol))
1393 ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
1394 else
1395 ok(hres == E_NOINTERFACE,
1396 "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
1397 if(SUCCEEDED(hres))
1398 IWinInetHttpInfo_Release(http_info);
1401 return S_OK;
1404 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
1406 if(iface == &objbsc) {
1407 CHECK_EXPECT(Obj_OnStopBinding);
1408 stopped_obj_binding = TRUE;
1409 }else {
1410 CHECK_EXPECT(OnStopBinding);
1411 stopped_binding = TRUE;
1414 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1416 /* ignore DNS failure */
1417 if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1418 return S_OK;
1420 if(filedwl_api)
1421 ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1422 else
1423 ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1424 ok(szError == NULL, "szError should be NULL\n");
1426 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) && emulate_protocol) {
1427 SetEvent(complete_event);
1428 if(iface != &objbsc)
1429 WaitForSingleObject(complete_event2, INFINITE);
1432 return S_OK;
1435 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1437 DWORD cbSize;
1439 if(iface == &objbsc)
1440 CHECK_EXPECT(Obj_GetBindInfo);
1441 else
1442 CHECK_EXPECT(GetBindInfo);
1444 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1446 *grfBINDF = bindf;
1447 cbSize = pbindinfo->cbSize;
1448 memset(pbindinfo, 0, cbSize);
1449 pbindinfo->cbSize = cbSize;
1451 return S_OK;
1454 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
1455 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1457 HRESULT hres;
1458 DWORD readed;
1459 BYTE buf[512];
1460 CHAR clipfmt[512];
1462 if(iface == &objbsc)
1463 ok(0, "unexpected call\n");
1465 CHECK_EXPECT2(OnDataAvailable);
1467 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1469 ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
1470 "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
1471 download_state);
1472 data_available = TRUE;
1474 ok(pformatetc != NULL, "pformatetx == NULL\n");
1475 if(pformatetc) {
1476 if (mime_type[0]) {
1477 clipfmt[0] = 0;
1478 ok(GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1),
1479 "GetClipboardFormatName failed, error %d\n", GetLastError());
1480 ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
1481 pformatetc->cfFormat, clipfmt, mime_type);
1482 } else {
1483 ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
1485 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1486 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
1487 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
1488 ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1491 ok(pstgmed != NULL, "stgmeg == NULL\n");
1492 ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1493 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1495 switch(pstgmed->tymed) {
1496 case TYMED_ISTREAM:
1497 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
1498 hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
1499 ok(hres == STG_E_ACCESSDENIED,
1500 "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1502 hres = IStream_Commit(U(*pstgmed).pstm, 0);
1503 ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1505 hres = IStream_Revert(U(*pstgmed).pstm);
1506 ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
1509 ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
1510 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
1511 while(hres == S_OK);
1512 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
1513 break;
1515 case TYMED_FILE:
1516 if(test_protocol == FILE_TEST)
1517 ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1518 "unexpected file name %s\n", debugstr_w(pstgmed->u.lpszFileName));
1519 else if(emulate_protocol)
1520 ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1521 "unexpected file name %s\n", debugstr_w(pstgmed->u.lpszFileName));
1522 else
1523 ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1526 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1527 && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1528 SetEvent(complete_event);
1530 return S_OK;
1533 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
1535 CHECK_EXPECT(OnObjectAvailable);
1537 if(iface != &objbsc)
1538 ok(0, "unexpected call\n");
1540 ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
1541 ok(punk != NULL, "punk == NULL\n");
1543 return S_OK;
1546 static HRESULT WINAPI statusclb_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo,
1547 DWORD *grfBINDF2, DWORD *pdwReserved)
1549 CHECK_EXPECT(GetBindInfoEx);
1551 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1552 ok(grfBINDF2 != NULL, "grfBINDF2 == NULL\n");
1553 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1554 ok(pdwReserved != NULL, "dwReserved == NULL\n");
1556 return S_OK;
1559 static const IBindStatusCallbackExVtbl BindStatusCallbackVtbl = {
1560 statusclb_QueryInterface,
1561 statusclb_AddRef,
1562 statusclb_Release,
1563 statusclb_OnStartBinding,
1564 statusclb_GetPriority,
1565 statusclb_OnLowResource,
1566 statusclb_OnProgress,
1567 statusclb_OnStopBinding,
1568 statusclb_GetBindInfo,
1569 statusclb_OnDataAvailable,
1570 statusclb_OnObjectAvailable,
1571 statusclb_GetBindInfoEx
1574 static IBindStatusCallbackEx bsc = { &BindStatusCallbackVtbl };
1575 static IBindStatusCallbackEx objbsc = { &BindStatusCallbackVtbl };
1577 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
1579 *ppv = NULL;
1580 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1581 return E_NOINTERFACE;
1584 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
1586 return 2;
1589 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
1591 return 1;
1594 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
1596 switch(mkp) {
1597 case MIMETYPEPROP:
1598 CHECK_EXPECT(PutProperty_MIMETYPEPROP);
1599 ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", debugstr_w(val));
1600 break;
1601 case CLASSIDPROP:
1602 CHECK_EXPECT(PutProperty_CLASSIDPROP);
1603 break;
1604 default:
1605 break;
1608 return S_OK;
1611 static const IMonikerPropVtbl MonikerPropVtbl = {
1612 MonikerProp_QueryInterface,
1613 MonikerProp_AddRef,
1614 MonikerProp_Release,
1615 MonikerProp_PutProperty
1618 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
1620 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
1622 *ppv = NULL;
1624 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
1625 *ppv = iface;
1626 else if(IsEqualGUID(&IID_IMonikerProp, riid))
1627 *ppv = &MonikerProp;
1629 if(*ppv)
1630 return S_OK;
1632 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1633 return E_NOINTERFACE;
1636 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
1638 return 2;
1641 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
1643 return 1;
1646 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
1648 ok(0, "unexpected call\n");
1649 return E_NOTIMPL;
1652 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
1654 ok(0, "unexpected call\n");
1655 return E_NOTIMPL;
1658 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
1659 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
1661 IUnknown *unk;
1662 HRESULT hres;
1664 static WCHAR cbinding_contextW[] =
1665 {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
1667 CHECK_EXPECT(Load);
1668 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1670 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1671 ok(!fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1672 else
1673 ok(fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1674 ok(pimkName != NULL, "pimkName == NULL\n");
1675 ok(pibc != NULL, "pibc == NULL\n");
1676 ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
1678 hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
1679 ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
1680 if(SUCCEEDED(hres)) {
1681 IBinding *binding;
1683 hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
1684 ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
1686 IBinding_Release(binding);
1687 IUnknown_Release(unk);
1690 SET_EXPECT(QueryInterface_IServiceProvider);
1691 hres = RegisterBindStatusCallback(pibc, (IBindStatusCallback*)&bsc, NULL, 0);
1692 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
1693 CHECK_CALLED(QueryInterface_IServiceProvider);
1695 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1696 SET_EXPECT(GetBindInfo);
1697 SET_EXPECT(OnStartBinding);
1698 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1699 if(test_protocol == FILE_TEST)
1700 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1701 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1702 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1703 SET_EXPECT(LockRequest);
1704 SET_EXPECT(OnDataAvailable);
1705 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1706 SET_EXPECT(OnStopBinding);
1708 hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
1709 ok(hres == S_OK, "Load failed: %08x\n", hres);
1711 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
1712 CHECK_CALLED(GetBindInfo);
1713 CHECK_CALLED(OnStartBinding);
1714 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
1715 if(test_protocol == FILE_TEST)
1716 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1717 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1718 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
1719 CHECK_CALLED(LockRequest);
1720 CHECK_CALLED(OnDataAvailable);
1721 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1722 CHECK_CALLED(OnStopBinding);
1724 if(unk)
1725 IUnknown_Release(unk);
1727 return S_OK;
1730 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
1732 ok(0, "unexpected call\n");
1733 return E_NOTIMPL;
1736 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
1738 ok(0, "unexpected call\n");
1739 return E_NOTIMPL;
1742 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
1744 ok(0, "unexpected call\n");
1745 return E_NOTIMPL;
1748 static const IPersistMonikerVtbl PersistMonikerVtbl = {
1749 PersistMoniker_QueryInterface,
1750 PersistMoniker_AddRef,
1751 PersistMoniker_Release,
1752 PersistMoniker_GetClassID,
1753 PersistMoniker_IsDirty,
1754 PersistMoniker_Load,
1755 PersistMoniker_Save,
1756 PersistMoniker_SaveCompleted,
1757 PersistMoniker_GetCurMoniker
1760 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
1762 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1764 *ppv = NULL;
1766 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1767 *ppv = iface;
1768 return S_OK;
1771 if(IsEqualGUID(&IID_IMarshal, riid))
1772 return E_NOINTERFACE;
1773 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1774 return E_NOINTERFACE;
1776 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1777 return E_NOTIMPL;
1780 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1782 return 2;
1785 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1787 return 1;
1790 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1792 CHECK_EXPECT(CreateInstance);
1793 ok(!outer, "outer = %p\n", outer);
1794 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1795 *ppv = &PersistMoniker;
1796 return S_OK;
1799 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1801 ok(0, "unexpected call\n");
1802 return S_OK;
1805 static const IClassFactoryVtbl ClassFactoryVtbl = {
1806 ClassFactory_QueryInterface,
1807 ClassFactory_AddRef,
1808 ClassFactory_Release,
1809 ClassFactory_CreateInstance,
1810 ClassFactory_LockServer
1813 static IClassFactory mime_cf = { &ClassFactoryVtbl };
1815 static void test_CreateAsyncBindCtx(void)
1817 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
1818 IUnknown *unk;
1819 HRESULT hres;
1820 ULONG ref;
1821 BIND_OPTS bindopts;
1823 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
1824 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1825 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
1827 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
1828 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1830 SET_EXPECT(QueryInterface_IServiceProvider);
1831 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
1832 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
1833 CHECK_CALLED(QueryInterface_IServiceProvider);
1835 bindopts.cbStruct = sizeof(bindopts);
1836 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1837 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1838 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1839 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1840 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1841 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1842 bindopts.grfMode);
1843 ok(bindopts.dwTickCountDeadline == 0,
1844 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1846 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1847 ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
1848 if(SUCCEEDED(hres))
1849 IUnknown_Release(unk);
1851 ref = IBindCtx_Release(bctx);
1852 ok(ref == 0, "bctx should be destroyed here\n");
1855 static void test_CreateAsyncBindCtxEx(void)
1857 IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
1858 IUnknown *unk;
1859 BIND_OPTS bindopts;
1860 HRESULT hres;
1862 static WCHAR testW[] = {'t','e','s','t',0};
1864 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
1865 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
1867 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1868 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1870 if(SUCCEEDED(hres)) {
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 IBindCtx_Release(bctx);
1885 CreateBindCtx(0, &bctx_arg);
1886 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1887 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1889 if(SUCCEEDED(hres)) {
1890 bindopts.cbStruct = sizeof(bindopts);
1891 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1892 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1893 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1894 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1895 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1896 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1897 bindopts.grfMode);
1898 ok(bindopts.dwTickCountDeadline == 0,
1899 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1901 IBindCtx_Release(bctx);
1904 IBindCtx_Release(bctx_arg);
1906 SET_EXPECT(QueryInterface_IServiceProvider);
1907 hres = CreateAsyncBindCtxEx(NULL, 0, (IBindStatusCallback*)&bsc, NULL, &bctx, 0);
1908 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1909 CHECK_CALLED(QueryInterface_IServiceProvider);
1911 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1912 ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
1913 if(SUCCEEDED(hres))
1914 IUnknown_Release(unk);
1916 IBindCtx_Release(bctx);
1918 hres = CreateBindCtx(0, &bctx2);
1919 ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
1921 hres = CreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
1922 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1924 hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
1925 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
1927 hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
1928 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1929 ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
1931 IBindCtx_Release(bctx);
1932 IBindCtx_Release(bctx2);
1935 static void test_GetBindInfoEx(IBindStatusCallback *holder)
1937 IBindStatusCallbackEx *bscex;
1938 BINDINFO bindinfo = {sizeof(bindinfo)};
1939 DWORD bindf, bindf2, dw;
1940 HRESULT hres;
1942 hres = IBindStatusCallback_QueryInterface(holder, &IID_IBindStatusCallbackEx, (void**)&bscex);
1943 if(FAILED(hres)) {
1944 win_skip("IBindStatusCallbackEx not supported\n");
1945 return;
1948 use_bscex = TRUE;
1950 bindf = 0;
1951 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1952 SET_EXPECT(GetBindInfoEx);
1953 hres = IBindStatusCallback_GetBindInfo(holder, &bindf, &bindinfo);
1954 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1955 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1956 CHECK_CALLED(GetBindInfoEx);
1958 bindf = bindf2 = dw = 0;
1959 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1960 SET_EXPECT(GetBindInfoEx);
1961 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
1962 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1963 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1964 CHECK_CALLED(GetBindInfoEx);
1966 use_bscex = FALSE;
1968 bindf = bindf2 = dw = 0xdeadbeef;
1969 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1970 SET_EXPECT(GetBindInfo);
1971 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
1972 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1973 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1974 CHECK_CALLED(GetBindInfo);
1975 ok(bindf2 == 0xdeadbeef, "bindf2 = %x\n", bindf2);
1976 ok(dw == 0xdeadbeef, "dw = %x\n", dw);
1978 IBindStatusCallbackEx_Release(bscex);
1981 static BOOL test_bscholder(IBindStatusCallback *holder)
1983 IServiceProvider *serv_prov;
1984 IHttpNegotiate *http_negotiate, *http_negotiate_serv;
1985 IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
1986 IAuthenticate *authenticate, *authenticate_serv;
1987 IInternetProtocol *protocol;
1988 BINDINFO bindinfo = {sizeof(bindinfo)};
1989 BOOL ret = TRUE;
1990 LPWSTR wstr;
1991 DWORD dw;
1992 HRESULT hres;
1994 hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
1995 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
1997 dw = 0xdeadbeef;
1998 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1999 SET_EXPECT(GetBindInfo);
2000 hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
2001 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2002 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2003 CHECK_CALLED(GetBindInfo);
2005 test_GetBindInfoEx(holder);
2007 SET_EXPECT(OnStartBinding);
2008 hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
2009 ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
2010 CHECK_CALLED(OnStartBinding);
2012 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
2013 ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
2015 SET_EXPECT(QueryInterface_IHttpNegotiate);
2016 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2017 (void**)&http_negotiate_serv);
2018 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2019 CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
2021 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2023 wstr = (void*)0xdeadbeef;
2024 SET_EXPECT(QueryInterface_IHttpNegotiate);
2025 SET_EXPECT(BeginningTransaction);
2026 hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
2027 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2028 CHECK_CALLED(BeginningTransaction);
2029 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
2030 ok(wstr == NULL, "wstr = %p\n", wstr);
2032 IHttpNegotiate_Release(http_negotiate_serv);
2034 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2035 (void**)&http_negotiate_serv);
2036 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2037 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2038 IHttpNegotiate_Release(http_negotiate_serv);
2040 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
2041 if(SUCCEEDED(hres)) {
2042 have_IHttpNegotiate2 = TRUE;
2044 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2045 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
2046 (void**)&http_negotiate2_serv);
2047 ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
2048 CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
2049 ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
2051 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2052 SET_EXPECT(GetRootSecurityId);
2053 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
2054 ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
2055 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2); /* IE8 */
2056 CHECK_CALLED(GetRootSecurityId);
2058 IHttpNegotiate_Release(http_negotiate2_serv);
2059 IHttpNegotiate_Release(http_negotiate2);
2060 }else {
2061 skip("Could not get IHttpNegotiate2\n");
2062 ret = FALSE;
2065 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2066 hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
2067 ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
2068 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2070 SET_EXPECT(QueryInterface_IHttpNegotiate);
2071 SET_EXPECT(OnResponse);
2072 wstr = (void*)0xdeadbeef;
2073 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
2074 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2075 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2076 CHECK_CALLED(OnResponse);
2078 IHttpNegotiate_Release(http_negotiate);
2080 hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
2081 ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
2083 SET_EXPECT(QueryInterface_IAuthenticate);
2084 SET_EXPECT(QueryService_IAuthenticate);
2085 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2086 (void**)&authenticate_serv);
2087 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2088 CLEAR_CALLED(QueryInterface_IAuthenticate); /* IE <8 */
2089 CLEAR_CALLED(QueryService_IAuthenticate); /* IE <8 */
2090 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2091 IAuthenticate_Release(authenticate_serv);
2093 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2094 (void**)&authenticate_serv);
2095 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2096 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2098 IAuthenticate_Release(authenticate);
2099 IAuthenticate_Release(authenticate_serv);
2101 SET_EXPECT(OnStopBinding);
2102 hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
2103 ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
2104 CHECK_CALLED(OnStopBinding);
2106 SET_EXPECT(QueryInterface_IInternetProtocol);
2107 SET_EXPECT(QueryService_IInternetProtocol);
2108 hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
2109 (void**)&protocol);
2110 ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
2111 CHECK_CALLED(QueryInterface_IInternetProtocol);
2112 CHECK_CALLED(QueryService_IInternetProtocol);
2114 IServiceProvider_Release(serv_prov);
2115 return ret;
2118 static BOOL test_RegisterBindStatusCallback(void)
2120 IBindStatusCallback *prevbsc, *clb;
2121 IBindCtx *bindctx;
2122 BOOL ret = TRUE;
2123 IUnknown *unk;
2124 HRESULT hres;
2126 hres = CreateBindCtx(0, &bindctx);
2127 ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
2129 SET_EXPECT(QueryInterface_IServiceProvider);
2131 hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
2132 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2134 SET_EXPECT(QueryInterface_IBindStatusCallback);
2135 SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
2136 prevbsc = (void*)0xdeadbeef;
2137 hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2138 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2139 ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc=%p\n", prevbsc);
2140 CHECK_CALLED(QueryInterface_IBindStatusCallback);
2141 CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
2143 CHECK_CALLED(QueryInterface_IServiceProvider);
2145 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2146 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2148 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2149 IUnknown_Release(unk);
2150 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2151 ok(clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2153 if(!test_bscholder(clb))
2154 ret = FALSE;
2156 IBindStatusCallback_Release(clb);
2158 hres = RevokeBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc);
2159 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2161 unk = (void*)0xdeadbeef;
2162 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2163 ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
2164 ok(unk == NULL, "unk != NULL\n");
2166 if(unk)
2167 IUnknown_Release(unk);
2169 hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
2170 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2172 hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
2173 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2175 hres = RevokeBindStatusCallback(bindctx, NULL);
2176 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2178 IBindCtx_Release(bindctx);
2179 return ret;
2182 #define BINDTEST_EMULATE 1
2183 #define BINDTEST_TOOBJECT 2
2184 #define BINDTEST_FILEDWLAPI 4
2186 static void init_bind_test(int protocol, DWORD flags, DWORD t)
2188 test_protocol = protocol;
2189 emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
2190 download_state = BEFORE_DOWNLOAD;
2191 stopped_binding = FALSE;
2192 stopped_obj_binding = FALSE;
2193 data_available = FALSE;
2194 mime_type[0] = 0;
2195 binding_hres = S_OK;
2196 bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
2197 tymed = t;
2198 filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
2201 static void test_BindToStorage(int protocol, BOOL emul, DWORD t)
2203 IMoniker *mon;
2204 HRESULT hres;
2205 LPOLESTR display_name;
2206 IBindCtx *bctx;
2207 MSG msg;
2208 IBindStatusCallback *previousclb;
2209 IUnknown *unk = (IUnknown*)0x00ff00ff;
2210 IBinding *bind;
2212 init_bind_test(protocol, emul ? BINDTEST_EMULATE : 0, t);
2214 SET_EXPECT(QueryInterface_IServiceProvider);
2215 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2216 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2217 CHECK_CALLED(QueryInterface_IServiceProvider);
2218 if(FAILED(hres))
2219 return;
2221 SET_EXPECT(QueryInterface_IServiceProvider);
2222 hres = RegisterBindStatusCallback(bctx, (IBindStatusCallback*)&bsc, &previousclb, 0);
2223 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2224 ok(previousclb == (IBindStatusCallback*)&bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2225 CHECK_CALLED(QueryInterface_IServiceProvider);
2226 if(previousclb)
2227 IBindStatusCallback_Release(previousclb);
2229 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2230 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2231 if(FAILED(hres)) {
2232 IBindCtx_Release(bctx);
2233 return;
2236 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2237 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2238 if(SUCCEEDED(hres))
2239 IBinding_Release(bind);
2241 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2242 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2243 ok(!lstrcmpW(display_name, urls[test_protocol]),
2244 "GetDisplayName got wrong name %s\n", debugstr_w(display_name));
2245 CoTaskMemFree(display_name);
2247 if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
2248 binding_hres = INET_E_DATA_NOT_AVAILABLE;
2250 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2251 SET_EXPECT(GetBindInfo);
2252 SET_EXPECT(QueryInterface_IInternetProtocol);
2253 if(!emulate_protocol)
2254 SET_EXPECT(QueryService_IInternetProtocol);
2255 SET_EXPECT(OnStartBinding);
2256 if(emulate_protocol) {
2257 if(is_urlmon_protocol(test_protocol))
2258 SET_EXPECT(SetPriority);
2259 SET_EXPECT(Start);
2260 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2261 SET_EXPECT(Terminate);
2262 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2263 SET_EXPECT(UnlockRequest);
2264 }else {
2265 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2266 SET_EXPECT(QueryInterface_IInternetBindInfo);
2267 SET_EXPECT(QueryService_IInternetBindInfo);
2268 SET_EXPECT(QueryInterface_IHttpNegotiate);
2269 SET_EXPECT(BeginningTransaction);
2270 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2271 SET_EXPECT(GetRootSecurityId);
2272 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2273 SET_EXPECT(OnProgress_CONNECTING);
2275 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST
2276 || test_protocol == FILE_TEST)
2277 SET_EXPECT(OnProgress_SENDINGREQUEST);
2278 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2279 SET_EXPECT(QueryInterface_IHttpNegotiate);
2280 SET_EXPECT(OnResponse);
2282 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2283 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2284 if(test_protocol == FILE_TEST)
2285 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2286 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2287 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2288 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2289 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2290 SET_EXPECT(OnDataAvailable);
2291 SET_EXPECT(OnStopBinding);
2294 hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2295 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2296 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2298 skip("Network unreachable, skipping tests\n");
2299 return;
2302 if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
2303 || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2304 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2305 ok(unk == NULL, "istr should be NULL\n");
2306 }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
2307 ok(hres == INET_E_DATA_NOT_AVAILABLE,
2308 "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
2309 ok(unk == NULL, "istr should be NULL\n");
2310 }else {
2311 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2312 ok(unk != NULL, "unk == NULL\n");
2314 if(unk)
2315 IUnknown_Release(unk);
2317 if(FAILED(hres))
2318 return;
2320 while((bindf & BINDF_ASYNCHRONOUS) &&
2321 !stopped_binding && GetMessage(&msg,NULL,0,0)) {
2322 TranslateMessage(&msg);
2323 DispatchMessage(&msg);
2326 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2327 CHECK_CALLED(GetBindInfo);
2328 CHECK_CALLED(QueryInterface_IInternetProtocol);
2329 if(!emulate_protocol)
2330 CHECK_CALLED(QueryService_IInternetProtocol);
2331 CHECK_CALLED(OnStartBinding);
2332 if(emulate_protocol) {
2333 if(is_urlmon_protocol(test_protocol))
2334 CHECK_CALLED(SetPriority);
2335 CHECK_CALLED(Start);
2336 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2337 if(tymed == TYMED_FILE)
2338 CLEAR_CALLED(Read);
2339 CHECK_CALLED(Terminate);
2341 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2342 CHECK_CALLED(UnlockRequest);
2343 }else {
2344 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2345 CLEAR_CALLED(QueryInterface_IInternetBindInfo);
2346 CLEAR_CALLED(QueryService_IInternetBindInfo);
2347 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2348 CHECK_CALLED(BeginningTransaction);
2349 if (have_IHttpNegotiate2)
2351 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2352 CHECK_CALLED(GetRootSecurityId);
2354 if(http_is_first || test_protocol == HTTPS_TEST) {
2355 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2356 CHECK_CALLED(OnProgress_CONNECTING);
2357 }else todo_wine {
2358 CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
2359 /* IE7 does call this */
2360 CLEAR_CALLED(OnProgress_CONNECTING);
2363 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2364 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2365 else if(test_protocol == FTP_TEST)
2366 todo_wine CHECK_CALLED(OnProgress_SENDINGREQUEST);
2367 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2368 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2369 CHECK_CALLED(OnResponse);
2371 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2372 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2373 if(test_protocol == FILE_TEST)
2374 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2375 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2376 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2377 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2378 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2379 CHECK_CALLED(OnDataAvailable);
2380 CHECK_CALLED(OnStopBinding);
2383 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2384 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2386 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2387 http_is_first = FALSE;
2390 static void test_BindToObject(int protocol, BOOL emul)
2392 IMoniker *mon;
2393 HRESULT hres;
2394 LPOLESTR display_name;
2395 IBindCtx *bctx;
2396 DWORD regid;
2397 MSG msg;
2398 IUnknown *unk = (IUnknown*)0x00ff00ff;
2399 IBinding *bind;
2401 init_bind_test(protocol, BINDTEST_TOOBJECT | (emul ? BINDTEST_EMULATE : 0), TYMED_ISTREAM);
2403 if(emul)
2404 CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
2405 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2407 SET_EXPECT(QueryInterface_IServiceProvider);
2408 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&objbsc, NULL, &bctx);
2409 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
2410 CHECK_CALLED(QueryInterface_IServiceProvider);
2411 if(FAILED(hres))
2412 return;
2414 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2415 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2416 if(FAILED(hres)) {
2417 IBindCtx_Release(bctx);
2418 return;
2421 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2422 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2423 if(SUCCEEDED(hres))
2424 IBinding_Release(bind);
2426 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2427 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2428 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
2430 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2431 SET_EXPECT(Obj_GetBindInfo);
2432 SET_EXPECT(QueryInterface_IInternetProtocol);
2433 if(!emulate_protocol)
2434 SET_EXPECT(QueryService_IInternetProtocol);
2435 SET_EXPECT(Obj_OnStartBinding);
2436 if(emulate_protocol) {
2437 if(is_urlmon_protocol(test_protocol))
2438 SET_EXPECT(SetPriority);
2439 SET_EXPECT(Start);
2440 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2441 SET_EXPECT(Terminate);
2442 if(test_protocol == FILE_TEST)
2443 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2444 SET_EXPECT(UnlockRequest);
2445 }else {
2446 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2447 SET_EXPECT(QueryInterface_IHttpNegotiate);
2448 SET_EXPECT(BeginningTransaction);
2449 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2450 SET_EXPECT(GetRootSecurityId);
2451 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
2452 SET_EXPECT(Obj_OnProgress_CONNECTING);
2454 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2455 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
2456 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2457 SET_EXPECT(QueryInterface_IHttpNegotiate);
2458 SET_EXPECT(OnResponse);
2460 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
2461 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
2462 if(test_protocol == FILE_TEST)
2463 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2464 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2465 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2466 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
2467 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
2468 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
2469 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
2470 SET_EXPECT(OnObjectAvailable);
2471 SET_EXPECT(Obj_OnStopBinding);
2474 hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
2476 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2477 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2479 skip( "Network unreachable, skipping tests\n" );
2480 return;
2483 /* no point testing the calls if binding didn't even work */
2484 if (FAILED(hres)) return;
2486 if(bindf & BINDF_ASYNCHRONOUS) {
2487 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
2488 ok(unk == NULL, "istr should be NULL\n");
2489 }else {
2490 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2491 ok(unk != NULL, "unk == NULL\n");
2492 if(emul)
2493 ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
2495 if(unk)
2496 IUnknown_Release(unk);
2498 while((bindf & BINDF_ASYNCHRONOUS) &&
2499 !((!emul || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
2500 TranslateMessage(&msg);
2501 DispatchMessage(&msg);
2504 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx);
2505 CHECK_CALLED(Obj_GetBindInfo);
2506 CHECK_CALLED(QueryInterface_IInternetProtocol);
2507 if(!emulate_protocol)
2508 CHECK_CALLED(QueryService_IInternetProtocol);
2509 CHECK_CALLED(Obj_OnStartBinding);
2510 if(emulate_protocol) {
2511 if(is_urlmon_protocol(test_protocol))
2512 CHECK_CALLED(SetPriority);
2513 CHECK_CALLED(Start);
2514 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2515 CHECK_CALLED(Terminate);
2516 if(test_protocol == FILE_TEST)
2517 CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
2518 CHECK_CALLED(UnlockRequest);
2519 }else {
2520 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2521 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2522 CHECK_CALLED(BeginningTransaction);
2523 if (have_IHttpNegotiate2)
2525 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2526 CHECK_CALLED(GetRootSecurityId);
2528 if(http_is_first) {
2529 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2530 CHECK_CALLED(Obj_OnProgress_CONNECTING);
2531 }else todo_wine {
2532 CHECK_NOT_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2533 /* IE7 does call this */
2534 CLEAR_CALLED(Obj_OnProgress_CONNECTING);
2537 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
2538 if(urls[test_protocol] == SHORT_RESPONSE_URL)
2539 CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
2540 else
2541 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
2543 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2544 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2545 CHECK_CALLED(OnResponse);
2547 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
2548 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
2549 if(test_protocol == FILE_TEST)
2550 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2551 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2552 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2553 CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
2554 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
2555 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
2556 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
2557 CHECK_CALLED(OnObjectAvailable);
2558 CHECK_CALLED(Obj_OnStopBinding);
2561 if(test_protocol != HTTP_TEST || test_protocol == HTTPS_TEST || emul || urls[test_protocol] == SHORT_RESPONSE_URL) {
2562 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2563 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2564 }else {
2565 todo_wine ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2567 if(bindf & BINDF_ASYNCHRONOUS)
2568 IBindCtx_Release(bctx);
2569 else
2570 todo_wine ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2573 if(emul)
2574 CoRevokeClassObject(regid);
2576 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2577 http_is_first = FALSE;
2580 static void test_URLDownloadToFile(DWORD prot, BOOL emul)
2582 BOOL res;
2583 HRESULT hres;
2585 init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);
2587 SET_EXPECT(GetBindInfo);
2588 SET_EXPECT(QueryInterface_IInternetProtocol);
2589 if(!emulate_protocol) {
2590 SET_EXPECT(QueryInterface_IServiceProvider);
2591 SET_EXPECT(QueryService_IInternetProtocol);
2593 SET_EXPECT(OnStartBinding);
2594 if(emulate_protocol) {
2595 if(is_urlmon_protocol(test_protocol))
2596 SET_EXPECT(SetPriority);
2597 SET_EXPECT(Start);
2598 SET_EXPECT(UnlockRequest);
2599 }else {
2600 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2601 SET_EXPECT(QueryInterface_IHttpNegotiate);
2602 SET_EXPECT(BeginningTransaction);
2603 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2604 SET_EXPECT(GetRootSecurityId);
2606 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2607 SET_EXPECT(OnProgress_SENDINGREQUEST);
2608 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2609 SET_EXPECT(QueryInterface_IHttpNegotiate);
2610 SET_EXPECT(OnResponse);
2612 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2613 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2614 if(test_protocol == FILE_TEST)
2615 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2616 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2617 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2618 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2619 SET_EXPECT(OnStopBinding);
2622 hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol],
2623 dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
2624 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2626 CHECK_CALLED(GetBindInfo);
2627 CHECK_CALLED(QueryInterface_IInternetProtocol);
2628 if(!emulate_protocol) {
2629 CHECK_CALLED(QueryInterface_IServiceProvider);
2630 CHECK_CALLED(QueryService_IInternetProtocol);
2632 CHECK_CALLED(OnStartBinding);
2633 if(emulate_protocol) {
2634 if(is_urlmon_protocol(test_protocol))
2635 CHECK_CALLED(SetPriority);
2636 CHECK_CALLED(Start);
2637 CHECK_CALLED(UnlockRequest);
2638 }else {
2639 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2640 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2641 CHECK_CALLED(BeginningTransaction);
2642 if (have_IHttpNegotiate2)
2644 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2645 CHECK_CALLED(GetRootSecurityId);
2648 if(test_protocol == FILE_TEST)
2649 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2650 else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2651 CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
2652 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2653 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2654 CHECK_CALLED(OnResponse);
2656 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2657 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2658 if(test_protocol == FILE_TEST)
2659 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2660 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2661 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2662 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2663 CHECK_CALLED(OnStopBinding);
2666 res = DeleteFileA(dwl_htmlA);
2667 ok(res, "DeleteFile failed: %u\n", GetLastError());
2669 if(prot != FILE_TEST || emul)
2670 return;
2672 hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
2673 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2675 res = DeleteFileA(dwl_htmlA);
2676 ok(res, "DeleteFile failed: %u\n", GetLastError());
2679 static void set_file_url(char *path)
2681 CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
2682 CHAR INDEX_HTMLA[MAX_PATH];
2684 lstrcpyA(file_urlA, "file:///");
2685 lstrcatA(file_urlA, path);
2686 MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
2688 lstrcpyA(INDEX_HTMLA, "file://");
2689 lstrcatA(INDEX_HTMLA, path);
2690 MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
2693 static void create_file(void)
2695 HANDLE file;
2696 DWORD size;
2697 CHAR path[MAX_PATH];
2699 static const char html_doc[] = "<HTML></HTML>";
2701 file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2702 FILE_ATTRIBUTE_NORMAL, NULL);
2703 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2704 if(file == INVALID_HANDLE_VALUE)
2705 return;
2707 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2708 CloseHandle(file);
2710 GetCurrentDirectoryA(MAX_PATH, path);
2711 lstrcatA(path, "\\");
2712 lstrcatA(path, wszIndexHtmlA);
2713 set_file_url(path);
2716 static void test_ReportResult(HRESULT exhres)
2718 IMoniker *mon = NULL;
2719 IBindCtx *bctx = NULL;
2720 IUnknown *unk = (void*)0xdeadbeef;
2721 HRESULT hres;
2723 init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2724 binding_hres = exhres;
2726 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2727 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2729 SET_EXPECT(QueryInterface_IServiceProvider);
2730 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2731 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2732 CHECK_CALLED(QueryInterface_IServiceProvider);
2734 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2735 SET_EXPECT(GetBindInfo);
2736 SET_EXPECT(QueryInterface_IInternetProtocol);
2737 SET_EXPECT(OnStartBinding);
2738 if(is_urlmon_protocol(test_protocol))
2739 SET_EXPECT(SetPriority);
2740 SET_EXPECT(Start);
2742 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2743 if(SUCCEEDED(exhres))
2744 ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
2745 else
2746 ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
2747 "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
2749 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2750 CHECK_CALLED(GetBindInfo);
2751 CHECK_CALLED(QueryInterface_IInternetProtocol);
2752 CHECK_CALLED(OnStartBinding);
2753 if(is_urlmon_protocol(test_protocol))
2754 CHECK_CALLED(SetPriority);
2755 CHECK_CALLED(Start);
2757 ok(unk == NULL, "unk=%p\n", unk);
2759 IBindCtx_Release(bctx);
2760 IMoniker_Release(mon);
2763 static void test_BindToStorage_fail(void)
2765 IMoniker *mon = NULL;
2766 IBindCtx *bctx = NULL;
2767 IUnknown *unk;
2768 HRESULT hres;
2770 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2771 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2772 if(FAILED(hres))
2773 return;
2775 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2776 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2778 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2779 ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
2780 "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
2782 IBindCtx_Release(bctx);
2784 IMoniker_Release(mon);
2786 test_ReportResult(E_NOTIMPL);
2787 test_ReportResult(S_FALSE);
2790 static void test_StdURLMoniker(void)
2792 IMoniker *mon, *async_mon;
2793 LPOLESTR display_name;
2794 HRESULT hres;
2796 hres = CoCreateInstance(&IID_IInternet, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2797 &IID_IMoniker, (void**)&mon);
2798 ok(hres == S_OK, "Could not create IInternet instance: %08x\n", hres);
2799 if(FAILED(hres))
2800 return;
2802 hres = IMoniker_QueryInterface(mon, &IID_IAsyncMoniker, (void**)&async_mon);
2803 ok(hres == S_OK, "Could not get IAsyncMoniker iface: %08x\n", hres);
2804 ok(mon == async_mon, "mon != async_mon\n");
2805 IMoniker_Release(async_mon);
2807 hres = IMoniker_GetDisplayName(mon, NULL, NULL, &display_name);
2808 ok(hres == E_OUTOFMEMORY, "GetDisplayName failed: %08x, expected E_OUTOFMEMORY\n", hres);
2810 IMoniker_Release(mon);
2813 static void gecko_installer_workaround(BOOL disable)
2815 HKEY hkey;
2816 DWORD res;
2818 static BOOL has_url = FALSE;
2819 static char url[2048];
2821 if(!disable && !has_url)
2822 return;
2824 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2825 if(res != ERROR_SUCCESS)
2826 return;
2828 if(disable) {
2829 DWORD type, size = sizeof(url);
2831 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2832 if(res == ERROR_SUCCESS && type == REG_SZ)
2833 has_url = TRUE;
2835 RegDeleteValue(hkey, "GeckoUrl");
2836 }else {
2837 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2840 RegCloseKey(hkey);
2843 START_TEST(url)
2845 gecko_installer_workaround(TRUE);
2847 complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2848 complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2849 thread_id = GetCurrentThreadId();
2850 create_file();
2852 test_create();
2854 trace("test CreateAsyncBindCtx...\n");
2855 test_CreateAsyncBindCtx();
2857 trace("test CreateAsyncBindCtxEx...\n");
2858 test_CreateAsyncBindCtxEx();
2860 trace("test RegisterBindStatusCallback...\n");
2861 if(test_RegisterBindStatusCallback()) {
2862 trace("test BindToStorage failures...\n");
2863 test_BindToStorage_fail();
2865 trace("synchronous http test (COM not initialised)...\n");
2866 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2868 CoInitialize(NULL);
2870 trace("test StdURLMoniker...\n");
2871 test_StdURLMoniker();
2873 trace("synchronous http test...\n");
2874 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2876 trace("synchronous http test (to object)...\n");
2877 test_BindToObject(HTTP_TEST, FALSE);
2879 trace("synchronous file test...\n");
2880 test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2882 trace("synchronous file test (to object)...\n");
2883 test_BindToObject(FILE_TEST, FALSE);
2885 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2887 trace("http test...\n");
2888 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2890 trace("http test (to file)...\n");
2891 test_BindToStorage(HTTP_TEST, FALSE, TYMED_FILE);
2893 trace("http test (to object)...\n");
2894 test_BindToObject(HTTP_TEST, FALSE);
2896 trace("http test (short response)...\n");
2897 http_is_first = TRUE;
2898 urls[HTTP_TEST] = SHORT_RESPONSE_URL;
2899 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2901 trace("http test (short response, to object)...\n");
2902 test_BindToObject(HTTP_TEST, FALSE);
2904 trace("emulated http test...\n");
2905 test_BindToStorage(HTTP_TEST, TRUE, TYMED_ISTREAM);
2907 trace("emulated http test (to object)...\n");
2908 test_BindToObject(HTTP_TEST, TRUE);
2910 trace("emulated http test (to file)...\n");
2911 test_BindToStorage(HTTP_TEST, TRUE, TYMED_FILE);
2913 trace("asynchronous https test...\n");
2914 test_BindToStorage(HTTPS_TEST, FALSE, TYMED_ISTREAM);
2916 trace("emulated https test...\n");
2917 test_BindToStorage(HTTPS_TEST, TRUE, TYMED_ISTREAM);
2919 trace("about test...\n");
2920 test_BindToStorage(ABOUT_TEST, FALSE, TYMED_ISTREAM);
2922 trace("about test (to file)...\n");
2923 test_BindToStorage(ABOUT_TEST, FALSE, TYMED_FILE);
2925 trace("about test (to object)...\n");
2926 test_BindToObject(ABOUT_TEST, FALSE);
2928 trace("emulated about test...\n");
2929 test_BindToStorage(ABOUT_TEST, TRUE, TYMED_ISTREAM);
2931 trace("emulated about test (to file)...\n");
2932 test_BindToStorage(ABOUT_TEST, TRUE, TYMED_FILE);
2934 trace("emulated about test (to object)...\n");
2935 test_BindToObject(ABOUT_TEST, TRUE);
2937 trace("file test...\n");
2938 test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2940 trace("file test (to file)...\n");
2941 test_BindToStorage(FILE_TEST, FALSE, TYMED_FILE);
2943 trace("file test (to object)...\n");
2944 test_BindToObject(FILE_TEST, FALSE);
2946 trace("emulated file test...\n");
2947 test_BindToStorage(FILE_TEST, TRUE, TYMED_ISTREAM);
2949 trace("emulated file test (to file)...\n");
2950 test_BindToStorage(FILE_TEST, TRUE, TYMED_FILE);
2952 trace("emulated file test (to object)...\n");
2953 test_BindToObject(FILE_TEST, TRUE);
2955 trace("emulated its test...\n");
2956 test_BindToStorage(ITS_TEST, TRUE, TYMED_ISTREAM);
2958 trace("emulated its test (to file)...\n");
2959 test_BindToStorage(ITS_TEST, TRUE, TYMED_FILE);
2961 trace("emulated mk test...\n");
2962 test_BindToStorage(MK_TEST, TRUE, TYMED_ISTREAM);
2964 trace("test URLDownloadToFile for file protocol...\n");
2965 test_URLDownloadToFile(FILE_TEST, FALSE);
2967 trace("test URLDownloadToFile for emulated file protocol...\n");
2968 test_URLDownloadToFile(FILE_TEST, TRUE);
2970 trace("test URLDownloadToFile for http protocol...\n");
2971 test_URLDownloadToFile(HTTP_TEST, FALSE);
2973 bindf |= BINDF_NOWRITECACHE;
2975 trace("ftp test...\n");
2976 test_BindToStorage(FTP_TEST, FALSE, TYMED_ISTREAM);
2978 trace("test failures...\n");
2979 test_BindToStorage_fail();
2982 DeleteFileA(wszIndexHtmlA);
2983 CloseHandle(complete_event);
2984 CloseHandle(complete_event2);
2985 CoUninitialize();
2987 gecko_installer_workaround(FALSE);