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