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