[URLMON_WINETEST] Sync with Wine Staging 4.0. CORE-15682
[reactos.git] / modules / 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 #include <stdarg.h>
23 #include <stdio.h>
24
25 #define COBJMACROS
26 #define NONAMELESSUNION
27 #define CONST_VTABLE
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "initguid.h"
32 #include "urlmon.h"
33 #include "wininet.h"
34 #include "mshtml.h"
35
36 #include "wine/test.h"
37
38 static HRESULT (WINAPI *pCreateAsyncBindCtxEx)(IBindCtx *, DWORD,
39 IBindStatusCallback *, IEnumFORMATETC *, IBindCtx **, DWORD);
40 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
41
42 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
43 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
44 DEFINE_GUID(IID_IBindStatusCallbackHolder,0x79eac9cc,0xbaf9,0x11ce,0x8c,0x82,0x00,0xaa,0x00,0x4b,0xa9,0x0b);
45 static const IID IID_undocumentedIE11 = {0xd5ae15f6,0x2032,0x488e,{0x8f,0x96,0xf9,0x24,0x06,0xd8,0xd8,0xb4}};
46 extern CLSID CLSID_AboutProtocol;
47
48 #define DEFINE_EXPECT(func) \
49 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
50
51 #define SET_EXPECT(func) \
52 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
53
54 #define CHECK_EXPECT2(func) \
55 do { \
56 ok(expect_ ##func, "unexpected call " #func "\n"); \
57 called_ ## func = TRUE; \
58 }while(0)
59
60 #define CHECK_EXPECT(func) \
61 do { \
62 CHECK_EXPECT2(func); \
63 expect_ ## func = FALSE; \
64 }while(0)
65
66 #define CHECK_CALLED(func) \
67 do { \
68 ok(called_ ## func, "expected " #func "\n"); \
69 expect_ ## func = called_ ## func = FALSE; \
70 }while(0)
71
72 #define CHECK_NOT_CALLED(func) \
73 do { \
74 ok(!called_ ## func, "unexpected " #func "\n"); \
75 expect_ ## func = called_ ## func = FALSE; \
76 }while(0)
77
78 #define CHECK_CALLED_BROKEN(func) \
79 do { \
80 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
81 expect_ ## func = called_ ## func = FALSE; \
82 }while(0)
83
84 #define CLEAR_CALLED(func) \
85 expect_ ## func = called_ ## func = FALSE
86
87 DEFINE_EXPECT(QueryInterface_IServiceProvider);
88 DEFINE_EXPECT(QueryInterface_IHttpNegotiate);
89 DEFINE_EXPECT(QueryInterface_IBindStatusCallback);
90 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackEx);
91 DEFINE_EXPECT(QueryInterface_IBindStatusCallbackHolder);
92 DEFINE_EXPECT(QueryInterface_IAuthenticate);
93 DEFINE_EXPECT(QueryInterface_IInternetProtocol);
94 DEFINE_EXPECT(QueryInterface_IWindowForBindingUI);
95 DEFINE_EXPECT(QueryInterface_IHttpSecurity);
96 DEFINE_EXPECT(QueryService_IAuthenticate);
97 DEFINE_EXPECT(QueryService_IInternetProtocol);
98 DEFINE_EXPECT(QueryService_IInternetBindInfo);
99 DEFINE_EXPECT(QueryService_IWindowForBindingUI);
100 DEFINE_EXPECT(QueryService_IHttpSecurity);
101 DEFINE_EXPECT(BeginningTransaction);
102 DEFINE_EXPECT(OnResponse);
103 DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
104 DEFINE_EXPECT(GetRootSecurityId);
105 DEFINE_EXPECT(GetBindInfo);
106 DEFINE_EXPECT(GetBindInfoEx);
107 DEFINE_EXPECT(OnStartBinding);
108 DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
109 DEFINE_EXPECT(OnProgress_CONNECTING);
110 DEFINE_EXPECT(OnProgress_REDIRECTING);
111 DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
112 DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
113 DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
114 DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
115 DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
116 DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
117 DEFINE_EXPECT(OnStopBinding);
118 DEFINE_EXPECT(OnDataAvailable);
119 DEFINE_EXPECT(OnObjectAvailable);
120 DEFINE_EXPECT(Obj_OnStartBinding);
121 DEFINE_EXPECT(Obj_OnStopBinding);
122 DEFINE_EXPECT(Obj_GetBindInfo);
123 DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
124 DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
125 DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
126 DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
127 DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
128 DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
129 DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
130 DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
131 DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
132 DEFINE_EXPECT(Obj_OnProgress_REDIRECTING);
133 DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
134 DEFINE_EXPECT(Start);
135 DEFINE_EXPECT(Read);
136 DEFINE_EXPECT(LockRequest);
137 DEFINE_EXPECT(Terminate);
138 DEFINE_EXPECT(UnlockRequest);
139 DEFINE_EXPECT(Continue);
140 DEFINE_EXPECT(Abort);
141 DEFINE_EXPECT(CreateInstance);
142 DEFINE_EXPECT(Load);
143 DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
144 DEFINE_EXPECT(PutProperty_CLASSIDPROP);
145 DEFINE_EXPECT(SetPriority);
146 DEFINE_EXPECT(GetWindow_IHttpSecurity);
147 DEFINE_EXPECT(GetWindow_IWindowForBindingUI);
148 DEFINE_EXPECT(GetWindow_ICodeInstall);
149 DEFINE_EXPECT(OnSecurityProblem);
150
151 static const WCHAR winetest_data_urlW[] =
152 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
153 't','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
154 static const WCHAR about_blankW[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
155
156 static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
157
158 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
159
160 static const WCHAR wszWineHQSite[] =
161 {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
162 static const WCHAR wszWineHQIP[] =
163 {'4','.','1','5','.','1','8','4','.','7','7',0};
164 static const CHAR wszIndexHtmlA[] = "index.html";
165 static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
166 static const CHAR dwl_htmlA[] = "dwl.html";
167 static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
168 static const CHAR test_txtA[] = "test.txt";
169 static const WCHAR emptyW[] = {0};
170
171 static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
172 data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api, post_test;
173 static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed, security_problem;
174 static const WCHAR *reported_url;
175 static CHAR mime_type[512];
176 static IInternetProtocolSink *protocol_sink = NULL;
177 static IBinding *current_binding;
178 static HANDLE complete_event, complete_event2;
179 static HRESULT binding_hres;
180 static HRESULT onsecurityproblem_hres;
181 static HRESULT abort_hres;
182 static BOOL have_IHttpNegotiate2, use_bscex, is_async_prot;
183 static BOOL test_redirect, use_cache_file, callback_read, no_callback, test_abort;
184 static WCHAR cache_file_name[MAX_PATH];
185 static WCHAR http_cache_file[MAX_PATH];
186 static BOOL only_check_prot_args = FALSE;
187 static BOOL invalid_cn_accepted = FALSE;
188 static BOOL abort_start = FALSE;
189 static BOOL abort_progress = FALSE;
190 static BOOL async_switch = FALSE;
191 static BOOL strict_bsc_qi;
192 static DWORD bindtest_flags;
193 static const char *test_file;
194
195 static WCHAR file_url[INTERNET_MAX_URL_LENGTH], current_url[INTERNET_MAX_URL_LENGTH];
196
197 static enum {
198 HTTP_TEST,
199 ABOUT_TEST,
200 FILE_TEST,
201 ITS_TEST,
202 MK_TEST,
203 HTTPS_TEST,
204 FTP_TEST,
205 WINETEST_TEST,
206 WINETEST_SYNC_TEST
207 } test_protocol;
208
209 static enum {
210 BEFORE_DOWNLOAD,
211 DOWNLOADING,
212 END_DOWNLOAD
213 } download_state;
214
215 static BOOL proxy_active(void)
216 {
217 HKEY internet_settings;
218 DWORD proxy_enable;
219 DWORD size;
220
221 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
222 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
223 return FALSE;
224
225 size = sizeof(DWORD);
226 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
227 proxy_enable = 0;
228
229 RegCloseKey(internet_settings);
230
231 return proxy_enable != 0;
232 }
233
234 static BOOL is_urlmon_protocol(int prot)
235 {
236 return prot == FILE_TEST || prot == HTTP_TEST || prot == HTTPS_TEST || prot == FTP_TEST || prot == MK_TEST;
237 }
238
239 static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
240 {
241 HRESULT hr;
242 IMoniker *mon1 = NULL;
243 IMoniker *mon2 = NULL;
244
245 hr = CreateURLMoniker(NULL, NULL, NULL);
246 ok(hr == E_INVALIDARG,
247 "Expected CreateURLMoniker to return E_INVALIDARG, got 0x%08x\n", hr);
248
249 mon1 = (IMoniker *)0xdeadbeef;
250 hr = CreateURLMoniker(NULL, NULL, &mon1);
251 ok(hr == E_INVALIDARG,
252 "Expected CreateURLMoniker to return E_INVALIDARG, got 0x%08x\n", hr);
253 ok(mon1 == NULL, "Expected the output pointer to be NULL, got %p\n", mon1);
254
255 hr = CreateURLMoniker(NULL, emptyW, NULL);
256 ok(hr == E_INVALIDARG,
257 "Expected CreateURLMoniker to return E_INVALIDARG, got 0x%08x\n", hr);
258
259 hr = CreateURLMoniker(NULL, emptyW, &mon1);
260 ok(hr == S_OK ||
261 broken(hr == MK_E_SYNTAX), /* IE5/IE5.01/IE6 SP2 */
262 "Expected CreateURLMoniker to return S_OK, got 0x%08x\n", hr);
263 if(mon1) IMoniker_Release(mon1);
264
265 hr = CreateURLMoniker(NULL, url1, &mon1);
266 ok(hr == S_OK, "failed to create moniker: 0x%08x\n", hr);
267 if(hr == S_OK) {
268 hr = CreateURLMoniker(mon1, url2, &mon2);
269 ok(hr == S_OK, "failed to create moniker: 0x%08x\n", hr);
270 }
271 if(mon1) IMoniker_Release(mon1);
272 if(mon2) IMoniker_Release(mon2);
273 }
274
275 static void test_create(void)
276 {
277 static const WCHAR relativeW[] = {'a','/','b','.','t','x','t',0};
278 IStream *stream;
279 IMoniker *mon;
280 IBindCtx *bctx;
281 HRESULT hr;
282
283 static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','s','/','d','a','t','a','.','p','h','p',0};
284
285 test_CreateURLMoniker(winetest_data_urlW, TEST_PART_URL_1);
286
287 mon = (void*)0xdeadbeef;
288 hr = CreateURLMoniker(NULL, relativeW, &mon);
289 ok(hr == S_OK, "got 0x%08x\n", hr);
290
291 hr = CreateBindCtx(0, &bctx);
292 ok(hr == S_OK, "got 0x%08x\n", hr);
293
294 stream = (void*)0xdeadbeef;
295 hr = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&stream);
296 todo_wine ok(hr == INET_E_UNKNOWN_PROTOCOL, "got 0x%08x\n", hr);
297 ok(stream == NULL, "got %p\n", stream);
298
299 hr = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, NULL);
300 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
301
302 stream = (void*)0xdeadbeef;
303 hr = IMoniker_BindToStorage(mon, NULL, NULL, &IID_IStream, (void**)&stream);
304 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
305 ok(stream == NULL || broken(stream == (void*)0xdeadbeef) /* starting XP SP3 it's set to null */,
306 "got %p\n", stream);
307
308 IMoniker_Release(mon);
309
310 mon = (void*)0xdaedbeef;
311 hr = CreateURLMoniker(NULL, winetest_data_urlW, &mon);
312 ok(hr == S_OK, "got 0x%08x\n", hr);
313
314 stream = (void*)0xdeadbeef;
315 hr = IMoniker_BindToStorage(mon, NULL, NULL, &IID_IStream, (void**)&stream);
316 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
317 ok(stream == NULL || broken(stream == (void*)0xdeadbeef) /* starting XP SP3 it's set to null */,
318 "got %p\n", stream);
319
320 hr = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, NULL);
321 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
322
323 IMoniker_Release(mon);
324 IBindCtx_Release(bctx);
325 }
326
327 static HRESULT WINAPI Priority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
328 {
329 ok(0, "unexpected call\n");
330 return E_NOINTERFACE;
331 }
332
333 static ULONG WINAPI Priority_AddRef(IInternetPriority *iface)
334 {
335 return 2;
336 }
337
338 static ULONG WINAPI Priority_Release(IInternetPriority *iface)
339 {
340 return 1;
341 }
342
343 static HRESULT WINAPI Priority_SetPriority(IInternetPriority *iface, LONG nPriority)
344 {
345 CHECK_EXPECT(SetPriority);
346 ok(!nPriority, "nPriority = %d\n", nPriority);
347 return S_OK;
348 }
349
350 static HRESULT WINAPI Priority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
351 {
352 ok(0, "unexpected call\n");
353 return S_OK;
354 }
355
356 static const IInternetPriorityVtbl InternetPriorityVtbl = {
357 Priority_QueryInterface,
358 Priority_AddRef,
359 Priority_Release,
360 Priority_SetPriority,
361 Priority_GetPriority
362 };
363
364 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
365
366 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
367 {
368 static const IID IID_undocumentedIE10 = {0x7daf9908,0x8415,0x4005,{0x95,0xae,0xbd,0x27,0xf6,0xe3,0xdc,0x00}};
369
370 *ppv = NULL;
371
372 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
373 *ppv = iface;
374 return S_OK;
375 }
376
377 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
378 if(!is_urlmon_protocol(test_protocol))
379 return E_NOINTERFACE;
380
381 *ppv = &InternetPriority;
382 return S_OK;
383 }
384
385 if(IsEqualGUID(&IID_IInternetProtocolEx, riid))
386 return E_NOINTERFACE; /* TODO */
387
388 if(IsEqualGUID(&IID_undocumentedIE10, riid)) {
389 trace("QI(%s)\n", wine_dbgstr_guid(riid));
390 return E_NOINTERFACE; /* TODO */
391 }
392
393 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
394 return E_NOINTERFACE;
395 }
396
397 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
398 {
399 return 2;
400 }
401
402 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
403 {
404 return 1;
405 }
406
407 static void test_switch_fail(void)
408 {
409 IInternetProtocolSink *binding_sink;
410 PROTOCOLDATA protocoldata = {0};
411 HRESULT hres;
412
413 static BOOL tested_switch_fail;
414
415 if(tested_switch_fail)
416 return;
417
418 tested_switch_fail = TRUE;
419
420 hres = IBinding_QueryInterface(current_binding, &IID_IInternetProtocolSink, (void**)&binding_sink);
421 ok(hres == S_OK, "Could not get IInternetProtocolSink iface: %08x\n", hres);
422 if(SUCCEEDED(hres)) {
423 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
424 ok(hres == E_FAIL, "Switch failed: %08x, expected E_FAIL\n", hres);
425 IInternetProtocolSink_Release(binding_sink);
426 }
427 }
428
429 static DWORD WINAPI thread_proc(PVOID arg)
430 {
431 PROTOCOLDATA protocoldata = {0};
432 HRESULT hres;
433
434 if(!no_callback) {
435 if(bind_to_object)
436 SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
437 else
438 SET_EXPECT(OnProgress_FINDINGRESOURCE);
439 }
440 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
441 BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
442 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
443 if(!no_callback) {
444 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
445 if(bind_to_object)
446 CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
447 else
448 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
449 }
450
451 if(!no_callback) {
452 if(bind_to_object)
453 SET_EXPECT(Obj_OnProgress_CONNECTING);
454 else
455 SET_EXPECT(OnProgress_CONNECTING);
456 }
457 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
458 BINDSTATUS_CONNECTING, wszWineHQIP);
459 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
460 if(!no_callback) {
461 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
462 if(bind_to_object)
463 CHECK_CALLED(Obj_OnProgress_CONNECTING);
464 else
465 CHECK_CALLED(OnProgress_CONNECTING);
466 }
467
468 if(!no_callback) {
469 if(bind_to_object)
470 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
471 else
472 SET_EXPECT(OnProgress_SENDINGREQUEST);
473 }
474 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
475 BINDSTATUS_SENDINGREQUEST, NULL);
476 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
477 if(!no_callback) {
478 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
479 if(bind_to_object)
480 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
481 else
482 CHECK_CALLED(OnProgress_SENDINGREQUEST);
483 }
484
485 if(test_redirect) {
486 if(bind_to_object)
487 SET_EXPECT(Obj_OnProgress_REDIRECTING);
488 else
489 SET_EXPECT(OnProgress_REDIRECTING);
490 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_REDIRECTING, winetest_data_urlW);
491 ok(hres == S_OK, "ReportProgress(BINDSTATUS_REFIRECTING) failed: %08x\n", hres);
492 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
493 if(bind_to_object)
494 CHECK_CALLED(Obj_OnProgress_REDIRECTING);
495 else
496 CHECK_CALLED(OnProgress_REDIRECTING);
497 }
498
499 test_switch_fail();
500
501 SET_EXPECT(Continue);
502 prot_state = 1;
503 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
504 ok(hres == S_OK, "Switch failed: %08x\n", hres);
505 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
506
507 CHECK_CALLED(Continue);
508 CHECK_CALLED(Read);
509 if(bind_to_object) {
510 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
511 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
512 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
513 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
514 CHECK_CALLED(CreateInstance);
515 CHECK_CALLED(PutProperty_MIMETYPEPROP);
516 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
517 CHECK_CALLED(Load);
518 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
519 CHECK_CALLED(OnObjectAvailable);
520 CHECK_CALLED(Obj_OnStopBinding);
521 }else if(!no_callback) {
522 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
523 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
524 CHECK_CALLED(OnDataAvailable);
525 }else {
526 CHECK_CALLED(LockRequest);
527 }
528
529 SET_EXPECT(Continue);
530 prot_state = 2;
531 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
532 ok(hres == S_OK, "Switch failed: %08x\n", hres);
533 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
534 CHECK_CALLED(Continue);
535 if(test_abort) {
536 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
537 CHECK_CALLED(OnStopBinding);
538 SetEvent(complete_event2);
539 return 0;
540 }else {
541 CHECK_CALLED(Read);
542 if(!no_callback) {
543 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
544 CHECK_CALLED(OnDataAvailable);
545 }
546 }
547
548 SET_EXPECT(Continue);
549 prot_state = 2;
550 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
551 ok(hres == S_OK, "Switch failed: %08x\n", hres);
552 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
553 CHECK_CALLED(Continue);
554 CHECK_CALLED(Read);
555 if(!no_callback) {
556 CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
557 CHECK_CALLED(OnDataAvailable);
558 }
559
560 SET_EXPECT(Continue);
561 prot_state = 3;
562 hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
563 ok(hres == S_OK, "Switch failed: %08x\n", hres);
564 ok( WaitForSingleObject(complete_event, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
565 CHECK_CALLED(Continue);
566 CHECK_CALLED(Read);
567 if(!no_callback) {
568 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
569 CHECK_CALLED(OnDataAvailable);
570 CHECK_CALLED(OnStopBinding);
571 }
572
573 SET_EXPECT(Read);
574
575 SetEvent(complete_event2);
576 return 0;
577 }
578
579 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
580 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
581 DWORD grfPI, HANDLE_PTR dwReserved)
582 {
583 BINDINFO bindinfo;
584 DWORD bind_info, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
585 HRESULT hres;
586
587 static const STGMEDIUM stgmed_zero = {0};
588 static const SECURITY_ATTRIBUTES sa_zero = {0};
589
590 CHECK_EXPECT(Start);
591
592 read = 0;
593
594 reported_url = szUrl;
595 if(!filedwl_api) /* FIXME */
596 ok(szUrl && !lstrcmpW(szUrl, current_url), "wrong url %s\n", wine_dbgstr_w(szUrl));
597 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
598 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
599 ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
600 ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
601
602 if(!filedwl_api && binding_hres != S_OK) {
603 SET_EXPECT(OnStopBinding);
604 SET_EXPECT(Terminate);
605 hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
606 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
607 CHECK_CALLED(OnStopBinding);
608 CHECK_CALLED(Terminate);
609
610 return S_OK;
611 }
612
613 memset(&bindinfo, 0, sizeof(bindinfo));
614 bindinfo.cbSize = 0;
615 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bind_info, &bindinfo);
616 ok(hres == E_INVALIDARG, "GetBindInfo returned: %08x, expected E_INVALIDARG\n", hres);
617
618 memset(&bindinfo, 0, sizeof(bindinfo));
619 bindinfo.cbSize = sizeof(bindinfo);
620 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bind_info, &bindinfo);
621 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
622
623 ok(bind_info & BINDF_FROMURLMON, "BINDF_FROMURLMON is not set\n");
624
625 if(filedwl_api || !is_urlmon_protocol(test_protocol) || tymed != TYMED_ISTREAM ||
626 !(bindf&BINDF_ASYNCSTORAGE) || !(bindf&BINDF_PULLDATA))
627 ok(bind_info & BINDF_NEEDFILE, "BINDF_NEEDFILE is not set\n");
628 else if(test_protocol != MK_TEST) /* IE10 sets BINDF_NEEDFILE for mk: protocol */
629 ok(!(bind_info & BINDF_NEEDFILE), "BINDF_NEEDFILE is set\n");
630
631 bind_info &= ~(BINDF_NEEDFILE|BINDF_FROMURLMON);
632 if(filedwl_api || no_callback)
633 ok(bind_info == BINDF_PULLDATA, "bind_info = %x, expected BINDF_PULLDATA\n", bind_info);
634 else
635 ok(bind_info == (bindf & ~(BINDF_NEEDFILE|BINDF_FROMURLMON)), "bind_info = %x, expected %x\n",
636 bind_info, (bindf & ~(BINDF_NEEDFILE|BINDF_FROMURLMON)));
637
638 ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
639 ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
640 ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
641 ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
642 ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
643 ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
644 ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
645 ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
646 ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
647 ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
648 ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
649 ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
650 ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
651 ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
652
653 if(only_check_prot_args)
654 return E_FAIL;
655
656 switch(test_protocol) {
657 case MK_TEST:
658 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
659 BINDSTATUS_DIRECTBIND, NULL);
660 ok(hres == S_OK,
661 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
662
663 case FILE_TEST:
664 case ITS_TEST:
665 if(bind_to_object)
666 SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
667 else
668 SET_EXPECT(OnProgress_SENDINGREQUEST);
669 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
670 BINDSTATUS_SENDINGREQUEST, emptyW);
671 ok(hres == S_OK,
672 "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
673 if(bind_to_object)
674 CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
675 else
676 CHECK_CALLED(OnProgress_SENDINGREQUEST);
677 case WINETEST_SYNC_TEST:
678 IInternetProtocolSink_AddRef(pOIProtSink);
679 protocol_sink = pOIProtSink;
680 default:
681 break;
682 }
683
684 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
685 IServiceProvider *service_provider;
686 IHttpNegotiate *http_negotiate;
687 IHttpNegotiate2 *http_negotiate2;
688 IHttpSecurity *http_security;
689 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
690 LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
691 BYTE sec_id[100];
692 DWORD fetched = 256, size = 100;
693 DWORD tid;
694
695 static const WCHAR wszMimes[] = {'*','/','*',0};
696
697 SET_EXPECT(QueryService_IInternetBindInfo);
698 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
699 &ua, 1, &fetched);
700 CLEAR_CALLED(QueryService_IInternetBindInfo); /* IE <8 */
701
702 ok(hres == E_NOINTERFACE,
703 "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
704 ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
705 ok(ua == (LPWSTR)0xdeadbeef, "ua = %p\n", ua);
706
707 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
708 accept_mimes, 256, &fetched);
709 ok(hres == S_OK,
710 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
711 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
712 ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");
713 CoTaskMemFree(accept_mimes[0]);
714
715 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
716 NULL, 256, &fetched);
717 ok(hres == E_INVALIDARG,
718 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
719
720 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
721 accept_mimes, 256, NULL);
722 ok(hres == E_INVALIDARG,
723 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
724
725 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
726 (void**)&service_provider);
727 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
728
729 SET_EXPECT(QueryInterface_IHttpNegotiate);
730 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
731 &IID_IHttpNegotiate, (void**)&http_negotiate);
732 CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
733 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
734
735 if(!no_callback) {
736 SET_EXPECT(BeginningTransaction);
737 SET_EXPECT(QueryInterface_IHttpNegotiate);
738 }
739 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, current_url,
740 NULL, 0, &additional_headers);
741 if(!no_callback) {
742 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
743 CHECK_CALLED(BeginningTransaction);
744 }
745 IHttpNegotiate_Release(http_negotiate);
746 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
747 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
748
749 SET_EXPECT(QueryInterface_IHttpNegotiate2);
750 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
751 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
752 CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
753 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
754
755 size = 512;
756 if(!no_callback) {
757 SET_EXPECT(QueryInterface_IHttpNegotiate2);
758 SET_EXPECT(GetRootSecurityId);
759 }
760 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
761 if(!no_callback) {
762 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2);
763 CHECK_CALLED(GetRootSecurityId);
764 }
765 IHttpNegotiate2_Release(http_negotiate2);
766 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
767 ok(size == (no_callback ? 512 : 13), "size=%d\n", size);
768
769 if(!no_callback) {
770 SET_EXPECT(QueryService_IHttpSecurity);
771 SET_EXPECT(QueryInterface_IHttpSecurity);
772 }
773 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpSecurity,
774 &IID_IHttpSecurity, (void**)&http_security);
775 ok(hres == (no_callback ? E_NOINTERFACE : S_OK), "QueryService failed: 0x%08x\n", hres);
776 if(!no_callback) {
777 CHECK_CALLED(QueryService_IHttpSecurity);
778 CHECK_CALLED(QueryInterface_IHttpSecurity);
779 }
780
781 IServiceProvider_Release(service_provider);
782
783 IInternetProtocolSink_AddRef(pOIProtSink);
784 protocol_sink = pOIProtSink;
785
786 if(async_switch) {
787 PROTOCOLDATA data;
788
789 memset(&data, 0, sizeof(data));
790 data.grfFlags = PI_FORCE_ASYNC;
791 prot_state = 0;
792 hres = IInternetProtocolSink_Switch(pOIProtSink, &data);
793 ok(hres == S_OK, "Switch failed: %08x\n", hres);
794 SET_EXPECT(Continue);
795 SetEvent(complete_event2);
796 return E_PENDING;
797 } else {
798 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
799 return S_OK;
800 }
801 }
802
803 if(test_protocol == FILE_TEST) {
804 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
805 BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+7);
806 ok(hres == S_OK,
807 "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
808
809 if(bind_to_object)
810 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
811 else
812 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
813 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
814 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
815 ok(hres == S_OK,
816 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
817 if(bind_to_object)
818 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
819 else
820 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
821 }else if(test_protocol == WINETEST_SYNC_TEST) {
822 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
823 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
824 ok(hres == S_OK,
825 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
826 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
827 }else {
828 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
829 ok(hres == S_OK,
830 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
831 }
832
833 if(test_protocol == ABOUT_TEST)
834 bscf |= BSCF_DATAFULLYAVAILABLE;
835 if(test_protocol == ITS_TEST)
836 bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
837
838 SET_EXPECT(Read);
839 if(bind_to_object) {
840 if(test_protocol != FILE_TEST && test_protocol != MK_TEST && test_protocol != WINETEST_SYNC_TEST)
841 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
842 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
843 if(test_protocol == FILE_TEST)
844 SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
845 SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
846 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
847 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
848 SET_EXPECT(CreateInstance);
849 SET_EXPECT(PutProperty_MIMETYPEPROP);
850 SET_EXPECT(PutProperty_CLASSIDPROP);
851 SET_EXPECT(Load);
852 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
853 SET_EXPECT(OnObjectAvailable);
854 SET_EXPECT(Obj_OnStopBinding);
855 }else {
856 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
857 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
858 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
859 if(test_protocol == FILE_TEST)
860 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
861 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
862 SET_EXPECT(LockRequest);
863 if(!filedwl_api)
864 SET_EXPECT(OnDataAvailable);
865 if(test_protocol != WINETEST_SYNC_TEST) /* Set in Read after ReportResult call */
866 SET_EXPECT(OnStopBinding);
867 }
868
869 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
870 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
871
872 CHECK_CALLED(Read);
873 if(bind_to_object) {
874 if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
875 CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
876 CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
877 if(test_protocol == FILE_TEST)
878 CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
879 CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
880 CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
881 CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
882 CHECK_CALLED(CreateInstance);
883 CHECK_CALLED(PutProperty_MIMETYPEPROP);
884 CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
885 CHECK_CALLED(Load);
886 CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
887 CHECK_CALLED(OnObjectAvailable);
888 CHECK_CALLED(Obj_OnStopBinding);
889 }else {
890 if(test_protocol != FILE_TEST && test_protocol != MK_TEST && test_protocol != WINETEST_SYNC_TEST)
891 CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
892 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
893 if(test_protocol == FILE_TEST)
894 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
895 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
896 CHECK_CALLED(LockRequest);
897 if(!filedwl_api)
898 CHECK_CALLED(OnDataAvailable);
899 CHECK_CALLED(OnStopBinding);
900 }
901
902 if(test_protocol == ITS_TEST) {
903 SET_EXPECT(Read);
904 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
905 ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
906 CHECK_CALLED(Read);
907 }else if(!bind_to_object && test_protocol == FILE_TEST) {
908 SET_EXPECT(Read);
909 hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
910 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
911 CHECK_CALLED(Read);
912 }
913
914 if(test_protocol != WINETEST_SYNC_TEST) {
915 SET_EXPECT(Terminate);
916 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
917 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
918 CHECK_CALLED(Terminate);
919 }
920
921 return S_OK;
922 }
923
924 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
925 PROTOCOLDATA *pProtocolData)
926 {
927 DWORD bscf = 0;
928 HRESULT hres;
929
930 CHECK_EXPECT(Continue);
931
932 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
933
934 if(!bind_to_object)
935 ok(reported_url && !lstrcmpW(reported_url, current_url), "wrong url %s\n", wine_dbgstr_w(reported_url));
936
937 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
938 if(!pProtocolData)
939 return S_OK;
940
941 switch(prot_state) {
942 case 0:
943 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
944 BINDSTATUS_SENDINGREQUEST, NULL);
945 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
946
947 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
948 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
949 ok(hres == S_OK,
950 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
951
952 bscf |= BSCF_FIRSTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION;
953 break;
954 case 1: {
955 IServiceProvider *service_provider;
956 IHttpNegotiate *http_negotiate;
957 static const WCHAR header[] = {'?',0};
958
959 hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
960 (void**)&service_provider);
961 ok(hres == S_OK, "Could not get IServiceProvicder\n");
962
963 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
964 &IID_IHttpNegotiate, (void**)&http_negotiate);
965 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
966
967 if(!no_callback) {
968 SET_EXPECT(QueryInterface_IHttpNegotiate);
969 SET_EXPECT(OnResponse);
970 }
971 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
972 if(!no_callback) {
973 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
974 CHECK_CALLED(OnResponse);
975 }
976 IHttpNegotiate_Release(http_negotiate);
977 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
978
979 if(test_protocol == HTTPS_TEST || test_redirect) {
980 hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
981 ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
982 }
983
984 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
985 BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
986 ok(hres == S_OK,
987 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
988
989 hres = IInternetProtocolSink_ReportProgress(protocol_sink,
990 BINDSTATUS_CACHEFILENAMEAVAILABLE, use_cache_file ? cache_file_name : cache_fileW);
991 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
992
993 bscf |= BSCF_FIRSTDATANOTIFICATION;
994 break;
995 }
996 case 2:
997 case 3:
998 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
999 break;
1000 }
1001
1002 hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
1003 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1004
1005 if(prot_state != 2 || !test_abort)
1006 SET_EXPECT(Read);
1007 switch(prot_state) {
1008 case 0:
1009 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
1010 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1011 SET_EXPECT(OnProgress_SENDINGREQUEST);
1012 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1013 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1014 SET_EXPECT(LockRequest);
1015 SET_EXPECT(OnStopBinding);
1016 break;
1017 case 1:
1018 if(bind_to_object) {
1019 SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1020 SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1021 SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1022 SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1023 SET_EXPECT(CreateInstance);
1024 SET_EXPECT(PutProperty_MIMETYPEPROP);
1025 SET_EXPECT(PutProperty_CLASSIDPROP);
1026 SET_EXPECT(Load);
1027 SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1028 SET_EXPECT(OnObjectAvailable);
1029 SET_EXPECT(Obj_OnStopBinding);
1030 }else if(!no_callback) {
1031 SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1032 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1033 SET_EXPECT(LockRequest);
1034 }else {
1035 SET_EXPECT(LockRequest);
1036 }
1037 break;
1038 case 2:
1039 if(!no_callback)
1040 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
1041 break;
1042 case 3:
1043 SET_EXPECT(OnProgress_DOWNLOADINGDATA);
1044 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
1045 }
1046 if(!no_callback) {
1047 if((!bind_to_object || prot_state >= 2) && (!test_abort || prot_state != 2))
1048 SET_EXPECT(OnDataAvailable);
1049 if(prot_state == 3 || (test_abort && prot_state == 2))
1050 SET_EXPECT(OnStopBinding);
1051 }
1052 return S_OK;
1053 }
1054
1055 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1056 DWORD dwOptions)
1057 {
1058 HRESULT hres;
1059
1060 CHECK_EXPECT(Abort);
1061
1062 ok(hrReason == E_ABORT, "hrReason = %08x\n", hrReason);
1063 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1064
1065 hres = IInternetProtocolSink_ReportResult(protocol_sink, E_ABORT, ERROR_SUCCESS, NULL);
1066 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1067
1068 return S_OK;
1069 }
1070
1071 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1072 {
1073 CHECK_EXPECT(Terminate);
1074
1075 ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
1076
1077 if(protocol_sink) {
1078 IInternetProtocolSink_Release(protocol_sink);
1079 protocol_sink = NULL;
1080 }
1081
1082 if(no_callback)
1083 SetEvent(complete_event);
1084 return S_OK;
1085 }
1086
1087 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1088 {
1089 ok(0, "unexpected call\n");
1090 return E_NOTIMPL;
1091 }
1092
1093 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1094 {
1095 ok(0, "unexpected call\n");
1096 return E_NOTIMPL;
1097 }
1098
1099 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
1100 ULONG cb, ULONG *pcbRead)
1101 {
1102 HRESULT hres;
1103
1104 static const char data[] = "<HTML></HTML>";
1105
1106 CHECK_EXPECT2(Read);
1107
1108 ok(pv != NULL, "pv == NULL\n");
1109 ok(cb != 0, "cb == 0\n");
1110 ok(pcbRead != NULL, "pcbRead == NULL\n");
1111
1112 if(async_switch) {
1113 if(prot_state++ > 1) {
1114 *pcbRead = 0;
1115 return S_FALSE;
1116 } else {
1117 memset(pv, '?', cb);
1118 *pcbRead = cb;
1119 return S_OK;
1120 }
1121 }
1122
1123 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) {
1124 static BOOL pending = TRUE;
1125
1126 pending = !pending;
1127
1128 switch(prot_state) {
1129 case 1:
1130 case 2:
1131 if(pending) {
1132 *pcbRead = 10;
1133 memset(pv, '?', 10);
1134 if(prot_state == 2 && no_callback)
1135 SetEvent(complete_event);
1136 return E_PENDING;
1137 }else {
1138 memset(pv, '?', cb);
1139 *pcbRead = cb;
1140 read++;
1141 return S_OK;
1142 }
1143 case 3:
1144 prot_state++;
1145
1146 *pcbRead = 0;
1147
1148 hres = IInternetProtocolSink_ReportData(protocol_sink,
1149 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
1150 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1151
1152 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
1153 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1154
1155 return S_FALSE;
1156 case 4:
1157 *pcbRead = 0;
1158 return S_FALSE;
1159 }
1160 }
1161
1162 if(read) {
1163 *pcbRead = 0;
1164 return S_FALSE;
1165 }
1166
1167 if(test_protocol == WINETEST_SYNC_TEST) {
1168 hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
1169 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1170
1171 SET_EXPECT(OnStopBinding);
1172 }
1173
1174 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1175 read += *pcbRead = sizeof(data)-1;
1176 memcpy(pv, data, sizeof(data));
1177 return S_OK;
1178 }
1179
1180 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1181 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1182 {
1183 ok(0, "unexpected call\n");
1184 return E_NOTIMPL;
1185 }
1186
1187 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1188 {
1189 CHECK_EXPECT(LockRequest);
1190 if(no_callback)
1191 SetEvent(complete_event);
1192 return S_OK;
1193 }
1194
1195 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
1196 {
1197 CHECK_EXPECT(UnlockRequest);
1198 return S_OK;
1199 }
1200
1201 static const IInternetProtocolVtbl ProtocolVtbl = {
1202 Protocol_QueryInterface,
1203 Protocol_AddRef,
1204 Protocol_Release,
1205 Protocol_Start,
1206 Protocol_Continue,
1207 Protocol_Abort,
1208 Protocol_Terminate,
1209 Protocol_Suspend,
1210 Protocol_Resume,
1211 Protocol_Read,
1212 Protocol_Seek,
1213 Protocol_LockRequest,
1214 Protocol_UnlockRequest
1215 };
1216
1217 static IInternetProtocol Protocol = { &ProtocolVtbl };
1218
1219 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
1220 {
1221 if(IsEqualGUID(&IID_IUnknown, riid)
1222 || IsEqualGUID(&IID_IHttpNegotiate, riid)
1223 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
1224 *ppv = iface;
1225 return S_OK;
1226 }
1227
1228 ok(0, "unexpected call\n");
1229 return E_NOINTERFACE;
1230 }
1231
1232 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
1233 {
1234 return 2;
1235 }
1236
1237 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
1238 {
1239 return 1;
1240 }
1241
1242 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
1243 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
1244 {
1245 if(onsecurityproblem_hres == S_OK)
1246 CHECK_EXPECT2(BeginningTransaction);
1247 else
1248 CHECK_EXPECT(BeginningTransaction);
1249
1250 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1251
1252 ok(!lstrcmpW(szURL, current_url), "szURL != current_url\n");
1253 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
1254 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1255 if(pszAdditionalHeaders)
1256 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1257
1258 return S_OK;
1259 }
1260
1261 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
1262 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
1263 {
1264 CHECK_EXPECT(OnResponse);
1265
1266 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1267
1268 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
1269 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
1270 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
1271 /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
1272 ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
1273 if(pszAdditionalRequestHeaders)
1274 ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
1275
1276 return S_OK;
1277 }
1278
1279 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
1280 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
1281 {
1282 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
1283
1284 CHECK_EXPECT(GetRootSecurityId);
1285
1286 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1287
1288 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
1289 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
1290 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
1291
1292 if(pbSecurityId == (void*)0xdeadbeef)
1293 return E_NOTIMPL;
1294
1295 if(pcbSecurityId) {
1296 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
1297 *pcbSecurityId = sizeof(sec_id);
1298 }
1299
1300 if(pbSecurityId)
1301 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
1302
1303 return E_FAIL;
1304 }
1305
1306 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
1307 HttpNegotiate_QueryInterface,
1308 HttpNegotiate_AddRef,
1309 HttpNegotiate_Release,
1310 HttpNegotiate_BeginningTransaction,
1311 HttpNegotiate_OnResponse,
1312 HttpNegotiate_GetRootSecurityId
1313 };
1314
1315 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };
1316
1317 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
1318 {
1319 ok(0, "Unexpected call\n");
1320 *ppv = NULL;
1321 if(IsEqualGUID(&IID_IHttpSecurity, riid) ||
1322 IsEqualGUID(&IID_IWindowForBindingUI, riid) ||
1323 IsEqualGUID(&IID_IUnknown, riid))
1324 {
1325 *ppv = iface;
1326 return S_OK;
1327 }
1328
1329 ok(0, "Unexpected interface requested.\n");
1330
1331 return E_NOINTERFACE;
1332 }
1333
1334 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
1335 {
1336 return 2;
1337 }
1338
1339 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
1340 {
1341 return 1;
1342 }
1343
1344 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity *iface, REFGUID rguidReason, HWND *phwnd)
1345 {
1346 if(IsEqualGUID(rguidReason, &IID_IHttpSecurity))
1347 CHECK_EXPECT(GetWindow_IHttpSecurity);
1348 else if(IsEqualGUID(rguidReason, &IID_IWindowForBindingUI))
1349 CHECK_EXPECT2(GetWindow_IWindowForBindingUI);
1350 else if(IsEqualGUID(rguidReason, &IID_ICodeInstall))
1351 CHECK_EXPECT(GetWindow_ICodeInstall);
1352 else
1353 ok(0, "Unexpected rguidReason: %s\n", wine_dbgstr_guid(rguidReason));
1354
1355 *phwnd = NULL;
1356 return S_OK;
1357 }
1358
1359 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
1360 {
1361 CHECK_EXPECT(OnSecurityProblem);
1362 if(!security_problem) {
1363 ok(dwProblem == ERROR_INTERNET_SEC_CERT_CN_INVALID ||
1364 broken(dwProblem == ERROR_INTERNET_SEC_CERT_ERRORS) /* Some versions of IE6 */,
1365 "Got problem: %d\n", dwProblem);
1366 security_problem = dwProblem;
1367
1368 if(dwProblem == ERROR_INTERNET_SEC_CERT_ERRORS)
1369 binding_hres = INET_E_SECURITY_PROBLEM;
1370 }else
1371 ok(dwProblem == security_problem, "Got problem: %d\n", dwProblem);
1372
1373 return onsecurityproblem_hres;
1374 }
1375
1376 static const IHttpSecurityVtbl HttpSecurityVtbl = {
1377 HttpSecurity_QueryInterface,
1378 HttpSecurity_AddRef,
1379 HttpSecurity_Release,
1380 HttpSecurity_GetWindow,
1381 HttpSecurity_OnSecurityProblem
1382 };
1383
1384 static IHttpSecurity HttpSecurity = { &HttpSecurityVtbl };
1385
1386 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1387 {
1388 ok(0, "unexpected call\n");
1389 return E_NOINTERFACE;
1390 }
1391
1392 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1393 {
1394 return 2;
1395 }
1396
1397 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1398 {
1399 return 1;
1400 }
1401
1402 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1403 REFGUID guidService, REFIID riid, void **ppv)
1404 {
1405 if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
1406 CHECK_EXPECT(QueryService_IAuthenticate);
1407 return E_NOTIMPL;
1408 }
1409
1410 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
1411 CHECK_EXPECT2(QueryService_IInternetProtocol);
1412 return E_NOTIMPL;
1413 }
1414
1415 if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
1416 CHECK_EXPECT(QueryService_IInternetBindInfo);
1417 return E_NOTIMPL;
1418 }
1419
1420 if(IsEqualGUID(&IID_IWindowForBindingUI, guidService)) {
1421 CHECK_EXPECT2(QueryService_IWindowForBindingUI);
1422 *ppv = &HttpSecurity;
1423 return S_OK;
1424 }
1425
1426 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
1427 CHECK_EXPECT(QueryService_IHttpSecurity);
1428 *ppv = &HttpSecurity;
1429 return S_OK;
1430 }
1431
1432 if(IsEqualGUID(&IID_IGetBindHandle, guidService)) {
1433 trace("QueryService(IID_IGetBindHandle)\n");
1434 *ppv = NULL;
1435 return E_NOINTERFACE;
1436 }
1437
1438 if(IsEqualGUID(&IID_undocumentedIE11, guidService)) {
1439 trace("QueryService(IID_undocumentedIE11)\n");
1440 *ppv = NULL;
1441 return E_NOINTERFACE;
1442 }
1443
1444 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
1445 return E_NOINTERFACE;
1446 }
1447
1448 static IServiceProviderVtbl ServiceProviderVtbl = {
1449 ServiceProvider_QueryInterface,
1450 ServiceProvider_AddRef,
1451 ServiceProvider_Release,
1452 ServiceProvider_QueryService
1453 };
1454
1455 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1456
1457 static IBindStatusCallbackEx objbsc;
1458
1459 static void test_WinInetHttpInfo(IWinInetHttpInfo *http_info, DWORD progress)
1460 {
1461 DWORD status, size;
1462 HRESULT hres, expect;
1463
1464 /* QueryInfo changes its behavior during this request */
1465 if(progress == BINDSTATUS_SENDINGREQUEST)
1466 return;
1467
1468 if(test_protocol==FTP_TEST && download_state==BEFORE_DOWNLOAD
1469 && progress!=BINDSTATUS_MIMETYPEAVAILABLE)
1470 expect = E_FAIL;
1471 else if(test_protocol == FTP_TEST)
1472 expect = S_FALSE;
1473 else
1474 expect = S_OK;
1475
1476 size = sizeof(DWORD);
1477 hres = IWinInetHttpInfo_QueryInfo(http_info, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
1478 &status, &size, NULL, NULL);
1479 ok(hres == expect || ((progress == BINDSTATUS_COOKIE_SENT || progress == BINDSTATUS_PROXYDETECTING) && hres == S_FALSE),
1480 "progress %u: hres = %x, expected %x\n", progress, hres, expect);
1481 if(hres == S_OK) {
1482 if(download_state == BEFORE_DOWNLOAD && progress != BINDSTATUS_MIMETYPEAVAILABLE && progress != BINDSTATUS_DECODING)
1483 ok(status == 0, "progress %u: status = %d\n", progress, status);
1484 else
1485 ok(status == HTTP_STATUS_OK, "progress %u: status = %d\n", progress, status);
1486 ok(size == sizeof(DWORD), "size = %d\n", size);
1487 }
1488
1489 size = sizeof(DWORD);
1490 hres = IWinInetHttpInfo_QueryOption(http_info, INTERNET_OPTION_HANDLE_TYPE, &status, &size);
1491 if(test_protocol == FTP_TEST) {
1492 if(download_state==BEFORE_DOWNLOAD && progress!=BINDSTATUS_MIMETYPEAVAILABLE)
1493 ok(hres == E_FAIL, "hres = %x\n", hres);
1494 else
1495 ok(hres == S_OK, "hres = %x\n", hres);
1496
1497 if(hres == S_OK)
1498 ok(status == INTERNET_HANDLE_TYPE_FTP_FILE, "status = %d\n", status);
1499 } else {
1500 ok(hres == S_OK, "hres = %x\n", hres);
1501 ok(status == INTERNET_HANDLE_TYPE_HTTP_REQUEST, "status = %d\n", status);
1502 }
1503 }
1504
1505 static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1506 {
1507 static const IID IID_undocumentedIE10 = {0xf286fa56,0xc1fd,0x4270,{0x8e,0x67,0xb3,0xeb,0x79,0x0a,0x81,0xe8}};
1508
1509 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1510
1511 if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1512 CHECK_EXPECT2(QueryInterface_IInternetProtocol);
1513 if(emulate_protocol) {
1514 *ppv = &Protocol;
1515 return S_OK;
1516 }else {
1517 return E_NOINTERFACE;
1518 }
1519 }else if (IsEqualGUID(&IID_IServiceProvider, riid)) {
1520 CHECK_EXPECT2(QueryInterface_IServiceProvider);
1521 *ppv = &ServiceProvider;
1522 return S_OK;
1523 }else if (IsEqualGUID(&IID_IHttpNegotiate, riid)) {
1524 CHECK_EXPECT2(QueryInterface_IHttpNegotiate);
1525 *ppv = &HttpNegotiate;
1526 return S_OK;
1527 }else if (IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
1528 CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1529 *ppv = &HttpNegotiate;
1530 return S_OK;
1531 }else if (IsEqualGUID(&IID_IAuthenticate, riid)) {
1532 CHECK_EXPECT(QueryInterface_IAuthenticate);
1533 return E_NOINTERFACE;
1534 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
1535 if(strict_bsc_qi)
1536 CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
1537 *ppv = iface;
1538 return S_OK;
1539 }else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid)) {
1540 CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
1541 return E_NOINTERFACE;
1542 }else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid)) {
1543 CHECK_EXPECT(QueryInterface_IBindStatusCallbackEx);
1544 if(!use_bscex)
1545 return E_NOINTERFACE;
1546 *ppv = iface;
1547 return S_OK;
1548 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
1549 /* TODO */
1550 }else if(IsEqualGUID(&IID_IWindowForBindingUI, riid)) {
1551 CHECK_EXPECT2(QueryInterface_IWindowForBindingUI);
1552 return E_NOINTERFACE;
1553 }else if(IsEqualGUID(&IID_IHttpSecurity, riid)) {
1554 CHECK_EXPECT2(QueryInterface_IHttpSecurity);
1555 return E_NOINTERFACE;
1556 }else if(IsEqualGUID(&IID_IGetBindHandle, riid)) {
1557 trace("QI(IID_IGetBindHandle)\n");
1558 *ppv = NULL;
1559 return E_NOINTERFACE;
1560 }else if(IsEqualGUID(&IID_undocumentedIE10, riid)) {
1561 trace("QI(IID_undocumentedIE10)\n");
1562 *ppv = NULL;
1563 return E_NOINTERFACE;
1564 }else if(IsEqualGUID(&IID_undocumentedIE11, riid)) {
1565 trace("QI(IID_undocumentedIE11)\n");
1566 *ppv = NULL;
1567 return E_NOINTERFACE;
1568 }else {
1569 ok(0, "unexpected interface %s\n", wine_dbgstr_guid(riid));
1570 }
1571
1572 return E_NOINTERFACE;
1573 }
1574
1575 static ULONG WINAPI statusclb_AddRef(IBindStatusCallbackEx *iface)
1576 {
1577 return 2;
1578 }
1579
1580 static ULONG WINAPI statusclb_Release(IBindStatusCallbackEx *iface)
1581 {
1582 return 1;
1583 }
1584
1585 static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved,
1586 IBinding *pib)
1587 {
1588 IWinInetHttpInfo *http_info;
1589 HRESULT hres;
1590 IMoniker *mon;
1591 DWORD res;
1592 CLSID clsid;
1593 LPOLESTR res_str;
1594
1595 if(iface == &objbsc)
1596 CHECK_EXPECT(Obj_OnStartBinding);
1597 else
1598 CHECK_EXPECT(OnStartBinding);
1599
1600 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1601
1602 ok(pib != NULL, "pib should not be NULL\n");
1603 ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);
1604
1605 if(pib == (void*)0xdeadbeef)
1606 return S_OK;
1607
1608 current_binding = pib;
1609
1610 hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
1611 ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
1612 if(SUCCEEDED(hres))
1613 IMoniker_Release(mon);
1614
1615 hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
1616 ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);
1617
1618 if(0) { /* crashes with native urlmon */
1619 hres = IBinding_GetBindResult(pib, NULL, &res, &res_str, NULL);
1620 ok(hres == E_INVALIDARG, "GetBindResult failed: %08x\n", hres);
1621 }
1622 hres = IBinding_GetBindResult(pib, &clsid, NULL, &res_str, NULL);
1623 ok(hres == E_INVALIDARG, "GetBindResult failed: %08x\n", hres);
1624 hres = IBinding_GetBindResult(pib, &clsid, &res, NULL, NULL);
1625 ok(hres == E_INVALIDARG, "GetBindResult failed: %08x\n", hres);
1626 hres = IBinding_GetBindResult(pib, &clsid, &res, &res_str, (void*)0xdeadbeef);
1627 ok(hres == E_INVALIDARG, "GetBindResult failed: %08x\n", hres);
1628
1629 hres = IBinding_GetBindResult(pib, &clsid, &res, &res_str, NULL);
1630 ok(hres == S_OK, "GetBindResult failed: %08x, expected S_OK\n", hres);
1631 ok(IsEqualCLSID(&clsid, &CLSID_NULL), "incorrect clsid: %s\n", wine_dbgstr_guid(&clsid));
1632 ok(!res, "incorrect res: %x\n", res);
1633 ok(!res_str, "incorrect res_str: %s\n", wine_dbgstr_w(res_str));
1634
1635 if(abort_start) {
1636 binding_hres = abort_hres;
1637 return abort_hres;
1638 }
1639
1640 return S_OK;
1641 }
1642
1643 static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1644 {
1645 ok(0, "unexpected call\n");
1646 return E_NOTIMPL;
1647 }
1648
1649 static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1650 {
1651 ok(0, "unexpected call\n");
1652 return E_NOTIMPL;
1653 }
1654
1655 static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
1656 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1657 {
1658 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1659
1660 switch(ulStatusCode) {
1661 case BINDSTATUS_FINDINGRESOURCE:
1662 if(iface == &objbsc)
1663 CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1664 else if(test_protocol == FTP_TEST)
1665 todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1666 else if(test_protocol == HTTPS_TEST && !bindtest_flags)
1667 todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1668 else
1669 CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1670 if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST))
1671 SetEvent(complete_event);
1672 break;
1673 case BINDSTATUS_CONNECTING:
1674 if(iface == &objbsc)
1675 CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1676 else if(test_protocol == FTP_TEST)
1677 todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
1678 else if(onsecurityproblem_hres == S_OK)
1679 CHECK_EXPECT2(OnProgress_CONNECTING);
1680 else
1681 CHECK_EXPECT(OnProgress_CONNECTING);
1682 if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST))
1683 SetEvent(complete_event);
1684 break;
1685 case BINDSTATUS_REDIRECTING:
1686 if(iface == &objbsc)
1687 CHECK_EXPECT(Obj_OnProgress_REDIRECTING);
1688 else
1689 CHECK_EXPECT(OnProgress_REDIRECTING);
1690 ok(!lstrcmpW(szStatusText, winetest_data_urlW), "unexpected status text %s\n",
1691 wine_dbgstr_w(szStatusText));
1692 if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST)
1693 && (!bind_to_object || iface == &objbsc))
1694 SetEvent(complete_event);
1695 break;
1696 case BINDSTATUS_SENDINGREQUEST:
1697 if(iface == &objbsc)
1698 CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1699 else if(test_protocol == FTP_TEST)
1700 CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
1701 else
1702 CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1703 if(emulate_protocol && (test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST))
1704 SetEvent(complete_event);
1705
1706 if(abort_progress) {
1707 if(filedwl_api)
1708 binding_hres = E_ABORT;
1709 return E_ABORT;
1710 }
1711
1712 break;
1713 case BINDSTATUS_MIMETYPEAVAILABLE:
1714 if(iface == &objbsc)
1715 CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
1716 else
1717 CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
1718 if(!bind_to_object)
1719 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1720 download_state);
1721 WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
1722 break;
1723 case BINDSTATUS_BEGINDOWNLOADDATA:
1724 if(iface == &objbsc)
1725 CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
1726 else
1727 CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1728 ok(szStatusText != NULL, "szStatusText == NULL\n");
1729 if(szStatusText) {
1730 if(filedwl_api) {
1731 /* FIXME */
1732 }else {
1733 ok(!lstrcmpW(szStatusText, current_url), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1734 }
1735 }
1736 if(!bind_to_object)
1737 ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
1738 download_state);
1739 download_state = DOWNLOADING;
1740 break;
1741 case BINDSTATUS_DOWNLOADINGDATA:
1742 CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1743 ok(iface != &objbsc, "unexpected call\n");
1744 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1745 download_state);
1746 if(test_abort) {
1747 HRESULT hres;
1748
1749 SET_EXPECT(Abort);
1750 hres = IBinding_Abort(current_binding);
1751 ok(hres == S_OK, "Abort failed: %08x\n", hres);
1752 CHECK_CALLED(Abort);
1753
1754 hres = IBinding_Abort(current_binding);
1755 ok(hres == E_FAIL, "Abort failed: %08x\n", hres);
1756
1757 binding_hres = E_ABORT;
1758 }
1759 break;
1760 case BINDSTATUS_ENDDOWNLOADDATA:
1761 if(iface == &objbsc)
1762 CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
1763 else
1764 CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1765 ok(szStatusText != NULL, "szStatusText == NULL\n");
1766 if(szStatusText) {
1767 if(filedwl_api) {
1768 /* FIXME */
1769 }else {
1770 ok(!lstrcmpW(szStatusText, current_url), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1771 }
1772 }
1773 ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
1774 download_state);
1775 download_state = END_DOWNLOAD;
1776 break;
1777 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1778 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST && test_protocol != WINETEST_TEST) {
1779 if(iface == &objbsc)
1780 CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1781 else
1782 CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1783 }else { /* FIXME */
1784 CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1785 CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
1786 }
1787
1788 ok(szStatusText != NULL, "szStatusText == NULL\n");
1789 if(szStatusText && test_protocol == FILE_TEST)
1790 ok(!lstrcmpW(file_url+7, szStatusText), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1791 break;
1792 case BINDSTATUS_CLASSIDAVAILABLE:
1793 {
1794 CLSID clsid;
1795 HRESULT hr;
1796 if(iface != &objbsc)
1797 ok(0, "unexpected call\n");
1798 else
1799 CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1800 hr = CLSIDFromString((LPCOLESTR)szStatusText, &clsid);
1801 ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
1802 ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
1803 "Expected clsid to be CLSID_HTMLDocument instead of %s\n", wine_dbgstr_guid(&clsid));
1804 break;
1805 }
1806 case BINDSTATUS_BEGINSYNCOPERATION:
1807 CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
1808 if(iface != &objbsc)
1809 ok(0, "unexpected call\n");
1810 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1811 break;
1812 case BINDSTATUS_ENDSYNCOPERATION:
1813 CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
1814 if(iface != &objbsc)
1815 ok(0, "unexpected call\n");
1816 ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
1817 break;
1818 case BINDSTATUS_PROXYDETECTING:
1819 trace("BINDSTATUS_PROXYDETECTING\n");
1820 break;
1821 case BINDSTATUS_COOKIE_SENT:
1822 trace("BINDSTATUS_COOKIE_SENT\n");
1823 break;
1824 case BINDSTATUS_DECODING:
1825 trace("BINDSTATUS_DECODING\n");
1826 break;
1827 default:
1828 ok(0, "unexpected code %d\n", ulStatusCode);
1829 };
1830
1831 if(current_binding) {
1832 IWinInetHttpInfo *http_info;
1833 HRESULT hres;
1834
1835 hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
1836 if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol)) {
1837 ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
1838 test_WinInetHttpInfo(http_info, ulStatusCode);
1839 } else
1840 ok(hres == E_NOINTERFACE,
1841 "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
1842 if(SUCCEEDED(hres))
1843 IWinInetHttpInfo_Release(http_info);
1844 }
1845
1846 return S_OK;
1847 }
1848
1849 static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
1850 {
1851 if(iface == &objbsc) {
1852 CHECK_EXPECT(Obj_OnStopBinding);
1853 stopped_obj_binding = TRUE;
1854 }else {
1855 CHECK_EXPECT(OnStopBinding);
1856 stopped_binding = TRUE;
1857 }
1858
1859 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1860
1861 if(only_check_prot_args) {
1862 todo_wine ok(hresult == S_OK, "Got %08x\n", hresult);
1863 return S_OK;
1864 }
1865
1866 /* ignore DNS failure */
1867 if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
1868 return S_OK;
1869
1870 if(filedwl_api) {
1871 if(!abort_progress && !abort_start)
1872 ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
1873 else if(abort_start && abort_hres == E_NOTIMPL)
1874 todo_wine ok(hresult == S_FALSE, "binding failed: %08x, expected S_FALSE\n", hresult);
1875 else
1876 ok(hresult == E_ABORT, "binding failed: %08x, expected E_ABORT\n", hresult);
1877 } else
1878 ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1879 ok(szError == NULL, "szError should be NULL\n");
1880
1881 if(current_binding) {
1882 CLSID clsid;
1883 DWORD res;
1884 LPOLESTR res_str;
1885 HRESULT hres;
1886
1887 hres = IBinding_GetBindResult(current_binding, &clsid, &res, &res_str, NULL);
1888 ok(hres == S_OK, "GetBindResult failed: %08x, expected S_OK\n", hres);
1889 ok(res == hresult, "res = %08x, expected %08x\n", res, binding_hres);
1890 ok(!res_str, "incorrect res_str = %s\n", wine_dbgstr_w(res_str));
1891
1892 if(hresult==S_OK || (abort_start && hresult!=S_FALSE) || hresult == REGDB_E_CLASSNOTREG) {
1893 ok(IsEqualCLSID(&clsid, &CLSID_NULL),
1894 "incorrect protocol CLSID: %s, expected CLSID_NULL\n",
1895 wine_dbgstr_guid(&clsid));
1896 }else if(emulate_protocol) {
1897 todo_wine ok(IsEqualCLSID(&clsid, &CLSID_FtpProtocol),
1898 "incorrect protocol CLSID: %s, expected CLSID_FtpProtocol\n",
1899 wine_dbgstr_guid(&clsid));
1900 }else if(test_protocol == FTP_TEST) {
1901 ok(IsEqualCLSID(&clsid, &CLSID_FtpProtocol),
1902 "incorrect protocol CLSID: %s, expected CLSID_FtpProtocol\n",
1903 wine_dbgstr_guid(&clsid));
1904 }else if(test_protocol == FILE_TEST) {
1905 ok(IsEqualCLSID(&clsid, &CLSID_FileProtocol),
1906 "incorrect protocol CLSID: %s, expected CLSID_FileProtocol\n",
1907 wine_dbgstr_guid(&clsid));
1908 }else if(test_protocol == HTTP_TEST) {
1909 ok(IsEqualCLSID(&clsid, &CLSID_HttpProtocol),
1910 "incorrect protocol CLSID: %s, expected CLSID_HttpProtocol\n",
1911 wine_dbgstr_guid(&clsid));
1912 }else if(test_protocol == HTTPS_TEST) {
1913 ok(IsEqualCLSID(&clsid, &CLSID_HttpSProtocol),
1914 "incorrect protocol CLSID: %s, expected CLSID_HttpSProtocol\n",
1915 wine_dbgstr_guid(&clsid));
1916 }else if(test_protocol == ABOUT_TEST) {
1917 ok(IsEqualCLSID(&clsid, &CLSID_AboutProtocol),
1918 "incorrect protocol CLSID: %s, expected CLSID_AboutProtocol\n",
1919 wine_dbgstr_guid(&clsid));
1920 }else {
1921 ok(0, "unexpected (%d)\n", test_protocol);
1922 }
1923 }
1924
1925 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST) && emulate_protocol) {
1926 SetEvent(complete_event);
1927 if(iface != &objbsc)
1928 ok( WaitForSingleObject(complete_event2, 90000) == WAIT_OBJECT_0, "wait timed out\n" );
1929 }
1930
1931 if(test_protocol == HTTP_TEST && !emulate_protocol && http_cache_file[0]) {
1932 HANDLE file = CreateFileW(http_cache_file, DELETE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1933 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1934 ok(file == INVALID_HANDLE_VALUE, "expected INVALID_HANDLE_VALUE, got %p\n", file);
1935 ok(GetLastError() == ERROR_SHARING_VIOLATION, "expected ERROR_SHARING_VIOLATION, got %u\n", GetLastError());
1936 http_cache_file[0] = 0;
1937 }
1938
1939 return S_OK;
1940 }
1941
1942 static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1943 {
1944 DWORD cbSize;
1945
1946 if(iface == &objbsc)
1947 CHECK_EXPECT(Obj_GetBindInfo);
1948 else
1949 CHECK_EXPECT(GetBindInfo);
1950
1951 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
1952
1953 *grfBINDF = bindf;
1954 cbSize = pbindinfo->cbSize;
1955 memset(pbindinfo, 0, cbSize);
1956 pbindinfo->cbSize = cbSize;
1957
1958 return S_OK;
1959 }
1960
1961 static void test_stream_seek(IStream *stream)
1962 {
1963 ULARGE_INTEGER new_pos;
1964 LARGE_INTEGER pos;
1965 HRESULT hres;
1966
1967 pos.QuadPart = 0;
1968 new_pos.QuadPart = 0xdeadbeef;
1969 hres = IStream_Seek(stream, pos, STREAM_SEEK_SET, &new_pos);
1970 ok(hres == S_OK, "Seek failed: %08x\n", hres);
1971 ok(!new_pos.QuadPart, "new_pos.QuadPart != 0\n");
1972
1973 pos.QuadPart = 0;
1974 new_pos.QuadPart = 0xdeadbeef;
1975 hres = IStream_Seek(stream, pos, STREAM_SEEK_END, &new_pos);
1976 ok(hres == S_OK, "Seek failed: %08x\n", hres);
1977 ok(new_pos.QuadPart, "new_pos.QuadPart = 0\n");
1978
1979 pos.QuadPart = 0;
1980 new_pos.QuadPart = 0xdeadbeef;
1981 hres = IStream_Seek(stream, pos, 100, &new_pos);
1982 ok(hres == E_FAIL, "Seek failed: %08x\n", hres);
1983 ok(new_pos.QuadPart == 0xdeadbeef, "unexpected new_pos.QuadPart\n");
1984 }
1985
1986 static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
1987 DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1988 {
1989 HRESULT hres;
1990 DWORD readed;
1991 BYTE buf[512];
1992 CHAR clipfmt[512];
1993
1994 if(iface == &objbsc)
1995 ok(0, "unexpected call\n");
1996
1997 CHECK_EXPECT2(OnDataAvailable);
1998
1999 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
2000
2001 ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
2002 "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
2003 download_state);
2004 data_available = TRUE;
2005
2006 if(bind_to_object && !is_async_prot)
2007 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION), "grfBSCF = %x\n", grfBSCF);
2008
2009 ok(pformatetc != NULL, "pformatetx == NULL\n");
2010 if(pformatetc) {
2011 if (mime_type[0]) {
2012 INT ret;
2013 clipfmt[0] = 0;
2014 ret = GetClipboardFormatNameA(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1);
2015 ok(ret, "GetClipboardFormatName failed, error %d\n", GetLastError());
2016 ok(!strcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
2017 pformatetc->cfFormat, clipfmt, mime_type);
2018 } else {
2019 ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
2020 }
2021 ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
2022 ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
2023 ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
2024 ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
2025 }
2026
2027 ok(pstgmed != NULL, "stgmeg == NULL\n");
2028 ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
2029 ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
2030
2031 switch(pstgmed->tymed) {
2032 case TYMED_ISTREAM: {
2033 IStream *stream = U(*pstgmed).pstm;
2034
2035 ok(stream != NULL, "U(*pstgmed).pstm == NULL\n");
2036
2037 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
2038 STATSTG stat;
2039
2040 hres = IStream_Write(stream, buf, 10, NULL);
2041 ok(hres == STG_E_ACCESSDENIED,
2042 "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
2043
2044 hres = IStream_Commit(stream, 0);
2045 ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
2046
2047 hres = IStream_Revert(stream);
2048 ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
2049
2050 hres = IStream_Stat(stream, NULL, STATFLAG_NONAME);
2051 ok(hres == E_FAIL, "hres = %x\n", hres);
2052 if(use_cache_file && emulate_protocol) {
2053 hres = IStream_Stat(stream, &stat, STATFLAG_DEFAULT);
2054 ok(hres == S_OK, "hres = %x\n", hres);
2055 ok(!lstrcmpW(stat.pwcsName, cache_file_name),
2056 "stat.pwcsName = %s, cache_file_name = %s\n",
2057 wine_dbgstr_w(stat.pwcsName), wine_dbgstr_w(cache_file_name));
2058 CoTaskMemFree(stat.pwcsName);
2059 ok(U(stat.cbSize).LowPart == (bindf&BINDF_ASYNCHRONOUS?0:6500),
2060 "stat.cbSize.LowPart = %u\n", U(stat.cbSize).LowPart);
2061 } else {
2062 hres = IStream_Stat(stream, &stat, STATFLAG_NONAME);
2063 ok(hres == S_OK, "hres = %x\n", hres);
2064 ok(!stat.pwcsName || broken(stat.pwcsName!=NULL),
2065 "stat.pwcsName = %s\n", wine_dbgstr_w(stat.pwcsName));
2066 }
2067 ok(stat.type == STGTY_STREAM, "stat.type = %x\n", stat.type);
2068 ok(U(stat.cbSize).HighPart == 0, "stat.cbSize.HighPart != 0\n");
2069 ok(stat.grfMode == (U(stat.cbSize).LowPart?GENERIC_READ:0), "stat.grfMode = %x\n", stat.grfMode);
2070 ok(stat.grfLocksSupported == 0, "stat.grfLocksSupported = %x\n", stat.grfLocksSupported);
2071 ok(stat.grfStateBits == 0, "stat.grfStateBits = %x\n", stat.grfStateBits);
2072 ok(stat.reserved == 0, "stat.reserved = %x\n", stat.reserved);
2073 }
2074
2075 if(callback_read) {
2076 do {
2077 hres = IStream_Read(stream, buf, 512, &readed);
2078 if(test_protocol == HTTP_TEST && emulate_protocol && readed)
2079 ok(buf[0] == (use_cache_file && !(bindf&BINDF_ASYNCHRONOUS) ? 'X' : '?'), "buf[0] = '%c'\n", buf[0]);
2080 }while(hres == S_OK);
2081 ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
2082 }
2083
2084 if(use_cache_file && (grfBSCF & BSCF_FIRSTDATANOTIFICATION) && !(bindf & BINDF_PULLDATA))
2085 test_stream_seek(stream);
2086 break;
2087 }
2088 case TYMED_FILE:
2089 if(test_protocol == FILE_TEST)
2090 ok(!lstrcmpW(pstgmed->u.lpszFileName, file_url+7),
2091 "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
2092 else if(emulate_protocol)
2093 ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
2094 "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
2095 else if(test_protocol == HTTP_TEST)
2096 lstrcpyW(http_cache_file, pstgmed->u.lpszFileName);
2097 else
2098 ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
2099 }
2100
2101 if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == WINETEST_TEST)
2102 && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
2103 SetEvent(complete_event);
2104
2105 return S_OK;
2106 }
2107
2108 static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
2109 {
2110 CHECK_EXPECT(OnObjectAvailable);
2111
2112 if(iface != &objbsc)
2113 ok(0, "unexpected call\n");
2114
2115 ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", wine_dbgstr_guid(riid));
2116 ok(punk != NULL, "punk == NULL\n");
2117
2118 return S_OK;
2119 }
2120
2121 static HRESULT WINAPI statusclb_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo,
2122 DWORD *grfBINDF2, DWORD *pdwReserved)
2123 {
2124 CHECK_EXPECT(GetBindInfoEx);
2125
2126 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
2127 ok(grfBINDF2 != NULL, "grfBINDF2 == NULL\n");
2128 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
2129 ok(pdwReserved != NULL, "dwReserved == NULL\n");
2130
2131 return S_OK;
2132 }
2133
2134 static const IBindStatusCallbackExVtbl BindStatusCallbackVtbl = {
2135 statusclb_QueryInterface,
2136 statusclb_AddRef,
2137 statusclb_Release,
2138 statusclb_OnStartBinding,
2139 statusclb_GetPriority,
2140 statusclb_OnLowResource,
2141 statusclb_OnProgress,
2142 statusclb_OnStopBinding,
2143 statusclb_GetBindInfo,
2144 statusclb_OnDataAvailable,
2145 statusclb_OnObjectAvailable,
2146 statusclb_GetBindInfoEx
2147 };
2148
2149 static IBindStatusCallbackEx bsc = { &BindStatusCallbackVtbl };
2150 static IBindStatusCallbackEx bsc2 = { &BindStatusCallbackVtbl };
2151 static IBindStatusCallbackEx objbsc = { &BindStatusCallbackVtbl };
2152
2153 static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
2154 {
2155 *ppv = NULL;
2156 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
2157 return E_NOINTERFACE;
2158 }
2159
2160 static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
2161 {
2162 return 2;
2163 }
2164
2165 static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
2166 {
2167 return 1;
2168 }
2169
2170 static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
2171 {
2172 switch(mkp) {
2173 case MIMETYPEPROP:
2174 CHECK_EXPECT(PutProperty_MIMETYPEPROP);
2175 ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", wine_dbgstr_w(val));
2176 break;
2177 case CLASSIDPROP:
2178 CHECK_EXPECT(PutProperty_CLASSIDPROP);
2179 break;
2180 default:
2181 break;
2182 }
2183
2184 return S_OK;
2185 }
2186
2187 static const IMonikerPropVtbl MonikerPropVtbl = {
2188 MonikerProp_QueryInterface,
2189 MonikerProp_AddRef,
2190 MonikerProp_Release,
2191 MonikerProp_PutProperty
2192 };
2193
2194 static IMonikerProp MonikerProp = { &MonikerPropVtbl };
2195
2196 static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
2197 {
2198 *ppv = NULL;
2199
2200 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
2201 *ppv = iface;
2202 else if(IsEqualGUID(&IID_IMonikerProp, riid))
2203 *ppv = &MonikerProp;
2204
2205 if(*ppv)
2206 return S_OK;
2207
2208 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
2209 return E_NOINTERFACE;
2210 }
2211
2212 static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
2213 {
2214 return 2;
2215 }
2216
2217 static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
2218 {
2219 return 1;
2220 }
2221
2222 static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
2223 {
2224 ok(0, "unexpected call\n");
2225 return E_NOTIMPL;
2226 }
2227
2228 static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
2229 {
2230 ok(0, "unexpected call\n");
2231 return E_NOTIMPL;
2232 }
2233
2234 static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
2235 IMoniker *pimkName, LPBC pibc, DWORD grfMode)
2236 {
2237 IUnknown *unk;
2238 HRESULT hres;
2239
2240 static WCHAR cbinding_contextW[] =
2241 {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
2242
2243 CHECK_EXPECT(Load);
2244 ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());
2245
2246 if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2247 ok(!fFullyAvailable, "fFullyAvailable = %x\n", fFullyAvailable);
2248 else
2249 ok(fFullyAvailable, "fFullyAvailable = %x\n", fFullyAvailable);
2250 ok(pimkName != NULL, "pimkName == NULL\n");
2251 ok(pibc != NULL, "pibc == NULL\n");
2252 ok(grfMode == 0x12, "grfMode = %x\n", grfMode);
2253
2254 hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
2255 ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
2256 if(SUCCEEDED(hres)) {
2257 IBinding *binding;
2258
2259 hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
2260 ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);
2261
2262 IBinding_Release(binding);
2263 IUnknown_Release(unk);
2264 }
2265
2266 SET_EXPECT(QueryInterface_IServiceProvider);
2267 hres = RegisterBindStatusCallback(pibc, (IBindStatusCallback*)&bsc, NULL, 0);
2268 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2269 CHECK_CALLED(QueryInterface_IServiceProvider);
2270
2271 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2272 SET_EXPECT(GetBindInfo);
2273 SET_EXPECT(OnStartBinding);
2274 if(test_redirect)
2275 SET_EXPECT(OnProgress_REDIRECTING);
2276 SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
2277 if(test_protocol == FILE_TEST)
2278 SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2279 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2280 SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
2281 SET_EXPECT(LockRequest);
2282 SET_EXPECT(OnDataAvailable);
2283 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2284 SET_EXPECT(OnStopBinding);
2285
2286 hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
2287 ok(hres == S_OK, "Load failed: %08x\n", hres);
2288
2289 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2290 CHECK_CALLED(GetBindInfo);
2291 CHECK_CALLED(OnStartBinding);
2292 if(test_redirect)
2293 CHECK_CALLED(OnProgress_REDIRECTING);
2294 CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
2295 if(test_protocol == FILE_TEST)
2296 CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2297 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2298 CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
2299 CHECK_CALLED(LockRequest);
2300 CHECK_CALLED(OnDataAvailable);
2301 if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
2302 CHECK_CALLED(OnStopBinding);
2303
2304 if(unk)
2305 IUnknown_Release(unk);
2306
2307 return S_OK;
2308 }
2309
2310 static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
2311 {
2312 ok(0, "unexpected call\n");
2313 return E_NOTIMPL;
2314 }
2315
2316 static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
2317 {
2318 ok(0, "unexpected call\n");
2319 return E_NOTIMPL;
2320 }
2321
2322 static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
2323 {
2324 ok(0, "unexpected call\n");
2325 return E_NOTIMPL;
2326 }
2327
2328 static const IPersistMonikerVtbl PersistMonikerVtbl = {
2329 PersistMoniker_QueryInterface,
2330 PersistMoniker_AddRef,
2331 PersistMoniker_Release,
2332 PersistMoniker_GetClassID,
2333 PersistMoniker_IsDirty,
2334 PersistMoniker_Load,
2335 PersistMoniker_Save,
2336 PersistMoniker_SaveCompleted,
2337 PersistMoniker_GetCurMoniker
2338 };
2339
2340 static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };
2341
2342 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2343 {
2344 *ppv = NULL;
2345
2346 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2347 *ppv = iface;
2348 return S_OK;
2349 }
2350
2351 if(IsEqualGUID(&IID_IMarshal, riid))
2352 return E_NOINTERFACE;
2353 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
2354 return E_NOINTERFACE;
2355
2356 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
2357 return E_NOTIMPL;
2358 }
2359
2360 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2361 {
2362 return 2;
2363 }
2364
2365 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2366 {
2367 return 1;
2368 }
2369
2370 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2371 {
2372 CHECK_EXPECT(CreateInstance);
2373 ok(!outer, "outer = %p\n", outer);
2374 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
2375 *ppv = &PersistMoniker;
2376 return S_OK;
2377 }
2378
2379 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2380 {
2381 ok(0, "unexpected call\n");
2382 return S_OK;
2383 }
2384
2385 static const IClassFactoryVtbl ClassFactoryVtbl = {
2386 ClassFactory_QueryInterface,
2387 ClassFactory_AddRef,
2388 ClassFactory_Release,
2389 ClassFactory_CreateInstance,
2390 ClassFactory_LockServer
2391 };
2392
2393 static IClassFactory mime_cf = { &ClassFactoryVtbl };
2394
2395 static HRESULT WINAPI ProtocolCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2396 {
2397 *ppv = NULL;
2398
2399 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2400 *ppv = iface;
2401 return S_OK;
2402 }
2403
2404 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid))
2405 return E_NOINTERFACE;
2406
2407 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
2408 return E_NOTIMPL;
2409 }
2410
2411 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2412 {
2413 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid))
2414 return E_NOINTERFACE;
2415
2416 ok(outer != NULL, "outer == NULL\n");
2417 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
2418 *ppv = &Protocol;
2419 return S_OK;
2420 }
2421
2422 static const IClassFactoryVtbl ProtocolCFVtbl = {
2423 ProtocolCF_QueryInterface,
2424 ClassFactory_AddRef,
2425 ClassFactory_Release,
2426 ProtocolCF_CreateInstance,
2427 ClassFactory_LockServer
2428 };
2429
2430 static IClassFactory protocol_cf = { &ProtocolCFVtbl };
2431
2432 static void test_CreateAsyncBindCtx(void)
2433 {
2434 IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
2435 IUnknown *unk;
2436 HRESULT hres;
2437 ULONG ref;
2438 BIND_OPTS bindopts;
2439
2440 hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
2441 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
2442 ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");
2443
2444 hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
2445 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
2446
2447 SET_EXPECT(QueryInterface_IServiceProvider);
2448 hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2449 ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
2450 CHECK_CALLED(QueryInterface_IServiceProvider);
2451
2452 bindopts.cbStruct = sizeof(bindopts);
2453 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
2454 ok(hres == S_OK, "IBindCtx_GetBindOptions failed: %08x\n", hres);
2455 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
2456 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
2457 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
2458 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
2459 bindopts.grfMode);
2460 ok(bindopts.dwTickCountDeadline == 0,
2461 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
2462
2463 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
2464 ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
2465 if(SUCCEEDED(hres))
2466 IUnknown_Release(unk);
2467
2468 ref = IBindCtx_Release(bctx);
2469 ok(ref == 0, "bctx should be destroyed here\n");
2470 }
2471
2472 static void test_CreateAsyncBindCtxEx(void)
2473 {
2474 IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
2475 IUnknown *unk;
2476 BIND_OPTS bindopts;
2477 HRESULT hres;
2478
2479 static WCHAR testW[] = {'t','e','s','t',0};
2480
2481 if (!pCreateAsyncBindCtxEx) {
2482 win_skip("CreateAsyncBindCtxEx not present\n");
2483 return;
2484 }
2485
2486 hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
2487 ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
2488
2489 hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2490 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2491
2492 if(SUCCEEDED(hres)) {
2493 bindopts.cbStruct = sizeof(bindopts);
2494 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
2495 ok(hres == S_OK, "IBindCtx_GetBindOptions failed: %08x\n", hres);
2496 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
2497 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
2498 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
2499 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
2500 bindopts.grfMode);
2501 ok(bindopts.dwTickCountDeadline == 0,
2502 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
2503
2504 IBindCtx_Release(bctx);
2505 }
2506
2507 CreateBindCtx(0, &bctx_arg);
2508 hres = pCreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2509 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2510
2511 if(SUCCEEDED(hres)) {
2512 bindopts.cbStruct = sizeof(bindopts);
2513 hres = IBindCtx_GetBindOptions(bctx, &bindopts);
2514 ok(hres == S_OK, "IBindCtx_GetBindOptions failed: %08x\n", hres);
2515 ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
2516 "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
2517 ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
2518 "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
2519 bindopts.grfMode);
2520 ok(bindopts.dwTickCountDeadline == 0,
2521 "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
2522
2523 IBindCtx_Release(bctx);
2524 }
2525
2526 IBindCtx_Release(bctx_arg);
2527
2528 SET_EXPECT(QueryInterface_IServiceProvider);
2529 hres = pCreateAsyncBindCtxEx(NULL, 0, (IBindStatusCallback*)&bsc, NULL, &bctx, 0);
2530 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2531 CHECK_CALLED(QueryInterface_IServiceProvider);
2532
2533 hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
2534 ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
2535 if(SUCCEEDED(hres))
2536 IUnknown_Release(unk);
2537
2538 IBindCtx_Release(bctx);
2539
2540 hres = CreateBindCtx(0, &bctx2);
2541 ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);
2542
2543 hres = pCreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
2544 ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2545
2546 hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
2547 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2548
2549 hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
2550 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2551 ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);
2552
2553 IBindCtx_Release(bctx);
2554 IBindCtx_Release(bctx2);
2555 }
2556
2557 static void test_GetBindInfoEx(IBindStatusCallback *holder)
2558 {
2559 IBindStatusCallbackEx *bscex;
2560 BINDINFO bindinfo = {sizeof(bindinfo)};
2561 DWORD bindf, bindf2, dw;
2562 HRESULT hres;
2563
2564 hres = IBindStatusCallback_QueryInterface(holder, &IID_IBindStatusCallbackEx, (void**)&bscex);
2565 if(FAILED(hres)) {
2566 win_skip("IBindStatusCallbackEx not supported\n");
2567 return;
2568 }
2569
2570 use_bscex = TRUE;
2571
2572 bindf = 0;
2573 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2574 SET_EXPECT(GetBindInfoEx);
2575 hres = IBindStatusCallback_GetBindInfo(holder, &bindf, &bindinfo);
2576 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2577 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2578 CHECK_CALLED(GetBindInfoEx);
2579
2580 bindf = bindf2 = dw = 0;
2581 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2582 SET_EXPECT(GetBindInfoEx);
2583 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
2584 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2585 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2586 CHECK_CALLED(GetBindInfoEx);
2587
2588 use_bscex = FALSE;
2589
2590 bindf = bindf2 = dw = 0xdeadbeef;
2591 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2592 SET_EXPECT(GetBindInfo);
2593 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
2594 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2595 CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
2596 CHECK_CALLED(GetBindInfo);
2597 ok(bindf2 == 0xdeadbeef, "bindf2 = %x\n", bindf2);
2598 ok(dw == 0xdeadbeef, "dw = %x\n", dw);
2599
2600 IBindStatusCallbackEx_Release(bscex);
2601 }
2602
2603 static BOOL test_bscholder(IBindStatusCallback *holder)
2604 {
2605 IServiceProvider *serv_prov;
2606 IHttpNegotiate *http_negotiate, *http_negotiate_serv;
2607 IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
2608 IAuthenticate *authenticate, *authenticate_serv;
2609 IInternetBindInfo *bind_info;
2610 IInternetProtocol *protocol;
2611 BINDINFO bindinfo = {sizeof(bindinfo)};
2612 BOOL ret = TRUE;
2613 LPWSTR wstr;
2614 DWORD dw;
2615 HRESULT hres;
2616
2617 hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
2618 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2619
2620 dw = 0xdeadbeef;
2621 SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2622 SET_EXPECT(GetBindInfo);
2623 hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
2624 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2625 CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2626 CHECK_CALLED(GetBindInfo);
2627
2628 test_GetBindInfoEx(holder);
2629
2630 SET_EXPECT(OnStartBinding);
2631 hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
2632 ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
2633 CHECK_CALLED(OnStartBinding);
2634
2635 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
2636 ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
2637
2638 SET_EXPECT(QueryInterface_IHttpNegotiate);
2639 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2640 (void**)&http_negotiate_serv);
2641 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2642 CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
2643
2644 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2645
2646 wstr = (void*)0xdeadbeef;
2647 SET_EXPECT(QueryInterface_IHttpNegotiate);
2648 SET_EXPECT(BeginningTransaction);
2649 hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, current_url, emptyW, 0, &wstr);
2650 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2651 CHECK_CALLED(BeginningTransaction);
2652 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
2653 ok(wstr == NULL, "wstr = %p\n", wstr);
2654
2655 IHttpNegotiate_Release(http_negotiate_serv);
2656
2657 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
2658 (void**)&http_negotiate_serv);
2659 ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2660 ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
2661 IHttpNegotiate_Release(http_negotiate_serv);
2662
2663 hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
2664 if(SUCCEEDED(hres)) {
2665 have_IHttpNegotiate2 = TRUE;
2666
2667 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2668 hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
2669 (void**)&http_negotiate2_serv);
2670 ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
2671 CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
2672 ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
2673
2674 SET_EXPECT(QueryInterface_IHttpNegotiate2);
2675 SET_EXPECT(GetRootSecurityId);
2676 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
2677 ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
2678 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2); /* IE8 */
2679 CHECK_CALLED(GetRootSecurityId);
2680
2681 IHttpNegotiate2_Release(http_negotiate2_serv);
2682 IHttpNegotiate2_Release(http_negotiate2);
2683 }else {
2684 skip("Could not get IHttpNegotiate2\n");
2685 ret = FALSE;
2686 }
2687
2688 SET_EXPECT(OnProgress_FINDINGRESOURCE);
2689 hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
2690 ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
2691 CHECK_CALLED(OnProgress_FINDINGRESOURCE);
2692
2693 SET_EXPECT(QueryInterface_IHttpNegotiate);
2694 SET_EXPECT(OnResponse);
2695 wstr = (void*)0xdeadbeef;
2696 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
2697 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2698 CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2699 CHECK_CALLED(OnResponse);
2700
2701 IHttpNegotiate_Release(http_negotiate);
2702
2703 hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
2704 ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);
2705
2706 SET_EXPECT(QueryInterface_IAuthenticate);
2707 SET_EXPECT(QueryService_IAuthenticate);
2708 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2709 (void**)&authenticate_serv);
2710 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2711 CLEAR_CALLED(QueryInterface_IAuthenticate); /* IE <8 */
2712 CLEAR_CALLED(QueryService_IAuthenticate); /* IE <8 */
2713 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2714 IAuthenticate_Release(authenticate_serv);
2715
2716 hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
2717 (void**)&authenticate_serv);
2718 ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2719 ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
2720
2721 IAuthenticate_Release(authenticate);
2722 IAuthenticate_Release(authenticate_serv);
2723
2724 hres = IBindStatusCallback_QueryInterface(holder, &IID_IInternetBindInfo, (void**)&bind_info);
2725 ok(hres == S_OK || broken(hres == E_NOINTERFACE /* win2k */), "Could not get IInternetBindInfo interface: %08x\n", hres);
2726
2727 if(SUCCEEDED(hres)) {
2728 hres = IInternetBindInfo_GetBindString(bind_info, BINDSTRING_USER_AGENT, &wstr, 1, &dw);
2729 ok(hres == E_NOINTERFACE, "GetBindString(BINDSTRING_USER_AGENT) failed: %08x\n", hres);
2730
2731 IInternetBindInfo_Release(bind_info);
2732 }
2733
2734 SET_EXPECT(OnStopBinding);
2735 hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
2736 ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
2737 CHECK_CALLED(OnStopBinding);
2738
2739 SET_EXPECT(QueryInterface_IInternetProtocol);
2740 SET_EXPECT(QueryService_IInternetProtocol);
2741 hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
2742 (void**)&protocol);
2743 ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
2744 CHECK_CALLED(QueryInterface_IInternetProtocol);
2745 CHECK_CALLED(QueryService_IInternetProtocol);
2746
2747 IServiceProvider_Release(serv_prov);
2748 return ret;
2749 }
2750
2751 static BOOL test_RegisterBindStatusCallback(void)
2752 {
2753 IBindStatusCallback *prevbsc, *clb, *prev_clb;
2754 IBindCtx *bindctx;
2755 BOOL ret = TRUE;
2756 IUnknown *unk;
2757 HRESULT hres;
2758
2759 strict_bsc_qi = TRUE;
2760
2761 hres = CreateBindCtx(0, &bindctx);
2762 ok(hres == S_OK, "BindCtx failed: %08x\n", hres);
2763
2764 SET_EXPECT(QueryInterface_IServiceProvider);
2765
2766 hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
2767 ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);
2768
2769 SET_EXPECT(QueryInterface_IBindStatusCallback);
2770 SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
2771 prevbsc = (void*)0xdeadbeef;
2772 hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2773 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2774 ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc=%p\n", prevbsc);
2775 CHECK_CALLED(QueryInterface_IBindStatusCallback);
2776 CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);
2777
2778 CHECK_CALLED(QueryInterface_IServiceProvider);
2779
2780 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2781 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2782
2783 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2784 IUnknown_Release(unk);
2785 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2786 ok(clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2787
2788 if(!test_bscholder(clb))
2789 ret = FALSE;
2790
2791 IBindStatusCallback_Release(clb);
2792
2793 hres = RevokeBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc);
2794 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2795
2796 unk = (void*)0xdeadbeef;
2797 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2798 ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
2799 ok(unk == NULL, "unk != NULL\n");
2800
2801 if(unk)
2802 IUnknown_Release(unk);
2803
2804 hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
2805 ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);
2806
2807 hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
2808 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2809
2810 hres = RevokeBindStatusCallback(bindctx, NULL);
2811 ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);
2812
2813 SET_EXPECT(QueryInterface_IServiceProvider);
2814 prevbsc = (void*)0xdeadbeef;
2815 hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2816 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2817 ok(!prevbsc, "prevbsc=%p\n", prevbsc);
2818 CHECK_CALLED(QueryInterface_IServiceProvider);
2819
2820 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2821 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2822
2823 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&prev_clb);
2824 IUnknown_Release(unk);
2825 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2826 ok(prev_clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2827
2828 SET_EXPECT(QueryInterface_IServiceProvider);
2829 prevbsc = (void*)0xdeadbeef;
2830 hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc2, &prevbsc, 0);
2831 ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2832 ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc != bsc\n");
2833 CHECK_CALLED(QueryInterface_IServiceProvider);
2834
2835 hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
2836 ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
2837
2838 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
2839 IUnknown_Release(unk);
2840 ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2841 ok(prev_clb == clb, "bsc != clb\n");
2842
2843 IBindStatusCallback_Release(clb);