mshtml: Use URL moniker to load http documents.
[wine] / dlls / urlmon / tests / url.c
1 /*
2  * UrlMon URL tests
3  *
4  * Copyright 2004 Kevin Koltzau
5  * Copyright 2004-2007 Jacek Caban for CodeWeavers
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define CONST_VTABLE
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "initguid.h"
32 #include "urlmon.h"
33 #include "wininet.h"
34 #include "mshtml.h"
35
36 #include "wine/test.h"
37
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);
41
42 #define DEFINE_EXPECT(func) \
43     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
44
45 #define SET_EXPECT(func) \
46     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
47
48 #define CHECK_EXPECT2(func) \
49     do { \
50         ok(expect_ ##func, "unexpected call " #func "\n"); \
51         called_ ## func = TRUE; \
52     }while(0)
53
54 #define CHECK_EXPECT(func) \
55     do { \
56         CHECK_EXPECT2(func); \
57         expect_ ## func = FALSE; \
58     }while(0)
59
60 #define CHECK_CALLED(func) \
61     do { \
62         ok(called_ ## func, "expected " #func "\n"); \
63         expect_ ## func = called_ ## func = FALSE; \
64     }while(0)
65
66 #define CHECK_NOT_CALLED(func) \
67     do { \
68         ok(!called_ ## func, "unexpected " #func "\n"); \
69         expect_ ## func = called_ ## func = FALSE; \
70     }while(0)
71
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)
77
78 #define CLEAR_CALLED(func) \
79     expect_ ## func = called_ ## func = FALSE
80
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);
134
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'};
137
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};
156
157
158 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
159
160 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
161
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};
172
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;
182
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
191 };
192
193 static WCHAR file_url[INTERNET_MAX_URL_LENGTH];
194
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;
204
205 static enum {
206     BEFORE_DOWNLOAD,
207     DOWNLOADING,
208     END_DOWNLOAD
209 } download_state;
210
211 static const char *debugstr_guid(REFIID riid)
212 {
213     static char buf[50];
214
215     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
216             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
217             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
218             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
219
220     return buf;
221 }
222
223 static BOOL is_urlmon_protocol(int prot)
224 {
225     return prot == FILE_TEST || prot == HTTP_TEST || prot == HTTPS_TEST || prot == FTP_TEST || prot == MK_TEST;
226 }
227
228 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
229 {
230     HRESULT hr;
231     IMoniker *mon1 = NULL;
232     IMoniker *mon2 = NULL;
233
234     hr = CreateURLMoniker(NULL, url1, &mon1);
235     ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
236     if(SUCCEEDED(hr)) {
237         hr = CreateURLMoniker(mon1, url2, &mon2);
238         ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
239     }
240     if(mon1) IMoniker_Release(mon1);
241     if(mon2) IMoniker_Release(mon2);
242 }
243
244 static void test_create(void)
245 {
246     test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
247 }
248
249 static HRESULT WINAPI Priority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
250 {
251     ok(0, "unexpected call\n");
252     return E_NOINTERFACE;
253 }
254
255 static ULONG WINAPI Priority_AddRef(IInternetPriority *iface)
256 {
257     return 2;
258 }
259
260 static ULONG WINAPI Priority_Release(IInternetPriority *iface)
261 {
262     return 1;
263 }
264
265 static HRESULT WINAPI Priority_SetPriority(IInternetPriority *iface, LONG nPriority)
266 {
267     CHECK_EXPECT(SetPriority);
268     ok(!nPriority, "nPriority = %d\n", nPriority);
269     return S_OK;
270 }
271
272 static HRESULT WINAPI Priority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
273 {
274     ok(0, "unexpected call\n");
275     return S_OK;
276 }
277
278 static const IInternetPriorityVtbl InternetPriorityVtbl = {
279     Priority_QueryInterface,
280     Priority_AddRef,
281     Priority_Release,
282     Priority_SetPriority,
283     Priority_GetPriority
284 };
285
286 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
287
288 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
289 {
290     *ppv = NULL;
291
292     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
293         *ppv = iface;
294         return S_OK;
295     }
296
297     if(IsEqualGUID(&IID_IInternetPriority, riid)) {
298         if(!is_urlmon_protocol(test_protocol))
299             return E_NOINTERFACE;
300
301         *ppv = &InternetPriority;
302         return S_OK;
303     }
304
305     if(IsEqualGUID(&IID_IInternetProtocolEx, riid))
306         return E_NOINTERFACE; /* TODO */
307
308     ok(0, "unexpected call %s\n", debugstr_guid(riid));
309     return E_NOINTERFACE;
310 }
311
312 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
313 {
314     return 2;
315 }
316
317 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
318 {
319     return 1;
320 }
321
322 static void test_switch_fail(void)
323 {
324     IInternetProtocolSink *binding_sink;
325     PROTOCOLDATA protocoldata;
326     HRESULT hres;
327
328     static BOOL tested_switch_fail;
329
330     if(tested_switch_fail)
331         return;
332
333     tested_switch_fail = TRUE;
334
335     hres = IBinding_QueryInterface(current_binding, &IID_IInternetProtocolSink, (void**)&binding_sink);
336     ok(hres == S_OK, "Could not get IInternetProtocolSink iface: %08x\n", hres);
337     if(SUCCEEDED(hres)) {
338         hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
339         ok(hres == E_FAIL, "Switch failed: %08x, expected E_FAIL\n", hres);
340         IInternetProtocolSink_Release(binding_sink);
341     }
342 }
343
344 static DWORD WINAPI thread_proc(PVOID arg)
345 {
346     PROTOCOLDATA protocoldata;
347     HRESULT hres;
348
349     if(bind_to_object)
350         SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
351     else
352         SET_EXPECT(OnProgress_FINDINGRESOURCE);
353     hres = IInternetProtocolSink_ReportProgress(protocol_sink,
354             BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
355     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
356     WaitForSingleObject(complete_event, INFINITE);
357     if(bind_to_object)
358         CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
359     else
360         CHECK_CALLED(OnProgress_FINDINGRESOURCE);
361
362     if(bind_to_object)
363         SET_EXPECT(Obj_OnProgress_CONNECTING);
364     else
365         SET_EXPECT(OnProgress_CONNECTING);
366     hres = IInternetProtocolSink_ReportProgress(protocol_sink,
367             BINDSTATUS_CONNECTING, wszWineHQIP);
368     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
369     WaitForSingleObject(complete_event, INFINITE);
370     if(bind_to_object)
371         CHECK_CALLED(Obj_OnProgress_CONNECTING);
372     else
373         CHECK_CALLED(OnProgress_CONNECTING);
374
375     if(bind_to_object)
376         SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
377     else
378         SET_EXPECT(OnProgress_SENDINGREQUEST);
379     hres = IInternetProtocolSink_ReportProgress(protocol_sink,
380             BINDSTATUS_SENDINGREQUEST, NULL);
381     ok(hres == S_OK, "ReportProxgress failed: %08x\n", hres);
382     WaitForSingleObject(complete_event, INFINITE);
383     if(bind_to_object)
384         CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
385     else
386         CHECK_CALLED(OnProgress_SENDINGREQUEST);
387
388     test_switch_fail();
389
390     SET_EXPECT(Continue);
391     prot_state = 1;
392     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
393     ok(hres == S_OK, "Switch failed: %08x\n", hres);
394     WaitForSingleObject(complete_event, INFINITE);
395
396     CHECK_CALLED(Continue);
397     CHECK_CALLED(Read);
398     if(bind_to_object) {
399         CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
400         CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
401         CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
402         CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
403         CHECK_CALLED(CreateInstance);
404         CHECK_CALLED(PutProperty_MIMETYPEPROP);
405         CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
406         CHECK_CALLED(Load);
407         CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
408         CHECK_CALLED(OnObjectAvailable);
409         CHECK_CALLED(Obj_OnStopBinding);
410     }else {
411         CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
412         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
413         CHECK_CALLED(LockRequest);
414         CHECK_CALLED(OnDataAvailable);
415     }
416
417     SET_EXPECT(Continue);
418     prot_state = 2;
419     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
420     ok(hres == S_OK, "Switch failed: %08x\n", hres);
421     WaitForSingleObject(complete_event, INFINITE);
422     CHECK_CALLED(Continue);
423     CHECK_CALLED(Read);
424     CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
425     CHECK_CALLED(OnDataAvailable);
426
427     SET_EXPECT(Continue);
428     prot_state = 2;
429     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
430     ok(hres == S_OK, "Switch failed: %08x\n", hres);
431     WaitForSingleObject(complete_event, INFINITE);
432     CHECK_CALLED(Continue);
433     CHECK_CALLED(Read);
434     CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
435     CHECK_CALLED(OnDataAvailable);
436
437     SET_EXPECT(Continue);
438     prot_state = 3;
439     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
440     ok(hres == S_OK, "Switch failed: %08x\n", hres);
441     WaitForSingleObject(complete_event, INFINITE);
442     CHECK_CALLED(Continue);
443     CHECK_CALLED(Read);
444     CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
445     CHECK_CALLED(OnDataAvailable);
446     CHECK_CALLED(OnStopBinding);
447
448     SET_EXPECT(Read);
449
450     SetEvent(complete_event2);
451     return 0;
452 }
453
454 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
455         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
456         DWORD grfPI, HANDLE_PTR dwReserved)
457 {
458     BINDINFO bindinfo;
459     DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
460     HRESULT hres;
461
462     static const STGMEDIUM stgmed_zero = {0};
463     static const SECURITY_ATTRIBUTES sa_zero = {0};
464
465     CHECK_EXPECT(Start);
466
467     read = 0;
468
469     if(!filedwl_api) /* FIXME */
470         ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", wine_dbgstr_w(szUrl));
471     ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
472     ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
473     ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
474     ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
475
476     if(!filedwl_api && binding_hres != S_OK) {
477         SET_EXPECT(OnStopBinding);
478         SET_EXPECT(Terminate);
479         hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
480         ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
481         CHECK_CALLED(OnStopBinding);
482         CHECK_CALLED(Terminate);
483
484         return S_OK;
485     }
486
487     memset(&bindinfo, 0, sizeof(bindinfo));
488     bindinfo.cbSize = sizeof(bindinfo);
489     hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
490     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
491
492     if(filedwl_api) {
493         ok(bindf == (BINDF_PULLDATA|BINDF_FROMURLMON|BINDF_NEEDFILE), "bindf=%08x\n", bindf);
494     }else if(tymed == TYMED_ISTREAM && is_urlmon_protocol(test_protocol)) {
495         ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
496                      |BINDF_FROMURLMON),
497            "bindf=%08x\n", bindf);
498     }else {
499         ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
500                      |BINDF_FROMURLMON|BINDF_NEEDFILE),
501            "bindf=%08x\n", bindf);
502     }
503
504     ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
505     ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
506     ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
507     ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
508     ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
509     ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
510     ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
511     ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
512     ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
513     ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
514     ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
515     ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
516     ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
517     ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
518
519     switch(test_protocol) {
520     case MK_TEST:
521         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
522                 BINDSTATUS_DIRECTBIND, NULL);
523         ok(hres == S_OK,
524            "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
525
526     case FILE_TEST:
527     case ITS_TEST:
528         if(bind_to_object)
529             SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
530         else
531             SET_EXPECT(OnProgress_SENDINGREQUEST);
532         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
533                 BINDSTATUS_SENDINGREQUEST, emptyW);
534         ok(hres == S_OK,
535            "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
536         if(bind_to_object)
537             CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
538         else
539             CHECK_CALLED(OnProgress_SENDINGREQUEST);
540     default:
541         break;
542     }
543
544     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
545         IServiceProvider *service_provider;
546         IHttpNegotiate *http_negotiate;
547         IHttpNegotiate2 *http_negotiate2;
548         LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
549         LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
550         BYTE sec_id[100];
551         DWORD fetched = 256, size = 100;
552         DWORD tid;
553
554         static const WCHAR wszMimes[] = {'*','/','*',0};
555
556         SET_EXPECT(QueryInterface_IInternetBindInfo);
557         SET_EXPECT(QueryService_IInternetBindInfo);
558         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
559                                                &ua, 1, &fetched);
560         CLEAR_CALLED(QueryInterface_IInternetBindInfo); /* IE <8 */
561         CLEAR_CALLED(QueryService_IInternetBindInfo); /* IE <8 */
562
563         ok(hres == E_NOINTERFACE,
564            "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
565         ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
566         ok(ua == (LPWSTR)0xdeadbeef, "ua =  %p\n", ua);
567
568         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
569                                                accept_mimes, 256, &fetched);
570         ok(hres == S_OK,
571            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
572         ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
573         ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
574
575         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
576                                                NULL, 256, &fetched);
577         ok(hres == E_INVALIDARG,
578            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
579
580         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
581                                                accept_mimes, 256, NULL);
582         ok(hres == E_INVALIDARG,
583            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
584
585         hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
586                                                 (void**)&service_provider);
587         ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
588
589         SET_EXPECT(QueryInterface_IHttpNegotiate);
590         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
591                 &IID_IHttpNegotiate, (void**)&http_negotiate);
592         CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
593         ok(hres == S_OK, "QueryService failed: %08x\n", hres);
594
595         SET_EXPECT(BeginningTransaction);
596         SET_EXPECT(QueryInterface_IHttpNegotiate);
597         hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
598                                                    NULL, 0, &additional_headers);
599         CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
600         CHECK_CALLED(BeginningTransaction);
601         IHttpNegotiate_Release(http_negotiate);
602         ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
603         ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
604
605         SET_EXPECT(QueryInterface_IHttpNegotiate2);
606         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
607                 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
608         CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
609         ok(hres == S_OK, "QueryService failed: %08x\n", hres);
610
611         size = 512;
612         SET_EXPECT(QueryInterface_IHttpNegotiate2);
613         SET_EXPECT(GetRootSecurityId);
614         hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
615         CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2);
616         CHECK_CALLED(GetRootSecurityId);
617         IHttpNegotiate2_Release(http_negotiate2);
618         ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
619         ok(size == 13, "size=%d\n", size);
620
621         IServiceProvider_Release(service_provider);
622
623         IInternetProtocolSink_AddRef(pOIProtSink);
624         protocol_sink = pOIProtSink;
625         CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
626
627         return S_OK;
628     }
629
630     if(test_protocol == FILE_TEST) {
631         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
632                 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
633         ok(hres == S_OK,
634            "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
635
636         if(bind_to_object)
637             SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
638         else
639             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
640         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
641                 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
642         ok(hres == S_OK,
643            "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
644         if(bind_to_object)
645             CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
646         else
647             CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
648     }else {
649         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
650                 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
651         ok(hres == S_OK,
652            "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
653     }
654
655     if(test_protocol == ABOUT_TEST)
656         bscf |= BSCF_DATAFULLYAVAILABLE;
657     if(test_protocol == ITS_TEST)
658         bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
659
660     SET_EXPECT(Read);
661     if(bind_to_object) {
662         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
663             SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
664         SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
665         if(test_protocol == FILE_TEST)
666             SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
667         SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
668         SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
669         SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
670         SET_EXPECT(CreateInstance);
671         SET_EXPECT(PutProperty_MIMETYPEPROP);
672         SET_EXPECT(PutProperty_CLASSIDPROP);
673         SET_EXPECT(Load);
674         SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
675         SET_EXPECT(OnObjectAvailable);
676         SET_EXPECT(Obj_OnStopBinding);
677     }else {
678         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
679             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
680         SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
681         if(test_protocol == FILE_TEST)
682             SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
683         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
684         SET_EXPECT(LockRequest);
685         if(!filedwl_api)
686             SET_EXPECT(OnDataAvailable);
687         SET_EXPECT(OnStopBinding);
688     }
689
690     hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
691     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
692
693     CHECK_CALLED(Read);
694     if(bind_to_object) {
695         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
696             CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
697         CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
698         if(test_protocol == FILE_TEST)
699             CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
700         CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
701         CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
702         CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
703         CHECK_CALLED(CreateInstance);
704         CHECK_CALLED(PutProperty_MIMETYPEPROP);
705         CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
706         CHECK_CALLED(Load);
707         CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
708         CHECK_CALLED(OnObjectAvailable);
709         CHECK_CALLED(Obj_OnStopBinding);
710     }else {
711         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
712             CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
713         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
714         if(test_protocol == FILE_TEST)
715             CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
716         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
717         CHECK_CALLED(LockRequest);
718         if(!filedwl_api)
719             CHECK_CALLED(OnDataAvailable);
720         CHECK_CALLED(OnStopBinding);
721     }
722
723     if(test_protocol == ITS_TEST) {
724         SET_EXPECT(Read);
725         hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
726         ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
727         CHECK_CALLED(Read);
728     }
729
730     SET_EXPECT(Terminate);
731     hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
732     ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
733     CHECK_CALLED(Terminate);
734
735     return S_OK;
736 }
737
738 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
739         PROTOCOLDATA *pProtocolData)
740 {
741     DWORD bscf = 0;
742     HRESULT hres;
743
744     CHECK_EXPECT(Continue);
745
746     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
747
748     ok(pProtocolData != NULL, "pProtocolData == NULL\n");
749     if(!pProtocolData)
750         return S_OK;
751
752     switch(prot_state) {
753     case 1: {
754         IServiceProvider *service_provider;
755         IHttpNegotiate *http_negotiate;
756         static WCHAR header[] = {'?',0};
757
758         hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
759                                                     (void**)&service_provider);
760         ok(hres == S_OK, "Could not get IServiceProvicder\n");
761
762         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
763                                              &IID_IHttpNegotiate, (void**)&http_negotiate);
764         ok(hres == S_OK, "Could not get IHttpNegotiate\n");
765
766         SET_EXPECT(QueryInterface_IHttpNegotiate);
767         SET_EXPECT(OnResponse);
768         hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
769         CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
770         CHECK_CALLED(OnResponse);
771         IHttpNegotiate_Release(http_negotiate);
772         ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
773
774         if(test_protocol == HTTPS_TEST) {
775             hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
776             ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
777         }
778
779         hres = IInternetProtocolSink_ReportProgress(protocol_sink,
780                 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
781         ok(hres == S_OK,
782            "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
783
784         if(tymed == TYMED_FILE) {
785             hres = IInternetProtocolSink_ReportProgress(protocol_sink,
786                     BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_fileW);
787             ok(hres == S_OK,
788                    "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
789         }
790
791         bscf |= BSCF_FIRSTDATANOTIFICATION;
792         break;
793     }
794     case 2:
795     case 3:
796         bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
797         break;
798     }
799
800     hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
801     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
802
803     SET_EXPECT(Read);
804     switch(prot_state) {
805     case 1:
806         if(bind_to_object) {
807             SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
808             SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
809             SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
810             SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
811             SET_EXPECT(CreateInstance);
812             SET_EXPECT(PutProperty_MIMETYPEPROP);
813             SET_EXPECT(PutProperty_CLASSIDPROP);
814             SET_EXPECT(Load);
815             SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
816             SET_EXPECT(OnObjectAvailable);
817             SET_EXPECT(Obj_OnStopBinding);
818         }else {
819             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
820             SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
821             SET_EXPECT(LockRequest);
822         }
823         break;
824     case 2:
825         SET_EXPECT(OnProgress_DOWNLOADINGDATA);
826         break;
827     case 3:
828         SET_EXPECT(OnProgress_DOWNLOADINGDATA);
829         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
830     }
831     if(!bind_to_object || prot_state >= 2)
832         SET_EXPECT(OnDataAvailable);
833     if(prot_state == 3)
834         SET_EXPECT(OnStopBinding);
835
836     return S_OK;
837 }
838
839 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
840         DWORD dwOptions)
841 {
842     ok(0, "unexpected call\n");
843     return E_NOTIMPL;
844 }
845
846 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
847 {
848     CHECK_EXPECT(Terminate);
849
850     ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
851
852     if(protocol_sink) {
853         IInternetProtocolSink_Release(protocol_sink);
854         protocol_sink = NULL;
855     }
856
857     return S_OK;
858 }
859
860 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
861 {
862     ok(0, "unexpected call\n");
863     return E_NOTIMPL;
864 }
865
866 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
867 {
868     ok(0, "unexpected call\n");
869     return E_NOTIMPL;
870 }
871
872 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
873         ULONG cb, ULONG *pcbRead)
874 {
875     static const char data[] = "<HTML></HTML>";
876
877     CHECK_EXPECT2(Read);
878
879     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
880         HRESULT hres;
881
882         static BOOL pending = TRUE;
883
884         pending = !pending;
885
886         switch(prot_state) {
887         case 1:
888         case 2:
889             if(pending) {
890                 *pcbRead = 10;
891                 memset(pv, '?', 10);
892                 return E_PENDING;
893             }else {
894                 memset(pv, '?', cb);
895                 *pcbRead = cb;
896                 read++;
897                 return S_OK;
898             }
899         case 3:
900             prot_state++;
901
902             *pcbRead = 0;
903
904             hres = IInternetProtocolSink_ReportData(protocol_sink,
905                     BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
906             ok(hres == S_OK, "ReportData failed: %08x\n", hres);
907
908             hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
909             ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
910
911             return S_FALSE;
912         case 4:
913             *pcbRead = 0;
914             return S_FALSE;
915         }
916     }
917
918     if(read) {
919         *pcbRead = 0;
920         return S_FALSE;
921     }
922
923     ok(pv != NULL, "pv == NULL\n");
924     ok(cb != 0, "cb == 0\n");
925     ok(pcbRead != NULL, "pcbRead == NULL\n");
926     if(pcbRead) {
927         ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
928         read += *pcbRead = sizeof(data)-1;
929     }
930     if(pv)
931         memcpy(pv, data, sizeof(data));
932
933     return S_OK;
934 }
935
936 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
937         LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
938 {
939     ok(0, "unexpected call\n");
940     return E_NOTIMPL;
941 }
942
943 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
944 {
945     CHECK_EXPECT(LockRequest);
946     return S_OK;
947 }
948
949 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
950 {
951     CHECK_EXPECT(UnlockRequest);
952     return S_OK;
953 }
954
955 static const IInternetProtocolVtbl ProtocolVtbl = {
956     Protocol_QueryInterface,
957     Protocol_AddRef,
958     Protocol_Release,
959     Protocol_Start,
960     Protocol_Continue,
961     Protocol_Abort,
962     Protocol_Terminate,
963     Protocol_Suspend,
964     Protocol_Resume,
965     Protocol_Read,
966     Protocol_Seek,
967     Protocol_LockRequest,
968     Protocol_UnlockRequest
969 };
970
971 static IInternetProtocol Protocol = { &ProtocolVtbl };
972
973 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
974 {
975     if(IsEqualGUID(&IID_IUnknown, riid)
976             || IsEqualGUID(&IID_IHttpNegotiate, riid)
977             || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
978         *ppv = iface;
979         return S_OK;
980     }
981
982     ok(0, "unexpected call\n");
983     return E_NOINTERFACE;
984 }
985
986 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
987 {
988     return 2;
989 }
990
991 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
992 {
993     return 1;
994 }
995
996 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
997         LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
998 {
999     CHECK_EXPECT(BeginningTransaction);
1000
1001     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1002
1003     ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
1004     ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
1005     ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1006     if(pszAdditionalHeaders)
1007         ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1008
1009     return S_OK;
1010 }
1011
1012 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
1013         LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
1014 {
1015     CHECK_EXPECT(OnResponse);
1016
1017     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1018
1019     ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
1020     ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
1021     ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
1022     /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
1023     ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1024     if(pszAdditionalRequestHeaders)
1025         ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1026
1027     return S_OK;
1028 }
1029
1030 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
1031         BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1032 {
1033     static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
1034
1035     CHECK_EXPECT(GetRootSecurityId);
1036
1037     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1038
1039     ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
1040     ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
1041     ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
1042
1043     if(pbSecurityId == (void*)0xdeadbeef)
1044         return E_NOTIMPL;
1045
1046     if(pcbSecurityId) {
1047         ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
1048         *pcbSecurityId = sizeof(sec_id);
1049     }
1050
1051     if(pbSecurityId)
1052         memcpy(pbSecurityId, sec_id, sizeof(sec_id));
1053
1054     return E_FAIL;
1055 }
1056
1057 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
1058     HttpNegotiate_QueryInterface,
1059     HttpNegotiate_AddRef,
1060     HttpNegotiate_Release,
1061     HttpNegotiate_BeginningTransaction,
1062     HttpNegotiate_OnResponse,
1063     HttpNegotiate_GetRootSecurityId
1064 };
1065
1066 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
1067
1068 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1069 {
1070     ok(0, "unexpected call\n");
1071     return E_NOINTERFACE;
1072 }
1073
1074 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1075 {
1076     return 2;
1077 }
1078
1079 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1080 {
1081     return 1;
1082 }
1083
1084 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1085         REFGUID guidService, REFIID riid, void **ppv)
1086 {
1087     if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
1088         CHECK_EXPECT(QueryService_IAuthenticate);
1089         return E_NOTIMPL;
1090     }
1091
1092     if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1093         CHECK_EXPECT2(QueryService_IInternetProtocol);
1094         return E_NOTIMPL;
1095     }
1096
1097     if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1098         CHECK_EXPECT(QueryService_IInternetBindInfo);
1099         return E_NOTIMPL;
1100     }
1101
1102     ok(0, "unexpected service %s\n", debugstr_guid(guidService));
1103     return E_NOINTERFACE;
1104 }
1105
1106 static IServiceProviderVtbl ServiceProviderVtbl = {
1107     ServiceProvider_QueryInterface,
1108     ServiceProvider_AddRef,
1109     ServiceProvider_Release,
1110     ServiceProvider_QueryService
1111 };
1112
1113 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1114
1115 static IBindStatusCallbackEx objbsc;
1116
1117 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1118 {
1119     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1120
1121     if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1122         CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1123         if(emulate_protocol) {
1124             *ppv = &Protocol;
1125             return S_OK;
1126         }else {
1127             return E_NOINTERFACE;
1128         }
1129     }
1130     else if (IsEqualGUID(&IID_IServiceProvider, riid))
1131     {
1132         CHECK_EXPECT2(QueryInterface_IServiceProvider);
1133         *ppv = &ServiceProvider;
1134         return S_OK;
1135     }
1136     else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
1137     {
1138         CHECK_EXPECT2(QueryInterface_IHttpNegotiate);
1139         *ppv = &HttpNegotiate;
1140         return S_OK;
1141     }
1142     else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
1143     {
1144         CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1145         *ppv = &HttpNegotiate;
1146         return S_OK;
1147     }
1148     else if (IsEqualGUID(&IID_IAuthenticate, riid))
1149     {
1150         CHECK_EXPECT(QueryInterface_IAuthenticate);
1151         return E_NOINTERFACE;
1152     }
1153     else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
1154     {
1155         CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1156         *ppv = iface;
1157         return S_OK;
1158     }
1159     else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
1160     {
1161         CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1162         return E_NOINTERFACE;
1163     }
1164     else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid))
1165     {
1166         CHECK_EXPECT(QueryInterface_IBindStatusCallbackEx);
1167         if(!use_bscex)
1168             return E_NOINTERFACE;
1169         *ppv = iface;
1170         return S_OK;
1171     }
1172     else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
1173     {
1174         /* TODO */
1175         CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1176     }
1177     else
1178     {
1179         ok(0, "unexpected interface %s\n", debugstr_guid(riid));
1180     }
1181
1182     return E_NOINTERFACE;
1183 }
1184
1185 static ULONG WINAPI statusclb_AddRef(IBindStatusCallbackEx *iface)
1186 {
1187     return 2;
1188 }
1189
1190 static ULONG WINAPI statusclb_Release(IBindStatusCallbackEx *iface)
1191 {
1192     return 1;
1193 }
1194
1195 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved,
1196         IBinding *pib)
1197 {
1198     IWinInetHttpInfo *http_info;
1199     HRESULT hres;
1200     IMoniker *mon;
1201
1202     if(iface == &objbsc)
1203         CHECK_EXPECT(Obj_OnStartBinding);
1204     else
1205         CHECK_EXPECT(OnStartBinding);
1206
1207     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1208
1209     ok(pib != NULL, "pib should not be NULL\n");
1210     ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1211
1212     if(pib == (void*)0xdeadbeef)
1213         return S_OK;
1214
1215     current_binding = pib;
1216
1217     hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1218     ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1219     if(SUCCEEDED(hres))
1220         IMoniker_Release(mon);
1221
1222     hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1223     ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1224
1225     return S_OK;
1226 }
1227
1228 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1229 {
1230     ok(0, "unexpected call\n");
1231     return E_NOTIMPL;
1232 }
1233
1234 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1235 {
1236     ok(0, "unexpected call\n");
1237     return E_NOTIMPL;
1238 }
1239
1240 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
1241         ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1242 {
1243     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1244
1245     switch(ulStatusCode) {
1246     case BINDSTATUS_FINDINGRESOURCE:
1247         if(iface == &objbsc)
1248             CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1249         else if(test_protocol == FTP_TEST)
1250             todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1251         else
1252             CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1253         if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1254             SetEvent(complete_event);
1255         break;
1256     case BINDSTATUS_CONNECTING:
1257         if(iface == &objbsc)
1258             CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1259         else if(test_protocol == FTP_TEST)
1260             todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
1261         else
1262             CHECK_EXPECT(OnProgress_CONNECTING);
1263         if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1264             SetEvent(complete_event);
1265         break;
1266     case BINDSTATUS_SENDINGREQUEST:
1267         if(iface == &objbsc)
1268             CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1269         else if(test_protocol == FTP_TEST)
1270             CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
1271         else
1272             CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1273         if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
1274             SetEvent(complete_event);
1275         break;
1276     case BINDSTATUS_MIMETYPEAVAILABLE:
1277         if(iface == &objbsc)
1278             CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1279         else
1280             CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1281         if(!bind_to_object)
1282             ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1283                download_state);
1284         WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1285         break;
1286     case BINDSTATUS_BEGINDOWNLOADDATA:
1287         if(iface == &objbsc)
1288             CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1289         else
1290             CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1291         ok(szStatusText != NULL, "szStatusText == NULL\n");
1292         if(szStatusText) {
1293             if(filedwl_api) {
1294                 /* FIXME */
1295             }else {
1296                 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1297             }
1298         }
1299         if(!bind_to_object)
1300             ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1301                download_state);
1302         download_state = DOWNLOADING;
1303         break;
1304     case BINDSTATUS_DOWNLOADINGDATA:
1305         CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1306         ok(iface != &objbsc, "unexpected call\n");
1307         ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1308            download_state);
1309         break;
1310     case BINDSTATUS_ENDDOWNLOADDATA:
1311         if(iface == &objbsc)
1312             CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1313         else
1314             CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1315         ok(szStatusText != NULL, "szStatusText == NULL\n");
1316         if(szStatusText) {
1317             if(filedwl_api) {
1318                 /* FIXME */
1319             }else {
1320                 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1321             }
1322         }
1323         ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1324            download_state);
1325         download_state = END_DOWNLOAD;
1326         break;
1327     case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1328         if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST) {
1329             if(iface == &objbsc)
1330                 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1331             else
1332                 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1333         }else {  /* FIXME */
1334             CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1335             CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1336         }
1337
1338         ok(szStatusText != NULL, "szStatusText == NULL\n");
1339         if(szStatusText && test_protocol == FILE_TEST)
1340             ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1341         break;
1342     case BINDSTATUS_CLASSIDAVAILABLE:
1343     {
1344         CLSID clsid;
1345         HRESULT hr;
1346         if(iface != &objbsc)
1347             ok(0, "unexpected call\n");
1348         else if(1||emulate_protocol)
1349             CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1350         else
1351             todo_wine CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1352         hr = CLSIDFromString((LPOLESTR)szStatusText, &clsid);
1353         ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1354         ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1355             "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1356         break;
1357     }
1358     case BINDSTATUS_BEGINSYNCOPERATION:
1359         CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1360         if(iface != &objbsc)
1361             ok(0, "unexpected call\n");
1362         ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1363         break;
1364     case BINDSTATUS_ENDSYNCOPERATION:
1365         CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1366         if(iface != &objbsc)
1367             ok(0, "unexpected call\n");
1368         ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1369         break;
1370     case BINDSTATUS_PROXYDETECTING:
1371         trace("BINDSTATUS_PROXYDETECTING\n");
1372         break;
1373     case BINDSTATUS_COOKIE_SENT:
1374         trace("BINDSTATUS_COOKIE_SENT\n");
1375         break;
1376     default:
1377         ok(0, "unexpected code %d\n", ulStatusCode);
1378     };
1379
1380     if(current_binding) {
1381         IWinInetHttpInfo *http_info;
1382         HRESULT hres;
1383
1384         hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
1385         if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol))
1386             ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
1387         else
1388             ok(hres == E_NOINTERFACE,
1389                "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
1390         if(SUCCEEDED(hres))
1391             IWinInetHttpInfo_Release(http_info);
1392     }
1393
1394     return S_OK;
1395 }
1396
1397 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
1398 {
1399     if(iface == &objbsc) {
1400         CHECK_EXPECT(Obj_OnStopBinding);
1401         stopped_obj_binding = TRUE;
1402     }else {
1403         CHECK_EXPECT(OnStopBinding);
1404         stopped_binding = TRUE;
1405     }
1406
1407     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1408
1409     /* ignore DNS failure */
1410     if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1411         return S_OK;
1412
1413     if(filedwl_api)
1414         ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1415     else
1416         ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1417     ok(szError == NULL, "szError should be NULL\n");
1418
1419     if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) && emulate_protocol) {
1420         SetEvent(complete_event);
1421         if(iface != &objbsc)
1422             WaitForSingleObject(complete_event2, INFINITE);
1423     }
1424
1425     return S_OK;
1426 }
1427
1428 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1429 {
1430     DWORD cbSize;
1431
1432     if(iface == &objbsc)
1433         CHECK_EXPECT(Obj_GetBindInfo);
1434     else
1435         CHECK_EXPECT(GetBindInfo);
1436
1437     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1438
1439     *grfBINDF = bindf;
1440     cbSize = pbindinfo->cbSize;
1441     memset(pbindinfo, 0, cbSize);
1442     pbindinfo->cbSize = cbSize;
1443
1444     return S_OK;
1445 }
1446
1447 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
1448         DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1449 {
1450     HRESULT hres;
1451     DWORD readed;
1452     BYTE buf[512];
1453     CHAR clipfmt[512];
1454
1455     if(iface == &objbsc)
1456         ok(0, "unexpected call\n");
1457
1458     CHECK_EXPECT2(OnDataAvailable);
1459
1460     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1461
1462     ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
1463        "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
1464        download_state);
1465     data_available = TRUE;
1466
1467     ok(pformatetc != NULL, "pformatetx == NULL\n");
1468     if(pformatetc) {
1469         if (mime_type[0]) {
1470             clipfmt[0] = 0;
1471             ok(GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1),
1472                "GetClipboardFormatName failed, error %d\n", GetLastError());
1473             ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
1474                pformatetc->cfFormat, clipfmt, mime_type);
1475         } else {
1476             ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
1477         }
1478         ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1479         ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
1480         ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
1481         ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1482     }
1483
1484     ok(pstgmed != NULL, "stgmeg == NULL\n");
1485     ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1486     ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1487
1488     switch(pstgmed->tymed) {
1489     case TYMED_ISTREAM:
1490         if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
1491             hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
1492             ok(hres == STG_E_ACCESSDENIED,
1493                "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1494
1495             hres = IStream_Commit(U(*pstgmed).pstm, 0);
1496             ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1497
1498             hres = IStream_Revert(U(*pstgmed).pstm);
1499             ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
1500         }
1501
1502         ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
1503         do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
1504         while(hres == S_OK);
1505         ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
1506         break;
1507
1508     case TYMED_FILE:
1509         if(test_protocol == FILE_TEST)
1510             ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1511                "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
1512         else if(emulate_protocol)
1513             ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1514                "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
1515         else
1516             ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1517     }
1518
1519     if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1520        && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1521         SetEvent(complete_event);
1522
1523     return S_OK;
1524 }
1525
1526 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
1527 {
1528     CHECK_EXPECT(OnObjectAvailable);
1529
1530     if(iface != &objbsc)
1531         ok(0, "unexpected call\n");
1532
1533     ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
1534     ok(punk != NULL, "punk == NULL\n");
1535
1536     return S_OK;
1537 }
1538
1539 static HRESULT WINAPI statusclb_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo,
1540         DWORD *grfBINDF2, DWORD *pdwReserved)
1541 {
1542     CHECK_EXPECT(GetBindInfoEx);
1543
1544     ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1545     ok(grfBINDF2 != NULL, "grfBINDF2 == NULL\n");
1546     ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1547     ok(pdwReserved != NULL, "dwReserved == NULL\n");
1548
1549     return S_OK;
1550 }
1551
1552 static const IBindStatusCallbackExVtbl BindStatusCallbackVtbl = {
1553     statusclb_QueryInterface,
1554     statusclb_AddRef,
1555     statusclb_Release,
1556     statusclb_OnStartBinding,
1557     statusclb_GetPriority,
1558     statusclb_OnLowResource,
1559     statusclb_OnProgress,
1560     statusclb_OnStopBinding,
1561     statusclb_GetBindInfo,
1562     statusclb_OnDataAvailable,
1563     statusclb_OnObjectAvailable,
1564     statusclb_GetBindInfoEx
1565 };
1566
1567 static IBindStatusCallbackEx bsc = { &BindStatusCallbackVtbl };
1568 static IBindStatusCallbackEx objbsc = { &BindStatusCallbackVtbl };
1569
1570 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
1571 {
1572     *ppv = NULL;
1573     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1574     return E_NOINTERFACE;
1575 }
1576
1577 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
1578 {
1579     return 2;
1580 }
1581
1582 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
1583 {
1584     return 1;
1585 }
1586
1587 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
1588 {
1589     switch(mkp) {
1590     case MIMETYPEPROP:
1591         CHECK_EXPECT(PutProperty_MIMETYPEPROP);
1592         ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", wine_dbgstr_w(val));
1593         break;
1594     case CLASSIDPROP:
1595         CHECK_EXPECT(PutProperty_CLASSIDPROP);
1596         break;
1597     default:
1598         break;
1599     }
1600
1601     return S_OK;
1602 }
1603
1604 static const IMonikerPropVtbl MonikerPropVtbl = {
1605     MonikerProp_QueryInterface,
1606     MonikerProp_AddRef,
1607     MonikerProp_Release,
1608     MonikerProp_PutProperty
1609 };
1610
1611 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
1612
1613 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
1614 {
1615     *ppv = NULL;
1616
1617     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
1618         *ppv = iface;
1619     else if(IsEqualGUID(&IID_IMonikerProp, riid))
1620         *ppv = &MonikerProp;
1621
1622     if(*ppv)
1623         return S_OK;
1624
1625     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1626     return E_NOINTERFACE;
1627 }
1628
1629 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
1630 {
1631     return 2;
1632 }
1633
1634 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
1635 {
1636     return 1;
1637 }
1638
1639 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
1640 {
1641     ok(0, "unexpected call\n");
1642     return E_NOTIMPL;
1643 }
1644
1645 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
1646 {
1647     ok(0, "unexpected call\n");
1648     return E_NOTIMPL;
1649 }
1650
1651 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
1652                                           IMoniker *pimkName, LPBC pibc, DWORD grfMode)
1653 {
1654     IUnknown *unk;
1655     HRESULT hres;
1656
1657     static WCHAR cbinding_contextW[] =
1658         {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
1659
1660     CHECK_EXPECT(Load);
1661     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1662
1663     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
1664         ok(!fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1665     else
1666         ok(fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
1667     ok(pimkName != NULL, "pimkName == NULL\n");
1668     ok(pibc != NULL, "pibc == NULL\n");
1669     ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
1670
1671     hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
1672     ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
1673     if(SUCCEEDED(hres)) {
1674         IBinding *binding;
1675
1676         hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
1677         ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
1678
1679         IBinding_Release(binding);
1680         IUnknown_Release(unk);
1681     }
1682
1683     SET_EXPECT(QueryInterface_IServiceProvider);
1684     hres = RegisterBindStatusCallback(pibc, (IBindStatusCallback*)&bsc, NULL, 0);
1685     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
1686     CHECK_CALLED(QueryInterface_IServiceProvider);
1687
1688     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1689     SET_EXPECT(GetBindInfo);
1690     SET_EXPECT(OnStartBinding);
1691     SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1692     if(test_protocol == FILE_TEST)
1693         SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1694     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1695         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1696     SET_EXPECT(LockRequest);
1697     SET_EXPECT(OnDataAvailable);
1698     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1699         SET_EXPECT(OnStopBinding);
1700
1701     hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
1702     ok(hres == S_OK, "Load failed: %08x\n", hres);
1703
1704     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
1705     CHECK_CALLED(GetBindInfo);
1706     CHECK_CALLED(OnStartBinding);
1707     CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
1708     if(test_protocol == FILE_TEST)
1709         CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1710     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1711         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
1712     CHECK_CALLED(LockRequest);
1713     CHECK_CALLED(OnDataAvailable);
1714     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
1715         CHECK_CALLED(OnStopBinding);
1716
1717     if(unk)
1718         IUnknown_Release(unk);
1719
1720     return S_OK;
1721 }
1722
1723 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
1724 {
1725     ok(0, "unexpected call\n");
1726     return E_NOTIMPL;
1727 }
1728
1729 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
1730 {
1731     ok(0, "unexpected call\n");
1732     return E_NOTIMPL;
1733 }
1734
1735 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
1736 {
1737     ok(0, "unexpected call\n");
1738     return E_NOTIMPL;
1739 }
1740
1741 static const IPersistMonikerVtbl PersistMonikerVtbl = {
1742     PersistMoniker_QueryInterface,
1743     PersistMoniker_AddRef,
1744     PersistMoniker_Release,
1745     PersistMoniker_GetClassID,
1746     PersistMoniker_IsDirty,
1747     PersistMoniker_Load,
1748     PersistMoniker_Save,
1749     PersistMoniker_SaveCompleted,
1750     PersistMoniker_GetCurMoniker
1751 };
1752
1753 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
1754
1755 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1756 {
1757     *ppv = NULL;
1758
1759     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1760         *ppv = iface;
1761         return S_OK;
1762     }
1763
1764     if(IsEqualGUID(&IID_IMarshal, riid))
1765         return E_NOINTERFACE;
1766     if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1767         return E_NOINTERFACE;
1768
1769     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1770     return E_NOTIMPL;
1771 }
1772
1773 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1774 {
1775     return 2;
1776 }
1777
1778 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1779 {
1780     return 1;
1781 }
1782
1783 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1784 {
1785     CHECK_EXPECT(CreateInstance);
1786     ok(!outer, "outer = %p\n", outer);
1787     ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1788     *ppv = &PersistMoniker;
1789     return S_OK;
1790 }
1791
1792 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1793 {
1794     ok(0, "unexpected call\n");
1795     return S_OK;
1796 }
1797
1798 static const IClassFactoryVtbl ClassFactoryVtbl = {
1799     ClassFactory_QueryInterface,
1800     ClassFactory_AddRef,
1801     ClassFactory_Release,
1802     ClassFactory_CreateInstance,
1803     ClassFactory_LockServer
1804 };
1805
1806 static IClassFactory mime_cf = { &ClassFactoryVtbl };
1807
1808 static void test_CreateAsyncBindCtx(void)
1809 {
1810     IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
1811     IUnknown *unk;
1812     HRESULT hres;
1813     ULONG ref;
1814     BIND_OPTS bindopts;
1815
1816     hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
1817     ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1818     ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
1819
1820     hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
1821     ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1822
1823     SET_EXPECT(QueryInterface_IServiceProvider);
1824     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
1825     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
1826     CHECK_CALLED(QueryInterface_IServiceProvider);
1827
1828     bindopts.cbStruct = sizeof(bindopts);
1829     hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1830     ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1831     ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1832                 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1833     ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1834                 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1835                 bindopts.grfMode);
1836     ok(bindopts.dwTickCountDeadline == 0,
1837                 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1838
1839     hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1840     ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
1841     if(SUCCEEDED(hres))
1842         IUnknown_Release(unk);
1843
1844     ref = IBindCtx_Release(bctx);
1845     ok(ref == 0, "bctx should be destroyed here\n");
1846 }
1847
1848 static void test_CreateAsyncBindCtxEx(void)
1849 {
1850     IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
1851     IUnknown *unk;
1852     BIND_OPTS bindopts;
1853     HRESULT hres;
1854
1855     static WCHAR testW[] = {'t','e','s','t',0};
1856
1857     hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
1858     ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
1859
1860     hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1861     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1862
1863     if(SUCCEEDED(hres)) {
1864         bindopts.cbStruct = sizeof(bindopts);
1865         hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1866         ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1867         ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1868                 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1869         ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1870                 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1871                 bindopts.grfMode);
1872         ok(bindopts.dwTickCountDeadline == 0,
1873                 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1874
1875         IBindCtx_Release(bctx);
1876     }
1877
1878     CreateBindCtx(0, &bctx_arg);
1879     hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1880     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1881
1882     if(SUCCEEDED(hres)) {
1883         bindopts.cbStruct = sizeof(bindopts);
1884         hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1885         ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1886         ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1887                 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1888         ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1889                 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1890                 bindopts.grfMode);
1891         ok(bindopts.dwTickCountDeadline == 0,
1892                 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1893
1894         IBindCtx_Release(bctx);
1895     }
1896
1897     IBindCtx_Release(bctx_arg);
1898
1899     SET_EXPECT(QueryInterface_IServiceProvider);
1900     hres = CreateAsyncBindCtxEx(NULL, 0, (IBindStatusCallback*)&bsc, NULL, &bctx, 0);
1901     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1902     CHECK_CALLED(QueryInterface_IServiceProvider);
1903
1904     hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
1905     ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
1906     if(SUCCEEDED(hres))
1907         IUnknown_Release(unk);
1908
1909     IBindCtx_Release(bctx);
1910
1911     hres = CreateBindCtx(0, &bctx2);
1912     ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
1913
1914     hres = CreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
1915     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1916
1917     hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
1918     ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
1919
1920     hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
1921     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1922     ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
1923
1924     IBindCtx_Release(bctx);
1925     IBindCtx_Release(bctx2);
1926 }
1927
1928 static void test_GetBindInfoEx(IBindStatusCallback *holder)
1929 {
1930     IBindStatusCallbackEx *bscex;
1931     BINDINFO bindinfo = {sizeof(bindinfo)};
1932     DWORD bindf, bindf2, dw;
1933     HRESULT hres;
1934
1935     hres = IBindStatusCallback_QueryInterface(holder, &IID_IBindStatusCallbackEx, (void**)&bscex);
1936     if(FAILED(hres)) {
1937         win_skip("IBindStatusCallbackEx not supported\n");
1938         return;
1939     }
1940
1941     use_bscex = TRUE;
1942
1943     bindf = 0;
1944     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1945     SET_EXPECT(GetBindInfoEx);
1946     hres = IBindStatusCallback_GetBindInfo(holder, &bindf, &bindinfo);
1947     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1948     CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1949     CHECK_CALLED(GetBindInfoEx);
1950
1951     bindf = bindf2 = dw = 0;
1952     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1953     SET_EXPECT(GetBindInfoEx);
1954     hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
1955     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1956     CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1957     CHECK_CALLED(GetBindInfoEx);
1958
1959     use_bscex = FALSE;
1960
1961     bindf = bindf2 = dw = 0xdeadbeef;
1962     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1963     SET_EXPECT(GetBindInfo);
1964     hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
1965     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1966     CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
1967     CHECK_CALLED(GetBindInfo);
1968     ok(bindf2 == 0xdeadbeef, "bindf2 = %x\n", bindf2);
1969     ok(dw == 0xdeadbeef, "dw = %x\n", dw);
1970
1971     IBindStatusCallbackEx_Release(bscex);
1972 }
1973
1974 static BOOL test_bscholder(IBindStatusCallback *holder)
1975 {
1976     IServiceProvider *serv_prov;
1977     IHttpNegotiate *http_negotiate, *http_negotiate_serv;
1978     IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
1979     IAuthenticate *authenticate, *authenticate_serv;
1980     IInternetProtocol *protocol;
1981     BINDINFO bindinfo = {sizeof(bindinfo)};
1982     BOOL ret = TRUE;
1983     LPWSTR wstr;
1984     DWORD dw;
1985     HRESULT hres;
1986
1987     hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
1988     ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
1989
1990     dw = 0xdeadbeef;
1991     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
1992     SET_EXPECT(GetBindInfo);
1993     hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
1994     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1995     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
1996     CHECK_CALLED(GetBindInfo);
1997
1998     test_GetBindInfoEx(holder);
1999
2000     SET_EXPECT(OnStartBinding);
2001     hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
2002     ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
2003     CHECK_CALLED(OnStartBinding);
2004
2005     hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
2006     ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
2007
2008     SET_EXPECT(QueryInterface_IHttpNegotiate);
2009     hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2010                                          (void**)&http_negotiate_serv);
2011     ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2012     CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
2013
2014     ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2015
2016     wstr = (void*)0xdeadbeef;
2017     SET_EXPECT(QueryInterface_IHttpNegotiate);
2018     SET_EXPECT(BeginningTransaction);
2019     hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
2020     CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2021     CHECK_CALLED(BeginningTransaction);
2022     ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
2023     ok(wstr == NULL, "wstr = %p\n", wstr);
2024
2025     IHttpNegotiate_Release(http_negotiate_serv);
2026
2027     hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2028                                          (void**)&http_negotiate_serv);
2029     ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2030     ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2031     IHttpNegotiate_Release(http_negotiate_serv);
2032
2033     hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
2034     if(SUCCEEDED(hres)) {
2035         have_IHttpNegotiate2 = TRUE;
2036
2037         SET_EXPECT(QueryInterface_IHttpNegotiate2);
2038         hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
2039                                              (void**)&http_negotiate2_serv);
2040         ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
2041         CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
2042         ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
2043
2044         SET_EXPECT(QueryInterface_IHttpNegotiate2);
2045         SET_EXPECT(GetRootSecurityId);
2046         hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
2047         ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
2048         CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2); /* IE8 */
2049         CHECK_CALLED(GetRootSecurityId);
2050
2051         IHttpNegotiate_Release(http_negotiate2_serv);
2052         IHttpNegotiate_Release(http_negotiate2);
2053     }else {
2054         skip("Could not get IHttpNegotiate2\n");
2055         ret = FALSE;
2056     }
2057
2058     SET_EXPECT(OnProgress_FINDINGRESOURCE);
2059     hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
2060     ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
2061     CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2062
2063     SET_EXPECT(QueryInterface_IHttpNegotiate);
2064     SET_EXPECT(OnResponse);
2065     wstr = (void*)0xdeadbeef;
2066     hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
2067     ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2068     CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2069     CHECK_CALLED(OnResponse);
2070
2071     IHttpNegotiate_Release(http_negotiate);
2072
2073     hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
2074     ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
2075
2076     SET_EXPECT(QueryInterface_IAuthenticate);
2077     SET_EXPECT(QueryService_IAuthenticate);
2078     hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2079                                          (void**)&authenticate_serv);
2080     ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2081     CLEAR_CALLED(QueryInterface_IAuthenticate); /* IE <8 */
2082     CLEAR_CALLED(QueryService_IAuthenticate); /* IE <8 */
2083     ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2084     IAuthenticate_Release(authenticate_serv);
2085
2086     hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2087                                          (void**)&authenticate_serv);
2088     ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2089     ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2090
2091     IAuthenticate_Release(authenticate);
2092     IAuthenticate_Release(authenticate_serv);
2093
2094     SET_EXPECT(OnStopBinding);
2095     hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
2096     ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
2097     CHECK_CALLED(OnStopBinding);
2098
2099     SET_EXPECT(QueryInterface_IInternetProtocol);
2100     SET_EXPECT(QueryService_IInternetProtocol);
2101     hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
2102                                          (void**)&protocol);
2103     ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
2104     CHECK_CALLED(QueryInterface_IInternetProtocol);
2105     CHECK_CALLED(QueryService_IInternetProtocol);
2106
2107     IServiceProvider_Release(serv_prov);
2108     return ret;
2109 }
2110
2111 static BOOL test_RegisterBindStatusCallback(void)
2112 {
2113     IBindStatusCallback *prevbsc, *clb;
2114     IBindCtx *bindctx;
2115     BOOL ret = TRUE;
2116     IUnknown *unk;
2117     HRESULT hres;
2118
2119     hres = CreateBindCtx(0, &bindctx);
2120     ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
2121
2122     SET_EXPECT(QueryInterface_IServiceProvider);
2123
2124     hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
2125     ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2126
2127     SET_EXPECT(QueryInterface_IBindStatusCallback);
2128     SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
2129     prevbsc = (void*)0xdeadbeef;
2130     hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2131     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2132     ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc=%p\n", prevbsc);
2133     CHECK_CALLED(QueryInterface_IBindStatusCallback);
2134     CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
2135
2136     CHECK_CALLED(QueryInterface_IServiceProvider);
2137
2138     hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2139     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2140
2141     hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2142     IUnknown_Release(unk);
2143     ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2144     ok(clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2145
2146     if(!test_bscholder(clb))
2147         ret = FALSE;
2148
2149     IBindStatusCallback_Release(clb);
2150
2151     hres = RevokeBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc);
2152     ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2153
2154     unk = (void*)0xdeadbeef;
2155     hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2156     ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
2157     ok(unk == NULL, "unk != NULL\n");
2158
2159     if(unk)
2160         IUnknown_Release(unk);
2161
2162     hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
2163     ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2164
2165     hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
2166     ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2167
2168     hres = RevokeBindStatusCallback(bindctx, NULL);
2169     ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2170
2171     IBindCtx_Release(bindctx);
2172     return ret;
2173 }
2174
2175 #define BINDTEST_EMULATE     1
2176 #define BINDTEST_TOOBJECT    2
2177 #define BINDTEST_FILEDWLAPI  4
2178
2179 static void init_bind_test(int protocol, DWORD flags, DWORD t)
2180 {
2181     test_protocol = protocol;
2182     emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
2183     download_state = BEFORE_DOWNLOAD;
2184     stopped_binding = FALSE;
2185     stopped_obj_binding = FALSE;
2186     data_available = FALSE;
2187     mime_type[0] = 0;
2188     binding_hres = S_OK;
2189     bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
2190     tymed = t;
2191     filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
2192 }
2193
2194 static void test_BindToStorage(int protocol, BOOL emul, DWORD t)
2195 {
2196     IMoniker *mon;
2197     HRESULT hres;
2198     LPOLESTR display_name;
2199     IBindCtx *bctx;
2200     MSG msg;
2201     IBindStatusCallback *previousclb;
2202     IUnknown *unk = (IUnknown*)0x00ff00ff;
2203     IBinding *bind;
2204
2205     init_bind_test(protocol, emul ? BINDTEST_EMULATE : 0, t);
2206
2207     SET_EXPECT(QueryInterface_IServiceProvider);
2208     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2209     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2210     CHECK_CALLED(QueryInterface_IServiceProvider);
2211     if(FAILED(hres))
2212         return;
2213
2214     SET_EXPECT(QueryInterface_IServiceProvider);
2215     hres = RegisterBindStatusCallback(bctx, (IBindStatusCallback*)&bsc, &previousclb, 0);
2216     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2217     ok(previousclb == (IBindStatusCallback*)&bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2218     CHECK_CALLED(QueryInterface_IServiceProvider);
2219     if(previousclb)
2220         IBindStatusCallback_Release(previousclb);
2221
2222     hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2223     ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2224     if(FAILED(hres)) {
2225         IBindCtx_Release(bctx);
2226         return;
2227     }
2228
2229     hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2230     ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2231     if(SUCCEEDED(hres))
2232         IBinding_Release(bind);
2233
2234     hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2235     ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2236     ok(!lstrcmpW(display_name, urls[test_protocol]),
2237        "GetDisplayName got wrong name %s\n", wine_dbgstr_w(display_name));
2238     CoTaskMemFree(display_name);
2239
2240     if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
2241         binding_hres = INET_E_DATA_NOT_AVAILABLE;
2242
2243     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2244     SET_EXPECT(GetBindInfo);
2245     SET_EXPECT(QueryInterface_IInternetProtocol);
2246     if(!emulate_protocol)
2247         SET_EXPECT(QueryService_IInternetProtocol);
2248     SET_EXPECT(OnStartBinding);
2249     if(emulate_protocol) {
2250         if(is_urlmon_protocol(test_protocol))
2251             SET_EXPECT(SetPriority);
2252         SET_EXPECT(Start);
2253         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2254             SET_EXPECT(Terminate);
2255         if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2256             SET_EXPECT(UnlockRequest);
2257     }else {
2258         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2259             SET_EXPECT(QueryInterface_IInternetBindInfo);
2260             SET_EXPECT(QueryService_IInternetBindInfo);
2261             SET_EXPECT(QueryInterface_IHttpNegotiate);
2262             SET_EXPECT(BeginningTransaction);
2263             SET_EXPECT(QueryInterface_IHttpNegotiate2);
2264             SET_EXPECT(GetRootSecurityId);
2265             SET_EXPECT(OnProgress_FINDINGRESOURCE);
2266             SET_EXPECT(OnProgress_CONNECTING);
2267         }
2268         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST
2269            || test_protocol == FILE_TEST)
2270             SET_EXPECT(OnProgress_SENDINGREQUEST);
2271         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2272             SET_EXPECT(QueryInterface_IHttpNegotiate);
2273             SET_EXPECT(OnResponse);
2274         }
2275         SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2276         SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2277         if(test_protocol == FILE_TEST)
2278             SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2279         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2280             SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2281         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2282         if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2283             SET_EXPECT(OnDataAvailable);
2284         SET_EXPECT(OnStopBinding);
2285     }
2286
2287     hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2288     if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2289         && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2290     {
2291         skip("Network unreachable, skipping tests\n");
2292         return;
2293     }
2294
2295     if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
2296        || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2297         ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2298         ok(unk == NULL, "istr should be NULL\n");
2299     }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
2300         ok(hres == INET_E_DATA_NOT_AVAILABLE,
2301            "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
2302         ok(unk == NULL, "istr should be NULL\n");
2303     }else {
2304         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2305         ok(unk != NULL, "unk == NULL\n");
2306     }
2307     if(unk)
2308         IUnknown_Release(unk);
2309
2310     if(FAILED(hres))
2311         return;
2312
2313     while((bindf & BINDF_ASYNCHRONOUS) &&
2314           !stopped_binding && GetMessage(&msg,NULL,0,0)) {
2315         TranslateMessage(&msg);
2316         DispatchMessage(&msg);
2317     }
2318
2319     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2320     CHECK_CALLED(GetBindInfo);
2321     CHECK_CALLED(QueryInterface_IInternetProtocol);
2322     if(!emulate_protocol)
2323         CHECK_CALLED(QueryService_IInternetProtocol);
2324     CHECK_CALLED(OnStartBinding);
2325     if(emulate_protocol) {
2326         if(is_urlmon_protocol(test_protocol))
2327             CHECK_CALLED(SetPriority);
2328         CHECK_CALLED(Start);
2329         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2330             if(tymed == TYMED_FILE)
2331                 CLEAR_CALLED(Read);
2332             CHECK_CALLED(Terminate);
2333         }
2334         if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2335             CHECK_CALLED(UnlockRequest);
2336     }else {
2337         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2338             CLEAR_CALLED(QueryInterface_IInternetBindInfo);
2339             CLEAR_CALLED(QueryService_IInternetBindInfo);
2340             CHECK_CALLED(QueryInterface_IHttpNegotiate);
2341             CHECK_CALLED(BeginningTransaction);
2342             if (have_IHttpNegotiate2)
2343             {
2344                 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2345                 CHECK_CALLED(GetRootSecurityId);
2346             }
2347             if(http_is_first || test_protocol == HTTPS_TEST) {
2348                 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2349                 CHECK_CALLED(OnProgress_CONNECTING);
2350             }else todo_wine {
2351                 CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
2352                 /* IE7 does call this */
2353                 CLEAR_CALLED(OnProgress_CONNECTING);
2354             }
2355         }
2356         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2357             CHECK_CALLED(OnProgress_SENDINGREQUEST);
2358         else if(test_protocol == FTP_TEST)
2359             todo_wine CHECK_CALLED(OnProgress_SENDINGREQUEST);
2360         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2361             CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2362             CHECK_CALLED(OnResponse);
2363         }
2364         CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2365         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2366         if(test_protocol == FILE_TEST)
2367             CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2368         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2369             CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2370         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2371         if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
2372             CHECK_CALLED(OnDataAvailable);
2373         CHECK_CALLED(OnStopBinding);
2374     }
2375
2376     ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2377     ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2378
2379     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2380         http_is_first = FALSE;
2381 }
2382
2383 static void test_BindToObject(int protocol, BOOL emul)
2384 {
2385     IMoniker *mon;
2386     HRESULT hres;
2387     LPOLESTR display_name;
2388     IBindCtx *bctx;
2389     DWORD regid;
2390     MSG msg;
2391     IUnknown *unk = (IUnknown*)0x00ff00ff;
2392     IBinding *bind;
2393
2394     init_bind_test(protocol, BINDTEST_TOOBJECT | (emul ? BINDTEST_EMULATE : 0), TYMED_ISTREAM);
2395
2396     if(emul)
2397         CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
2398                               CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2399
2400     SET_EXPECT(QueryInterface_IServiceProvider);
2401     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&objbsc, NULL, &bctx);
2402     ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
2403     CHECK_CALLED(QueryInterface_IServiceProvider);
2404     if(FAILED(hres))
2405         return;
2406
2407     hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2408     ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2409     if(FAILED(hres)) {
2410         IBindCtx_Release(bctx);
2411         return;
2412     }
2413
2414     hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2415     ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2416     if(SUCCEEDED(hres))
2417         IBinding_Release(bind);
2418
2419     hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2420     ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2421     ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
2422
2423     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2424     SET_EXPECT(Obj_GetBindInfo);
2425     SET_EXPECT(QueryInterface_IInternetProtocol);
2426     if(!emulate_protocol)
2427         SET_EXPECT(QueryService_IInternetProtocol);
2428     SET_EXPECT(Obj_OnStartBinding);
2429     if(emulate_protocol) {
2430         if(is_urlmon_protocol(test_protocol))
2431             SET_EXPECT(SetPriority);
2432         SET_EXPECT(Start);
2433         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2434             SET_EXPECT(Terminate);
2435         if(test_protocol == FILE_TEST)
2436             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2437         SET_EXPECT(UnlockRequest);
2438     }else {
2439         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2440             SET_EXPECT(QueryInterface_IHttpNegotiate);
2441             SET_EXPECT(BeginningTransaction);
2442             SET_EXPECT(QueryInterface_IHttpNegotiate2);
2443             SET_EXPECT(GetRootSecurityId);
2444             SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
2445             SET_EXPECT(Obj_OnProgress_CONNECTING);
2446         }
2447         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2448             SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
2449         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2450             SET_EXPECT(QueryInterface_IHttpNegotiate);
2451             SET_EXPECT(OnResponse);
2452         }
2453         SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
2454         SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
2455         if(test_protocol == FILE_TEST)
2456             SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2457         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2458             SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2459         SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
2460         SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
2461         SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
2462         SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
2463         SET_EXPECT(OnObjectAvailable);
2464         SET_EXPECT(Obj_OnStopBinding);
2465     }
2466
2467     hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
2468
2469     if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2470         && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2471     {
2472         skip( "Network unreachable, skipping tests\n" );
2473         return;
2474     }
2475
2476     /* no point testing the calls if binding didn't even work */
2477     if (FAILED(hres)) return;
2478
2479     if(bindf & BINDF_ASYNCHRONOUS) {
2480         ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
2481         ok(unk == NULL, "istr should be NULL\n");
2482     }else {
2483         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2484         ok(unk != NULL, "unk == NULL\n");
2485         if(emul)
2486             ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
2487     }
2488     if(unk)
2489         IUnknown_Release(unk);
2490
2491     while((bindf & BINDF_ASYNCHRONOUS) &&
2492           !((!emul || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
2493         TranslateMessage(&msg);
2494         DispatchMessage(&msg);
2495     }
2496
2497     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx);
2498     CHECK_CALLED(Obj_GetBindInfo);
2499     CHECK_CALLED(QueryInterface_IInternetProtocol);
2500     if(!emulate_protocol)
2501         CHECK_CALLED(QueryService_IInternetProtocol);
2502     CHECK_CALLED(Obj_OnStartBinding);
2503     if(emulate_protocol) {
2504         if(is_urlmon_protocol(test_protocol))
2505             CHECK_CALLED(SetPriority);
2506         CHECK_CALLED(Start);
2507         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2508             CHECK_CALLED(Terminate);
2509         if(test_protocol == FILE_TEST)
2510             CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
2511         CHECK_CALLED(UnlockRequest);
2512     }else {
2513         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2514             CHECK_CALLED(QueryInterface_IHttpNegotiate);
2515             CHECK_CALLED(BeginningTransaction);
2516             if (have_IHttpNegotiate2)
2517             {
2518                 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2519                 CHECK_CALLED(GetRootSecurityId);
2520             }
2521             if(http_is_first) {
2522                 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2523                 CHECK_CALLED(Obj_OnProgress_CONNECTING);
2524             }else todo_wine {
2525                 CHECK_NOT_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2526                 /* IE7 does call this */
2527                 CLEAR_CALLED(Obj_OnProgress_CONNECTING);
2528             }
2529         }
2530         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
2531             if(urls[test_protocol] == SHORT_RESPONSE_URL)
2532                 CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
2533             else
2534                 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
2535         }
2536         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2537             CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2538             CHECK_CALLED(OnResponse);
2539         }
2540         CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
2541         CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
2542         if(test_protocol == FILE_TEST)
2543             CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2544         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2545             CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2546         CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
2547         CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
2548         CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
2549         CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
2550         CHECK_CALLED(OnObjectAvailable);
2551         CHECK_CALLED(Obj_OnStopBinding);
2552     }
2553
2554     if(test_protocol != HTTP_TEST || emul || urls[test_protocol] == SHORT_RESPONSE_URL || !(bindf & BINDF_ASYNCHRONOUS)) {
2555         ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2556         ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2557     }else {
2558         todo_wine ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2559         IBindCtx_Release(bctx);
2560     }
2561
2562     if(emul)
2563         CoRevokeClassObject(regid);
2564
2565     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2566         http_is_first = FALSE;
2567 }
2568
2569 static void test_URLDownloadToFile(DWORD prot, BOOL emul)
2570 {
2571     BOOL res;
2572     HRESULT hres;
2573
2574     init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);
2575
2576     SET_EXPECT(GetBindInfo);
2577     SET_EXPECT(QueryInterface_IInternetProtocol);
2578     if(!emulate_protocol) {
2579         SET_EXPECT(QueryInterface_IServiceProvider);
2580         SET_EXPECT(QueryService_IInternetProtocol);
2581     }
2582     SET_EXPECT(OnStartBinding);
2583     if(emulate_protocol) {
2584         if(is_urlmon_protocol(test_protocol))
2585             SET_EXPECT(SetPriority);
2586         SET_EXPECT(Start);
2587         SET_EXPECT(UnlockRequest);
2588     }else {
2589         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2590             SET_EXPECT(QueryInterface_IHttpNegotiate);
2591             SET_EXPECT(BeginningTransaction);
2592             SET_EXPECT(QueryInterface_IHttpNegotiate2);
2593             SET_EXPECT(GetRootSecurityId);
2594         }
2595         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2596             SET_EXPECT(OnProgress_SENDINGREQUEST);
2597         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2598             SET_EXPECT(QueryInterface_IHttpNegotiate);
2599             SET_EXPECT(OnResponse);
2600         }
2601         SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2602         SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2603         if(test_protocol == FILE_TEST)
2604             SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2605         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2606             SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2607         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2608         SET_EXPECT(OnStopBinding);
2609     }
2610
2611     hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol],
2612             dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
2613     ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2614
2615     CHECK_CALLED(GetBindInfo);
2616     CHECK_CALLED(QueryInterface_IInternetProtocol);
2617     if(!emulate_protocol) {
2618         CHECK_CALLED(QueryInterface_IServiceProvider);
2619         CHECK_CALLED(QueryService_IInternetProtocol);
2620     }
2621     CHECK_CALLED(OnStartBinding);
2622     if(emulate_protocol) {
2623         if(is_urlmon_protocol(test_protocol))
2624             CHECK_CALLED(SetPriority);
2625         CHECK_CALLED(Start);
2626         CHECK_CALLED(UnlockRequest);
2627     }else {
2628         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2629             CHECK_CALLED(QueryInterface_IHttpNegotiate);
2630             CHECK_CALLED(BeginningTransaction);
2631             if (have_IHttpNegotiate2)
2632             {
2633                 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2634                 CHECK_CALLED(GetRootSecurityId);
2635             }
2636         }
2637         if(test_protocol == FILE_TEST)
2638             CHECK_CALLED(OnProgress_SENDINGREQUEST);
2639         else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2640             CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
2641         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2642             CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2643             CHECK_CALLED(OnResponse);
2644         }
2645         CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2646         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2647         if(test_protocol == FILE_TEST)
2648             CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2649         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2650             CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2651         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2652         CHECK_CALLED(OnStopBinding);
2653     }
2654
2655     res = DeleteFileA(dwl_htmlA);
2656     ok(res, "DeleteFile failed: %u\n", GetLastError());
2657
2658     if(prot != FILE_TEST || emul)
2659         return;
2660
2661     hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
2662     ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
2663
2664     res = DeleteFileA(dwl_htmlA);
2665     ok(res, "DeleteFile failed: %u\n", GetLastError());
2666 }
2667
2668 static void set_file_url(char *path)
2669 {
2670     CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
2671     CHAR INDEX_HTMLA[MAX_PATH];
2672
2673     lstrcpyA(file_urlA, "file:///");
2674     lstrcatA(file_urlA, path);
2675     MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
2676
2677     lstrcpyA(INDEX_HTMLA, "file://");
2678     lstrcatA(INDEX_HTMLA, path);
2679     MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
2680 }
2681
2682 static void create_file(void)
2683 {
2684     HANDLE file;
2685     DWORD size;
2686     CHAR path[MAX_PATH];
2687
2688     static const char html_doc[] = "<HTML></HTML>";
2689
2690     file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2691             FILE_ATTRIBUTE_NORMAL, NULL);
2692     ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2693     if(file == INVALID_HANDLE_VALUE)
2694         return;
2695
2696     WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2697     CloseHandle(file);
2698
2699     GetCurrentDirectoryA(MAX_PATH, path);
2700     lstrcatA(path, "\\");
2701     lstrcatA(path, wszIndexHtmlA);
2702     set_file_url(path);
2703 }
2704
2705 static void test_ReportResult(HRESULT exhres)
2706 {
2707     IMoniker *mon = NULL;
2708     IBindCtx *bctx = NULL;
2709     IUnknown *unk = (void*)0xdeadbeef;
2710     HRESULT hres;
2711
2712     init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
2713     binding_hres = exhres;
2714
2715     hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2716     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2717
2718     SET_EXPECT(QueryInterface_IServiceProvider);
2719     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2720     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2721     CHECK_CALLED(QueryInterface_IServiceProvider);
2722
2723     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2724     SET_EXPECT(GetBindInfo);
2725     SET_EXPECT(QueryInterface_IInternetProtocol);
2726     SET_EXPECT(OnStartBinding);
2727     if(is_urlmon_protocol(test_protocol))
2728         SET_EXPECT(SetPriority);
2729     SET_EXPECT(Start);
2730
2731     hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2732     if(SUCCEEDED(exhres))
2733         ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
2734     else
2735         ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
2736            "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
2737
2738     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2739     CHECK_CALLED(GetBindInfo);
2740     CHECK_CALLED(QueryInterface_IInternetProtocol);
2741     CHECK_CALLED(OnStartBinding);
2742     if(is_urlmon_protocol(test_protocol))
2743         CHECK_CALLED(SetPriority);
2744     CHECK_CALLED(Start);
2745
2746     ok(unk == NULL, "unk=%p\n", unk);
2747
2748     IBindCtx_Release(bctx);
2749     IMoniker_Release(mon);
2750 }
2751
2752 static void test_BindToStorage_fail(void)
2753 {
2754     IMoniker *mon = NULL;
2755     IBindCtx *bctx = NULL;
2756     IUnknown *unk;
2757     HRESULT hres;
2758
2759     hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2760     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2761     if(FAILED(hres))
2762         return;
2763
2764     hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2765     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2766
2767     hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
2768     ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
2769        "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
2770
2771     IBindCtx_Release(bctx);
2772
2773     IMoniker_Release(mon);
2774
2775     test_ReportResult(E_NOTIMPL);
2776     test_ReportResult(S_FALSE);
2777 }
2778
2779 static void test_StdURLMoniker(void)
2780 {
2781     IMoniker *mon, *async_mon;
2782     LPOLESTR display_name;
2783     HRESULT hres;
2784
2785     hres = CoCreateInstance(&IID_IInternet, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2786             &IID_IMoniker, (void**)&mon);
2787     ok(hres == S_OK, "Could not create IInternet instance: %08x\n", hres);
2788     if(FAILED(hres))
2789         return;
2790
2791     hres = IMoniker_QueryInterface(mon, &IID_IAsyncMoniker, (void**)&async_mon);
2792     ok(hres == S_OK, "Could not get IAsyncMoniker iface: %08x\n", hres);
2793     ok(mon == async_mon, "mon != async_mon\n");
2794     IMoniker_Release(async_mon);
2795
2796     hres = IMoniker_GetDisplayName(mon, NULL, NULL, &display_name);
2797     ok(hres == E_OUTOFMEMORY, "GetDisplayName failed: %08x, expected E_OUTOFMEMORY\n", hres);
2798
2799     IMoniker_Release(mon);
2800 }
2801
2802 static void gecko_installer_workaround(BOOL disable)
2803 {
2804     HKEY hkey;
2805     DWORD res;
2806
2807     static BOOL has_url = FALSE;
2808     static char url[2048];
2809
2810     if(!disable && !has_url)
2811         return;
2812
2813     res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
2814     if(res != ERROR_SUCCESS)
2815         return;
2816
2817     if(disable) {
2818         DWORD type, size = sizeof(url);
2819
2820         res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
2821         if(res == ERROR_SUCCESS && type == REG_SZ)
2822             has_url = TRUE;
2823
2824         RegDeleteValue(hkey, "GeckoUrl");
2825     }else {
2826         RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
2827     }
2828
2829     RegCloseKey(hkey);
2830 }
2831
2832 START_TEST(url)
2833 {
2834     gecko_installer_workaround(TRUE);
2835
2836     complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2837     complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
2838     thread_id = GetCurrentThreadId();
2839     create_file();
2840
2841     test_create();
2842
2843     trace("test CreateAsyncBindCtx...\n");
2844     test_CreateAsyncBindCtx();
2845
2846     trace("test CreateAsyncBindCtxEx...\n");
2847     test_CreateAsyncBindCtxEx();
2848
2849     trace("test RegisterBindStatusCallback...\n");
2850     if(test_RegisterBindStatusCallback()) {
2851         trace("test BindToStorage failures...\n");
2852         test_BindToStorage_fail();
2853
2854         trace("synchronous http test (COM not initialised)...\n");
2855         test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2856
2857         CoInitialize(NULL);
2858
2859         trace("test StdURLMoniker...\n");
2860         test_StdURLMoniker();
2861
2862         trace("synchronous http test...\n");
2863         test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2864
2865         trace("synchronous http test (to object)...\n");
2866         test_BindToObject(HTTP_TEST, FALSE);
2867
2868         trace("synchronous file test...\n");
2869         test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2870
2871         trace("synchronous file test (to object)...\n");
2872         test_BindToObject(FILE_TEST, FALSE);
2873
2874         bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2875
2876         trace("http test...\n");
2877         test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2878
2879         trace("http test (to file)...\n");
2880         test_BindToStorage(HTTP_TEST, FALSE, TYMED_FILE);
2881
2882         trace("http test (to object)...\n");
2883         test_BindToObject(HTTP_TEST, FALSE);
2884
2885         trace("http test (short response)...\n");
2886         http_is_first = TRUE;
2887         urls[HTTP_TEST] = SHORT_RESPONSE_URL;
2888         test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2889
2890         trace("http test (short response, to object)...\n");
2891         test_BindToObject(HTTP_TEST, FALSE);
2892
2893         trace("emulated http test...\n");
2894         test_BindToStorage(HTTP_TEST, TRUE, TYMED_ISTREAM);
2895
2896         trace("emulated http test (to object)...\n");
2897         test_BindToObject(HTTP_TEST, TRUE);
2898
2899         trace("emulated http test (to file)...\n");
2900         test_BindToStorage(HTTP_TEST, TRUE, TYMED_FILE);
2901
2902         trace("asynchronous https test...\n");
2903         test_BindToStorage(HTTPS_TEST, FALSE, TYMED_ISTREAM);
2904
2905         trace("emulated https test...\n");
2906         test_BindToStorage(HTTPS_TEST, TRUE, TYMED_ISTREAM);
2907
2908         trace("about test...\n");
2909         test_BindToStorage(ABOUT_TEST, FALSE, TYMED_ISTREAM);
2910
2911         trace("about test (to file)...\n");
2912         test_BindToStorage(ABOUT_TEST, FALSE, TYMED_FILE);
2913
2914         trace("about test (to object)...\n");
2915         test_BindToObject(ABOUT_TEST, FALSE);
2916
2917         trace("emulated about test...\n");
2918         test_BindToStorage(ABOUT_TEST, TRUE, TYMED_ISTREAM);
2919
2920         trace("emulated about test (to file)...\n");
2921         test_BindToStorage(ABOUT_TEST, TRUE, TYMED_FILE);
2922
2923         trace("emulated about test (to object)...\n");
2924         test_BindToObject(ABOUT_TEST, TRUE);
2925
2926         trace("file test...\n");
2927         test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
2928
2929         trace("file test (to file)...\n");
2930         test_BindToStorage(FILE_TEST, FALSE, TYMED_FILE);
2931
2932         trace("file test (to object)...\n");
2933         test_BindToObject(FILE_TEST, FALSE);
2934
2935         trace("emulated file test...\n");
2936         test_BindToStorage(FILE_TEST, TRUE, TYMED_ISTREAM);
2937
2938         trace("emulated file test (to file)...\n");
2939         test_BindToStorage(FILE_TEST, TRUE, TYMED_FILE);
2940
2941         trace("emulated file test (to object)...\n");
2942         test_BindToObject(FILE_TEST, TRUE);
2943
2944         trace("emulated its test...\n");
2945         test_BindToStorage(ITS_TEST, TRUE, TYMED_ISTREAM);
2946
2947         trace("emulated its test (to file)...\n");
2948         test_BindToStorage(ITS_TEST, TRUE, TYMED_FILE);
2949
2950         trace("emulated mk test...\n");
2951         test_BindToStorage(MK_TEST, TRUE, TYMED_ISTREAM);
2952
2953         trace("test URLDownloadToFile for file protocol...\n");
2954         test_URLDownloadToFile(FILE_TEST, FALSE);
2955
2956         trace("test URLDownloadToFile for emulated file protocol...\n");
2957         test_URLDownloadToFile(FILE_TEST, TRUE);
2958
2959         trace("test URLDownloadToFile for http protocol...\n");
2960         test_URLDownloadToFile(HTTP_TEST, FALSE);
2961
2962         bindf |= BINDF_NOWRITECACHE;
2963
2964         trace("ftp test...\n");
2965         test_BindToStorage(FTP_TEST, FALSE, TYMED_ISTREAM);
2966
2967         trace("test failures...\n");
2968         test_BindToStorage_fail();
2969     }
2970
2971     DeleteFileA(wszIndexHtmlA);
2972     CloseHandle(complete_event);
2973     CloseHandle(complete_event2);
2974     CoUninitialize();
2975
2976     gecko_installer_workaround(FALSE);
2977 }