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
26 #define NONAMELESSUNION
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) \
50 ok(expect_ ##func, "unexpected call " #func "\n"); \
51 called_ ## func = TRUE; \
54 #define CHECK_EXPECT(func) \
56 CHECK_EXPECT2(func); \
57 expect_ ## func = FALSE; \
60 #define CHECK_CALLED(func) \
62 ok(called_ ## func, "expected " #func "\n"); \
63 expect_ ## func = called_ ## func = FALSE; \
66 #define CHECK_NOT_CALLED(func) \
68 ok(!called_ ## func, "unexpected " #func "\n"); \
69 expect_ ## func = called_ ## func = FALSE; \
72 #define CLEAR_CALLED(func) \
73 expect_ ## func = called_ ## func = FALSE
75 DEFINE_EXPECT(QueryInterface_IServiceProvider);
76 DEFINE_EXPECT(QueryInterface_IHttpNegotiate);
77 DEFINE_EXPECT(QueryInterface_IBindStatusCallback);
78 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackHolder);
79 DEFINE_EXPECT(QueryInterface_IInternetBindInfo);
80 DEFINE_EXPECT(QueryInterface_IAuthenticate);
81 DEFINE_EXPECT(QueryInterface_IInternetProtocol);
82 DEFINE_EXPECT(QueryService_IAuthenticate);
83 DEFINE_EXPECT(QueryService_IInternetProtocol);
84 DEFINE_EXPECT(QueryService_IInternetBindInfo);
85 DEFINE_EXPECT(BeginningTransaction);
86 DEFINE_EXPECT(OnResponse);
87 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
88 DEFINE_EXPECT(GetRootSecurityId);
89 DEFINE_EXPECT(GetBindInfo);
90 DEFINE_EXPECT(OnStartBinding);
91 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
92 DEFINE_EXPECT(OnProgress_CONNECTING);
93 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
94 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
95 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
96 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
97 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
98 DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
99 DEFINE_EXPECT(OnStopBinding);
100 DEFINE_EXPECT(OnDataAvailable);
101 DEFINE_EXPECT(OnObjectAvailable);
102 DEFINE_EXPECT(Obj_OnStartBinding);
103 DEFINE_EXPECT(Obj_OnStopBinding);
104 DEFINE_EXPECT(Obj_GetBindInfo);
105 DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
106 DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
107 DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
108 DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
109 DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
110 DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
111 DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
112 DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
113 DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
114 DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
115 DEFINE_EXPECT(Start);
117 DEFINE_EXPECT(LockRequest);
118 DEFINE_EXPECT(Terminate);
119 DEFINE_EXPECT(UnlockRequest);
120 DEFINE_EXPECT(Continue);
121 DEFINE_EXPECT(CreateInstance);
123 DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
124 DEFINE_EXPECT(PutProperty_CLASSIDPROP);
126 static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
127 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
129 static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
130 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
131 static const WCHAR SHORT_RESPONSE_URL[] =
132 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
133 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
134 'p','o','s','t','t','e','s','t','.','p','h','p',0};
135 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
136 static WCHAR INDEX_HTML[MAX_PATH];
137 static const WCHAR ITS_URL[] =
138 {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
139 static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
140 't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
141 static const WCHAR https_urlW[] =
142 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',
143 '/','t','e','s','t','.','h','t','m','l',0};
146 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
148 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
150 static const WCHAR wszWineHQSite[] =
151 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
152 static const WCHAR wszWineHQIP[] =
153 {'2','0','9','.','3','2','.','1','4','1','.','3',0};
154 static const CHAR wszIndexHtmlA[] = "index.html";
155 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
156 static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
157 static const CHAR dwl_htmlA[] = "dwl.html";
158 static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
159 static const WCHAR emptyW[] = {0};
161 static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
162 data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api;
163 static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed;
164 static CHAR mime_type[512];
165 static IInternetProtocolSink *protocol_sink = NULL;
166 static HANDLE complete_event, complete_event2;
167 static HRESULT binding_hres;
168 static BOOL have_IHttpNegotiate2;
170 static LPCWSTR urls[] = {
179 static WCHAR file_url[INTERNET_MAX_URL_LENGTH];
196 static const char *debugstr_w(LPCWSTR str)
198 static char buf[1024];
199 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
203 static const char *debugstr_guid(REFIID riid)
207 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
208 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
209 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
210 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
215 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
218 IMoniker *mon1 = NULL;
219 IMoniker *mon2 = NULL;
221 hr = CreateURLMoniker(NULL, url1, &mon1);
222 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
224 hr = CreateURLMoniker(mon1, url2, &mon2);
225 ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
227 if(mon1) IMoniker_Release(mon1);
228 if(mon2) IMoniker_Release(mon2);
231 static void test_create(void)
233 test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
236 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
238 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
244 return E_NOINTERFACE;
247 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
252 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
257 static DWORD WINAPI thread_proc(PVOID arg)
259 PROTOCOLDATA protocoldata;
263 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
265 SET_EXPECT(OnProgress_FINDINGRESOURCE);
266 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
267 BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
268 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
269 WaitForSingleObject(complete_event, INFINITE);
271 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
273 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
276 SET_EXPECT(Obj_OnProgress_CONNECTING);
278 SET_EXPECT(OnProgress_CONNECTING);
279 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
280 BINDSTATUS_CONNECTING, wszWineHQIP);
281 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
282 WaitForSingleObject(complete_event, INFINITE);
284 CHECK_CALLED(Obj_OnProgress_CONNECTING);
286 CHECK_CALLED(OnProgress_CONNECTING);
289 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
291 SET_EXPECT(OnProgress_SENDINGREQUEST);
292 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
293 BINDSTATUS_SENDINGREQUEST, NULL);
294 ok(hres == S_OK, "ReportProxgress failed: %08x\n", hres);
295 WaitForSingleObject(complete_event, INFINITE);
297 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
299 CHECK_CALLED(OnProgress_SENDINGREQUEST);
301 SET_EXPECT(Continue);
303 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
304 ok(hres == S_OK, "Switch failed: %08x\n", hres);
305 WaitForSingleObject(complete_event, INFINITE);
307 CHECK_CALLED(Continue);
310 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
311 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
312 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
313 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
314 CHECK_CALLED(CreateInstance);
315 CHECK_CALLED(PutProperty_MIMETYPEPROP);
316 CLEAR_CALLED(PutProperty_CLASSIDPROP);
318 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
319 CHECK_CALLED(OnObjectAvailable);
320 CHECK_CALLED(Obj_OnStopBinding);
322 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
323 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
324 CHECK_CALLED(LockRequest);
325 CHECK_CALLED(OnDataAvailable);
328 SET_EXPECT(Continue);
330 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
331 ok(hres == S_OK, "Switch failed: %08x\n", hres);
332 WaitForSingleObject(complete_event, INFINITE);
333 CHECK_CALLED(Continue);
335 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
336 CHECK_CALLED(OnDataAvailable);
338 SET_EXPECT(Continue);
340 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
341 ok(hres == S_OK, "Switch failed: %08x\n", hres);
342 WaitForSingleObject(complete_event, INFINITE);
343 CHECK_CALLED(Continue);
345 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
346 CHECK_CALLED(OnDataAvailable);
348 SET_EXPECT(Continue);
350 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
351 ok(hres == S_OK, "Switch failed: %08x\n", hres);
352 WaitForSingleObject(complete_event, INFINITE);
353 CHECK_CALLED(Continue);
355 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
356 CHECK_CALLED(OnDataAvailable);
357 CHECK_CALLED(OnStopBinding);
361 SetEvent(complete_event2);
365 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
366 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
367 DWORD grfPI, DWORD dwReserved)
370 DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
373 static const STGMEDIUM stgmed_zero = {0};
374 static const SECURITY_ATTRIBUTES sa_zero = {0};
380 if(!filedwl_api) /* FIXME */
381 ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", debugstr_w(szUrl));
382 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
383 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
384 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
385 ok(dwReserved == 0, "dwReserved=%d, expected 0\n", dwReserved);
387 if(!filedwl_api && binding_hres != S_OK) {
388 SET_EXPECT(OnStopBinding);
389 SET_EXPECT(Terminate);
390 hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
391 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
392 CHECK_CALLED(OnStopBinding);
393 CHECK_CALLED(Terminate);
398 memset(&bindinfo, 0, sizeof(bindinfo));
399 bindinfo.cbSize = sizeof(bindinfo);
400 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
401 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
404 ok(bindf == (BINDF_PULLDATA|BINDF_FROMURLMON|BINDF_NEEDFILE), "bindf=%08x\n", bindf);
405 }else if(tymed == TYMED_ISTREAM
406 && (test_protocol == FILE_TEST || test_protocol == MK_TEST
407 || test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)) {
408 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
410 "bindf=%08x\n", bindf);
412 ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
413 |BINDF_FROMURLMON|BINDF_NEEDFILE),
414 "bindf=%08x\n", bindf);
417 ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
418 ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
419 ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
420 ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
421 ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
422 ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
423 ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
424 ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
425 ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
426 ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
427 ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
428 ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
429 ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
430 ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
432 switch(test_protocol) {
434 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
435 BINDSTATUS_DIRECTBIND, NULL);
437 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
442 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
444 SET_EXPECT(OnProgress_SENDINGREQUEST);
445 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
446 BINDSTATUS_SENDINGREQUEST, emptyW);
448 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
450 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
452 CHECK_CALLED(OnProgress_SENDINGREQUEST);
457 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
458 IServiceProvider *service_provider;
459 IHttpNegotiate *http_negotiate;
460 IHttpNegotiate2 *http_negotiate2;
461 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
462 LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
464 DWORD fetched = 256, size = 100;
467 static const WCHAR wszMimes[] = {'*','/','*',0};
469 SET_EXPECT(QueryInterface_IInternetBindInfo);
470 SET_EXPECT(QueryService_IInternetBindInfo);
471 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
474 CHECK_CALLED(QueryInterface_IInternetBindInfo);
475 CHECK_CALLED(QueryService_IInternetBindInfo);
477 ok(hres == E_NOINTERFACE,
478 "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
479 ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
480 ok(ua == (LPWSTR)0xdeadbeef, "ua = %p\n", ua);
482 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
483 accept_mimes, 256, &fetched);
485 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
486 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
487 ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
489 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
490 NULL, 256, &fetched);
491 ok(hres == E_INVALIDARG,
492 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
494 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
495 accept_mimes, 256, NULL);
496 ok(hres == E_INVALIDARG,
497 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
499 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
500 (void**)&service_provider);
501 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
503 SET_EXPECT(QueryInterface_IHttpNegotiate);
504 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
505 &IID_IHttpNegotiate, (void**)&http_negotiate);
506 CHECK_CALLED(QueryInterface_IHttpNegotiate);
507 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
509 SET_EXPECT(BeginningTransaction);
510 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
511 NULL, 0, &additional_headers);
512 CHECK_CALLED(BeginningTransaction);
513 IHttpNegotiate_Release(http_negotiate);
514 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
515 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
517 SET_EXPECT(QueryInterface_IHttpNegotiate2);
518 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
519 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
520 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
521 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
524 SET_EXPECT(GetRootSecurityId);
525 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
526 CHECK_CALLED(GetRootSecurityId);
527 IHttpNegotiate2_Release(http_negotiate2);
528 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
529 ok(size == 13, "size=%d\n", size);
531 IServiceProvider_Release(service_provider);
533 IInternetProtocolSink_AddRef(pOIProtSink);
534 protocol_sink = pOIProtSink;
535 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
540 if(test_protocol == FILE_TEST) {
541 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
542 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
544 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
547 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
549 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
550 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
551 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
553 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
555 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
557 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
559 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
560 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
562 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
565 if(test_protocol == ABOUT_TEST)
566 bscf |= BSCF_DATAFULLYAVAILABLE;
567 if(test_protocol == ITS_TEST)
568 bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
572 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
573 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
574 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
575 if(test_protocol == FILE_TEST)
576 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
577 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
578 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
579 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
580 SET_EXPECT(CreateInstance);
581 SET_EXPECT(PutProperty_MIMETYPEPROP);
582 SET_EXPECT(PutProperty_CLASSIDPROP);
584 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
585 SET_EXPECT(OnObjectAvailable);
586 SET_EXPECT(Obj_OnStopBinding);
588 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
589 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
590 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
591 if(test_protocol == FILE_TEST)
592 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
593 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
594 SET_EXPECT(LockRequest);
596 SET_EXPECT(OnDataAvailable);
597 SET_EXPECT(OnStopBinding);
600 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
601 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
605 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
606 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
607 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
608 if(test_protocol == FILE_TEST)
609 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
610 CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
611 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
612 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
613 CHECK_CALLED(CreateInstance);
614 CHECK_CALLED(PutProperty_MIMETYPEPROP);
615 CLEAR_CALLED(PutProperty_CLASSIDPROP);
617 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
618 CHECK_CALLED(OnObjectAvailable);
619 CHECK_CALLED(Obj_OnStopBinding);
621 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
622 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
623 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
624 if(test_protocol == FILE_TEST)
625 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
626 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
627 CHECK_CALLED(LockRequest);
629 CHECK_CALLED(OnDataAvailable);
630 CHECK_CALLED(OnStopBinding);
633 if(test_protocol == ITS_TEST) {
635 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
636 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
640 SET_EXPECT(Terminate);
641 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
642 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
643 CHECK_CALLED(Terminate);
648 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
649 PROTOCOLDATA *pProtocolData)
654 CHECK_EXPECT(Continue);
656 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
658 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
664 IServiceProvider *service_provider;
665 IHttpNegotiate *http_negotiate;
666 static WCHAR header[] = {'?',0};
668 hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
669 (void**)&service_provider);
670 ok(hres == S_OK, "Could not get IServiceProvicder\n");
672 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
673 &IID_IHttpNegotiate, (void**)&http_negotiate);
674 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
676 SET_EXPECT(OnResponse);
677 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
678 CHECK_CALLED(OnResponse);
679 IHttpNegotiate_Release(http_negotiate);
680 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
682 if(test_protocol == HTTPS_TEST) {
683 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
684 ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
687 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
688 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
690 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
692 if(tymed == TYMED_FILE) {
693 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
694 BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_fileW);
696 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
699 bscf |= BSCF_FIRSTDATANOTIFICATION;
704 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
708 hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
709 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
715 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
716 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
717 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
718 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
719 SET_EXPECT(CreateInstance);
720 SET_EXPECT(PutProperty_MIMETYPEPROP);
721 SET_EXPECT(PutProperty_CLASSIDPROP);
723 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
724 SET_EXPECT(OnObjectAvailable);
725 SET_EXPECT(Obj_OnStopBinding);
727 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
728 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
729 SET_EXPECT(LockRequest);
733 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
736 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
737 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
739 if(!bind_to_object || prot_state >= 2)
740 SET_EXPECT(OnDataAvailable);
742 SET_EXPECT(OnStopBinding);
747 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
750 ok(0, "unexpected call\n");
754 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
756 CHECK_EXPECT(Terminate);
758 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
761 IInternetProtocolSink_Release(protocol_sink);
762 protocol_sink = NULL;
768 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
770 ok(0, "unexpected call\n");
774 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
776 ok(0, "unexpected call\n");
780 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
781 ULONG cb, ULONG *pcbRead)
783 static const char data[] = "<HTML></HTML>";
787 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
790 static BOOL pending = TRUE;
812 hres = IInternetProtocolSink_ReportData(protocol_sink,
813 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
814 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
816 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
817 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
831 ok(pv != NULL, "pv == NULL\n");
832 ok(cb != 0, "cb == 0\n");
833 ok(pcbRead != NULL, "pcbRead == NULL\n");
835 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
836 read += *pcbRead = sizeof(data)-1;
839 memcpy(pv, data, sizeof(data));
844 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
845 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
847 ok(0, "unexpected call\n");
851 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
853 CHECK_EXPECT(LockRequest);
857 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
859 CHECK_EXPECT(UnlockRequest);
863 static const IInternetProtocolVtbl ProtocolVtbl = {
864 Protocol_QueryInterface,
875 Protocol_LockRequest,
876 Protocol_UnlockRequest
879 static IInternetProtocol Protocol = { &ProtocolVtbl };
881 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
883 if(IsEqualGUID(&IID_IUnknown, riid)
884 || IsEqualGUID(&IID_IHttpNegotiate, riid)
885 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
890 ok(0, "unexpected call\n");
891 return E_NOINTERFACE;
894 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
899 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
904 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
905 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
907 CHECK_EXPECT(BeginningTransaction);
909 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
911 ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
912 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
913 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
914 if(pszAdditionalHeaders)
915 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
920 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
921 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
923 CHECK_EXPECT(OnResponse);
925 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
927 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
928 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
929 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
930 /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
931 ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
932 if(pszAdditionalRequestHeaders)
933 ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
938 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
939 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
941 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
943 CHECK_EXPECT(GetRootSecurityId);
945 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
947 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
948 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
949 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
951 if(pbSecurityId == (void*)0xdeadbeef)
955 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
956 *pcbSecurityId = sizeof(sec_id);
960 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
965 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
966 HttpNegotiate_QueryInterface,
967 HttpNegotiate_AddRef,
968 HttpNegotiate_Release,
969 HttpNegotiate_BeginningTransaction,
970 HttpNegotiate_OnResponse,
971 HttpNegotiate_GetRootSecurityId
974 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
976 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
978 ok(0, "unexpected call\n");
979 return E_NOINTERFACE;
982 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
987 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
992 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
993 REFGUID guidService, REFIID riid, void **ppv)
995 if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
996 CHECK_EXPECT(QueryService_IAuthenticate);
1000 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1001 CHECK_EXPECT2(QueryService_IInternetProtocol);
1005 if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1006 CHECK_EXPECT(QueryService_IInternetBindInfo);
1010 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
1011 return E_NOINTERFACE;
1014 static IServiceProviderVtbl ServiceProviderVtbl = {
1015 ServiceProvider_QueryInterface,
1016 ServiceProvider_AddRef,
1017 ServiceProvider_Release,
1018 ServiceProvider_QueryService
1021 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1023 static IBindStatusCallback objbsc;
1025 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallback *iface, REFIID riid, void **ppv)
1027 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1029 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1030 CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1031 if(emulate_protocol) {
1035 return E_NOINTERFACE;
1038 else if (IsEqualGUID(&IID_IServiceProvider, riid))
1040 CHECK_EXPECT2(QueryInterface_IServiceProvider);
1041 *ppv = &ServiceProvider;
1044 else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
1046 CHECK_EXPECT(QueryInterface_IHttpNegotiate);
1047 *ppv = &HttpNegotiate;
1050 else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
1052 CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1053 *ppv = &HttpNegotiate;
1056 else if (IsEqualGUID(&IID_IAuthenticate, riid))
1058 CHECK_EXPECT(QueryInterface_IAuthenticate);
1059 return E_NOINTERFACE;
1061 else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
1063 CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1067 else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
1069 CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1070 return E_NOINTERFACE;
1072 else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
1075 CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1079 ok(0, "unexpected interface %s\n", debugstr_guid(riid));
1082 return E_NOINTERFACE;
1085 static ULONG WINAPI statusclb_AddRef(IBindStatusCallback *iface)
1090 static ULONG WINAPI statusclb_Release(IBindStatusCallback *iface)
1095 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallback *iface, DWORD dwReserved,
1098 IWinInetHttpInfo *http_info;
1102 if(iface == &objbsc)
1103 CHECK_EXPECT(Obj_OnStartBinding);
1105 CHECK_EXPECT(OnStartBinding);
1107 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1109 ok(pib != NULL, "pib should not be NULL\n");
1110 ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1112 if(pib == (void*)0xdeadbeef)
1115 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1116 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1118 IMoniker_Release(mon);
1120 hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1121 ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1126 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
1128 ok(0, "unexpected call\n");
1132 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
1134 ok(0, "unexpected call\n");
1138 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
1139 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1141 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1143 switch(ulStatusCode) {
1144 case BINDSTATUS_FINDINGRESOURCE:
1145 if(iface == &objbsc)
1146 CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1148 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1149 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1150 SetEvent(complete_event);
1152 case BINDSTATUS_CONNECTING:
1153 if(iface == &objbsc)
1154 CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1156 CHECK_EXPECT(OnProgress_CONNECTING);
1157 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1158 SetEvent(complete_event);
1160 case BINDSTATUS_SENDINGREQUEST:
1161 if(iface == &objbsc)
1162 CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1164 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1165 if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1166 SetEvent(complete_event);
1168 case BINDSTATUS_MIMETYPEAVAILABLE:
1169 if(iface == &objbsc)
1170 CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1172 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1174 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1176 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1178 case BINDSTATUS_BEGINDOWNLOADDATA:
1179 if(iface == &objbsc)
1180 CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1182 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1183 ok(szStatusText != NULL, "szStatusText == NULL\n");
1188 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1192 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1194 download_state = DOWNLOADING;
1196 case BINDSTATUS_DOWNLOADINGDATA:
1197 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1198 if(iface == &objbsc)
1199 todo_wine ok(0, "unexpected call\n");
1200 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1203 case BINDSTATUS_ENDDOWNLOADDATA:
1204 if(iface == &objbsc)
1205 CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1207 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1208 ok(szStatusText != NULL, "szStatusText == NULL\n");
1213 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1216 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1218 download_state = END_DOWNLOAD;
1220 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1221 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST) {
1222 if(iface == &objbsc)
1223 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1225 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1227 CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1228 CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1231 ok(szStatusText != NULL, "szStatusText == NULL\n");
1232 if(szStatusText && test_protocol == FILE_TEST)
1233 ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", debugstr_w(szStatusText));
1235 case BINDSTATUS_CLASSIDAVAILABLE:
1239 if(iface != &objbsc)
1240 ok(0, "unexpected call\n");
1241 else if(1||emulate_protocol)
1242 CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1244 todo_wine CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1245 hr = CLSIDFromString((LPOLESTR)szStatusText, &clsid);
1246 ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1247 ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1248 "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1251 case BINDSTATUS_BEGINSYNCOPERATION:
1252 CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1253 if(iface != &objbsc)
1254 ok(0, "unexpected call\n");
1255 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1257 case BINDSTATUS_ENDSYNCOPERATION:
1258 CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1259 if(iface != &objbsc)
1260 ok(0, "unexpected call\n");
1261 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1263 case BINDSTATUS_PROXYDETECTING:
1264 trace("BINDSTATUS_PROXYDETECTING\n");
1267 ok(0, "unexpected code %d\n", ulStatusCode);
1272 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
1274 if(iface == &objbsc) {
1275 CHECK_EXPECT(Obj_OnStopBinding);
1276 stopped_obj_binding = TRUE;
1278 CHECK_EXPECT(OnStopBinding);
1279 stopped_binding = TRUE;
1282 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1284 /* ignore DNS failure */
1285 if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1289 ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1291 ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1292 ok(szError == NULL, "szError should be NULL\n");
1294 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) && emulate_protocol) {
1295 SetEvent(complete_event);
1296 if(iface != &objbsc)
1297 WaitForSingleObject(complete_event2, INFINITE);
1303 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1307 if(iface == &objbsc)
1308 CHECK_EXPECT(Obj_GetBindInfo);
1310 CHECK_EXPECT(GetBindInfo);
1312 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1315 cbSize = pbindinfo->cbSize;
1316 memset(pbindinfo, 0, cbSize);
1317 pbindinfo->cbSize = cbSize;
1322 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
1323 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1330 if(iface == &objbsc)
1331 ok(0, "unexpected call\n");
1333 CHECK_EXPECT2(OnDataAvailable);
1335 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1337 ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
1338 "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
1340 data_available = TRUE;
1342 ok(pformatetc != NULL, "pformatetx == NULL\n");
1346 ok(GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1),
1347 "GetClipboardFormatName failed, error %d\n", GetLastError());
1348 ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
1349 pformatetc->cfFormat, clipfmt, mime_type);
1351 ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
1353 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1354 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
1355 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
1356 ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1359 ok(pstgmed != NULL, "stgmeg == NULL\n");
1360 ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1361 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1363 switch(pstgmed->tymed) {
1365 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
1366 hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
1367 ok(hres == STG_E_ACCESSDENIED,
1368 "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1370 hres = IStream_Commit(U(*pstgmed).pstm, 0);
1371 ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1373 hres = IStream_Revert(U(*pstgmed).pstm);
1374 ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
1377 ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
1378 do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
1379 while(hres == S_OK);
1380 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
1384 if(test_protocol == FILE_TEST)
1385 ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1386 "unexpected file name %s\n", debugstr_w(pstgmed->u.lpszFileName));
1387 else if(emulate_protocol)
1388 ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1389 "unexpected file name %s\n", debugstr_w(pstgmed->u.lpszFileName));
1391 ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1394 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1395 && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1396 SetEvent(complete_event);
1401 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
1403 CHECK_EXPECT(OnObjectAvailable);
1405 if(iface != &objbsc)
1406 ok(0, "unexpected call\n");
1408 ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
1409 ok(punk != NULL, "punk == NULL\n");
1414 static const IBindStatusCallbackVtbl BindStatusCallbackVtbl = {
1415 statusclb_QueryInterface,
1418 statusclb_OnStartBinding,
1419 statusclb_GetPriority,
1420 statusclb_OnLowResource,
1421 statusclb_OnProgress,
1422 statusclb_OnStopBinding,
1423 statusclb_GetBindInfo,
1424 statusclb_OnDataAvailable,
1425 statusclb_OnObjectAvailable
1428 static IBindStatusCallback bsc = { &BindStatusCallbackVtbl };
1429 static IBindStatusCallback objbsc = { &BindStatusCallbackVtbl };
1431 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
1434 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1435 return E_NOINTERFACE;
1438 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
1443 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
1448 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
1452 CHECK_EXPECT(PutProperty_MIMETYPEPROP);
1453 ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", debugstr_w(val));
1456 CHECK_EXPECT(PutProperty_CLASSIDPROP);
1465 static const IMonikerPropVtbl MonikerPropVtbl = {
1466 MonikerProp_QueryInterface,
1468 MonikerProp_Release,
1469 MonikerProp_PutProperty
1472 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
1474 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
1478 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
1480 else if(IsEqualGUID(&IID_IMonikerProp, riid))
1481 *ppv = &MonikerProp;
1486 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1487 return E_NOINTERFACE;
1490 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
1495 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
1500 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
1502 ok(0, "unexpected call\n");
1506 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
1508 ok(0, "unexpected call\n");
1512 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
1513 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
1518 static WCHAR cbinding_contextW[] =
1519 {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
1522 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1524 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1525 ok(!fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1527 ok(fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1528 ok(pimkName != NULL, "pimkName == NULL\n");
1529 ok(pibc != NULL, "pibc == NULL\n");
1530 ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
1532 hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
1533 ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
1534 if(SUCCEEDED(hres)) {
1537 hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
1538 ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
1540 IBinding_Release(binding);
1541 IUnknown_Release(unk);
1544 SET_EXPECT(QueryInterface_IServiceProvider);
1545 hres = RegisterBindStatusCallback(pibc, &bsc, NULL, 0);
1546 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
1547 CHECK_CALLED(QueryInterface_IServiceProvider);
1549 SET_EXPECT(GetBindInfo);
1550 SET_EXPECT(OnStartBinding);
1551 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1552 if(test_protocol == FILE_TEST)
1553 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1554 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1555 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1556 SET_EXPECT(LockRequest);
1557 SET_EXPECT(OnDataAvailable);
1558 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1559 SET_EXPECT(OnStopBinding);
1561 hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
1562 ok(hres == S_OK, "Load failed: %08x\n", hres);
1564 CHECK_CALLED(GetBindInfo);
1565 CHECK_CALLED(OnStartBinding);
1566 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
1567 if(test_protocol == FILE_TEST)
1568 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1569 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1570 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
1571 CHECK_CALLED(LockRequest);
1572 CHECK_CALLED(OnDataAvailable);
1573 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1574 CHECK_CALLED(OnStopBinding);
1577 IUnknown_Release(unk);
1582 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
1584 ok(0, "unexpected call\n");
1588 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
1590 ok(0, "unexpected call\n");
1594 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
1596 ok(0, "unexpected call\n");
1600 static const IPersistMonikerVtbl PersistMonikerVtbl = {
1601 PersistMoniker_QueryInterface,
1602 PersistMoniker_AddRef,
1603 PersistMoniker_Release,
1604 PersistMoniker_GetClassID,
1605 PersistMoniker_IsDirty,
1606 PersistMoniker_Load,
1607 PersistMoniker_Save,
1608 PersistMoniker_SaveCompleted,
1609 PersistMoniker_GetCurMoniker
1612 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
1614 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1618 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1623 if(IsEqualGUID(&IID_IMarshal, riid))
1624 return E_NOINTERFACE;
1625 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1626 return E_NOINTERFACE;
1628 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1632 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1637 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1642 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1644 CHECK_EXPECT(CreateInstance);
1645 ok(!outer, "outer = %p\n", outer);
1646 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1647 *ppv = &PersistMoniker;
1651 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1653 ok(0, "unexpected call\n");
1657 static const IClassFactoryVtbl ClassFactoryVtbl = {
1658 ClassFactory_QueryInterface,
1659 ClassFactory_AddRef,
1660 ClassFactory_Release,
1661 ClassFactory_CreateInstance,
1662 ClassFactory_LockServer
1665 static IClassFactory mime_cf = { &ClassFactoryVtbl };
1667 static void test_CreateAsyncBindCtx(void)
1669 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
1675 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
1676 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1677 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
1679 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
1680 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1682 SET_EXPECT(QueryInterface_IServiceProvider);
1683 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
1684 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
1685 CHECK_CALLED(QueryInterface_IServiceProvider);
1687 bindopts.cbStruct = sizeof(bindopts);
1688 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1689 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1690 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1691 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1692 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1693 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1695 ok(bindopts.dwTickCountDeadline == 0,
1696 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1698 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1699 ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
1701 IUnknown_Release(unk);
1703 ref = IBindCtx_Release(bctx);
1704 ok(ref == 0, "bctx should be destroyed here\n");
1707 static void test_CreateAsyncBindCtxEx(void)
1709 IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
1714 static WCHAR testW[] = {'t','e','s','t',0};
1716 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
1717 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
1719 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1720 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1722 if(SUCCEEDED(hres)) {
1723 bindopts.cbStruct = sizeof(bindopts);
1724 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1725 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1726 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1727 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1728 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1729 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1731 ok(bindopts.dwTickCountDeadline == 0,
1732 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1734 IBindCtx_Release(bctx);
1737 CreateBindCtx(0, &bctx_arg);
1738 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1739 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1741 if(SUCCEEDED(hres)) {
1742 bindopts.cbStruct = sizeof(bindopts);
1743 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1744 ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1745 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1746 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1747 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1748 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1750 ok(bindopts.dwTickCountDeadline == 0,
1751 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1753 IBindCtx_Release(bctx);
1756 IBindCtx_Release(bctx_arg);
1758 SET_EXPECT(QueryInterface_IServiceProvider);
1759 hres = CreateAsyncBindCtxEx(NULL, 0, &bsc, NULL, &bctx, 0);
1760 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1761 CHECK_CALLED(QueryInterface_IServiceProvider);
1763 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1764 ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
1766 IUnknown_Release(unk);
1768 IBindCtx_Release(bctx);
1770 hres = CreateBindCtx(0, &bctx2);
1771 ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
1773 hres = CreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
1774 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1776 hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
1777 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
1779 hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
1780 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1781 ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
1783 IBindCtx_Release(bctx);
1784 IBindCtx_Release(bctx2);
1787 static BOOL test_bscholder(IBindStatusCallback *holder)
1789 IServiceProvider *serv_prov;
1790 IHttpNegotiate *http_negotiate, *http_negotiate_serv;
1791 IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
1792 IAuthenticate *authenticate, *authenticate_serv;
1793 IInternetProtocol *protocol;
1794 BINDINFO bindinfo = {sizeof(bindinfo)};
1800 hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
1801 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
1804 SET_EXPECT(GetBindInfo);
1805 hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
1806 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1807 CHECK_CALLED(GetBindInfo);
1809 SET_EXPECT(OnStartBinding);
1810 hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
1811 ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
1812 CHECK_CALLED(OnStartBinding);
1814 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
1815 ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
1817 wstr = (void*)0xdeadbeef;
1818 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol], (void*)0xdeadbeef, 0xff, &wstr);
1819 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
1820 ok(wstr == NULL, "wstr = %p\n", wstr);
1822 SET_EXPECT(QueryInterface_IHttpNegotiate);
1823 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
1824 (void**)&http_negotiate_serv);
1825 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
1826 CHECK_CALLED(QueryInterface_IHttpNegotiate);
1828 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
1830 wstr = (void*)0xdeadbeef;
1831 SET_EXPECT(BeginningTransaction);
1832 hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
1833 CHECK_CALLED(BeginningTransaction);
1834 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
1835 ok(wstr == NULL, "wstr = %p\n", wstr);
1837 IHttpNegotiate_Release(http_negotiate_serv);
1839 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
1840 (void**)&http_negotiate_serv);
1841 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
1842 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
1843 IHttpNegotiate_Release(http_negotiate_serv);
1845 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1846 if(SUCCEEDED(hres)) {
1847 have_IHttpNegotiate2 = TRUE;
1848 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
1849 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x\n", hres);
1851 SET_EXPECT(QueryInterface_IHttpNegotiate2);
1852 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
1853 (void**)&http_negotiate2_serv);
1854 ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
1855 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
1856 ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
1858 SET_EXPECT(GetRootSecurityId);
1859 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
1860 ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
1861 CHECK_CALLED(GetRootSecurityId);
1863 IHttpNegotiate_Release(http_negotiate2_serv);
1864 IHttpNegotiate_Release(http_negotiate2);
1866 skip("Could not get IHttpNegotiate2\n");
1870 SET_EXPECT(OnProgress_FINDINGRESOURCE);
1871 hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
1872 ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
1873 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
1875 SET_EXPECT(OnResponse);
1876 wstr = (void*)0xdeadbeef;
1877 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
1878 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1879 CHECK_CALLED(OnResponse);
1881 IHttpNegotiate_Release(http_negotiate);
1883 hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
1884 ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
1886 SET_EXPECT(QueryInterface_IAuthenticate);
1887 SET_EXPECT(QueryService_IAuthenticate);
1888 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
1889 (void**)&authenticate_serv);
1890 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
1891 CHECK_CALLED(QueryInterface_IAuthenticate);
1892 CHECK_CALLED(QueryService_IAuthenticate);
1893 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
1894 IAuthenticate_Release(authenticate_serv);
1896 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
1897 (void**)&authenticate_serv);
1898 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
1899 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
1901 IAuthenticate_Release(authenticate);
1902 IAuthenticate_Release(authenticate_serv);
1904 SET_EXPECT(OnStopBinding);
1905 hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
1906 ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
1907 CHECK_CALLED(OnStopBinding);
1909 SET_EXPECT(QueryInterface_IInternetProtocol);
1910 SET_EXPECT(QueryService_IInternetProtocol);
1911 hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
1913 ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
1914 CHECK_CALLED(QueryInterface_IInternetProtocol);
1915 CHECK_CALLED(QueryService_IInternetProtocol);
1917 IServiceProvider_Release(serv_prov);
1921 static BOOL test_RegisterBindStatusCallback(void)
1923 IBindStatusCallback *prevbsc, *clb;
1929 hres = CreateBindCtx(0, &bindctx);
1930 ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
1932 SET_EXPECT(QueryInterface_IServiceProvider);
1934 hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
1935 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
1937 SET_EXPECT(QueryInterface_IBindStatusCallback);
1938 SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
1939 prevbsc = (void*)0xdeadbeef;
1940 hres = RegisterBindStatusCallback(bindctx, &bsc, &prevbsc, 0);
1941 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
1942 ok(prevbsc == &bsc, "prevbsc=%p\n", prevbsc);
1943 CHECK_CALLED(QueryInterface_IBindStatusCallback);
1944 CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
1946 CHECK_CALLED(QueryInterface_IServiceProvider);
1948 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
1949 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1951 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
1952 IUnknown_Release(unk);
1953 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
1954 ok(clb != &bsc, "bsc == clb\n");
1956 if(!test_bscholder(clb))
1959 IBindStatusCallback_Release(clb);
1961 hres = RevokeBindStatusCallback(bindctx, &bsc);
1962 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
1964 unk = (void*)0xdeadbeef;
1965 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
1966 ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
1967 ok(unk == NULL, "unk != NULL\n");
1970 IUnknown_Release(unk);
1972 hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
1973 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
1975 hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
1976 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
1978 hres = RevokeBindStatusCallback(bindctx, NULL);
1979 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
1981 IBindCtx_Release(bindctx);
1985 #define BINDTEST_EMULATE 1
1986 #define BINDTEST_TOOBJECT 2
1987 #define BINDTEST_FILEDWLAPI 4
1989 static void init_bind_test(int protocol, DWORD flags, DWORD t)
1991 test_protocol = protocol;
1992 emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
1993 download_state = BEFORE_DOWNLOAD;
1994 stopped_binding = FALSE;
1995 stopped_obj_binding = FALSE;
1996 data_available = FALSE;
1998 binding_hres = S_OK;
1999 bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
2001 filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
2004 static void test_BindToStorage(int protocol, BOOL emul, DWORD t)
2008 LPOLESTR display_name;
2011 IBindStatusCallback *previousclb;
2012 IUnknown *unk = (IUnknown*)0x00ff00ff;
2015 init_bind_test(protocol, emul ? BINDTEST_EMULATE : 0, t);
2017 SET_EXPECT(QueryInterface_IServiceProvider);
2018 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
2019 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2020 CHECK_CALLED(QueryInterface_IServiceProvider);
2024 SET_EXPECT(QueryInterface_IServiceProvider);
2025 hres = RegisterBindStatusCallback(bctx, &bsc, &previousclb, 0);
2026 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2027 ok(previousclb == &bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2028 CHECK_CALLED(QueryInterface_IServiceProvider);
2030 IBindStatusCallback_Release(previousclb);
2032 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2033 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2035 IBindCtx_Release(bctx);
2039 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2040 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2042 IBinding_Release(bind);
2044 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2045 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2046 ok(!lstrcmpW(display_name, urls[test_protocol]),
2047 "GetDisplayName got wrong name %s\n", debugstr_w(display_name));
2048 CoTaskMemFree(display_name);
2050 if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
2051 binding_hres = INET_E_DATA_NOT_AVAILABLE;
2053 SET_EXPECT(GetBindInfo);
2054 SET_EXPECT(QueryInterface_IInternetProtocol);
2055 if(!emulate_protocol)
2056 SET_EXPECT(QueryService_IInternetProtocol);
2057 SET_EXPECT(OnStartBinding);
2058 if(emulate_protocol) {
2060 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2061 SET_EXPECT(Terminate);
2062 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2063 SET_EXPECT(UnlockRequest);
2065 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2066 SET_EXPECT(QueryInterface_IInternetBindInfo);
2067 SET_EXPECT(QueryService_IInternetBindInfo);
2068 SET_EXPECT(QueryInterface_IHttpNegotiate);
2069 SET_EXPECT(BeginningTransaction);
2070 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2071 SET_EXPECT(GetRootSecurityId);
2072 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2073 SET_EXPECT(OnProgress_CONNECTING);
2075 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2076 SET_EXPECT(OnProgress_SENDINGREQUEST);
2077 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2078 SET_EXPECT(OnResponse);
2079 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2080 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2081 if(test_protocol == FILE_TEST)
2082 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2083 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2084 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2085 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2086 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2087 SET_EXPECT(OnDataAvailable);
2088 SET_EXPECT(OnStopBinding);
2091 hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2092 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2093 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2095 skip("Network unreachable, skipping tests\n");
2099 if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
2100 || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2101 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2102 ok(unk == NULL, "istr should be NULL\n");
2103 }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
2104 ok(hres == INET_E_DATA_NOT_AVAILABLE,
2105 "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
2106 ok(unk == NULL, "istr should be NULL\n");
2108 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2109 ok(unk != NULL, "unk == NULL\n");
2112 IUnknown_Release(unk);
2117 while((bindf & BINDF_ASYNCHRONOUS) &&
2118 !stopped_binding && GetMessage(&msg,NULL,0,0)) {
2119 TranslateMessage(&msg);
2120 DispatchMessage(&msg);
2123 CHECK_CALLED(GetBindInfo);
2124 CHECK_CALLED(QueryInterface_IInternetProtocol);
2125 if(!emulate_protocol)
2126 CHECK_CALLED(QueryService_IInternetProtocol);
2127 CHECK_CALLED(OnStartBinding);
2128 if(emulate_protocol) {
2129 CHECK_CALLED(Start);
2130 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2131 if(tymed == TYMED_FILE)
2133 CHECK_CALLED(Terminate);
2135 if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2136 CHECK_CALLED(UnlockRequest);
2138 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2139 CLEAR_CALLED(QueryInterface_IInternetBindInfo);
2140 CLEAR_CALLED(QueryService_IInternetBindInfo);
2141 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2142 CHECK_CALLED(BeginningTransaction);
2143 if (have_IHttpNegotiate2)
2145 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2146 CHECK_CALLED(GetRootSecurityId);
2148 if(http_is_first || test_protocol == HTTPS_TEST) {
2149 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2150 CHECK_CALLED(OnProgress_CONNECTING);
2152 CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
2153 /* IE7 does call this */
2154 CLEAR_CALLED(OnProgress_CONNECTING);
2157 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2158 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2159 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2160 CHECK_CALLED(OnResponse);
2161 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2162 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2163 if(test_protocol == FILE_TEST)
2164 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2165 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2166 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2167 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2168 if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2169 CHECK_CALLED(OnDataAvailable);
2170 CHECK_CALLED(OnStopBinding);
2173 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2174 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2176 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2177 http_is_first = FALSE;
2180 static void test_BindToObject(int protocol, BOOL emul)
2184 LPOLESTR display_name;
2188 IUnknown *unk = (IUnknown*)0x00ff00ff;
2191 init_bind_test(protocol, BINDTEST_TOOBJECT | (emul ? BINDTEST_EMULATE : 0), TYMED_ISTREAM);
2194 CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
2195 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
2197 SET_EXPECT(QueryInterface_IServiceProvider);
2198 hres = CreateAsyncBindCtx(0, &objbsc, NULL, &bctx);
2199 ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
2200 CHECK_CALLED(QueryInterface_IServiceProvider);
2204 hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2205 ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2207 IBindCtx_Release(bctx);
2211 hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2212 ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2214 IBinding_Release(bind);
2216 hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2217 ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2218 ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
2220 SET_EXPECT(Obj_GetBindInfo);
2221 SET_EXPECT(QueryInterface_IInternetProtocol);
2222 if(!emulate_protocol)
2223 SET_EXPECT(QueryService_IInternetProtocol);
2224 SET_EXPECT(Obj_OnStartBinding);
2225 if(emulate_protocol) {
2227 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2228 SET_EXPECT(Terminate);
2229 if(test_protocol == FILE_TEST)
2230 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2231 SET_EXPECT(UnlockRequest);
2233 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2234 SET_EXPECT(QueryInterface_IHttpNegotiate);
2235 SET_EXPECT(BeginningTransaction);
2236 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2237 SET_EXPECT(GetRootSecurityId);
2238 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
2239 SET_EXPECT(Obj_OnProgress_CONNECTING);
2241 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2242 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
2243 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2244 SET_EXPECT(OnResponse);
2245 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
2246 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
2247 if(test_protocol == FILE_TEST)
2248 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2249 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2250 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2251 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
2252 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
2253 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
2254 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
2255 SET_EXPECT(OnObjectAvailable);
2256 SET_EXPECT(Obj_OnStopBinding);
2259 hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
2261 if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2262 && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2264 skip( "Network unreachable, skipping tests\n" );
2268 /* no point testing the calls if binding didn't even work */
2269 if (FAILED(hres)) return;
2271 if(bindf & BINDF_ASYNCHRONOUS) {
2272 ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
2273 ok(unk == NULL, "istr should be NULL\n");
2275 ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2276 ok(unk != NULL, "unk == NULL\n");
2278 ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
2281 IUnknown_Release(unk);
2283 while((bindf & BINDF_ASYNCHRONOUS) &&
2284 !((!emul || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
2285 TranslateMessage(&msg);
2286 DispatchMessage(&msg);
2289 CHECK_CALLED(Obj_GetBindInfo);
2290 CHECK_CALLED(QueryInterface_IInternetProtocol);
2291 if(!emulate_protocol)
2292 CHECK_CALLED(QueryService_IInternetProtocol);
2293 CHECK_CALLED(Obj_OnStartBinding);
2294 if(emulate_protocol) {
2295 CHECK_CALLED(Start);
2296 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2297 CHECK_CALLED(Terminate);
2298 if(test_protocol == FILE_TEST)
2299 CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
2300 CHECK_CALLED(UnlockRequest);
2302 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2303 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2304 CHECK_CALLED(BeginningTransaction);
2305 if (have_IHttpNegotiate2)
2307 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2308 CHECK_CALLED(GetRootSecurityId);
2311 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2312 CHECK_CALLED(Obj_OnProgress_CONNECTING);
2314 CHECK_NOT_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2315 /* IE7 does call this */
2316 CLEAR_CALLED(Obj_OnProgress_CONNECTING);
2319 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
2320 if(urls[test_protocol] == SHORT_RESPONSE_URL)
2321 CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
2323 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
2325 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2326 CHECK_CALLED(OnResponse);
2327 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
2328 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
2329 if(test_protocol == FILE_TEST)
2330 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2331 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2332 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2333 CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
2334 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
2335 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
2336 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
2337 CHECK_CALLED(OnObjectAvailable);
2338 CHECK_CALLED(Obj_OnStopBinding);
2341 if(test_protocol != HTTP_TEST || test_protocol == HTTPS_TEST || emul || urls[test_protocol] == SHORT_RESPONSE_URL) {
2342 ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2343 ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2345 todo_wine ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2347 if(bindf & BINDF_ASYNCHRONOUS)
2348 IBindCtx_Release(bctx);
2350 todo_wine ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2354 CoRevokeClassObject(regid);
2356 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2357 http_is_first = FALSE;
2360 static void test_URLDownloadToFile(DWORD prot, BOOL emul)
2365 init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);
2367 SET_EXPECT(GetBindInfo);
2368 SET_EXPECT(QueryInterface_IInternetProtocol);
2369 if(!emulate_protocol) {
2370 SET_EXPECT(QueryInterface_IServiceProvider);
2371 SET_EXPECT(QueryService_IInternetProtocol);
2373 SET_EXPECT(OnStartBinding);
2374 if(emulate_protocol) {
2376 SET_EXPECT(UnlockRequest);
2378 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2379 SET_EXPECT(QueryInterface_IHttpNegotiate);
2380 SET_EXPECT(BeginningTransaction);
2381 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2382 SET_EXPECT(GetRootSecurityId);
2384 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2385 SET_EXPECT(OnProgress_SENDINGREQUEST);
2386 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2387 SET_EXPECT(OnResponse);
2388 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2389 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2390 if(test_protocol == FILE_TEST)
2391 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2392 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2393 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2394 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2395 SET_EXPECT(OnStopBinding);
2398 hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], dwl_htmlW, 0, &bsc);
2399 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2401 CHECK_CALLED(GetBindInfo);
2402 CHECK_CALLED(QueryInterface_IInternetProtocol);
2403 if(!emulate_protocol) {
2404 CHECK_CALLED(QueryInterface_IServiceProvider);
2405 CHECK_CALLED(QueryService_IInternetProtocol);
2407 CHECK_CALLED(OnStartBinding);
2408 if(emulate_protocol) {
2409 CHECK_CALLED(Start);
2410 CHECK_CALLED(UnlockRequest);
2412 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2413 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2414 CHECK_CALLED(BeginningTransaction);
2415 if (have_IHttpNegotiate2)
2417 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2418 CHECK_CALLED(GetRootSecurityId);
2421 if(test_protocol == FILE_TEST)
2422 CHECK_CALLED(OnProgress_SENDINGREQUEST);
2423 else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2424 CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
2425 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2426 CHECK_CALLED(OnResponse);
2427 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2428 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2429 if(test_protocol == FILE_TEST)
2430 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2431 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2432 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2433 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2434 CHECK_CALLED(OnStopBinding);
2437 res = DeleteFileA(dwl_htmlA);
2438 ok(res, "DeleteFile failed: %u\n", GetLastError());
2440 if(prot != FILE_TEST || emul)
2443 hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
2444 ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2446 res = DeleteFileA(dwl_htmlA);
2447 ok(res, "DeleteFile failed: %u\n", GetLastError());
2450 static void set_file_url(char *path)
2452 CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
2453 CHAR INDEX_HTMLA[MAX_PATH];
2455 lstrcpyA(file_urlA, "file:///");
2456 lstrcatA(file_urlA, path);
2457 MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
2459 lstrcpyA(INDEX_HTMLA, "file://");
2460 lstrcatA(INDEX_HTMLA, path);
2461 MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
2464 static void create_file(void)
2468 CHAR path[MAX_PATH];
2470 static const char html_doc[] = "<HTML></HTML>";
2472 file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2473 FILE_ATTRIBUTE_NORMAL, NULL);
2474 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2475 if(file == INVALID_HANDLE_VALUE)
2478 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2481 GetCurrentDirectoryA(MAX_PATH, path);
2482 lstrcatA(path, "\\");
2483 lstrcatA(path, wszIndexHtmlA);
2487 static void test_ReportResult(HRESULT exhres)
2489 IMoniker *mon = NULL;
2490 IBindCtx *bctx = NULL;
2491 IUnknown *unk = (void*)0xdeadbeef;
2494 init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2495 binding_hres = exhres;
2497 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2498 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2500 SET_EXPECT(QueryInterface_IServiceProvider);
2501 hres = CreateAsyncBindCtx(0, &bsc, NULL, &bctx);
2502 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2503 CHECK_CALLED(QueryInterface_IServiceProvider);
2505 SET_EXPECT(GetBindInfo);
2506 SET_EXPECT(QueryInterface_IInternetProtocol);
2507 SET_EXPECT(OnStartBinding);
2510 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2511 if(SUCCEEDED(exhres))
2512 ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
2514 ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
2515 "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
2517 CHECK_CALLED(GetBindInfo);
2518 CHECK_CALLED(QueryInterface_IInternetProtocol);
2519 CHECK_CALLED(OnStartBinding);
2520 CHECK_CALLED(Start);
2522 ok(unk == NULL, "unk=%p\n", unk);
2524 IBindCtx_Release(bctx);
2525 IMoniker_Release(mon);
2528 static void test_BindToStorage_fail(void)
2530 IMoniker *mon = NULL;
2531 IBindCtx *bctx = NULL;
2535 hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2536 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2540 hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2541 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2543 hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2544 ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
2545 "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
2547 IBindCtx_Release(bctx);
2549 IMoniker_Release(mon);
2551 test_ReportResult(E_NOTIMPL);
2552 test_ReportResult(S_FALSE);
2555 static void gecko_installer_workaround(BOOL disable)
2560 static BOOL has_url = FALSE;
2561 static char url[2048];
2563 if(!disable && !has_url)
2566 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2567 if(res != ERROR_SUCCESS)
2571 DWORD type, size = sizeof(url);
2573 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2574 if(res == ERROR_SUCCESS && type == REG_SZ)
2577 RegDeleteValue(hkey, "GeckoUrl");
2579 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2587 gecko_installer_workaround(TRUE);
2589 complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2590 complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2591 thread_id = GetCurrentThreadId();
2595 test_CreateAsyncBindCtx();
2596 test_CreateAsyncBindCtxEx();
2598 if(test_RegisterBindStatusCallback()) {
2599 test_BindToStorage_fail();
2601 trace("synchronous http test (COM not initialised)...\n");
2602 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2606 trace("synchronous http test...\n");
2607 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2609 trace("synchronous http test (to object)...\n");
2610 test_BindToObject(HTTP_TEST, FALSE);
2612 trace("synchronous file test...\n");
2613 test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2615 trace("synchronous file test (to object)...\n");
2616 test_BindToObject(FILE_TEST, FALSE);
2618 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2620 trace("http test...\n");
2621 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2623 trace("http test (to file)...\n");
2624 test_BindToStorage(HTTP_TEST, FALSE, TYMED_FILE);
2626 trace("http test (to object)...\n");
2627 test_BindToObject(HTTP_TEST, FALSE);
2629 trace("http test (short response)...\n");
2630 http_is_first = TRUE;
2631 urls[HTTP_TEST] = SHORT_RESPONSE_URL;
2632 test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2634 trace("http test (short response, to object)...\n");
2635 test_BindToObject(HTTP_TEST, FALSE);
2637 trace("emulated http test...\n");
2638 test_BindToStorage(HTTP_TEST, TRUE, TYMED_ISTREAM);
2640 trace("emulated http test (to object)...\n");
2641 test_BindToObject(HTTP_TEST, TRUE);
2643 trace("emulated http test (to file)...\n");
2644 test_BindToStorage(HTTP_TEST, TRUE, TYMED_FILE);
2646 trace("asynchronous https test...\n");
2647 test_BindToStorage(HTTPS_TEST, FALSE, TYMED_ISTREAM);
2649 trace("emulated https test...\n");
2650 test_BindToStorage(HTTPS_TEST, TRUE, TYMED_ISTREAM);
2652 trace("about test...\n");
2653 test_BindToStorage(ABOUT_TEST, FALSE, TYMED_ISTREAM);
2655 trace("about test (to file)...\n");
2656 test_BindToStorage(ABOUT_TEST, FALSE, TYMED_FILE);
2658 trace("about test (to object)...\n");
2659 test_BindToObject(ABOUT_TEST, FALSE);
2661 trace("emulated about test...\n");
2662 test_BindToStorage(ABOUT_TEST, TRUE, TYMED_ISTREAM);
2664 trace("emulated about test (to file)...\n");
2665 test_BindToStorage(ABOUT_TEST, TRUE, TYMED_FILE);
2667 trace("emulated about test (to object)...\n");
2668 test_BindToObject(ABOUT_TEST, TRUE);
2670 trace("file test...\n");
2671 test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2673 trace("file test (to file)...\n");
2674 test_BindToStorage(FILE_TEST, FALSE, TYMED_FILE);
2676 trace("file test (to object)...\n");
2677 test_BindToObject(FILE_TEST, FALSE);
2679 trace("emulated file test...\n");
2680 test_BindToStorage(FILE_TEST, TRUE, TYMED_ISTREAM);
2682 trace("emulated file test (to file)...\n");
2683 test_BindToStorage(FILE_TEST, TRUE, TYMED_FILE);
2685 trace("emulated file test (to object)...\n");
2686 test_BindToObject(FILE_TEST, TRUE);
2688 trace("emulated its test...\n");
2689 test_BindToStorage(ITS_TEST, TRUE, TYMED_ISTREAM);
2691 trace("emulated its test (to file)...\n");
2692 test_BindToStorage(ITS_TEST, TRUE, TYMED_FILE);
2694 trace("emulated mk test...\n");
2695 test_BindToStorage(MK_TEST, TRUE, TYMED_ISTREAM);
2697 trace("test URLDownloadToFile for file protocol...\n");
2698 test_URLDownloadToFile(FILE_TEST, FALSE);
2700 trace("test URLDownloadToFile for emulated file protocol...\n");
2701 test_URLDownloadToFile(FILE_TEST, TRUE);
2703 trace("test URLDownloadToFile for http protocol...\n");
2704 test_URLDownloadToFile(HTTP_TEST, FALSE);
2706 trace("test failures...\n");
2707 test_BindToStorage_fail();
2710 DeleteFileA(wszIndexHtmlA);
2711 CloseHandle(complete_event);
2712 CloseHandle(complete_event2);
2715 gecko_installer_workaround(FALSE);