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