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