mshtml: Don't cache HTMLAttributesCollection results.
[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 static HRESULT (WINAPI *pCreateAsyncBindCtxEx)(IBindCtx *, DWORD,
39                 IBindStatusCallback *, IEnumFORMATETC *, IBindCtx **, DWORD);
40 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
41
42 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
43 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
44 DEFINE_GUID(IID_IBindStatusCallbackHolder,0x79eac9cc,0xbaf9,0x11ce,0x8c,0x82,0x00,0xaa,0x00,0x4b,0xa9,0x0b);
45
46 #define DEFINE_EXPECT(func) \
47     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
48
49 #define SET_EXPECT(func) \
50     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
51
52 #define CHECK_EXPECT2(func) \
53     do { \
54         ok(expect_ ##func, "unexpected call " #func "\n"); \
55         called_ ## func = TRUE; \
56     }while(0)
57
58 #define CHECK_EXPECT(func) \
59     do { \
60         CHECK_EXPECT2(func); \
61         expect_ ## func = FALSE; \
62     }while(0)
63
64 #define CHECK_CALLED(func) \
65     do { \
66         ok(called_ ## func, "expected " #func "\n"); \
67         expect_ ## func = called_ ## func = FALSE; \
68     }while(0)
69
70 #define CHECK_NOT_CALLED(func) \
71     do { \
72         ok(!called_ ## func, "unexpected " #func "\n"); \
73         expect_ ## func = called_ ## func = FALSE; \
74     }while(0)
75
76 #define CHECK_CALLED_BROKEN(func) \
77     do { \
78         ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
79         expect_ ## func = called_ ## func = FALSE; \
80     }while(0)
81
82 #define CLEAR_CALLED(func) \
83     expect_ ## func = called_ ## func = FALSE
84
85 DEFINE_EXPECT(QueryInterface_IServiceProvider);
86 DEFINE_EXPECT(QueryInterface_IHttpNegotiate);
87 DEFINE_EXPECT(QueryInterface_IBindStatusCallback);
88 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackEx);
89 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackHolder);
90 DEFINE_EXPECT(QueryInterface_IInternetBindInfo);
91 DEFINE_EXPECT(QueryInterface_IAuthenticate);
92 DEFINE_EXPECT(QueryInterface_IInternetProtocol);
93 DEFINE_EXPECT(QueryInterface_IWindowForBindingUI);
94 DEFINE_EXPECT(QueryInterface_IHttpSecurity);
95 DEFINE_EXPECT(QueryService_IAuthenticate);
96 DEFINE_EXPECT(QueryService_IInternetProtocol);
97 DEFINE_EXPECT(QueryService_IInternetBindInfo);
98 DEFINE_EXPECT(QueryService_IWindowForBindingUI);
99 DEFINE_EXPECT(QueryService_IHttpSecurity);
100 DEFINE_EXPECT(BeginningTransaction);
101 DEFINE_EXPECT(OnResponse);
102 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
103 DEFINE_EXPECT(GetRootSecurityId);
104 DEFINE_EXPECT(GetBindInfo);
105 DEFINE_EXPECT(GetBindInfoEx);
106 DEFINE_EXPECT(OnStartBinding);
107 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
108 DEFINE_EXPECT(OnProgress_CONNECTING);
109 DEFINE_EXPECT(OnProgress_REDIRECTING);
110 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
111 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
112 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
113 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
114 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
115 DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
116 DEFINE_EXPECT(OnStopBinding);
117 DEFINE_EXPECT(OnDataAvailable);
118 DEFINE_EXPECT(OnObjectAvailable);
119 DEFINE_EXPECT(Obj_OnStartBinding);
120 DEFINE_EXPECT(Obj_OnStopBinding);
121 DEFINE_EXPECT(Obj_GetBindInfo);
122 DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
123 DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
124 DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
125 DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
126 DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
127 DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
128 DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
129 DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
130 DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
131 DEFINE_EXPECT(Obj_OnProgress_REDIRECTING);
132 DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
133 DEFINE_EXPECT(Start);
134 DEFINE_EXPECT(Read);
135 DEFINE_EXPECT(LockRequest);
136 DEFINE_EXPECT(Terminate);
137 DEFINE_EXPECT(UnlockRequest);
138 DEFINE_EXPECT(Continue);
139 DEFINE_EXPECT(Abort);
140 DEFINE_EXPECT(CreateInstance);
141 DEFINE_EXPECT(Load);
142 DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
143 DEFINE_EXPECT(PutProperty_CLASSIDPROP);
144 DEFINE_EXPECT(SetPriority);
145 DEFINE_EXPECT(GetWindow_IHttpSecurity);
146 DEFINE_EXPECT(GetWindow_IWindowForBindingUI);
147 DEFINE_EXPECT(OnSecurityProblem);
148
149 static const WCHAR winetest_data_urlW[] =
150     {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
151      't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
152
153 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','s','/','d','a','t','a','.','p','h','p','\0'};
154
155 static const WCHAR winetest_post_urlW[] =
156         {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
157          't','e','s','t','s','/','p','o','s','t','.','p','h','p',0};
158 static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
159 static WCHAR INDEX_HTML[MAX_PATH];
160 static const WCHAR ITS_URL[] =
161     {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
162 static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
163     't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
164 static const WCHAR https_urlW[] =
165     {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',
166      '/','t','e','s','t','.','h','t','m','l',0};
167 static const WCHAR https_invalid_cn_urlW[] =
168     {'h','t','t','p','s',':','/','/','2','0','9','.','4','6','.','2','5','.','1','3','2',
169      '/','t','e','s','t','.','h','t','m','l',0};
170 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
171     '/','p','u','b','/','o','t','h','e','r','/',
172     'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
173 static const WCHAR winetest_urlW[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t',0};
174
175
176 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
177
178 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
179
180 static const WCHAR wszWineHQSite[] =
181     {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
182 static const WCHAR wszWineHQIP[] =
183     {'2','0','9','.','3','2','.','1','4','1','.','3',0};
184 static const CHAR wszIndexHtmlA[] = "index.html";
185 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
186 static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
187 static const CHAR dwl_htmlA[] = "dwl.html";
188 static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
189 static const CHAR test_txtA[] = "test.txt";
190 static const WCHAR emptyW[] = {0};
191
192 static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
193     data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api;
194 static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed, security_problem;
195 static CHAR mime_type[512];
196 static IInternetProtocolSink *protocol_sink = NULL;
197 static IBinding *current_binding;
198 static HANDLE complete_event, complete_event2;
199 static HRESULT binding_hres;
200 static HRESULT onsecurityproblem_hres;
201 static HRESULT abort_hres;
202 static BOOL have_IHttpNegotiate2, use_bscex, is_async_prot;
203 static BOOL test_redirect, use_cache_file, callback_read, no_callback, test_abort;
204 static WCHAR cache_file_name[MAX_PATH];
205 static BOOL only_check_prot_args = FALSE;
206 static BOOL invalid_cn_accepted = FALSE;
207 static BOOL abort_start = FALSE;
208 static BOOL abort_progress = FALSE;
209
210 static LPCWSTR urls[] = {
211     winetest_data_urlW,
212     ABOUT_BLANK,
213     INDEX_HTML,
214     ITS_URL,
215     MK_URL,
216     https_urlW,
217     ftp_urlW,
218     winetest_urlW
219 };
220
221 static WCHAR file_url[INTERNET_MAX_URL_LENGTH];
222
223 static enum {
224     HTTP_TEST,
225     ABOUT_TEST,
226     FILE_TEST,
227     ITS_TEST,
228     MK_TEST,
229     HTTPS_TEST,
230     FTP_TEST,
231     WINETEST_TEST
232 } test_protocol;
233
234 static enum {
235     BEFORE_DOWNLOAD,
236     DOWNLOADING,
237     END_DOWNLOAD
238 } download_state;
239
240 static const char *debugstr_guid(REFIID riid)
241 {
242     static char buf[50];
243
244     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
245             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
246             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
247             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
248
249     return buf;
250 }
251
252 static BOOL proxy_active(void)
253 {
254     HKEY internet_settings;
255     DWORD proxy_enable;
256     DWORD size;
257
258     if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
259                       0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
260         return FALSE;
261
262     size = sizeof(DWORD);
263     if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
264         proxy_enable = 0;
265
266     RegCloseKey(internet_settings);
267
268     return proxy_enable != 0;
269 }
270
271 static BOOL is_urlmon_protocol(int prot)
272 {
273     return prot == FILE_TEST || prot == HTTP_TEST || prot == HTTPS_TEST || prot == FTP_TEST || prot == MK_TEST;
274 }
275
276 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
277 {
278     HRESULT hr;
279     IMoniker *mon1 = NULL;
280     IMoniker *mon2 = NULL;
281
282     hr = CreateURLMoniker(NULL, NULL, NULL);
283     ok(hr == E_INVALIDARG,
284        "Expected CreateURLMoniker to return E_INVALIDARG, got 0x%08x\n", hr);
285
286     mon1 = (IMoniker *)0xdeadbeef;
287     hr = CreateURLMoniker(NULL, NULL, &mon1);
288     ok(hr == E_INVALIDARG,
289        "Expected CreateURLMoniker to return E_INVALIDARG, got 0x%08x\n", hr);
290     ok(mon1 == NULL, "Expected the output pointer to be NULL, got %p\n", mon1);
291
292     hr = CreateURLMoniker(NULL, emptyW, NULL);
293     ok(hr == E_INVALIDARG,
294        "Expected CreateURLMoniker to return E_INVALIDARG, got 0x%08x\n", hr);
295
296     hr = CreateURLMoniker(NULL, emptyW, &mon1);
297     ok(hr == S_OK ||
298        broken(hr == MK_E_SYNTAX), /* IE5/IE5.01/IE6 SP2 */
299        "Expected CreateURLMoniker to return S_OK, got 0x%08x\n", hr);
300     if(mon1) IMoniker_Release(mon1);
301
302     hr = CreateURLMoniker(NULL, url1, &mon1);
303     ok(hr == S_OK, "failed to create moniker: 0x%08x\n", hr);
304     if(hr == S_OK) {
305         hr = CreateURLMoniker(mon1, url2, &mon2);
306         ok(hr == S_OK, "failed to create moniker: 0x%08x\n", hr);
307     }
308     if(mon1) IMoniker_Release(mon1);
309     if(mon2) IMoniker_Release(mon2);
310 }
311
312 static void test_create(void)
313 {
314     static const WCHAR relativeW[] = {'a','/','b','.','t','x','t',0};
315     IStream *stream;
316     IMoniker *mon;
317     IBindCtx *bctx;
318     HRESULT hr;
319
320     test_CreateURLMoniker(winetest_data_urlW, TEST_PART_URL_1);
321
322     mon = (void*)0xdeadbeef;
323     hr = CreateURLMoniker(NULL, relativeW, &mon);
324     ok(hr == S_OK, "got 0x%08x\n", hr);
325
326     hr = CreateBindCtx(0, &bctx);
327     ok(hr == S_OK, "got 0x%08x\n", hr);
328
329     stream = (void*)0xdeadbeef;
330     hr = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&stream);
331     todo_wine ok(hr == INET_E_UNKNOWN_PROTOCOL, "got 0x%08x\n", hr);
332     ok(stream == NULL, "got %p\n", stream);
333
334     hr = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, NULL);
335     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
336
337     stream = (void*)0xdeadbeef;
338     hr = IMoniker_BindToStorage(mon, NULL, NULL, &IID_IStream, (void**)&stream);
339     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
340     ok(stream == NULL || broken(stream == (void*)0xdeadbeef) /* starting XP SP3 it's set to null */,
341         "got %p\n", stream);
342
343     IMoniker_Release(mon);
344
345     mon = (void*)0xdaedbeef;
346     hr = CreateURLMoniker(NULL, winetest_data_urlW, &mon);
347     ok(hr == S_OK, "got 0x%08x\n", hr);
348
349     stream = (void*)0xdeadbeef;
350     hr = IMoniker_BindToStorage(mon, NULL, NULL, &IID_IStream, (void**)&stream);
351     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
352     ok(stream == NULL || broken(stream == (void*)0xdeadbeef) /* starting XP SP3 it's set to null */,
353         "got %p\n", stream);
354
355     hr = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, NULL);
356     ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
357
358     IMoniker_Release(mon);
359     IBindCtx_Release(bctx);
360 }
361
362 static HRESULT WINAPI Priority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
363 {
364     ok(0, "unexpected call\n");
365     return E_NOINTERFACE;
366 }
367
368 static ULONG WINAPI Priority_AddRef(IInternetPriority *iface)
369 {
370     return 2;
371 }
372
373 static ULONG WINAPI Priority_Release(IInternetPriority *iface)
374 {
375     return 1;
376 }
377
378 static HRESULT WINAPI Priority_SetPriority(IInternetPriority *iface, LONG nPriority)
379 {
380     CHECK_EXPECT(SetPriority);
381     ok(!nPriority, "nPriority = %d\n", nPriority);
382     return S_OK;
383 }
384
385 static HRESULT WINAPI Priority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
386 {
387     ok(0, "unexpected call\n");
388     return S_OK;
389 }
390
391 static const IInternetPriorityVtbl InternetPriorityVtbl = {
392     Priority_QueryInterface,
393     Priority_AddRef,
394     Priority_Release,
395     Priority_SetPriority,
396     Priority_GetPriority
397 };
398
399 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
400
401 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
402 {
403     *ppv = NULL;
404
405     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
406         *ppv = iface;
407         return S_OK;
408     }
409
410     if(IsEqualGUID(&IID_IInternetPriority, riid)) {
411         if(!is_urlmon_protocol(test_protocol))
412             return E_NOINTERFACE;
413
414         *ppv = &InternetPriority;
415         return S_OK;
416     }
417
418     if(IsEqualGUID(&IID_IInternetProtocolEx, riid))
419         return E_NOINTERFACE; /* TODO */
420
421     ok(0, "unexpected call %s\n", debugstr_guid(riid));
422     return E_NOINTERFACE;
423 }
424
425 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
426 {
427     return 2;
428 }
429
430 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
431 {
432     return 1;
433 }
434
435 static void test_switch_fail(void)
436 {
437     IInternetProtocolSink *binding_sink;
438     PROTOCOLDATA protocoldata = {0};
439     HRESULT hres;
440
441     static BOOL tested_switch_fail;
442
443     if(tested_switch_fail)
444         return;
445
446     tested_switch_fail = TRUE;
447
448     hres = IBinding_QueryInterface(current_binding, &IID_IInternetProtocolSink, (void**)&binding_sink);
449     ok(hres == S_OK, "Could not get IInternetProtocolSink iface: %08x\n", hres);
450     if(SUCCEEDED(hres)) {
451         hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
452         ok(hres == E_FAIL, "Switch failed: %08x, expected E_FAIL\n", hres);
453         IInternetProtocolSink_Release(binding_sink);
454     }
455 }
456
457 static DWORD WINAPI thread_proc(PVOID arg)
458 {
459     PROTOCOLDATA protocoldata = {0};
460     HRESULT hres;
461
462     if(!no_callback) {
463         if(bind_to_object)
464             SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
465         else
466             SET_EXPECT(OnProgress_FINDINGRESOURCE);
467     }
468     hres = IInternetProtocolSink_ReportProgress(protocol_sink,
469             BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
470     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
471     if(!no_callback) {
472         WaitForSingleObject(complete_event, INFINITE);
473         if(bind_to_object)
474             CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
475         else
476             CHECK_CALLED(OnProgress_FINDINGRESOURCE);
477     }
478
479     if(!no_callback) {
480         if(bind_to_object)
481             SET_EXPECT(Obj_OnProgress_CONNECTING);
482         else
483             SET_EXPECT(OnProgress_CONNECTING);
484     }
485     hres = IInternetProtocolSink_ReportProgress(protocol_sink,
486             BINDSTATUS_CONNECTING, wszWineHQIP);
487     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
488     if(!no_callback) {
489         WaitForSingleObject(complete_event, INFINITE);
490         if(bind_to_object)
491             CHECK_CALLED(Obj_OnProgress_CONNECTING);
492         else
493             CHECK_CALLED(OnProgress_CONNECTING);
494     }
495
496     if(!no_callback) {
497         if(bind_to_object)
498             SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
499         else
500             SET_EXPECT(OnProgress_SENDINGREQUEST);
501     }
502     hres = IInternetProtocolSink_ReportProgress(protocol_sink,
503             BINDSTATUS_SENDINGREQUEST, NULL);
504     ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
505     if(!no_callback) {
506         WaitForSingleObject(complete_event, INFINITE);
507         if(bind_to_object)
508             CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
509         else
510             CHECK_CALLED(OnProgress_SENDINGREQUEST);
511     }
512
513     if(test_redirect) {
514         if(bind_to_object)
515             SET_EXPECT(Obj_OnProgress_REDIRECTING);
516         else
517             SET_EXPECT(OnProgress_REDIRECTING);
518         hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_REDIRECTING, winetest_data_urlW);
519         ok(hres == S_OK, "ReportProgress(BINDSTATUS_REFIRECTING) failed: %08x\n", hres);
520         WaitForSingleObject(complete_event, INFINITE);
521         if(bind_to_object)
522             CHECK_CALLED(Obj_OnProgress_REDIRECTING);
523         else
524             CHECK_CALLED(OnProgress_REDIRECTING);
525     }
526
527     test_switch_fail();
528
529     SET_EXPECT(Continue);
530     prot_state = 1;
531     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
532     ok(hres == S_OK, "Switch failed: %08x\n", hres);
533     WaitForSingleObject(complete_event, INFINITE);
534
535     CHECK_CALLED(Continue);
536     CHECK_CALLED(Read);
537     if(bind_to_object) {
538         CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
539         CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
540         CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
541         CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
542         CHECK_CALLED(CreateInstance);
543         CHECK_CALLED(PutProperty_MIMETYPEPROP);
544         CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
545         CHECK_CALLED(Load);
546         CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
547         CHECK_CALLED(OnObjectAvailable);
548         CHECK_CALLED(Obj_OnStopBinding);
549     }else if(!no_callback) {
550         CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
551         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
552         CHECK_CALLED(OnDataAvailable);
553     }else {
554         CHECK_CALLED(LockRequest);
555     }
556
557     SET_EXPECT(Continue);
558     prot_state = 2;
559     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
560     ok(hres == S_OK, "Switch failed: %08x\n", hres);
561     WaitForSingleObject(complete_event, INFINITE);
562     CHECK_CALLED(Continue);
563     if(test_abort) {
564         CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
565         CHECK_CALLED(OnStopBinding);
566         SetEvent(complete_event2);
567         return 0;
568     }else {
569         CHECK_CALLED(Read);
570         if(!no_callback) {
571             CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
572             CHECK_CALLED(OnDataAvailable);
573         }
574     }
575
576     SET_EXPECT(Continue);
577     prot_state = 2;
578     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
579     ok(hres == S_OK, "Switch failed: %08x\n", hres);
580     WaitForSingleObject(complete_event, INFINITE);
581     CHECK_CALLED(Continue);
582     CHECK_CALLED(Read);
583     if(!no_callback) {
584         CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
585         CHECK_CALLED(OnDataAvailable);
586     }
587
588     SET_EXPECT(Continue);
589     prot_state = 3;
590     hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
591     ok(hres == S_OK, "Switch failed: %08x\n", hres);
592     WaitForSingleObject(complete_event, INFINITE);
593     CHECK_CALLED(Continue);
594     CHECK_CALLED(Read);
595     if(!no_callback) {
596         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
597         CHECK_CALLED(OnDataAvailable);
598         CHECK_CALLED(OnStopBinding);
599     }
600
601     SET_EXPECT(Read);
602
603     SetEvent(complete_event2);
604     return 0;
605 }
606
607 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
608         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
609         DWORD grfPI, HANDLE_PTR dwReserved)
610 {
611     BINDINFO bindinfo;
612     DWORD bind_info, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
613     HRESULT hres;
614
615     static const STGMEDIUM stgmed_zero = {0};
616     static const SECURITY_ATTRIBUTES sa_zero = {0};
617
618     CHECK_EXPECT(Start);
619
620     read = 0;
621
622     if(!filedwl_api) /* FIXME */
623         ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", wine_dbgstr_w(szUrl));
624     ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
625     ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
626     ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
627     ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
628
629     if(!filedwl_api && binding_hres != S_OK) {
630         SET_EXPECT(OnStopBinding);
631         SET_EXPECT(Terminate);
632         hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
633         ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
634         CHECK_CALLED(OnStopBinding);
635         CHECK_CALLED(Terminate);
636
637         return S_OK;
638     }
639
640     memset(&bindinfo, 0, sizeof(bindinfo));
641     bindinfo.cbSize = sizeof(bindinfo);
642     hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bind_info, &bindinfo);
643     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
644
645     ok(bind_info & BINDF_FROMURLMON, "BINDF_FROMURLMON is not set\n");
646
647     if(filedwl_api || !is_urlmon_protocol(test_protocol) || tymed != TYMED_ISTREAM ||
648        !(bindf&BINDF_ASYNCSTORAGE) || !(bindf&BINDF_PULLDATA))
649         ok(bind_info & BINDF_NEEDFILE, "BINDF_NEEDFILE is not set\n");
650     else
651         ok(!(bind_info & BINDF_NEEDFILE), "BINDF_NEEDFILE is set\n");
652
653     bind_info &= ~(BINDF_NEEDFILE|BINDF_FROMURLMON);
654     if(filedwl_api || no_callback)
655         ok(bind_info == BINDF_PULLDATA, "bind_info = %x, expected BINDF_PULLDATA\n", bind_info);
656     else
657         ok(bind_info == (bindf & ~(BINDF_NEEDFILE|BINDF_FROMURLMON)), "bind_info = %x, expected %x\n",
658            bind_info, (bindf & ~(BINDF_NEEDFILE|BINDF_FROMURLMON)));
659
660     ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
661     ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
662     ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
663     ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
664     ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
665     ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
666     ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
667     ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
668     ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
669     ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
670     ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
671     ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
672     ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
673     ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
674
675     if(only_check_prot_args)
676         return E_FAIL;
677
678     switch(test_protocol) {
679     case MK_TEST:
680         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
681                 BINDSTATUS_DIRECTBIND, NULL);
682         ok(hres == S_OK,
683            "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
684
685     case FILE_TEST:
686     case ITS_TEST:
687         if(bind_to_object)
688             SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
689         else
690             SET_EXPECT(OnProgress_SENDINGREQUEST);
691         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
692                 BINDSTATUS_SENDINGREQUEST, emptyW);
693         ok(hres == S_OK,
694            "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
695         if(bind_to_object)
696             CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
697         else
698             CHECK_CALLED(OnProgress_SENDINGREQUEST);
699     default:
700         break;
701     }
702
703     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
704         IServiceProvider *service_provider;
705         IHttpNegotiate *http_negotiate;
706         IHttpNegotiate2 *http_negotiate2;
707         IHttpSecurity *http_security;
708         LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
709         LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
710         BYTE sec_id[100];
711         DWORD fetched = 256, size = 100;
712         DWORD tid;
713
714         static const WCHAR wszMimes[] = {'*','/','*',0};
715
716         SET_EXPECT(QueryInterface_IInternetBindInfo);
717         SET_EXPECT(QueryService_IInternetBindInfo);
718         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
719                                                &ua, 1, &fetched);
720         CLEAR_CALLED(QueryInterface_IInternetBindInfo); /* IE <8 */
721         CLEAR_CALLED(QueryService_IInternetBindInfo); /* IE <8 */
722
723         ok(hres == E_NOINTERFACE,
724            "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
725         ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
726         ok(ua == (LPWSTR)0xdeadbeef, "ua =  %p\n", ua);
727
728         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
729                                                accept_mimes, 256, &fetched);
730         ok(hres == S_OK,
731            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
732         ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
733         ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
734         CoTaskMemFree(accept_mimes[0]);
735
736         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
737                                                NULL, 256, &fetched);
738         ok(hres == E_INVALIDARG,
739            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
740
741         hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
742                                                accept_mimes, 256, NULL);
743         ok(hres == E_INVALIDARG,
744            "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
745
746         hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
747                                                 (void**)&service_provider);
748         ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
749
750         SET_EXPECT(QueryInterface_IHttpNegotiate);
751         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
752                 &IID_IHttpNegotiate, (void**)&http_negotiate);
753         CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
754         ok(hres == S_OK, "QueryService failed: %08x\n", hres);
755
756         if(!no_callback) {
757             SET_EXPECT(BeginningTransaction);
758             SET_EXPECT(QueryInterface_IHttpNegotiate);
759         }
760         hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
761                                                    NULL, 0, &additional_headers);
762         if(!no_callback) {
763             CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
764             CHECK_CALLED(BeginningTransaction);
765         }
766         IHttpNegotiate_Release(http_negotiate);
767         ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
768         ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
769
770         SET_EXPECT(QueryInterface_IHttpNegotiate2);
771         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
772                 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
773         CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
774         ok(hres == S_OK, "QueryService failed: %08x\n", hres);
775
776         size = 512;
777         if(!no_callback) {
778             SET_EXPECT(QueryInterface_IHttpNegotiate2);
779             SET_EXPECT(GetRootSecurityId);
780         }
781         hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
782         if(!no_callback) {
783             CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2);
784             CHECK_CALLED(GetRootSecurityId);
785         }
786         IHttpNegotiate2_Release(http_negotiate2);
787         ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
788         ok(size == no_callback ? 512 : 13, "size=%d\n", size);
789
790         if(!no_callback) {
791             SET_EXPECT(QueryService_IHttpSecurity);
792             SET_EXPECT(QueryInterface_IHttpSecurity);
793         }
794         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpSecurity,
795                 &IID_IHttpSecurity, (void**)&http_security);
796         ok(hres == (no_callback ? E_NOINTERFACE : S_OK), "QueryService failed: 0x%08x\n", hres);
797         if(!no_callback) {
798             CHECK_CALLED(QueryService_IHttpSecurity);
799             CHECK_CALLED(QueryInterface_IHttpSecurity);
800         }
801
802         IServiceProvider_Release(service_provider);
803
804         IInternetProtocolSink_AddRef(pOIProtSink);
805         protocol_sink = pOIProtSink;
806         CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
807
808         return S_OK;
809     }
810
811     if(test_protocol == FILE_TEST) {
812         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
813                 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
814         ok(hres == S_OK,
815            "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
816
817         if(bind_to_object)
818             SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
819         else
820             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
821         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
822                 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
823         ok(hres == S_OK,
824            "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
825         if(bind_to_object)
826             CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
827         else
828             CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
829     }else {
830         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
831                 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
832         ok(hres == S_OK,
833            "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
834     }
835
836     if(test_protocol == ABOUT_TEST)
837         bscf |= BSCF_DATAFULLYAVAILABLE;
838     if(test_protocol == ITS_TEST)
839         bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
840
841     SET_EXPECT(Read);
842     if(bind_to_object) {
843         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
844             SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
845         SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
846         if(test_protocol == FILE_TEST)
847             SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
848         SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
849         SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
850         SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
851         SET_EXPECT(CreateInstance);
852         SET_EXPECT(PutProperty_MIMETYPEPROP);
853         SET_EXPECT(PutProperty_CLASSIDPROP);
854         SET_EXPECT(Load);
855         SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
856         SET_EXPECT(OnObjectAvailable);
857         SET_EXPECT(Obj_OnStopBinding);
858     }else {
859         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
860             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
861         SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
862         if(test_protocol == FILE_TEST)
863             SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
864         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
865         SET_EXPECT(LockRequest);
866         if(!filedwl_api)
867             SET_EXPECT(OnDataAvailable);
868         SET_EXPECT(OnStopBinding);
869     }
870
871     hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
872     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
873
874     CHECK_CALLED(Read);
875     if(bind_to_object) {
876         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
877             CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
878         CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
879         if(test_protocol == FILE_TEST)
880             CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
881         CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
882         CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
883         CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
884         CHECK_CALLED(CreateInstance);
885         CHECK_CALLED(PutProperty_MIMETYPEPROP);
886         CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
887         CHECK_CALLED(Load);
888         CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
889         CHECK_CALLED(OnObjectAvailable);
890         CHECK_CALLED(Obj_OnStopBinding);
891     }else {
892         if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
893             CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
894         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
895         if(test_protocol == FILE_TEST)
896             CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
897         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
898         CHECK_CALLED(LockRequest);
899         if(!filedwl_api)
900             CHECK_CALLED(OnDataAvailable);
901         CHECK_CALLED(OnStopBinding);
902     }
903
904     if(test_protocol == ITS_TEST) {
905         SET_EXPECT(Read);
906         hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
907         ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
908         CHECK_CALLED(Read);
909     }else if(!bind_to_object && test_protocol == ABOUT_TEST) {
910         SET_EXPECT(Read);
911         hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
912         ok(hres == S_OK, "ReportData failed: %08x\n", hres);
913         CHECK_CALLED(Read);
914     }
915
916     SET_EXPECT(Terminate);
917     hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
918     ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
919     CHECK_CALLED(Terminate);
920
921     return S_OK;
922 }
923
924 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
925         PROTOCOLDATA *pProtocolData)
926 {
927     DWORD bscf = 0;
928     HRESULT hres;
929
930     CHECK_EXPECT(Continue);
931
932     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
933
934     ok(pProtocolData != NULL, "pProtocolData == NULL\n");
935     if(!pProtocolData)
936         return S_OK;
937
938     switch(prot_state) {
939     case 1: {
940         IServiceProvider *service_provider;
941         IHttpNegotiate *http_negotiate;
942         static WCHAR header[] = {'?',0};
943
944         hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
945                                                     (void**)&service_provider);
946         ok(hres == S_OK, "Could not get IServiceProvicder\n");
947
948         hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
949                                              &IID_IHttpNegotiate, (void**)&http_negotiate);
950         ok(hres == S_OK, "Could not get IHttpNegotiate\n");
951
952         if(!no_callback) {
953             SET_EXPECT(QueryInterface_IHttpNegotiate);
954             SET_EXPECT(OnResponse);
955         }
956         hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
957         if(!no_callback) {
958             CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
959             CHECK_CALLED(OnResponse);
960         }
961         IHttpNegotiate_Release(http_negotiate);
962         ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
963
964         if(test_protocol == HTTPS_TEST || test_redirect) {
965             hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
966             ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
967         }
968
969         hres = IInternetProtocolSink_ReportProgress(protocol_sink,
970                 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
971         ok(hres == S_OK,
972            "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
973
974         hres = IInternetProtocolSink_ReportProgress(protocol_sink,
975             BINDSTATUS_CACHEFILENAMEAVAILABLE, use_cache_file ? cache_file_name : cache_fileW);
976         ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
977
978         bscf |= BSCF_FIRSTDATANOTIFICATION;
979         break;
980     }
981     case 2:
982     case 3:
983         bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
984         break;
985     }
986
987     hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
988     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
989
990     if(prot_state != 2 || !test_abort)
991         SET_EXPECT(Read);
992     switch(prot_state) {
993     case 1:
994         if(bind_to_object) {
995             SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
996             SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
997             SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
998             SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
999             SET_EXPECT(CreateInstance);
1000             SET_EXPECT(PutProperty_MIMETYPEPROP);
1001             SET_EXPECT(PutProperty_CLASSIDPROP);
1002             SET_EXPECT(Load);
1003             SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1004             SET_EXPECT(OnObjectAvailable);
1005             SET_EXPECT(Obj_OnStopBinding);
1006         }else if(!no_callback) {
1007             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1008             SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1009             SET_EXPECT(LockRequest);
1010         }else {
1011             SET_EXPECT(LockRequest);
1012         }
1013         break;
1014     case 2:
1015         if(!no_callback)
1016             SET_EXPECT(OnProgress_DOWNLOADINGDATA);
1017         break;
1018     case 3:
1019         SET_EXPECT(OnProgress_DOWNLOADINGDATA);
1020         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1021     }
1022     if(!no_callback) {
1023         if((!bind_to_object || prot_state >= 2) && (!test_abort || prot_state != 2))
1024             SET_EXPECT(OnDataAvailable);
1025         if(prot_state == 3 || (test_abort && prot_state == 2))
1026             SET_EXPECT(OnStopBinding);
1027     }
1028     return S_OK;
1029 }
1030
1031 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1032         DWORD dwOptions)
1033 {
1034     HRESULT hres;
1035
1036     CHECK_EXPECT(Abort);
1037
1038     ok(hrReason == E_ABORT, "hrReason = %08x\n", hrReason);
1039     ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1040
1041     hres = IInternetProtocolSink_ReportResult(protocol_sink, E_ABORT, ERROR_SUCCESS, NULL);
1042     ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1043
1044     return S_OK;
1045 }
1046
1047 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1048 {
1049     CHECK_EXPECT(Terminate);
1050
1051     ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
1052
1053     if(protocol_sink) {
1054         IInternetProtocolSink_Release(protocol_sink);
1055         protocol_sink = NULL;
1056     }
1057
1058     if(no_callback)
1059         SetEvent(complete_event);
1060     return S_OK;
1061 }
1062
1063 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1064 {
1065     ok(0, "unexpected call\n");
1066     return E_NOTIMPL;
1067 }
1068
1069 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1070 {
1071     ok(0, "unexpected call\n");
1072     return E_NOTIMPL;
1073 }
1074
1075 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
1076         ULONG cb, ULONG *pcbRead)
1077 {
1078     static const char data[] = "<HTML></HTML>";
1079
1080     CHECK_EXPECT2(Read);
1081
1082     ok(pv != NULL, "pv == NULL\n");
1083     ok(cb != 0, "cb == 0\n");
1084     ok(pcbRead != NULL, "pcbRead == NULL\n");
1085
1086     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
1087         HRESULT hres;
1088
1089         static int pending = TRUE;
1090
1091         pending = !pending;
1092
1093         switch(prot_state) {
1094         case 1:
1095         case 2:
1096             if(pending) {
1097                 *pcbRead = 10;
1098                 memset(pv, '?', 10);
1099                 if(prot_state == 2 && no_callback)
1100                     SetEvent(complete_event);
1101                 return E_PENDING;
1102             }else {
1103                 memset(pv, '?', cb);
1104                 *pcbRead = cb;
1105                 read++;
1106                 return S_OK;
1107             }
1108         case 3:
1109             prot_state++;
1110
1111             *pcbRead = 0;
1112
1113             hres = IInternetProtocolSink_ReportData(protocol_sink,
1114                     BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
1115             ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1116
1117             hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
1118             ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1119
1120             return S_FALSE;
1121         case 4:
1122             *pcbRead = 0;
1123             return S_FALSE;
1124         }
1125     }
1126
1127     if(read) {
1128         *pcbRead = 0;
1129         return S_FALSE;
1130     }
1131
1132     ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1133     read += *pcbRead = sizeof(data)-1;
1134     memcpy(pv, data, sizeof(data));
1135     return S_OK;
1136 }
1137
1138 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1139         LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1140 {
1141     ok(0, "unexpected call\n");
1142     return E_NOTIMPL;
1143 }
1144
1145 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1146 {
1147     CHECK_EXPECT(LockRequest);
1148     if(no_callback)
1149         SetEvent(complete_event);
1150     return S_OK;
1151 }
1152
1153 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
1154 {
1155     CHECK_EXPECT(UnlockRequest);
1156     return S_OK;
1157 }
1158
1159 static const IInternetProtocolVtbl ProtocolVtbl = {
1160     Protocol_QueryInterface,
1161     Protocol_AddRef,
1162     Protocol_Release,
1163     Protocol_Start,
1164     Protocol_Continue,
1165     Protocol_Abort,
1166     Protocol_Terminate,
1167     Protocol_Suspend,
1168     Protocol_Resume,
1169     Protocol_Read,
1170     Protocol_Seek,
1171     Protocol_LockRequest,
1172     Protocol_UnlockRequest
1173 };
1174
1175 static IInternetProtocol Protocol = { &ProtocolVtbl };
1176
1177 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
1178 {
1179     if(IsEqualGUID(&IID_IUnknown, riid)
1180             || IsEqualGUID(&IID_IHttpNegotiate, riid)
1181             || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
1182         *ppv = iface;
1183         return S_OK;
1184     }
1185
1186     ok(0, "unexpected call\n");
1187     return E_NOINTERFACE;
1188 }
1189
1190 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
1191 {
1192     return 2;
1193 }
1194
1195 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
1196 {
1197     return 1;
1198 }
1199
1200 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
1201         LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
1202 {
1203     if(onsecurityproblem_hres == S_OK)
1204         CHECK_EXPECT2(BeginningTransaction);
1205     else
1206         CHECK_EXPECT(BeginningTransaction);
1207
1208     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1209
1210     ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
1211     ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
1212     ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1213     if(pszAdditionalHeaders)
1214         ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1215
1216     return S_OK;
1217 }
1218
1219 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
1220         LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
1221 {
1222     CHECK_EXPECT(OnResponse);
1223
1224     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1225
1226     ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
1227     ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
1228     ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
1229     /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
1230     ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1231     if(pszAdditionalRequestHeaders)
1232         ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1233
1234     return S_OK;
1235 }
1236
1237 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
1238         BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1239 {
1240     static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
1241
1242     CHECK_EXPECT(GetRootSecurityId);
1243
1244     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1245
1246     ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
1247     ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
1248     ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
1249
1250     if(pbSecurityId == (void*)0xdeadbeef)
1251         return E_NOTIMPL;
1252
1253     if(pcbSecurityId) {
1254         ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
1255         *pcbSecurityId = sizeof(sec_id);
1256     }
1257
1258     if(pbSecurityId)
1259         memcpy(pbSecurityId, sec_id, sizeof(sec_id));
1260
1261     return E_FAIL;
1262 }
1263
1264 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
1265     HttpNegotiate_QueryInterface,
1266     HttpNegotiate_AddRef,
1267     HttpNegotiate_Release,
1268     HttpNegotiate_BeginningTransaction,
1269     HttpNegotiate_OnResponse,
1270     HttpNegotiate_GetRootSecurityId
1271 };
1272
1273 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
1274
1275 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
1276 {
1277     ok(0, "Unexpected call\n");
1278     *ppv = NULL;
1279     if(IsEqualGUID(&IID_IHttpSecurity, riid) ||
1280        IsEqualGUID(&IID_IWindowForBindingUI, riid) ||
1281        IsEqualGUID(&IID_IUnknown, riid))
1282     {
1283         *ppv = iface;
1284         return S_OK;
1285     }
1286
1287     ok(0, "Unexpected interface requested.\n");
1288
1289     return E_NOINTERFACE;
1290 }
1291
1292 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
1293 {
1294     return 2;
1295 }
1296
1297 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
1298 {
1299     return 1;
1300 }
1301
1302 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity *iface, REFGUID rguidReason, HWND *phwnd)
1303 {
1304     if(IsEqualGUID(rguidReason, &IID_IHttpSecurity))
1305         CHECK_EXPECT(GetWindow_IHttpSecurity);
1306     else if(IsEqualGUID(rguidReason, &IID_IWindowForBindingUI))
1307         CHECK_EXPECT2(GetWindow_IWindowForBindingUI);
1308     else
1309         ok(0, "Unexpected rguidReason: %s\n", debugstr_guid(rguidReason));
1310
1311     *phwnd = NULL;
1312     return S_OK;
1313 }
1314
1315 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
1316 {
1317     CHECK_EXPECT(OnSecurityProblem);
1318     if(!security_problem) {
1319         ok(dwProblem == ERROR_INTERNET_SEC_CERT_CN_INVALID ||
1320            broken(dwProblem == ERROR_INTERNET_SEC_CERT_ERRORS) /* Some versions of IE6 */,
1321            "Got problem: %d\n", dwProblem);
1322         security_problem = dwProblem;
1323
1324         if(dwProblem == ERROR_INTERNET_SEC_CERT_ERRORS)
1325             binding_hres = INET_E_SECURITY_PROBLEM;
1326     }else
1327         ok(dwProblem == security_problem, "Got problem: %d\n", dwProblem);
1328
1329     return onsecurityproblem_hres;
1330 }
1331
1332 static const IHttpSecurityVtbl HttpSecurityVtbl = {
1333     HttpSecurity_QueryInterface,
1334     HttpSecurity_AddRef,
1335     HttpSecurity_Release,
1336     HttpSecurity_GetWindow,
1337     HttpSecurity_OnSecurityProblem
1338 };
1339
1340 static IHttpSecurity HttpSecurity = { &HttpSecurityVtbl };
1341
1342 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1343 {
1344     ok(0, "unexpected call\n");
1345     return E_NOINTERFACE;
1346 }
1347
1348 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1349 {
1350     return 2;
1351 }
1352
1353 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1354 {
1355     return 1;
1356 }
1357
1358 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1359         REFGUID guidService, REFIID riid, void **ppv)
1360 {
1361     if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
1362         CHECK_EXPECT(QueryService_IAuthenticate);
1363         return E_NOTIMPL;
1364     }
1365
1366     if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1367         CHECK_EXPECT2(QueryService_IInternetProtocol);
1368         return E_NOTIMPL;
1369     }
1370
1371     if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1372         CHECK_EXPECT(QueryService_IInternetBindInfo);
1373         return E_NOTIMPL;
1374     }
1375
1376     if(IsEqualGUID(&IID_IWindowForBindingUI, guidService)) {
1377         CHECK_EXPECT2(QueryService_IWindowForBindingUI);
1378         *ppv = &HttpSecurity;
1379         return S_OK;
1380     }
1381
1382     if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
1383         CHECK_EXPECT(QueryService_IHttpSecurity);
1384         *ppv = &HttpSecurity;
1385         return S_OK;
1386     }
1387
1388     ok(0, "unexpected service %s\n", debugstr_guid(guidService));
1389     return E_NOINTERFACE;
1390 }
1391
1392 static IServiceProviderVtbl ServiceProviderVtbl = {
1393     ServiceProvider_QueryInterface,
1394     ServiceProvider_AddRef,
1395     ServiceProvider_Release,
1396     ServiceProvider_QueryService
1397 };
1398
1399 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1400
1401 static IBindStatusCallbackEx objbsc;
1402
1403 static void test_WinInetHttpInfo(IWinInetHttpInfo *http_info, DWORD progress)
1404 {
1405     DWORD status, size;
1406     HRESULT hres, expect;
1407
1408     /* QueryInfo changes it's behavior during this request */
1409     if(progress == BINDSTATUS_SENDINGREQUEST)
1410         return;
1411
1412     if(test_protocol==FTP_TEST && download_state==BEFORE_DOWNLOAD
1413             && progress!=BINDSTATUS_MIMETYPEAVAILABLE)
1414         expect = E_FAIL;
1415     else if(test_protocol == FTP_TEST)
1416         expect = S_FALSE;
1417     else
1418         expect = S_OK;
1419
1420     size = sizeof(DWORD);
1421     hres = IWinInetHttpInfo_QueryInfo(http_info, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
1422             &status, &size, NULL, NULL);
1423     ok(hres == expect, "hres = %x, expected %x\n", hres, expect);
1424     if(hres == S_OK) {
1425         if(download_state==BEFORE_DOWNLOAD && progress!=BINDSTATUS_MIMETYPEAVAILABLE)
1426             ok(status == 0, "status = %d\n", status);
1427         else
1428             ok(status == HTTP_STATUS_OK, "status = %d\n", status);
1429         ok(size == sizeof(DWORD), "size = %d\n", size);
1430     }
1431
1432     size = sizeof(DWORD);
1433     hres = IWinInetHttpInfo_QueryOption(http_info, INTERNET_OPTION_HANDLE_TYPE, &status, &size);
1434     if(test_protocol == FTP_TEST) {
1435         if(download_state==BEFORE_DOWNLOAD && progress!=BINDSTATUS_MIMETYPEAVAILABLE)
1436             ok(hres == E_FAIL, "hres = %x\n", hres);
1437         else
1438             ok(hres == S_OK, "hres = %x\n", hres);
1439
1440         if(hres == S_OK)
1441             ok(status == INTERNET_HANDLE_TYPE_FTP_FILE, "status = %d\n", status);
1442     } else {
1443         ok(hres == S_OK, "hres = %x\n", hres);
1444         ok(status == INTERNET_HANDLE_TYPE_HTTP_REQUEST, "status = %d\n", status);
1445     }
1446 }
1447
1448 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1449 {
1450     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1451
1452     if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1453         CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1454         if(emulate_protocol) {
1455             *ppv = &Protocol;
1456             return S_OK;
1457         }else {
1458             return E_NOINTERFACE;
1459         }
1460     }
1461     else if (IsEqualGUID(&IID_IServiceProvider, riid))
1462     {
1463         CHECK_EXPECT2(QueryInterface_IServiceProvider);
1464         *ppv = &ServiceProvider;
1465         return S_OK;
1466     }
1467     else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
1468     {
1469         CHECK_EXPECT2(QueryInterface_IHttpNegotiate);
1470         *ppv = &HttpNegotiate;
1471         return S_OK;
1472     }
1473     else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
1474     {
1475         CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1476         *ppv = &HttpNegotiate;
1477         return S_OK;
1478     }
1479     else if (IsEqualGUID(&IID_IAuthenticate, riid))
1480     {
1481         CHECK_EXPECT(QueryInterface_IAuthenticate);
1482         return E_NOINTERFACE;
1483     }
1484     else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
1485     {
1486         CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1487         *ppv = iface;
1488         return S_OK;
1489     }
1490     else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
1491     {
1492         CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1493         return E_NOINTERFACE;
1494     }
1495     else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid))
1496     {
1497         CHECK_EXPECT(QueryInterface_IBindStatusCallbackEx);
1498         if(!use_bscex)
1499             return E_NOINTERFACE;
1500         *ppv = iface;
1501         return S_OK;
1502     }
1503     else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
1504     {
1505         /* TODO */
1506         CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1507     }
1508     else if(IsEqualGUID(&IID_IWindowForBindingUI, riid))
1509     {
1510         CHECK_EXPECT2(QueryInterface_IWindowForBindingUI);
1511         return E_NOINTERFACE;
1512     }
1513     else if(IsEqualGUID(&IID_IHttpSecurity, riid))
1514     {
1515         CHECK_EXPECT2(QueryInterface_IHttpSecurity);
1516         return E_NOINTERFACE;
1517     }
1518     else
1519     {
1520         ok(0, "unexpected interface %s\n", debugstr_guid(riid));
1521     }
1522
1523     return E_NOINTERFACE;
1524 }
1525
1526 static ULONG WINAPI statusclb_AddRef(IBindStatusCallbackEx *iface)
1527 {
1528     return 2;
1529 }
1530
1531 static ULONG WINAPI statusclb_Release(IBindStatusCallbackEx *iface)
1532 {
1533     return 1;
1534 }
1535
1536 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved,
1537         IBinding *pib)
1538 {
1539     IWinInetHttpInfo *http_info;
1540     HRESULT hres;
1541     IMoniker *mon;
1542
1543     if(iface == &objbsc)
1544         CHECK_EXPECT(Obj_OnStartBinding);
1545     else
1546         CHECK_EXPECT(OnStartBinding);
1547
1548     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1549
1550     ok(pib != NULL, "pib should not be NULL\n");
1551     ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1552
1553     if(pib == (void*)0xdeadbeef)
1554         return S_OK;
1555
1556     current_binding = pib;
1557
1558     hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1559     ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1560     if(SUCCEEDED(hres))
1561         IMoniker_Release(mon);
1562
1563     hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1564     ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1565
1566     if(abort_start) {
1567         binding_hres = abort_hres;
1568         return abort_hres;
1569     }
1570
1571     return S_OK;
1572 }
1573
1574 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1575 {
1576     ok(0, "unexpected call\n");
1577     return E_NOTIMPL;
1578 }
1579
1580 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1581 {
1582     ok(0, "unexpected call\n");
1583     return E_NOTIMPL;
1584 }
1585
1586 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
1587         ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1588 {
1589     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1590
1591     switch(ulStatusCode) {
1592     case BINDSTATUS_FINDINGRESOURCE:
1593         if(iface == &objbsc)
1594             CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1595         else if(test_protocol == FTP_TEST)
1596             todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1597         else
1598             CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1599         if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST))
1600             SetEvent(complete_event);
1601         break;
1602     case BINDSTATUS_CONNECTING:
1603         if(iface == &objbsc)
1604             CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1605         else if(test_protocol == FTP_TEST)
1606             todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
1607         else if(onsecurityproblem_hres == S_OK)
1608             CHECK_EXPECT2(OnProgress_CONNECTING);
1609         else
1610             CHECK_EXPECT(OnProgress_CONNECTING);
1611         if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST))
1612             SetEvent(complete_event);
1613         break;
1614     case BINDSTATUS_REDIRECTING:
1615         if(iface == &objbsc)
1616             CHECK_EXPECT(Obj_OnProgress_REDIRECTING);
1617         else
1618             CHECK_EXPECT(OnProgress_REDIRECTING);
1619         ok(!lstrcmpW(szStatusText, winetest_data_urlW), "unexpected status text %s\n",
1620            wine_dbgstr_w(szStatusText));
1621         if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST)
1622                 && (!bind_to_object || iface == &objbsc))
1623             SetEvent(complete_event);
1624         break;
1625     case BINDSTATUS_SENDINGREQUEST:
1626         if(iface == &objbsc)
1627             CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1628         else if(test_protocol == FTP_TEST)
1629             CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
1630         else
1631             CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1632         if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST))
1633             SetEvent(complete_event);
1634
1635         if(abort_progress) {
1636             if(filedwl_api)
1637                 binding_hres = E_ABORT;
1638             return E_ABORT;
1639         }
1640
1641         break;
1642     case BINDSTATUS_MIMETYPEAVAILABLE:
1643         if(iface == &objbsc)
1644             CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1645         else
1646             CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1647         if(!bind_to_object)
1648             ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1649                download_state);
1650         WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1651         break;
1652     case BINDSTATUS_BEGINDOWNLOADDATA:
1653         if(iface == &objbsc)
1654             CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1655         else
1656             CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1657         ok(szStatusText != NULL, "szStatusText == NULL\n");
1658         if(szStatusText) {
1659             if(filedwl_api) {
1660                 /* FIXME */
1661             }else {
1662                 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1663             }
1664         }
1665         if(!bind_to_object)
1666             ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1667                download_state);
1668         download_state = DOWNLOADING;
1669         break;
1670     case BINDSTATUS_DOWNLOADINGDATA:
1671         CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1672         ok(iface != &objbsc, "unexpected call\n");
1673         ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1674            download_state);
1675         if(test_abort) {
1676             HRESULT hres;
1677
1678             SET_EXPECT(Abort);
1679             hres = IBinding_Abort(current_binding);
1680             ok(hres == S_OK, "Abort failed: %08x\n", hres);
1681             CHECK_CALLED(Abort);
1682
1683             hres = IBinding_Abort(current_binding);
1684             ok(hres == E_FAIL, "Abort failed: %08x\n", hres);
1685
1686             binding_hres = E_ABORT;
1687         }
1688         break;
1689     case BINDSTATUS_ENDDOWNLOADDATA:
1690         if(iface == &objbsc)
1691             CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1692         else
1693             CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1694         ok(szStatusText != NULL, "szStatusText == NULL\n");
1695         if(szStatusText) {
1696             if(filedwl_api) {
1697                 /* FIXME */
1698             }else {
1699                 ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1700             }
1701         }
1702         ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1703            download_state);
1704         download_state = END_DOWNLOAD;
1705         break;
1706     case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1707         if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST && test_protocol != WINETEST_TEST) {
1708             if(iface == &objbsc)
1709                 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1710             else
1711                 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1712         }else {  /* FIXME */
1713             CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1714             CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1715         }
1716
1717         ok(szStatusText != NULL, "szStatusText == NULL\n");
1718         if(szStatusText && test_protocol == FILE_TEST)
1719             ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1720         break;
1721     case BINDSTATUS_CLASSIDAVAILABLE:
1722     {
1723         CLSID clsid;
1724         HRESULT hr;
1725         if(iface != &objbsc)
1726             ok(0, "unexpected call\n");
1727         else
1728             CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1729         hr = CLSIDFromString((LPCOLESTR)szStatusText, &clsid);
1730         ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1731         ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1732             "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1733         break;
1734     }
1735     case BINDSTATUS_BEGINSYNCOPERATION:
1736         CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1737         if(iface != &objbsc)
1738             ok(0, "unexpected call\n");
1739         ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1740         break;
1741     case BINDSTATUS_ENDSYNCOPERATION:
1742         CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1743         if(iface != &objbsc)
1744             ok(0, "unexpected call\n");
1745         ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1746         break;
1747     case BINDSTATUS_PROXYDETECTING:
1748         trace("BINDSTATUS_PROXYDETECTING\n");
1749         break;
1750     case BINDSTATUS_COOKIE_SENT:
1751         trace("BINDSTATUS_COOKIE_SENT\n");
1752         break;
1753     default:
1754         ok(0, "unexpected code %d\n", ulStatusCode);
1755     };
1756
1757     if(current_binding) {
1758         IWinInetHttpInfo *http_info;
1759         HRESULT hres;
1760
1761         hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
1762         if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol)) {
1763             ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
1764             test_WinInetHttpInfo(http_info, ulStatusCode);
1765         } else
1766             ok(hres == E_NOINTERFACE,
1767                "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
1768         if(SUCCEEDED(hres))
1769             IWinInetHttpInfo_Release(http_info);
1770     }
1771
1772     return S_OK;
1773 }
1774
1775 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
1776 {
1777     if(iface == &objbsc) {
1778         CHECK_EXPECT(Obj_OnStopBinding);
1779         stopped_obj_binding = TRUE;
1780     }else {
1781         CHECK_EXPECT(OnStopBinding);
1782         stopped_binding = TRUE;
1783     }
1784
1785     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1786
1787     if(only_check_prot_args) {
1788         todo_wine ok(hresult == S_OK, "Got %08x\n", hresult);
1789         return S_OK;
1790     }
1791
1792     /* ignore DNS failure */
1793     if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1794         return S_OK;
1795
1796     if(filedwl_api) {
1797         if(!abort_progress && !abort_start)
1798             ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1799         else if(abort_start && abort_hres == E_NOTIMPL)
1800             todo_wine ok(hresult == S_FALSE, "binding failed: %08x, expected S_FALSE\n", hresult);
1801         else
1802             ok(hresult == E_ABORT, "binding failed: %08x, expected E_ABORT\n", hresult);
1803     } else
1804         ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1805     ok(szError == NULL, "szError should be NULL\n");
1806
1807     if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) && emulate_protocol) {
1808         SetEvent(complete_event);
1809         if(iface != &objbsc)
1810             WaitForSingleObject(complete_event2, INFINITE);
1811     }
1812
1813     return S_OK;
1814 }
1815
1816 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1817 {
1818     DWORD cbSize;
1819
1820     if(iface == &objbsc)
1821         CHECK_EXPECT(Obj_GetBindInfo);
1822     else
1823         CHECK_EXPECT(GetBindInfo);
1824
1825     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1826
1827     *grfBINDF = bindf;
1828     cbSize = pbindinfo->cbSize;
1829     memset(pbindinfo, 0, cbSize);
1830     pbindinfo->cbSize = cbSize;
1831
1832     return S_OK;
1833 }
1834
1835 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
1836         DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1837 {
1838     HRESULT hres;
1839     DWORD readed;
1840     BYTE buf[512];
1841     CHAR clipfmt[512];
1842
1843     if(iface == &objbsc)
1844         ok(0, "unexpected call\n");
1845
1846     CHECK_EXPECT2(OnDataAvailable);
1847
1848     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1849
1850     ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
1851        "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
1852        download_state);
1853     data_available = TRUE;
1854
1855     if(bind_to_object && !is_async_prot)
1856         ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION), "grfBSCF = %x\n", grfBSCF);
1857
1858     ok(pformatetc != NULL, "pformatetx == NULL\n");
1859     if(pformatetc) {
1860         if (mime_type[0]) {
1861             INT ret;
1862             clipfmt[0] = 0;
1863             ret = GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1);
1864             ok(ret, "GetClipboardFormatName failed, error %d\n", GetLastError());
1865             ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
1866                pformatetc->cfFormat, clipfmt, mime_type);
1867         } else {
1868             ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
1869         }
1870         ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1871         ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
1872         ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
1873         ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1874     }
1875
1876     ok(pstgmed != NULL, "stgmeg == NULL\n");
1877     ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1878     ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1879
1880     switch(pstgmed->tymed) {
1881     case TYMED_ISTREAM:
1882         if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
1883             STATSTG stat;
1884
1885             hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
1886             ok(hres == STG_E_ACCESSDENIED,
1887                "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1888
1889             hres = IStream_Commit(U(*pstgmed).pstm, 0);
1890             ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1891
1892             hres = IStream_Revert(U(*pstgmed).pstm);
1893             ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
1894
1895             hres = IStream_Stat(U(*pstgmed).pstm, NULL, STATFLAG_NONAME);
1896             ok(hres == E_FAIL, "hres = %x\n", hres);
1897             if(use_cache_file && emulate_protocol) {
1898                 hres = IStream_Stat(U(*pstgmed).pstm, &stat, STATFLAG_DEFAULT);
1899                 ok(hres == S_OK, "hres = %x\n", hres);
1900                 ok(!lstrcmpW(stat.pwcsName, cache_file_name),
1901                         "stat.pwcsName = %s, cache_file_name = %s\n",
1902                         wine_dbgstr_w(stat.pwcsName), wine_dbgstr_w(cache_file_name));
1903                 CoTaskMemFree(stat.pwcsName);
1904                 ok(U(stat.cbSize).LowPart == (bindf&BINDF_ASYNCHRONOUS?0:6500),
1905                         "stat.cbSize.LowPart = %u\n", U(stat.cbSize).LowPart);
1906             } else {
1907                 hres = IStream_Stat(U(*pstgmed).pstm, &stat, STATFLAG_NONAME);
1908                 ok(hres == S_OK, "hres = %x\n", hres);
1909                 ok(!stat.pwcsName || broken(stat.pwcsName!=NULL),
1910                         "stat.pwcsName = %s\n", wine_dbgstr_w(stat.pwcsName));
1911             }
1912             ok(stat.type == STGTY_STREAM, "stat.type = %x\n", stat.type);
1913             ok(U(stat.cbSize).HighPart == 0, "stat.cbSize.HighPart != 0\n");
1914             ok(stat.grfMode == (U(stat.cbSize).LowPart?GENERIC_READ:0), "stat.grfMode = %x\n", stat.grfMode);
1915             ok(stat.grfLocksSupported == 0, "stat.grfLocksSupported = %x\n", stat.grfLocksSupported);
1916             ok(stat.grfStateBits == 0, "stat.grfStateBits = %x\n", stat.grfStateBits);
1917             ok(stat.reserved == 0, "stat.reserved = %x\n", stat.reserved);
1918         }
1919
1920         ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
1921         if(callback_read) {
1922             do {
1923                 hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
1924                 if(test_protocol == HTTP_TEST && emulate_protocol && readed)
1925                     ok(buf[0] == (use_cache_file && !(bindf&BINDF_ASYNCHRONOUS) ? 'X' : '?'), "buf[0] = '%c'\n", buf[0]);
1926             }while(hres == S_OK);
1927             ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
1928         }
1929         break;
1930
1931     case TYMED_FILE:
1932         if(test_protocol == FILE_TEST)
1933             ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1934                "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
1935         else if(emulate_protocol)
1936             ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1937                "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
1938         else
1939             ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1940     }
1941
1942     if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST)
1943        && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1944         SetEvent(complete_event);
1945
1946     return S_OK;
1947 }
1948
1949 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
1950 {
1951     CHECK_EXPECT(OnObjectAvailable);
1952
1953     if(iface != &objbsc)
1954         ok(0, "unexpected call\n");
1955
1956     ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
1957     ok(punk != NULL, "punk == NULL\n");
1958
1959     return S_OK;
1960 }
1961
1962 static HRESULT WINAPI statusclb_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo,
1963         DWORD *grfBINDF2, DWORD *pdwReserved)
1964 {
1965     CHECK_EXPECT(GetBindInfoEx);
1966
1967     ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1968     ok(grfBINDF2 != NULL, "grfBINDF2 == NULL\n");
1969     ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1970     ok(pdwReserved != NULL, "dwReserved == NULL\n");
1971
1972     return S_OK;
1973 }
1974
1975 static const IBindStatusCallbackExVtbl BindStatusCallbackVtbl = {
1976     statusclb_QueryInterface,
1977     statusclb_AddRef,
1978     statusclb_Release,
1979     statusclb_OnStartBinding,
1980     statusclb_GetPriority,
1981     statusclb_OnLowResource,
1982     statusclb_OnProgress,
1983     statusclb_OnStopBinding,
1984     statusclb_GetBindInfo,
1985     statusclb_OnDataAvailable,
1986     statusclb_OnObjectAvailable,
1987     statusclb_GetBindInfoEx
1988 };
1989
1990 static IBindStatusCallbackEx bsc = { &BindStatusCallbackVtbl };
1991 static IBindStatusCallbackEx bsc2 = { &BindStatusCallbackVtbl };
1992 static IBindStatusCallbackEx objbsc = { &BindStatusCallbackVtbl };
1993
1994 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
1995 {
1996     *ppv = NULL;
1997     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1998     return E_NOINTERFACE;
1999 }
2000
2001 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
2002 {
2003     return 2;
2004 }
2005
2006 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
2007 {
2008     return 1;
2009 }
2010
2011 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
2012 {
2013     switch(mkp) {
2014     case MIMETYPEPROP:
2015         CHECK_EXPECT(PutProperty_MIMETYPEPROP);
2016         ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", wine_dbgstr_w(val));
2017         break;
2018     case CLASSIDPROP:
2019         CHECK_EXPECT(PutProperty_CLASSIDPROP);
2020         break;
2021     default:
2022         break;
2023     }
2024
2025     return S_OK;
2026 }
2027
2028 static const IMonikerPropVtbl MonikerPropVtbl = {
2029     MonikerProp_QueryInterface,
2030     MonikerProp_AddRef,
2031     MonikerProp_Release,
2032     MonikerProp_PutProperty
2033 };
2034
2035 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
2036
2037 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
2038 {
2039     *ppv = NULL;
2040
2041     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
2042         *ppv = iface;
2043     else if(IsEqualGUID(&IID_IMonikerProp, riid))
2044         *ppv = &MonikerProp;
2045
2046     if(*ppv)
2047         return S_OK;
2048
2049     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2050     return E_NOINTERFACE;
2051 }
2052
2053 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
2054 {
2055     return 2;
2056 }
2057
2058 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
2059 {
2060     return 1;
2061 }
2062
2063 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
2064 {
2065     ok(0, "unexpected call\n");
2066     return E_NOTIMPL;
2067 }
2068
2069 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
2070 {
2071     ok(0, "unexpected call\n");
2072     return E_NOTIMPL;
2073 }
2074
2075 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
2076                                           IMoniker *pimkName, LPBC pibc, DWORD grfMode)
2077 {
2078     IUnknown *unk;
2079     HRESULT hres;
2080
2081     static WCHAR cbinding_contextW[] =
2082         {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
2083
2084     CHECK_EXPECT(Load);
2085     ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
2086
2087     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2088         ok(!fFullyAvailable, "fFullyAvailable = %x\n", fFullyAvailable);
2089     else
2090         ok(fFullyAvailable, "fFullyAvailable = %x\n", fFullyAvailable);
2091     ok(pimkName != NULL, "pimkName == NULL\n");
2092     ok(pibc != NULL, "pibc == NULL\n");
2093     ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
2094
2095     hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
2096     ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
2097     if(SUCCEEDED(hres)) {
2098         IBinding *binding;
2099
2100         hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
2101         ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
2102
2103         IBinding_Release(binding);
2104         IUnknown_Release(unk);
2105     }
2106
2107     SET_EXPECT(QueryInterface_IServiceProvider);
2108     hres = RegisterBindStatusCallback(pibc, (IBindStatusCallback*)&bsc, NULL, 0);
2109     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2110     CHECK_CALLED(QueryInterface_IServiceProvider);
2111
2112     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2113     SET_EXPECT(GetBindInfo);
2114     SET_EXPECT(OnStartBinding);
2115     if(test_redirect)
2116         SET_EXPECT(OnProgress_REDIRECTING);
2117     SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2118     if(test_protocol == FILE_TEST)
2119         SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2120     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2121         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2122     SET_EXPECT(LockRequest);
2123     SET_EXPECT(OnDataAvailable);
2124     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2125         SET_EXPECT(OnStopBinding);
2126
2127     hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
2128     ok(hres == S_OK, "Load failed: %08x\n", hres);
2129
2130     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2131     CHECK_CALLED(GetBindInfo);
2132     CHECK_CALLED(OnStartBinding);
2133     if(test_redirect)
2134         CHECK_CALLED(OnProgress_REDIRECTING);
2135     CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2136     if(test_protocol == FILE_TEST)
2137         CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2138     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2139         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2140     CHECK_CALLED(LockRequest);
2141     CHECK_CALLED(OnDataAvailable);
2142     if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2143         CHECK_CALLED(OnStopBinding);
2144
2145     if(unk)
2146         IUnknown_Release(unk);
2147
2148     return S_OK;
2149 }
2150
2151 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
2152 {
2153     ok(0, "unexpected call\n");
2154     return E_NOTIMPL;
2155 }
2156
2157 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
2158 {
2159     ok(0, "unexpected call\n");
2160     return E_NOTIMPL;
2161 }
2162
2163 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
2164 {
2165     ok(0, "unexpected call\n");
2166     return E_NOTIMPL;
2167 }
2168
2169 static const IPersistMonikerVtbl PersistMonikerVtbl = {
2170     PersistMoniker_QueryInterface,
2171     PersistMoniker_AddRef,
2172     PersistMoniker_Release,
2173     PersistMoniker_GetClassID,
2174     PersistMoniker_IsDirty,
2175     PersistMoniker_Load,
2176     PersistMoniker_Save,
2177     PersistMoniker_SaveCompleted,
2178     PersistMoniker_GetCurMoniker
2179 };
2180
2181 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
2182
2183 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2184 {
2185     *ppv = NULL;
2186
2187     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2188         *ppv = iface;
2189         return S_OK;
2190     }
2191
2192     if(IsEqualGUID(&IID_IMarshal, riid))
2193         return E_NOINTERFACE;
2194     if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
2195         return E_NOINTERFACE;
2196
2197     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2198     return E_NOTIMPL;
2199 }
2200
2201 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2202 {
2203     return 2;
2204 }
2205
2206 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2207 {
2208     return 1;
2209 }
2210
2211 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2212 {
2213     CHECK_EXPECT(CreateInstance);
2214     ok(!outer, "outer = %p\n", outer);
2215     ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2216     *ppv = &PersistMoniker;
2217     return S_OK;
2218 }
2219
2220 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2221 {
2222     ok(0, "unexpected call\n");
2223     return S_OK;
2224 }
2225
2226 static const IClassFactoryVtbl ClassFactoryVtbl = {
2227     ClassFactory_QueryInterface,
2228     ClassFactory_AddRef,
2229     ClassFactory_Release,
2230     ClassFactory_CreateInstance,
2231     ClassFactory_LockServer
2232 };
2233
2234 static IClassFactory mime_cf = { &ClassFactoryVtbl };
2235
2236 static HRESULT WINAPI ProtocolCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2237 {
2238     *ppv = NULL;
2239
2240     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2241         *ppv = iface;
2242         return S_OK;
2243     }
2244
2245     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid))
2246         return E_NOINTERFACE;
2247
2248     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2249     return E_NOTIMPL;
2250 }
2251
2252 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2253 {
2254     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid))
2255         return E_NOINTERFACE;
2256
2257     todo_wine ok(outer != NULL, "outer == NULL\n");
2258     todo_wine ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
2259     *ppv = &Protocol;
2260     return S_OK;
2261 }
2262
2263 static const IClassFactoryVtbl ProtocolCFVtbl = {
2264     ProtocolCF_QueryInterface,
2265     ClassFactory_AddRef,
2266     ClassFactory_Release,
2267     ProtocolCF_CreateInstance,
2268     ClassFactory_LockServer
2269 };
2270
2271 static IClassFactory protocol_cf = { &ProtocolCFVtbl };
2272
2273 static void test_CreateAsyncBindCtx(void)
2274 {
2275     IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
2276     IUnknown *unk;
2277     HRESULT hres;
2278     ULONG ref;
2279     BIND_OPTS bindopts;
2280
2281     hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
2282     ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
2283     ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
2284
2285     hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
2286     ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
2287
2288     SET_EXPECT(QueryInterface_IServiceProvider);
2289     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2290     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
2291     CHECK_CALLED(QueryInterface_IServiceProvider);
2292
2293     bindopts.cbStruct = sizeof(bindopts);
2294     hres = IBindCtx_GetBindOptions(bctx, &bindopts);
2295     ok(hres == S_OK, "IBindCtx_GetBindOptions failed: %08x\n", hres);
2296     ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
2297                 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
2298     ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
2299                 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
2300                 bindopts.grfMode);
2301     ok(bindopts.dwTickCountDeadline == 0,
2302                 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
2303
2304     hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
2305     ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
2306     if(SUCCEEDED(hres))
2307         IUnknown_Release(unk);
2308
2309     ref = IBindCtx_Release(bctx);
2310     ok(ref == 0, "bctx should be destroyed here\n");
2311 }
2312
2313 static void test_CreateAsyncBindCtxEx(void)
2314 {
2315     IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
2316     IUnknown *unk;
2317     BIND_OPTS bindopts;
2318     HRESULT hres;
2319
2320     static WCHAR testW[] = {'t','e','s','t',0};
2321
2322     if (!pCreateAsyncBindCtxEx) {
2323         win_skip("CreateAsyncBindCtxEx not present\n");
2324         return;
2325     }
2326
2327     hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
2328     ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
2329
2330     hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2331     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2332
2333     if(SUCCEEDED(hres)) {
2334         bindopts.cbStruct = sizeof(bindopts);
2335         hres = IBindCtx_GetBindOptions(bctx, &bindopts);
2336         ok(hres == S_OK, "IBindCtx_GetBindOptions failed: %08x\n", hres);
2337         ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
2338                 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
2339         ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
2340                 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
2341                 bindopts.grfMode);
2342         ok(bindopts.dwTickCountDeadline == 0,
2343                 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
2344
2345         IBindCtx_Release(bctx);
2346     }
2347
2348     CreateBindCtx(0, &bctx_arg);
2349     hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2350     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2351
2352     if(SUCCEEDED(hres)) {
2353         bindopts.cbStruct = sizeof(bindopts);
2354         hres = IBindCtx_GetBindOptions(bctx, &bindopts);
2355         ok(hres == S_OK, "IBindCtx_GetBindOptions failed: %08x\n", hres);
2356         ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
2357                 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
2358         ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
2359                 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
2360                 bindopts.grfMode);
2361         ok(bindopts.dwTickCountDeadline == 0,
2362                 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
2363
2364         IBindCtx_Release(bctx);
2365     }
2366
2367     IBindCtx_Release(bctx_arg);
2368
2369     SET_EXPECT(QueryInterface_IServiceProvider);
2370     hres = pCreateAsyncBindCtxEx(NULL, 0, (IBindStatusCallback*)&bsc, NULL, &bctx, 0);
2371     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2372     CHECK_CALLED(QueryInterface_IServiceProvider);
2373
2374     hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
2375     ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
2376     if(SUCCEEDED(hres))
2377         IUnknown_Release(unk);
2378
2379     IBindCtx_Release(bctx);
2380
2381     hres = CreateBindCtx(0, &bctx2);
2382     ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
2383
2384     hres = pCreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
2385     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2386
2387     hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
2388     ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2389
2390     hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
2391     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2392     ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
2393
2394     IBindCtx_Release(bctx);
2395     IBindCtx_Release(bctx2);
2396 }
2397
2398 static void test_GetBindInfoEx(IBindStatusCallback *holder)
2399 {
2400     IBindStatusCallbackEx *bscex;
2401     BINDINFO bindinfo = {sizeof(bindinfo)};
2402     DWORD bindf, bindf2, dw;
2403     HRESULT hres;
2404
2405     hres = IBindStatusCallback_QueryInterface(holder, &IID_IBindStatusCallbackEx, (void**)&bscex);
2406     if(FAILED(hres)) {
2407         win_skip("IBindStatusCallbackEx not supported\n");
2408         return;
2409     }
2410
2411     use_bscex = TRUE;
2412
2413     bindf = 0;
2414     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2415     SET_EXPECT(GetBindInfoEx);
2416     hres = IBindStatusCallback_GetBindInfo(holder, &bindf, &bindinfo);
2417     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2418     CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2419     CHECK_CALLED(GetBindInfoEx);
2420
2421     bindf = bindf2 = dw = 0;
2422     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2423     SET_EXPECT(GetBindInfoEx);
2424     hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
2425     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2426     CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2427     CHECK_CALLED(GetBindInfoEx);
2428
2429     use_bscex = FALSE;
2430
2431     bindf = bindf2 = dw = 0xdeadbeef;
2432     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2433     SET_EXPECT(GetBindInfo);
2434     hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
2435     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2436     CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2437     CHECK_CALLED(GetBindInfo);
2438     ok(bindf2 == 0xdeadbeef, "bindf2 = %x\n", bindf2);
2439     ok(dw == 0xdeadbeef, "dw = %x\n", dw);
2440
2441     IBindStatusCallbackEx_Release(bscex);
2442 }
2443
2444 static BOOL test_bscholder(IBindStatusCallback *holder)
2445 {
2446     IServiceProvider *serv_prov;
2447     IHttpNegotiate *http_negotiate, *http_negotiate_serv;
2448     IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
2449     IAuthenticate *authenticate, *authenticate_serv;
2450     IInternetProtocol *protocol;
2451     BINDINFO bindinfo = {sizeof(bindinfo)};
2452     BOOL ret = TRUE;
2453     LPWSTR wstr;
2454     DWORD dw;
2455     HRESULT hres;
2456
2457     hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
2458     ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2459
2460     dw = 0xdeadbeef;
2461     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2462     SET_EXPECT(GetBindInfo);
2463     hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
2464     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2465     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2466     CHECK_CALLED(GetBindInfo);
2467
2468     test_GetBindInfoEx(holder);
2469
2470     SET_EXPECT(OnStartBinding);
2471     hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
2472     ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
2473     CHECK_CALLED(OnStartBinding);
2474
2475     hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
2476     ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
2477
2478     SET_EXPECT(QueryInterface_IHttpNegotiate);
2479     hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2480                                          (void**)&http_negotiate_serv);
2481     ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2482     CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
2483
2484     ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2485
2486     wstr = (void*)0xdeadbeef;
2487     SET_EXPECT(QueryInterface_IHttpNegotiate);
2488     SET_EXPECT(BeginningTransaction);
2489     hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
2490     CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2491     CHECK_CALLED(BeginningTransaction);
2492     ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
2493     ok(wstr == NULL, "wstr = %p\n", wstr);
2494
2495     IHttpNegotiate_Release(http_negotiate_serv);
2496
2497     hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2498                                          (void**)&http_negotiate_serv);
2499     ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2500     ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2501     IHttpNegotiate_Release(http_negotiate_serv);
2502
2503     hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
2504     if(SUCCEEDED(hres)) {
2505         have_IHttpNegotiate2 = TRUE;
2506
2507         SET_EXPECT(QueryInterface_IHttpNegotiate2);
2508         hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
2509                                              (void**)&http_negotiate2_serv);
2510         ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
2511         CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
2512         ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
2513
2514         SET_EXPECT(QueryInterface_IHttpNegotiate2);
2515         SET_EXPECT(GetRootSecurityId);
2516         hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
2517         ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
2518         CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2); /* IE8 */
2519         CHECK_CALLED(GetRootSecurityId);
2520
2521         IHttpNegotiate_Release(http_negotiate2_serv);
2522         IHttpNegotiate_Release(http_negotiate2);
2523     }else {
2524         skip("Could not get IHttpNegotiate2\n");
2525         ret = FALSE;
2526     }
2527
2528     SET_EXPECT(OnProgress_FINDINGRESOURCE);
2529     hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
2530     ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
2531     CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2532
2533     SET_EXPECT(QueryInterface_IHttpNegotiate);
2534     SET_EXPECT(OnResponse);
2535     wstr = (void*)0xdeadbeef;
2536     hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
2537     ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2538     CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2539     CHECK_CALLED(OnResponse);
2540
2541     IHttpNegotiate_Release(http_negotiate);
2542
2543     hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
2544     ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
2545
2546     SET_EXPECT(QueryInterface_IAuthenticate);
2547     SET_EXPECT(QueryService_IAuthenticate);
2548     hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2549                                          (void**)&authenticate_serv);
2550     ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2551     CLEAR_CALLED(QueryInterface_IAuthenticate); /* IE <8 */
2552     CLEAR_CALLED(QueryService_IAuthenticate); /* IE <8 */
2553     ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2554     IAuthenticate_Release(authenticate_serv);
2555
2556     hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2557                                          (void**)&authenticate_serv);
2558     ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2559     ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2560
2561     IAuthenticate_Release(authenticate);
2562     IAuthenticate_Release(authenticate_serv);
2563
2564     SET_EXPECT(OnStopBinding);
2565     hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
2566     ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
2567     CHECK_CALLED(OnStopBinding);
2568
2569     SET_EXPECT(QueryInterface_IInternetProtocol);
2570     SET_EXPECT(QueryService_IInternetProtocol);
2571     hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
2572                                          (void**)&protocol);
2573     ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
2574     CHECK_CALLED(QueryInterface_IInternetProtocol);
2575     CHECK_CALLED(QueryService_IInternetProtocol);
2576
2577     IServiceProvider_Release(serv_prov);
2578     return ret;
2579 }
2580
2581 static BOOL test_RegisterBindStatusCallback(void)
2582 {
2583     IBindStatusCallback *prevbsc, *clb, *prev_clb;
2584     IBindCtx *bindctx;
2585     BOOL ret = TRUE;
2586     IUnknown *unk;
2587     HRESULT hres;
2588
2589     hres = CreateBindCtx(0, &bindctx);
2590     ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
2591
2592     SET_EXPECT(QueryInterface_IServiceProvider);
2593
2594     hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
2595     ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2596
2597     SET_EXPECT(QueryInterface_IBindStatusCallback);
2598     SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
2599     prevbsc = (void*)0xdeadbeef;
2600     hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2601     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2602     ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc=%p\n", prevbsc);
2603     CHECK_CALLED(QueryInterface_IBindStatusCallback);
2604     CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
2605
2606     CHECK_CALLED(QueryInterface_IServiceProvider);
2607
2608     hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2609     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2610
2611     hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2612     IUnknown_Release(unk);
2613     ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2614     ok(clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2615
2616     if(!test_bscholder(clb))
2617         ret = FALSE;
2618
2619     IBindStatusCallback_Release(clb);
2620
2621     hres = RevokeBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc);
2622     ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2623
2624     unk = (void*)0xdeadbeef;
2625     hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2626     ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
2627     ok(unk == NULL, "unk != NULL\n");
2628
2629     if(unk)
2630         IUnknown_Release(unk);
2631
2632     hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
2633     ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2634
2635     hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
2636     ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2637
2638     hres = RevokeBindStatusCallback(bindctx, NULL);
2639     ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2640
2641     SET_EXPECT(QueryInterface_IServiceProvider);
2642     prevbsc = (void*)0xdeadbeef;
2643     hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2644     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2645     ok(!prevbsc, "prevbsc=%p\n", prevbsc);
2646     CHECK_CALLED(QueryInterface_IServiceProvider);
2647
2648     hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2649     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2650
2651     hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&prev_clb);
2652     IUnknown_Release(unk);
2653     ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2654     ok(prev_clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2655
2656     SET_EXPECT(QueryInterface_IServiceProvider);
2657     prevbsc = (void*)0xdeadbeef;
2658     hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc2, &prevbsc, 0);
2659     ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2660     ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc != bsc\n");
2661     CHECK_CALLED(QueryInterface_IServiceProvider);
2662
2663     hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2664     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2665
2666     hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2667     IUnknown_Release(unk);
2668     ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2669     ok(prev_clb  == clb, "bsc != clb\n");
2670
2671     IBindStatusCallback_Release(clb);
2672     IBindStatusCallback_Release(prev_clb);
2673
2674     IBindCtx_Release(bindctx);
2675     return ret;
2676 }
2677
2678 #define BINDTEST_EMULATE            0x0001
2679 #define BINDTEST_TOOBJECT           0x0002
2680 #define BINDTEST_FILEDWLAPI         0x0004
2681 #define BINDTEST_HTTPRESPONSE       0x0008
2682 #define BINDTEST_REDIRECT           0x0010
2683 #define BINDTEST_USE_CACHE          0x0020
2684 #define BINDTEST_NO_CALLBACK_READ   0x0040
2685 #define BINDTEST_NO_CALLBACK        0x0080
2686 #define BINDTEST_ABORT              0x0100
2687 #define BINDTEST_INVALID_CN         0x0200
2688 #define BINDTEST_ABORT_START        0x0400
2689 #define BINDTEST_ABORT_PROGRESS     0x0800
2690
2691 static void init_bind_test(int protocol, DWORD flags, DWORD t)
2692 {
2693     test_protocol = protocol;
2694     emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
2695     download_state = BEFORE_DOWNLOAD;
2696     stopped_binding = FALSE;
2697     stopped_obj_binding = FALSE;
2698     data_available = FALSE;
2699     mime_type[0] = 0;
2700     binding_hres = S_OK;
2701     bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
2702     tymed = t;
2703     filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
2704     if(flags & BINDTEST_HTTPRESPONSE)
2705         urls[HTTP_TEST] = winetest_post_urlW;
2706     else
2707         urls[HTTP_TEST] = winetest_data_urlW;
2708     if(flags & BINDTEST_INVALID_CN)
2709         urls[HTTPS_TEST] = https_invalid_cn_urlW;
2710     else
2711         urls[HTTPS_TEST] = https_urlW;
2712     test_redirect = (flags & BINDTEST_REDIRECT) != 0;
2713     use_cache_file = (flags & BINDTEST_USE_CACHE) != 0;
2714     callback_read = !(flags & BINDTEST_NO_CALLBACK_READ);
2715     no_callback = (flags & BINDTEST_NO_CALLBACK) != 0;
2716     test_abort = (flags & BINDTEST_ABORT) != 0;
2717     abort_start = (flags & BINDTEST_ABORT_START) != 0;
2718     abort_progress = (flags & BINDTEST_ABORT_PROGRESS) != 0;
2719     is_async_prot = protocol == HTTP_TEST || protocol == HTTPS_TEST || protocol == FTP_TEST || protocol == WINETEST_TEST;
2720 }
2721
2722 static void test_BindToStorage(int protocol, DWORD flags, DWORD t)
2723 {
2724     IMoniker *mon;
2725     HRESULT hres;
2726     LPOLESTR display_name;
2727     IBindCtx *bctx = NULL;
2728     MSG msg;
2729     IBindStatusCallback *previousclb;
2730     IUnknown *unk = (IUnknown*)0x00ff00ff;
2731     IBinding *bind;
2732
2733     init_bind_test(protocol, flags, t);
2734
2735     if(no_callback) {
2736         hres = CreateBindCtx(0, &bctx);
2737         ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
2738     }else {
2739         SET_EXPECT(QueryInterface_IServiceProvider);
2740         hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2741         ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
2742         CHECK_CALLED(QueryInterface_IServiceProvider);
2743         if(FAILED(hres))
2744             return;
2745
2746         SET_EXPECT(QueryInterface_IServiceProvider);
2747         hres = RegisterBindStatusCallback(bctx, (IBindStatusCallback*)&bsc, &previousclb, 0);
2748         ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2749         ok(previousclb == (IBindStatusCallback*)&bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2750         CHECK_CALLED(QueryInterface_IServiceProvider);
2751         if(previousclb)
2752             IBindStatusCallback_Release(previousclb);
2753     }
2754
2755     hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2756     ok(hres == S_OK, "failed to create moniker: %08x\n", hres);
2757     if(FAILED(hres))
2758         return;
2759
2760     hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
2761     ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
2762     if(SUCCEEDED(hres))
2763         IBinding_Release(bind);
2764
2765     hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2766     ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
2767     ok(!lstrcmpW(display_name, urls[test_protocol]),
2768        "GetDisplayName got wrong name %s\n", wine_dbgstr_w(display_name));
2769     CoTaskMemFree(display_name);
2770
2771     if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
2772         binding_hres = INET_E_DATA_NOT_AVAILABLE;
2773     if((flags & BINDTEST_INVALID_CN) && !invalid_cn_accepted &&
2774        (onsecurityproblem_hres != S_OK || security_problem == ERROR_INTERNET_SEC_CERT_ERRORS)) {
2775         if(security_problem == ERROR_INTERNET_SEC_CERT_ERRORS)
2776             binding_hres = INET_E_SECURITY_PROBLEM;
2777         else
2778             binding_hres = INET_E_INVALID_CERTIFICATE;
2779     }
2780
2781
2782     if(only_check_prot_args)
2783         SET_EXPECT(OnStopBinding);
2784     if(!no_callback) {
2785         SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2786         SET_EXPECT(GetBindInfo);
2787         SET_EXPECT(QueryInterface_IInternetProtocol);
2788         if(!emulate_protocol)
2789             SET_EXPECT(QueryService_IInternetProtocol);
2790         SET_EXPECT(OnStartBinding);
2791     }
2792     if(emulate_protocol) {
2793         if(is_urlmon_protocol(test_protocol))
2794             SET_EXPECT(SetPriority);
2795         SET_EXPECT(Start);
2796         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST)
2797             SET_EXPECT(Terminate);
2798         if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2799             SET_EXPECT(UnlockRequest);
2800     }else {
2801         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
2802             SET_EXPECT(QueryInterface_IInternetBindInfo);
2803             SET_EXPECT(QueryService_IInternetBindInfo);
2804             if(!abort_start)
2805                 SET_EXPECT(QueryInterface_IHttpNegotiate);
2806             SET_EXPECT(QueryInterface_IWindowForBindingUI);
2807             SET_EXPECT(QueryService_IWindowForBindingUI);
2808             SET_EXPECT(GetWindow_IWindowForBindingUI);
2809             if(!abort_start) {
2810                 SET_EXPECT(BeginningTransaction);
2811                 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2812                 SET_EXPECT(GetRootSecurityId);
2813                 if(http_is_first)
2814                     SET_EXPECT(OnProgress_FINDINGRESOURCE);
2815                 SET_EXPECT(OnProgress_CONNECTING);
2816             }
2817             if(flags & BINDTEST_INVALID_CN) {
2818                 SET_EXPECT(QueryInterface_IHttpSecurity);
2819                 SET_EXPECT(QueryService_IHttpSecurity);
2820                 SET_EXPECT(OnSecurityProblem);
2821                 if(SUCCEEDED(onsecurityproblem_hres))
2822                     SET_EXPECT(GetWindow_IHttpSecurity);
2823             }
2824         }
2825         if(!no_callback) {
2826             if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST
2827                || test_protocol == FILE_TEST || test_protocol == WINETEST_TEST) && !abort_start)
2828                 SET_EXPECT(OnProgress_SENDINGREQUEST);
2829             if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
2830                 SET_EXPECT(QueryInterface_IHttpNegotiate);
2831                 SET_EXPECT(OnResponse);
2832             }
2833             if(!abort_start) {
2834                 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2835                 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2836             }
2837             if(test_protocol == FILE_TEST)
2838                 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2839             if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST || test_protocol == WINETEST_TEST)
2840                 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
2841             if(!abort_start)
2842                 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2843             if((tymed != TYMED_FILE || test_protocol != ABOUT_TEST) && !abort_start)
2844                 SET_EXPECT(OnDataAvailable);
2845             SET_EXPECT(OnStopBinding);
2846         }
2847     }
2848
2849     hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2850     if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2851         && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2852     {
2853         skip("Network unreachable, skipping tests\n");
2854         return;
2855     }
2856
2857     if(only_check_prot_args) {
2858         ok(hres == E_FAIL, "Got %08x\n", hres);
2859         CHECK_CALLED(OnStopBinding);
2860     } else if(abort_start)
2861         ok(hres == abort_hres, "IMoniker_BindToStorage failed: %08x, expected %08x\n", hres, abort_hres);
2862     else if(abort_progress)
2863         ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2864     else if(no_callback) {
2865         if(emulate_protocol)
2866             WaitForSingleObject(complete_event2, INFINITE);
2867         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2868         ok(unk != NULL, "unk == NULL\n");
2869     }else if(!(bindf & BINDF_ASYNCHRONOUS) && tymed == TYMED_FILE) {
2870         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2871         ok(unk == NULL, "unk != NULL\n");
2872     }else if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
2873        || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2874         ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
2875         ok(unk == NULL, "istr should be NULL\n");
2876     }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
2877         ok(hres == INET_E_DATA_NOT_AVAILABLE,
2878            "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
2879         ok(unk == NULL, "istr should be NULL\n");
2880     }else if((flags & BINDTEST_INVALID_CN) && binding_hres != S_OK) {
2881         ok(hres == binding_hres, "Got %08x\n", hres);
2882         ok(unk == NULL, "Got %p\n", unk);
2883     }else if((flags & BINDTEST_INVALID_CN) && invalid_cn_accepted) {
2884         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2885         ok(unk != NULL, "unk == NULL\n");
2886         if(unk == NULL) {
2887             ok(0, "Expected security problem to be ignored.\n");
2888             invalid_cn_accepted = FALSE;
2889             binding_hres = INET_E_INVALID_CERTIFICATE;
2890         }
2891     }else {
2892         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2893         ok(unk != NULL, "unk == NULL\n");
2894     }
2895     if(unk && callback_read && !no_callback) {
2896         IUnknown_Release(unk);
2897         unk = NULL;
2898     }
2899
2900     if(FAILED(hres) && !(flags & BINDTEST_INVALID_CN) && !(flags & BINDTEST_ABORT_START))
2901         return;
2902
2903     if((bindf & BINDF_ASYNCHRONOUS) && !no_callback) {
2904         while(!stopped_binding && GetMessage(&msg,NULL,0,0)) {
2905             TranslateMessage(&msg);
2906             DispatchMessage(&msg);
2907         }
2908     }
2909
2910     if(!no_callback) {
2911         CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2912         CHECK_CALLED(GetBindInfo);
2913         if(abort_start)
2914             todo_wine CHECK_CALLED(QueryInterface_IInternetProtocol);
2915         else
2916             CHECK_CALLED(QueryInterface_IInternetProtocol);
2917         if(!emulate_protocol) {
2918             if(abort_start)
2919                 todo_wine CHECK_CALLED(QueryService_IInternetProtocol);
2920             else
2921                 CHECK_CALLED(QueryService_IInternetProtocol);
2922         }
2923         CHECK_CALLED(OnStartBinding);
2924     }
2925     if(emulate_protocol) {
2926         if(is_urlmon_protocol(test_protocol))
2927             CHECK_CALLED(SetPriority);
2928         CHECK_CALLED(Start);
2929         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
2930             if(tymed == TYMED_FILE)
2931                 CLEAR_CALLED(Read);
2932             CHECK_CALLED(Terminate);
2933         }
2934         if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
2935             CHECK_CALLED(UnlockRequest);
2936     }else {
2937         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
2938             CLEAR_CALLED(QueryInterface_IInternetBindInfo);
2939             CLEAR_CALLED(QueryService_IInternetBindInfo);
2940             if(!abort_start)
2941                 CHECK_CALLED(QueryInterface_IHttpNegotiate);
2942             CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
2943             CLEAR_CALLED(QueryService_IWindowForBindingUI);
2944             CLEAR_CALLED(GetWindow_IWindowForBindingUI);
2945             if(!abort_start)
2946                 CHECK_CALLED(BeginningTransaction);
2947             if (have_IHttpNegotiate2 && !abort_start)
2948             {
2949                 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
2950                 CHECK_CALLED(GetRootSecurityId);
2951             }
2952             if(http_is_first) {
2953                 if (! proxy_active())
2954                 {
2955                     CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2956                     CHECK_CALLED(OnProgress_CONNECTING);
2957                 }
2958                 else
2959                 {
2960                     CLEAR_CALLED(OnProgress_FINDINGRESOURCE);
2961                     CLEAR_CALLED(OnProgress_CONNECTING);
2962                 }
2963             }else if(!abort_start) {
2964                 /* IE7 does call this */
2965                 CLEAR_CALLED(OnProgress_CONNECTING);
2966             }
2967             if((flags & BINDTEST_INVALID_CN) && !invalid_cn_accepted)  {
2968                 CHECK_CALLED(QueryInterface_IHttpSecurity);
2969                 CHECK_CALLED(QueryService_IHttpSecurity);
2970                 CHECK_CALLED(OnSecurityProblem);
2971             }else {
2972                 CHECK_NOT_CALLED(QueryInterface_IHttpSecurity);
2973                 CHECK_NOT_CALLED(QueryService_IHttpSecurity);
2974                 CHECK_NOT_CALLED(OnSecurityProblem);
2975             }
2976         }
2977         if(!no_callback) {
2978             if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST || test_protocol == WINETEST_TEST) {
2979                 if(flags & BINDTEST_INVALID_CN)
2980                     CLEAR_CALLED(OnProgress_SENDINGREQUEST);
2981                 else if(!abort_start)
2982                     CHECK_CALLED(OnProgress_SENDINGREQUEST);
2983             } else if(test_protocol == FTP_TEST)
2984                 todo_wine CHECK_CALLED(OnProgress_SENDINGREQUEST);
2985             if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
2986                 CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2987                 if((!(flags & BINDTEST_INVALID_CN) || (binding_hres == S_OK)) && !abort_start) {
2988                     CHECK_CALLED(OnResponse);
2989                 }
2990             }
2991             if((!(flags & BINDTEST_INVALID_CN) || binding_hres == S_OK) && !abort_start) {
2992                 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2993                 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2994                 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2995             }
2996             if(test_protocol == FILE_TEST)
2997                 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2998             if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST  || test_protocol == WINETEST_TEST)
2999                 CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
3000             if((flags & BINDTEST_INVALID_CN)) {
3001                 if(binding_hres == S_OK)
3002                     CHECK_CALLED(OnDataAvailable);
3003                 else
3004                     CHECK_NOT_CALLED(OnDataAvailable);
3005             }else if((tymed != TYMED_FILE || test_protocol != ABOUT_TEST) && !abort_start)
3006                 CHECK_CALLED(OnDataAvailable);
3007             CHECK_CALLED(OnStopBinding);
3008         }
3009     }
3010
3011     ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
3012     if(bctx)
3013         ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
3014
3015     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3016         http_is_first = FALSE;
3017
3018     if((flags & BINDTEST_INVALID_CN) && onsecurityproblem_hres == S_OK && security_problem != ERROR_INTERNET_SEC_CERT_ERRORS)
3019         invalid_cn_accepted = TRUE;
3020
3021     if(unk) {
3022         BYTE buf[512];
3023         DWORD readed;
3024         IStream *stream;
3025
3026         hres = IUnknown_QueryInterface(unk, &IID_IStream, (void**)&stream);
3027         ok(hres == S_OK, "Could not get IStream iface: %08x\n", hres);
3028         IUnknown_Release(unk);
3029
3030         do {
3031             readed = 0xdeadbeef;
3032             hres = IStream_Read(stream, buf, sizeof(buf), &readed);
3033             ok(readed != 0xdeadbeef, "readed = 0xdeadbeef\n");
3034             if(emulate_protocol && test_protocol == HTTP_TEST && readed)
3035                 ok(buf[0] == (use_cache_file && !(bindf&BINDF_ASYNCHRONOUS) ? 'X' : '?'), "buf[0] = '%c'\n", buf[0]);
3036         }while(hres == S_OK);
3037         ok(hres == S_FALSE, "IStream_Read returned %08x\n", hres);
3038         ok(!readed, "readed = %d\n", readed);
3039
3040         IStream_Release(stream);
3041     }
3042 }
3043
3044 static void test_BindToObject(int protocol, DWORD flags)
3045 {
3046     IMoniker *mon;
3047     HRESULT hres;
3048     LPOLESTR display_name;
3049     IBindCtx *bctx;
3050     DWORD regid;
3051     MSG msg;
3052     IUnknown *unk = (IUnknown*)0x00ff00ff;
3053     IBinding *bind;
3054
3055     init_bind_test(protocol, BINDTEST_TOOBJECT|flags, TYMED_ISTREAM);
3056
3057     if(emulate_protocol)
3058         CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
3059                               CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
3060
3061     SET_EXPECT(QueryInterface_IServiceProvider);
3062     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&objbsc, NULL, &bctx);
3063     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
3064     CHECK_CALLED(QueryInterface_IServiceProvider);
3065     if(FAILED(hres))
3066         return;
3067
3068     hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
3069     ok(hres == S_OK, "failed to create moniker: %08x\n", hres);
3070     if(FAILED(hres)) {
3071         IBindCtx_Release(bctx);
3072         return;
3073     }
3074
3075     hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
3076     ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
3077     if(SUCCEEDED(hres))
3078         IBinding_Release(bind);
3079
3080     hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
3081     ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
3082     ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");
3083     CoTaskMemFree(display_name);
3084
3085     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
3086     SET_EXPECT(Obj_GetBindInfo);
3087     SET_EXPECT(QueryInterface_IInternetProtocol);
3088     if(!emulate_protocol)
3089         SET_EXPECT(QueryService_IInternetProtocol);
3090     SET_EXPECT(Obj_OnStartBinding);
3091     if(emulate_protocol) {
3092         if(is_urlmon_protocol(test_protocol))
3093             SET_EXPECT(SetPriority);
3094         SET_EXPECT(Start);
3095         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3096             SET_EXPECT(Terminate);
3097         if(test_protocol == FILE_TEST)
3098             SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
3099         SET_EXPECT(UnlockRequest);
3100     }else {
3101         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3102             SET_EXPECT(QueryInterface_IHttpNegotiate);
3103             SET_EXPECT(BeginningTransaction);
3104             SET_EXPECT(QueryInterface_IHttpNegotiate2);
3105             SET_EXPECT(GetRootSecurityId);
3106             if(http_is_first)
3107                 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
3108             SET_EXPECT(Obj_OnProgress_CONNECTING);
3109             SET_EXPECT(QueryInterface_IWindowForBindingUI);
3110             SET_EXPECT(QueryService_IWindowForBindingUI);
3111             SET_EXPECT(GetWindow_IWindowForBindingUI);
3112         }
3113         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
3114             SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
3115         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3116             SET_EXPECT(QueryInterface_IHttpNegotiate);
3117             SET_EXPECT(OnResponse);
3118         }
3119         SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
3120         SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
3121         if(test_protocol == FILE_TEST)
3122             SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
3123         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3124             SET_EXPECT(OnProgress_DOWNLOADINGDATA);
3125         SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
3126         SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
3127         SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
3128         SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
3129         SET_EXPECT(OnObjectAvailable);
3130         SET_EXPECT(Obj_OnStopBinding);
3131     }
3132
3133     hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
3134
3135     if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3136         && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
3137     {
3138         skip( "Network unreachable, skipping tests\n" );
3139         return;
3140     }
3141
3142     /* no point testing the calls if binding didn't even work */
3143     if (FAILED(hres)) return;
3144
3145     if(bindf & BINDF_ASYNCHRONOUS) {
3146         ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
3147         ok(unk == NULL, "istr should be NULL\n");
3148     }else {
3149         ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
3150         ok(unk != NULL, "unk == NULL\n");
3151         if(emulate_protocol)
3152             ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
3153     }
3154     if(unk)
3155         IUnknown_Release(unk);
3156
3157     while((bindf & BINDF_ASYNCHRONOUS) &&
3158           !((!emulate_protocol || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
3159         TranslateMessage(&msg);
3160         DispatchMessage(&msg);
3161     }
3162
3163     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx);
3164     CHECK_CALLED(Obj_GetBindInfo);
3165     CHECK_CALLED(QueryInterface_IInternetProtocol);
3166     if(!emulate_protocol)
3167         CHECK_CALLED(QueryService_IInternetProtocol);
3168     CHECK_CALLED(Obj_OnStartBinding);
3169     if(emulate_protocol) {
3170         if(is_urlmon_protocol(test_protocol))
3171             CHECK_CALLED(SetPriority);
3172         CHECK_CALLED(Start);
3173         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3174             CHECK_CALLED(Terminate);
3175         if(test_protocol == FILE_TEST)
3176             CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
3177         CHECK_CALLED(UnlockRequest);
3178     }else {
3179         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3180             CHECK_CALLED(QueryInterface_IHttpNegotiate);
3181             CHECK_CALLED(BeginningTransaction);
3182             if (have_IHttpNegotiate2)
3183             {
3184                 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
3185                 CHECK_CALLED(GetRootSecurityId);
3186             }
3187             if(http_is_first) {
3188                 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
3189                 CHECK_CALLED(Obj_OnProgress_CONNECTING);
3190             }else {
3191                 /* IE7 does call this */
3192                 CLEAR_CALLED(Obj_OnProgress_CONNECTING);
3193             }
3194             CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
3195             CLEAR_CALLED(QueryService_IWindowForBindingUI);
3196             CLEAR_CALLED(GetWindow_IWindowForBindingUI);
3197         }
3198         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
3199             if(urls[test_protocol] == winetest_post_urlW)
3200                 CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
3201             else
3202                 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
3203         }
3204         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3205             CLEAR_CALLED(QueryInterface_IHttpNegotiate);
3206             CHECK_CALLED(OnResponse);
3207         }
3208         CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
3209         CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
3210         if(test_protocol == FILE_TEST)
3211             CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
3212         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3213             CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
3214         CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
3215         CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
3216         CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
3217         CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
3218         CHECK_CALLED(OnObjectAvailable);
3219         CHECK_CALLED(Obj_OnStopBinding);
3220     }
3221
3222     ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
3223     if(test_protocol != HTTP_TEST || emulate_protocol || !(bindf & BINDF_ASYNCHRONOUS))
3224         ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
3225     else
3226         IBindCtx_Release(bctx);
3227
3228     if(emulate_protocol)
3229         CoRevokeClassObject(regid);
3230
3231     if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3232         http_is_first = FALSE;
3233 }
3234
3235 static void test_URLDownloadToFile(DWORD prot, BOOL emul)
3236 {
3237     BOOL res;
3238     HRESULT hres;
3239
3240     init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);
3241
3242     SET_EXPECT(GetBindInfo);
3243     SET_EXPECT(QueryInterface_IInternetProtocol);
3244     if(!emulate_protocol) {
3245         SET_EXPECT(QueryInterface_IServiceProvider);
3246         SET_EXPECT(QueryService_IInternetProtocol);
3247     }
3248     SET_EXPECT(OnStartBinding);
3249     if(emulate_protocol) {
3250         if(is_urlmon_protocol(test_protocol))
3251             SET_EXPECT(SetPriority);
3252         SET_EXPECT(Start);
3253         SET_EXPECT(UnlockRequest);
3254     }else {
3255         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3256             SET_EXPECT(QueryInterface_IHttpNegotiate);
3257             SET_EXPECT(BeginningTransaction);
3258             SET_EXPECT(QueryInterface_IHttpNegotiate2);
3259             SET_EXPECT(GetRootSecurityId);
3260             SET_EXPECT(QueryInterface_IWindowForBindingUI);
3261             SET_EXPECT(OnProgress_CONNECTING);
3262         }
3263         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
3264             SET_EXPECT(OnProgress_SENDINGREQUEST);
3265         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3266             SET_EXPECT(QueryInterface_IHttpNegotiate);
3267             SET_EXPECT(OnResponse);
3268         }
3269         SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
3270         SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
3271         if(test_protocol == FILE_TEST)
3272             SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
3273         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3274             SET_EXPECT(OnProgress_DOWNLOADINGDATA);
3275         SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
3276         SET_EXPECT(OnStopBinding);
3277     }
3278
3279     hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol],
3280             dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
3281     ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
3282
3283     CHECK_CALLED(GetBindInfo);
3284     CHECK_CALLED(QueryInterface_IInternetProtocol);
3285     if(!emulate_protocol) {
3286         CHECK_CALLED(QueryInterface_IServiceProvider);
3287         CHECK_CALLED(QueryService_IInternetProtocol);
3288     }
3289     CHECK_CALLED(OnStartBinding);
3290     if(emulate_protocol) {
3291         if(is_urlmon_protocol(test_protocol))
3292             CHECK_CALLED(SetPriority);
3293         CHECK_CALLED(Start);
3294         CHECK_CALLED(UnlockRequest);
3295     }else {
3296         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3297             CHECK_CALLED(QueryInterface_IHttpNegotiate);
3298             CHECK_CALLED(BeginningTransaction);
3299             if (have_IHttpNegotiate2)
3300             {
3301                 CHECK_CALLED(QueryInterface_IHttpNegotiate2);
3302                 CHECK_CALLED(GetRootSecurityId);
3303             }
3304             CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
3305             CLEAR_CALLED(OnProgress_CONNECTING);
3306         }
3307         if(test_protocol == FILE_TEST)
3308             CHECK_CALLED(OnProgress_SENDINGREQUEST);
3309         else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3310             CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
3311         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
3312             CLEAR_CALLED(QueryInterface_IHttpNegotiate);
3313             CHECK_CALLED(OnResponse);
3314         }
3315         CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
3316         CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
3317         if(test_protocol == FILE_TEST)
3318             CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
3319         if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
3320             CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
3321         CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
3322         CHECK_CALLED(OnStopBinding);
3323     }
3324
3325     res = DeleteFileA(dwl_htmlA);
3326     ok(res, "DeleteFile failed: %u\n", GetLastError());
3327
3328     if(prot != FILE_TEST || emul)
3329         return;
3330
3331     hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
3332     ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
3333
3334     res = DeleteFileA(dwl_htmlA);
3335     ok(res, "DeleteFile failed: %u\n", GetLastError());
3336 }
3337
3338 static void test_URLDownloadToFile_abort(void)
3339 {
3340     HRESULT hres;
3341
3342     init_bind_test(HTTP_TEST, BINDTEST_FILEDWLAPI|BINDTEST_ABORT_PROGRESS, TYMED_FILE);
3343
3344     SET_EXPECT(GetBindInfo);
3345     SET_EXPECT(QueryInterface_IInternetProtocol);
3346     SET_EXPECT(QueryInterface_IServiceProvider);
3347     SET_EXPECT(QueryService_IInternetProtocol);
3348     SET_EXPECT(OnStartBinding);
3349     SET_EXPECT(QueryInterface_IHttpNegotiate);
3350     SET_EXPECT(QueryInterface_IHttpNegotiate2);
3351     SET_EXPECT(BeginningTransaction);
3352     SET_EXPECT(GetRootSecurityId);
3353     SET_EXPECT(QueryInterface_IWindowForBindingUI);
3354     SET_EXPECT(OnProgress_CONNECTING);
3355     SET_EXPECT(OnProgress_SENDINGREQUEST);
3356     SET_EXPECT(OnStopBinding);
3357
3358     hres = URLDownloadToFileW(NULL, urls[HTTP_TEST], dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
3359     ok(hres == E_ABORT, "URLDownloadToFile failed: %08x, expected E_ABORT\n", hres);
3360
3361     CHECK_CALLED(GetBindInfo);
3362     CHECK_CALLED(QueryInterface_IInternetProtocol);
3363     CHECK_CALLED(QueryInterface_IServiceProvider);
3364     CHECK_CALLED(QueryService_IInternetProtocol);
3365     CHECK_CALLED(OnStartBinding);
3366     CHECK_CALLED(QueryInterface_IHttpNegotiate);
3367     CHECK_CALLED(QueryInterface_IHttpNegotiate2);
3368     CHECK_CALLED(BeginningTransaction);
3369     CHECK_CALLED(GetRootSecurityId);
3370     CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
3371     CHECK_CALLED(OnProgress_SENDINGREQUEST);
3372     CLEAR_CALLED(OnProgress_CONNECTING);
3373     CHECK_CALLED(OnStopBinding);
3374
3375     init_bind_test(HTTP_TEST, BINDTEST_FILEDWLAPI|BINDTEST_ABORT_START, TYMED_FILE);
3376
3377     SET_EXPECT(GetBindInfo);
3378     SET_EXPECT(QueryInterface_IInternetProtocol);
3379     SET_EXPECT(QueryInterface_IServiceProvider);
3380     SET_EXPECT(QueryService_IInternetProtocol);
3381     SET_EXPECT(OnStartBinding);
3382     SET_EXPECT(OnStopBinding);
3383
3384     abort_hres = E_ABORT;
3385     hres = URLDownloadToFileW(NULL, urls[HTTP_TEST], dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
3386     ok(hres == E_ABORT, "URLDownloadToFile failed: %08x, expected E_ABORT\n", hres);
3387
3388     CHECK_CALLED(GetBindInfo);
3389     todo_wine CHECK_CALLED(QueryInterface_IInternetProtocol);
3390     todo_wine CHECK_CALLED(QueryInterface_IServiceProvider);
3391     todo_wine CHECK_CALLED(QueryService_IInternetProtocol);
3392     CHECK_CALLED(OnStartBinding);
3393     CHECK_CALLED(OnStopBinding);
3394
3395     init_bind_test(HTTP_TEST, BINDTEST_FILEDWLAPI|BINDTEST_ABORT_START, TYMED_FILE);
3396
3397     SET_EXPECT(GetBindInfo);
3398     SET_EXPECT(QueryInterface_IInternetProtocol);
3399     SET_EXPECT(QueryInterface_IServiceProvider);
3400     SET_EXPECT(QueryService_IInternetProtocol);
3401     SET_EXPECT(OnStartBinding);
3402     SET_EXPECT(QueryInterface_IHttpNegotiate);
3403     SET_EXPECT(QueryInterface_IHttpNegotiate2);
3404     SET_EXPECT(BeginningTransaction);
3405     SET_EXPECT(GetRootSecurityId);
3406     SET_EXPECT(QueryInterface_IWindowForBindingUI);
3407     SET_EXPECT(OnResponse);
3408     SET_EXPECT(OnProgress_CONNECTING);
3409     SET_EXPECT(OnProgress_SENDINGREQUEST);
3410     SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
3411     SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
3412     SET_EXPECT(OnProgress_DOWNLOADINGDATA);
3413     SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
3414     SET_EXPECT(OnStopBinding);
3415
3416     /* URLDownloadToFile doesn't abort if E_NOTIMPL is returned from the
3417      * IBindStatusCallback's OnStartBinding function.
3418      */
3419     abort_hres = E_NOTIMPL;
3420     hres = URLDownloadToFileW(NULL, urls[HTTP_TEST], dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
3421     ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);
3422
3423     CHECK_CALLED(GetBindInfo);
3424     CHECK_CALLED(QueryInterface_IInternetProtocol);
3425     CHECK_CALLED(QueryInterface_IServiceProvider);
3426     CHECK_CALLED(QueryService_IInternetProtocol);
3427     CHECK_CALLED(OnStartBinding);
3428     CHECK_CALLED(QueryInterface_IHttpNegotiate);
3429     CHECK_CALLED(QueryInterface_IHttpNegotiate2);
3430     CHECK_CALLED(BeginningTransaction);
3431     CHECK_CALLED(GetRootSecurityId);
3432     CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
3433     CHECK_CALLED(OnResponse);
3434     CLEAR_CALLED(OnProgress_CONNECTING);
3435     CHECK_CALLED(OnProgress_SENDINGREQUEST);
3436     CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
3437     CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
3438     CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
3439     CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
3440     CHECK_CALLED(OnStopBinding);
3441
3442     DeleteFileA(dwl_htmlA);
3443 }
3444
3445 static void set_file_url(char *path)
3446 {
3447     CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
3448     CHAR INDEX_HTMLA[MAX_PATH];
3449
3450     lstrcpyA(file_urlA, "file:///");
3451     lstrcatA(file_urlA, path);
3452     MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
3453
3454     lstrcpyA(INDEX_HTMLA, "file://");
3455     lstrcatA(INDEX_HTMLA, path);
3456     MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
3457 }
3458
3459 static void create_file(void)
3460 {
3461     HANDLE file;
3462     DWORD size;
3463     CHAR path[MAX_PATH];
3464
3465     static const char html_doc[] = "<HTML></HTML>";
3466
3467     file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
3468             FILE_ATTRIBUTE_NORMAL, NULL);
3469     ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
3470     if(file == INVALID_HANDLE_VALUE)
3471         return;
3472
3473     WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
3474     CloseHandle(file);
3475
3476     GetCurrentDirectoryA(MAX_PATH, path);
3477     lstrcatA(path, "\\");
3478     lstrcatA(path, wszIndexHtmlA);
3479     set_file_url(path);
3480 }
3481
3482 static void create_cache_file(void)
3483 {
3484     char buf[6500], curdir[MAX_PATH];
3485     HANDLE file;
3486     DWORD size;
3487
3488     file = CreateFileA(test_txtA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
3489             FILE_ATTRIBUTE_NORMAL, NULL);
3490     ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
3491     if(file == INVALID_HANDLE_VALUE)
3492         return;
3493
3494     memset(buf, 'X', sizeof(buf));
3495     WriteFile(file, buf, sizeof(buf), &size, NULL);
3496     CloseHandle(file);
3497
3498     memset(curdir, 0, sizeof(curdir));
3499     GetCurrentDirectoryA(MAX_PATH, curdir);
3500     lstrcatA(curdir, "\\");
3501     lstrcatA(curdir, test_txtA);
3502
3503     MultiByteToWideChar(CP_ACP, 0, curdir, -1, cache_file_name, MAX_PATH);
3504 }
3505
3506 static void test_ReportResult(HRESULT exhres)
3507 {
3508     IMoniker *mon = NULL;
3509     IBindCtx *bctx = NULL;
3510     IUnknown *unk = (void*)0xdeadbeef;
3511     HRESULT hres;
3512
3513     init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3514     binding_hres = exhres;
3515
3516     hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
3517     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
3518
3519     SET_EXPECT(QueryInterface_IServiceProvider);
3520     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
3521     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
3522     CHECK_CALLED(QueryInterface_IServiceProvider);
3523
3524     SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
3525     SET_EXPECT(GetBindInfo);
3526     SET_EXPECT(QueryInterface_IInternetProtocol);
3527     SET_EXPECT(OnStartBinding);
3528     if(is_urlmon_protocol(test_protocol))
3529         SET_EXPECT(SetPriority);
3530     SET_EXPECT(Start);
3531
3532     hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
3533     if(SUCCEEDED(exhres))
3534         ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
3535     else
3536         ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
3537            "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
3538
3539     CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
3540     CHECK_CALLED(GetBindInfo);
3541     CHECK_CALLED(QueryInterface_IInternetProtocol);
3542     CHECK_CALLED(OnStartBinding);
3543     if(is_urlmon_protocol(test_protocol))
3544         CHECK_CALLED(SetPriority);
3545     CHECK_CALLED(Start);
3546
3547     ok(unk == NULL, "unk=%p\n", unk);
3548
3549     IBindCtx_Release(bctx);
3550     IMoniker_Release(mon);
3551 }
3552
3553 static void test_BindToStorage_fail(void)
3554 {
3555     IMoniker *mon = NULL;
3556     IBindCtx *bctx = NULL;
3557     IUnknown *unk;
3558     HRESULT hres;
3559
3560     hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
3561     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
3562     if(FAILED(hres))
3563         return;
3564
3565     hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
3566     ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
3567
3568     unk = (void*)0xdeadbeef;
3569     hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
3570     ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
3571        "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
3572     ok(unk == NULL, "got %p\n", unk);
3573
3574     IBindCtx_Release(bctx);
3575
3576     IMoniker_Release(mon);
3577
3578     test_ReportResult(E_NOTIMPL);
3579     test_ReportResult(S_FALSE);
3580 }
3581
3582 static void test_StdURLMoniker(void)
3583 {
3584     IMoniker *mon, *async_mon;
3585     LPOLESTR display_name;
3586     IBindCtx *bctx;
3587     IUnknown *unk;
3588     HRESULT hres;
3589
3590     hres = CoCreateInstance(&IID_IInternet, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
3591             &IID_IMoniker, (void**)&mon);
3592     ok(hres == S_OK, "Could not create IInternet instance: %08x\n", hres);
3593     if(FAILED(hres))
3594         return;
3595
3596     hres = IMoniker_QueryInterface(mon, &IID_IAsyncMoniker, (void**)&async_mon);
3597     ok(hres == S_OK, "Could not get IAsyncMoniker iface: %08x\n", hres);
3598     ok(mon == async_mon, "mon != async_mon\n");
3599     IMoniker_Release(async_mon);
3600
3601     hres = IMoniker_GetDisplayName(mon, NULL, NULL, &display_name);
3602     ok(hres == E_OUTOFMEMORY, "GetDisplayName failed: %08x, expected E_OUTOFMEMORY\n", hres);
3603
3604     if(pCreateUri) {
3605       IUriContainer *uri_container;
3606       IUri *uri;
3607
3608       hres = IMoniker_QueryInterface(mon, &IID_IUriContainer, (void**)&uri_container);
3609       ok(hres == S_OK, "Could not get IUriMoniker iface: %08x\n", hres);
3610
3611
3612       uri = (void*)0xdeadbeef;
3613       hres = IUriContainer_GetIUri(uri_container, &uri);
3614       ok(hres == S_FALSE, "GetIUri failed: %08x\n", hres);
3615       ok(!uri, "uri = %p, expected NULL\n", uri);
3616
3617       IUriContainer_Release(uri_container);
3618     }
3619
3620     SET_EXPECT(QueryInterface_IServiceProvider);
3621     hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
3622     ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
3623     CHECK_CALLED(QueryInterface_IServiceProvider);
3624
3625     unk = (void*)0xdeadbeef;
3626     hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
3627     ok(hres == MK_E_SYNTAX, "BindToStorage failed: %08x, expected MK_E_SYNTAX\n", hres);
3628     ok(!unk, "unk = %p\n", unk);
3629
3630     unk = (void*)0xdeadbeef;
3631     hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
3632     ok(hres == MK_E_SYNTAX, "BindToStorage failed: %08x, expected MK_E_SYNTAX\n", hres);
3633     ok(!unk, "unk = %p\n", unk);
3634
3635     IMoniker_Release(mon);
3636 }
3637
3638 static void register_protocols(void)
3639 {
3640     IInternetSession *session;
3641     HRESULT hres;
3642
3643     static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
3644
3645     hres = CoInternetGetSession(0, &session, 0);
3646     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3647     if(FAILED(hres))
3648         return;
3649
3650     hres = IInternetSession_RegisterNameSpace(session, &protocol_cf, &IID_NULL,
3651             winetestW, 0, NULL, 0);
3652     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3653
3654     IInternetSession_Release(session);
3655 }
3656
3657 START_TEST(url)
3658 {
3659     HMODULE hurlmon;
3660
3661     hurlmon = GetModuleHandle("urlmon.dll");
3662     pCreateAsyncBindCtxEx = (void*) GetProcAddress(hurlmon, "CreateAsyncBindCtxEx");
3663
3664     if(!GetProcAddress(hurlmon, "CompareSecurityIds")) {
3665         win_skip("Too old IE\n");
3666         return;
3667     }
3668
3669     pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
3670     if(!pCreateUri)
3671         win_skip("IUri not supported\n");
3672
3673     complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
3674     complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
3675     thread_id = GetCurrentThreadId();
3676     create_file();
3677     create_cache_file();
3678     register_protocols();
3679
3680     test_create();
3681
3682     trace("test CreateAsyncBindCtx...\n");
3683     test_CreateAsyncBindCtx();
3684
3685     trace("test CreateAsyncBindCtxEx...\n");
3686     test_CreateAsyncBindCtxEx();
3687
3688     trace("test RegisterBindStatusCallback...\n");
3689     if(test_RegisterBindStatusCallback()) {
3690         trace("test BindToStorage failures...\n");
3691         test_BindToStorage_fail();
3692
3693         trace("synchronous http test (COM not initialised)...\n");
3694         test_BindToStorage(HTTP_TEST, 0, TYMED_ISTREAM);
3695
3696         CoInitialize(NULL);
3697
3698         trace("test StdURLMoniker...\n");
3699         test_StdURLMoniker();
3700
3701         trace("synchronous http test...\n");
3702         test_BindToStorage(HTTP_TEST, 0, TYMED_ISTREAM);
3703
3704         trace("emulated synchronous http test (to file)...\n");
3705         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE, TYMED_FILE);
3706
3707         trace("synchronous http test (to object)...\n");
3708         test_BindToObject(HTTP_TEST, 0);
3709
3710         trace("emulated synchronous http test (with cache)...\n");
3711         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_USE_CACHE, TYMED_ISTREAM);
3712
3713         trace("emulated synchronous http test (with cache, no read)...\n");
3714         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_USE_CACHE|BINDTEST_NO_CALLBACK_READ, TYMED_ISTREAM);
3715
3716         trace("synchronous http test (with cache, no read)...\n");
3717         test_BindToStorage(HTTP_TEST, BINDTEST_USE_CACHE|BINDTEST_NO_CALLBACK_READ, TYMED_ISTREAM);
3718
3719         trace("synchronous file test...\n");
3720         test_BindToStorage(FILE_TEST, 0, TYMED_ISTREAM);
3721
3722         trace("emulated synchronous file test (to file)...\n");
3723         test_BindToStorage(FILE_TEST, BINDTEST_EMULATE, TYMED_FILE);
3724
3725         trace("synchronous file test (to object)...\n");
3726         test_BindToObject(FILE_TEST, 0);
3727
3728         trace("file test (no callback)...\n");
3729         test_BindToStorage(FILE_TEST, BINDTEST_NO_CALLBACK, TYMED_ISTREAM);
3730
3731         trace("synchronous https test (invalid CN, dialog)\n");
3732         onsecurityproblem_hres = S_FALSE;
3733         http_is_first = TRUE;
3734         test_BindToStorage(HTTPS_TEST, BINDTEST_INVALID_CN, TYMED_ISTREAM);
3735
3736         trace("synchronous https test (invalid CN, fail)\n");
3737         onsecurityproblem_hres = E_FAIL;
3738         test_BindToStorage(HTTPS_TEST, BINDTEST_INVALID_CN, TYMED_ISTREAM);
3739
3740         trace("synchronous https test (invalid CN, accept)\n");
3741         onsecurityproblem_hres = S_OK;
3742         test_BindToStorage(HTTPS_TEST, BINDTEST_INVALID_CN, TYMED_ISTREAM);
3743
3744         trace("asynchronous https test (invalid CN, dialog 2)\n");
3745         onsecurityproblem_hres = S_FALSE;
3746         test_BindToStorage(HTTPS_TEST, BINDTEST_INVALID_CN, TYMED_ISTREAM);
3747         invalid_cn_accepted = FALSE;
3748
3749         bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
3750
3751         trace("about test (no read)...\n");
3752         test_BindToStorage(ABOUT_TEST, BINDTEST_NO_CALLBACK_READ, TYMED_ISTREAM);
3753
3754         trace("http test...\n");
3755         test_BindToStorage(HTTP_TEST, 0, TYMED_ISTREAM);
3756
3757         trace("http test (to file)...\n");
3758         test_BindToStorage(HTTP_TEST, 0, TYMED_FILE);
3759
3760         trace("http test (to object)...\n");
3761         test_BindToObject(HTTP_TEST, 0);
3762
3763         trace("http test (short response)...\n");
3764         test_BindToStorage(HTTP_TEST, BINDTEST_HTTPRESPONSE, TYMED_ISTREAM);
3765
3766         trace("http test (short response, to object)...\n");
3767         test_BindToObject(HTTP_TEST, 0);
3768
3769         trace("http test (abort start binding E_NOTIMPL)...\n");
3770         abort_hres = E_NOTIMPL;
3771         test_BindToStorage(HTTP_TEST, BINDTEST_ABORT_START, TYMED_FILE);
3772
3773         trace("http test (abort start binding E_ABORT)...\n");
3774         abort_hres = E_ABORT;
3775         test_BindToStorage(HTTP_TEST, BINDTEST_ABORT_START, TYMED_FILE);
3776
3777         trace("http test (abort progress)...\n");
3778         test_BindToStorage(HTTP_TEST, BINDTEST_ABORT_PROGRESS, TYMED_FILE);
3779
3780         trace("emulated http test...\n");
3781         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3782
3783         trace("emulated http test (to object)...\n");
3784         test_BindToObject(HTTP_TEST, BINDTEST_EMULATE);
3785
3786         trace("emulated http test (to object, redirect)...\n");
3787         test_BindToObject(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_REDIRECT);
3788
3789         trace("emulated http test (to file)...\n");
3790         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE, TYMED_FILE);
3791
3792         trace("emulated http test (redirect)...\n");
3793         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_REDIRECT, TYMED_ISTREAM);
3794
3795         trace("emulated http test (with cache)...\n");
3796         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_USE_CACHE, TYMED_ISTREAM);
3797
3798         trace("winetest test (no callback)...\n");
3799         test_BindToStorage(WINETEST_TEST, BINDTEST_EMULATE|BINDTEST_NO_CALLBACK|BINDTEST_USE_CACHE, TYMED_ISTREAM);
3800
3801         trace("asynchronous https test...\n");
3802         http_is_first = TRUE;
3803         test_BindToStorage(HTTPS_TEST, 0, TYMED_ISTREAM);
3804
3805         trace("emulated https test...\n");
3806         test_BindToStorage(HTTPS_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3807
3808         trace("about test...\n");
3809         test_BindToStorage(ABOUT_TEST, 0, TYMED_ISTREAM);
3810
3811         trace("about test (to file)...\n");
3812         test_BindToStorage(ABOUT_TEST, 0, TYMED_FILE);
3813
3814         trace("about test (to object)...\n");
3815         test_BindToObject(ABOUT_TEST, 0);
3816
3817         trace("emulated about test...\n");
3818         test_BindToStorage(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3819
3820         trace("emulated about test (to file)...\n");
3821         test_BindToStorage(ABOUT_TEST, BINDTEST_EMULATE, TYMED_FILE);
3822
3823         trace("emulated about test (to object)...\n");
3824         test_BindToObject(ABOUT_TEST, BINDTEST_EMULATE);
3825
3826         trace("file test...\n");
3827         test_BindToStorage(FILE_TEST, 0, TYMED_ISTREAM);
3828
3829         trace("file test (to file)...\n");
3830         test_BindToStorage(FILE_TEST, 0, TYMED_FILE);
3831
3832         trace("file test (to object)...\n");
3833         test_BindToObject(FILE_TEST, 0);
3834
3835         trace("emulated file test...\n");
3836         test_BindToStorage(FILE_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3837
3838         trace("emulated file test (to file)...\n");
3839         test_BindToStorage(FILE_TEST, BINDTEST_EMULATE, TYMED_FILE);
3840
3841         trace("emulated file test (to object)...\n");
3842         test_BindToObject(FILE_TEST, BINDTEST_EMULATE);
3843
3844         trace("emulated its test...\n");
3845         test_BindToStorage(ITS_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3846
3847         trace("emulated its test (to file)...\n");
3848         test_BindToStorage(ITS_TEST, BINDTEST_EMULATE, TYMED_FILE);
3849
3850         trace("emulated mk test...\n");
3851         test_BindToStorage(MK_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3852
3853         trace("test URLDownloadToFile for file protocol...\n");
3854         test_URLDownloadToFile(FILE_TEST, FALSE);
3855
3856         trace("test URLDownloadToFile for emulated file protocol...\n");
3857         test_URLDownloadToFile(FILE_TEST, TRUE);
3858
3859         trace("test URLDownloadToFile for http protocol...\n");
3860         test_URLDownloadToFile(HTTP_TEST, FALSE);
3861
3862         trace("test URLDownloadToFile abort...\n");
3863         test_URLDownloadToFile_abort();
3864
3865         trace("test emulated http abort...\n");
3866         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE|BINDTEST_ABORT, TYMED_ISTREAM);
3867
3868         bindf |= BINDF_NOWRITECACHE;
3869
3870         trace("ftp test...\n");
3871         test_BindToStorage(FTP_TEST, 0, TYMED_ISTREAM);
3872
3873         trace("test failures...\n");
3874         test_BindToStorage_fail();
3875
3876         bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE;
3877         only_check_prot_args = TRUE; /* Fail after checking arguments to Protocol_Start */
3878
3879         trace("check emulated http protocol arguments...\n");
3880         test_BindToStorage(HTTP_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
3881     }
3882
3883     DeleteFileA(wszIndexHtmlA);
3884     DeleteFileA(test_txtA);
3885     CloseHandle(complete_event);
3886     CloseHandle(complete_event2);
3887     CoUninitialize();
3888 }