[URLMON_WINETEST]
[reactos.git] / rostests / winetests / urlmon / protocol.c
1 /*
2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "urlmon.h"
30 #include "wininet.h"
31
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
34
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
37
38 #define CHECK_EXPECT2(func) \
39 do { \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
42 }while(0)
43
44 #define CHECK_EXPECT(func) \
45 do { \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
48 }while(0)
49
50 #define CHECK_CALLED(func) \
51 do { \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
54 }while(0)
55
56 #define CHECK_NOT_CALLED(func) \
57 do { \
58 ok(!called_ ## func, "unexpected " #func "\n"); \
59 expect_ ## func = called_ ## func = FALSE; \
60 }while(0)
61
62 #define CLEAR_CALLED(func) \
63 expect_ ## func = called_ ## func = FALSE
64
65 DEFINE_EXPECT(GetBindInfo);
66 DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
67 DEFINE_EXPECT(ReportProgress_DIRECTBIND);
68 DEFINE_EXPECT(ReportProgress_RAWMIMETYPE);
69 DEFINE_EXPECT(ReportProgress_FINDINGRESOURCE);
70 DEFINE_EXPECT(ReportProgress_CONNECTING);
71 DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
72 DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
73 DEFINE_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
74 DEFINE_EXPECT(ReportProgress_PROTOCOLCLASSID);
75 DEFINE_EXPECT(ReportProgress_COOKIE_SENT);
76 DEFINE_EXPECT(ReportProgress_REDIRECTING);
77 DEFINE_EXPECT(ReportProgress_ENCODING);
78 DEFINE_EXPECT(ReportProgress_ACCEPTRANGES);
79 DEFINE_EXPECT(ReportProgress_PROXYDETECTING);
80 DEFINE_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
81 DEFINE_EXPECT(ReportProgress_DECODING);
82 DEFINE_EXPECT(ReportData);
83 DEFINE_EXPECT(ReportData2);
84 DEFINE_EXPECT(ReportResult);
85 DEFINE_EXPECT(GetBindString_ACCEPT_MIMES);
86 DEFINE_EXPECT(GetBindString_USER_AGENT);
87 DEFINE_EXPECT(GetBindString_POST_COOKIE);
88 DEFINE_EXPECT(GetBindString_URL);
89 DEFINE_EXPECT(QueryService_HttpNegotiate);
90 DEFINE_EXPECT(QueryService_InternetProtocol);
91 DEFINE_EXPECT(QueryService_HttpSecurity);
92 DEFINE_EXPECT(QueryInterface_IWinInetInfo);
93 DEFINE_EXPECT(QueryInterface_IWinInetHttpInfo);
94 DEFINE_EXPECT(BeginningTransaction);
95 DEFINE_EXPECT(GetRootSecurityId);
96 DEFINE_EXPECT(OnResponse);
97 DEFINE_EXPECT(Switch);
98 DEFINE_EXPECT(Continue);
99 DEFINE_EXPECT(CreateInstance);
100 DEFINE_EXPECT(Start);
101 DEFINE_EXPECT(Terminate);
102 DEFINE_EXPECT(Read);
103 DEFINE_EXPECT(Read2);
104 DEFINE_EXPECT(SetPriority);
105 DEFINE_EXPECT(LockRequest);
106 DEFINE_EXPECT(UnlockRequest);
107 DEFINE_EXPECT(MimeFilter_CreateInstance);
108 DEFINE_EXPECT(MimeFilter_Start);
109 DEFINE_EXPECT(MimeFilter_ReportProgress);
110 DEFINE_EXPECT(MimeFilter_ReportData);
111 DEFINE_EXPECT(MimeFilter_ReportResult);
112 DEFINE_EXPECT(MimeFilter_Terminate);
113 DEFINE_EXPECT(MimeFilter_LockRequest);
114 DEFINE_EXPECT(MimeFilter_UnlockRequest);
115 DEFINE_EXPECT(MimeFilter_Read);
116 DEFINE_EXPECT(MimeFilter_Switch);
117 DEFINE_EXPECT(MimeFilter_Continue);
118
119 static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
120 static const WCHAR index_url[] =
121 {'f','i','l','e',':','i','n','d','e','x','.','h','t','m','l',0};
122
123 static const WCHAR acc_mimeW[] = {'*','/','*',0};
124 static const WCHAR user_agentW[] = {'W','i','n','e',0};
125 static const WCHAR text_htmlW[] = {'t','e','x','t','/','h','t','m','l',0};
126 static const WCHAR hostW[] = {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
127 static const WCHAR winehq_ipW[] = {'2','0','9','.','4','6','.','2','5','.','1','3','4',0};
128 static const WCHAR emptyW[] = {0};
129 static const WCHAR gzipW[] = {'g','z','i','p',0};
130
131 static HRESULT expect_hrResult;
132 static LPCWSTR file_name, http_url, expect_wsz;
133 static IInternetProtocol *async_protocol = NULL;
134 static BOOL first_data_notif, http_is_first, http_post_test, test_redirect;
135 static int state = 0, prot_state, read_report_data;
136 static DWORD bindf, ex_priority , pi;
137 static IInternetProtocol *binding_protocol, *filtered_protocol;
138 static IInternetBindInfo *prot_bind_info;
139 static IInternetProtocolSink *binding_sink, *filtered_sink;
140 static void *expect_pv;
141 static HANDLE event_complete, event_complete2, event_continue, event_continue_done;
142 static BOOL binding_test;
143 static PROTOCOLDATA protocoldata, *pdata, continue_protdata;
144 static DWORD prot_read, pi, filter_state;
145 static BOOL security_problem;
146 static BOOL async_read_pending, mimefilter_test, direct_read, wait_for_switch, emulate_prot, short_read;
147
148 static enum {
149 FILE_TEST,
150 HTTP_TEST,
151 HTTPS_TEST,
152 FTP_TEST,
153 MK_TEST,
154 BIND_TEST
155 } tested_protocol;
156
157 static const WCHAR protocol_names[][10] = {
158 {'f','i','l','e',0},
159 {'h','t','t','p',0},
160 {'h','t','t','p','s',0},
161 {'f','t','p',0},
162 {'m','k',0},
163 {'t','e','s','t',0}
164 };
165
166 static const WCHAR binding_urls[][130] = {
167 {'f','i','l','e',':','t','e','s','t','.','h','t','m','l',0},
168 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
169 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0},
170 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
171 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0},
172 {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
173 '/','p','u','b','/','o','t','h','e','r',
174 '/','w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0},
175 {'m','k',':','t','e','s','t',0},
176 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0}
177 };
178
179 static const char *debugstr_guid(REFIID riid)
180 {
181 static char buf[50];
182
183 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
184 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
185 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
186 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
187
188 return buf;
189 }
190
191 static int strcmp_wa(LPCWSTR strw, const char *stra)
192 {
193 CHAR buf[512];
194 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
195 return lstrcmpA(stra, buf);
196 }
197
198 /* lstrcmpW is not implemented on Win9x */
199 static int strcmp_ww(LPCWSTR strw1, LPCWSTR strw2)
200 {
201 CHAR stra1[512], stra2[512];
202 WideCharToMultiByte(CP_ACP, 0, strw1, -1, stra1, MAX_PATH, NULL, NULL);
203 WideCharToMultiByte(CP_ACP, 0, strw2, -1, stra2, MAX_PATH, NULL, NULL);
204 return lstrcmpA(stra1, stra2);
205 }
206
207 static HRESULT WINAPI HttpSecurity_QueryInterface(IHttpSecurity *iface, REFIID riid, void **ppv)
208 {
209 if(IsEqualGUID(&IID_IUnknown, riid)
210 || IsEqualGUID(&IID_IHttpSecurity, riid)) {
211 *ppv = iface;
212 return S_OK;
213 }
214
215 ok(0, "unexpected call\n");
216 return E_NOINTERFACE;
217 }
218
219 static ULONG WINAPI HttpSecurity_AddRef(IHttpSecurity *iface)
220 {
221 return 2;
222 }
223
224 static ULONG WINAPI HttpSecurity_Release(IHttpSecurity *iface)
225 {
226 return 1;
227 }
228
229 static HRESULT WINAPI HttpSecurity_GetWindow(IHttpSecurity* iface, REFGUID rguidReason, HWND *phwnd)
230 {
231 trace("HttpSecurity_GetWindow\n");
232
233 return S_FALSE;
234 }
235
236 static HRESULT WINAPI HttpSecurity_OnSecurityProblem(IHttpSecurity *iface, DWORD dwProblem)
237 {
238 trace("Security problem: %u\n", dwProblem);
239 ok(dwProblem == ERROR_INTERNET_SEC_CERT_REV_FAILED, "Expected ERROR_INTERNET_SEC_CERT_REV_FAILED got %u\n", dwProblem);
240
241 /* Only retry once */
242 if (security_problem)
243 return E_ABORT;
244
245 security_problem = TRUE;
246 SET_EXPECT(BeginningTransaction);
247
248 return RPC_E_RETRY;
249 }
250
251 static IHttpSecurityVtbl HttpSecurityVtbl = {
252 HttpSecurity_QueryInterface,
253 HttpSecurity_AddRef,
254 HttpSecurity_Release,
255 HttpSecurity_GetWindow,
256 HttpSecurity_OnSecurityProblem
257 };
258
259 static IHttpSecurity http_security = { &HttpSecurityVtbl };
260
261 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
262 {
263 if(IsEqualGUID(&IID_IUnknown, riid)
264 || IsEqualGUID(&IID_IHttpNegotiate, riid)
265 || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
266 *ppv = iface;
267 return S_OK;
268 }
269
270 ok(0, "unexpected call\n");
271 return E_NOINTERFACE;
272 }
273
274 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
275 {
276 return 2;
277 }
278
279 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
280 {
281 return 1;
282 }
283
284 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
285 LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
286 {
287 LPWSTR addl_headers;
288
289 static const WCHAR wszHeaders[] =
290 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t',
291 'i','o','n','/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o',
292 'd','e','d','\r','\n',0};
293
294 CHECK_EXPECT(BeginningTransaction);
295
296 if(binding_test)
297 ok(!strcmp_ww(szURL, binding_urls[tested_protocol]), "szURL != http_url\n");
298 else
299 ok(!strcmp_ww(szURL, http_url), "szURL != http_url\n");
300 ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
301 ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
302 if(pszAdditionalHeaders)
303 {
304 ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");
305 if (http_post_test)
306 {
307 addl_headers = CoTaskMemAlloc(sizeof(wszHeaders));
308 if (!addl_headers)
309 {
310 http_post_test = FALSE;
311 skip("Out of memory\n");
312 return E_OUTOFMEMORY;
313 }
314 memcpy(addl_headers, wszHeaders, sizeof(wszHeaders));
315 *pszAdditionalHeaders = addl_headers;
316 }
317 }
318
319 return S_OK;
320 }
321
322 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
323 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
324 {
325 CHECK_EXPECT(OnResponse);
326
327 ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
328 ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
329 ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
330 ok(pszAdditionalRequestHeaders == NULL, "pszAdditionalHeaders != NULL\n");
331
332 return S_OK;
333 }
334
335 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
336 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
337 {
338 static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};
339
340 CHECK_EXPECT(GetRootSecurityId);
341
342 ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
343 ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
344 ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");
345
346 if(pcbSecurityId) {
347 ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
348 *pcbSecurityId = sizeof(sec_id);
349 }
350
351 if(pbSecurityId)
352 memcpy(pbSecurityId, sec_id, sizeof(sec_id));
353
354 return E_FAIL;
355 }
356
357 static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
358 HttpNegotiate_QueryInterface,
359 HttpNegotiate_AddRef,
360 HttpNegotiate_Release,
361 HttpNegotiate_BeginningTransaction,
362 HttpNegotiate_OnResponse,
363 HttpNegotiate_GetRootSecurityId
364 };
365
366 static IHttpNegotiate2 http_negotiate = { &HttpNegotiateVtbl };
367
368 static HRESULT QueryInterface(REFIID,void**);
369
370 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
371 {
372 return QueryInterface(riid, ppv);
373 }
374
375 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
376 {
377 return 2;
378 }
379
380 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
381 {
382 return 1;
383 }
384
385 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
386 REFIID riid, void **ppv)
387 {
388 if(IsEqualGUID(&IID_IHttpNegotiate, guidService) || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
389 CHECK_EXPECT2(QueryService_HttpNegotiate);
390 return IHttpNegotiate2_QueryInterface(&http_negotiate, riid, ppv);
391 }
392
393 if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
394 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid\n");
395 CHECK_EXPECT(QueryService_InternetProtocol);
396 return E_NOINTERFACE;
397 }
398
399 if(IsEqualGUID(&IID_IHttpSecurity, guidService)) {
400 ok(IsEqualGUID(&IID_IHttpSecurity, riid), "unexpected riid\n");
401 CHECK_EXPECT(QueryService_HttpSecurity);
402 return IHttpSecurity_QueryInterface(&http_security, riid, ppv);
403 }
404
405 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
406 return E_FAIL;
407 }
408
409 static const IServiceProviderVtbl ServiceProviderVtbl = {
410 ServiceProvider_QueryInterface,
411 ServiceProvider_AddRef,
412 ServiceProvider_Release,
413 ServiceProvider_QueryService
414 };
415
416 static IServiceProvider service_provider = { &ServiceProviderVtbl };
417
418 static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
419 {
420 return QueryInterface(riid, ppv);
421 }
422
423 static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
424 {
425 return 2;
426 }
427
428 static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
429 {
430 return 1;
431 }
432
433 static void call_continue(PROTOCOLDATA *protocol_data)
434 {
435 HRESULT hres;
436
437 if(!state) {
438 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST)
439 CLEAR_CALLED(ReportProgress_COOKIE_SENT);
440 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST || tested_protocol == FTP_TEST) {
441 if (http_is_first) {
442 CLEAR_CALLED(ReportProgress_FINDINGRESOURCE);
443 CLEAR_CALLED(ReportProgress_CONNECTING);
444 CLEAR_CALLED(ReportProgress_PROXYDETECTING);
445 }else if(test_redirect) {
446 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
447 }else todo_wine {
448 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
449 /* IE7 does call this */
450 CLEAR_CALLED(ReportProgress_CONNECTING);
451 }
452 }
453 if(tested_protocol == FTP_TEST)
454 todo_wine CHECK_CALLED(ReportProgress_SENDINGREQUEST);
455 else if (tested_protocol != HTTPS_TEST)
456 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
457 if(test_redirect)
458 CHECK_CALLED(ReportProgress_REDIRECTING);
459 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
460 SET_EXPECT(OnResponse);
461 if(tested_protocol == HTTPS_TEST || test_redirect)
462 SET_EXPECT(ReportProgress_ACCEPTRANGES);
463 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
464 if(bindf & BINDF_NEEDFILE)
465 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
466 }
467 }
468
469 SET_EXPECT(ReportData);
470 hres = IInternetProtocol_Continue(async_protocol, protocol_data);
471 ok(hres == S_OK, "Continue failed: %08x\n", hres);
472 if(tested_protocol == FTP_TEST)
473 CLEAR_CALLED(ReportData);
474 else if (! security_problem)
475 CHECK_CALLED(ReportData);
476
477 if (!state) {
478 if (! security_problem)
479 {
480 state = 1;
481 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
482 CHECK_CALLED(OnResponse);
483 if(tested_protocol == HTTPS_TEST)
484 CHECK_CALLED(ReportProgress_ACCEPTRANGES);
485 else if(test_redirect)
486 CLEAR_CALLED(ReportProgress_ACCEPTRANGES);
487 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
488 if(bindf & BINDF_NEEDFILE)
489 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
490 }
491 }
492 else
493 {
494 security_problem = FALSE;
495 SET_EXPECT(ReportProgress_CONNECTING);
496 }
497 }
498 }
499
500 static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
501 {
502 if(tested_protocol == FTP_TEST)
503 CHECK_EXPECT2(Switch);
504 else
505 CHECK_EXPECT(Switch);
506
507 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
508 if(binding_test) {
509 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
510 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
511 pProtocolData->grfFlags, protocoldata.grfFlags );
512 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
513 pProtocolData->dwState, protocoldata.dwState );
514 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
515 pProtocolData->pData, protocoldata.pData );
516 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
517 pProtocolData->cbData, protocoldata.cbData );
518 }
519
520 pdata = pProtocolData;
521
522 if(binding_test) {
523 SetEvent(event_complete);
524 WaitForSingleObject(event_complete2, INFINITE);
525 return S_OK;
526 }if(direct_read) {
527 continue_protdata = *pProtocolData;
528 SetEvent(event_continue);
529 WaitForSingleObject(event_continue_done, INFINITE);
530 }else {
531 call_continue(pProtocolData);
532 SetEvent(event_complete);
533 }
534
535 return S_OK;
536 }
537
538 static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
539 LPCWSTR szStatusText)
540 {
541 static const WCHAR null_guid[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-',
542 '0','0','0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0','0','}',0};
543 static const WCHAR text_plain[] = {'t','e','x','t','/','p','l','a','i','n',0};
544
545 switch(ulStatusCode) {
546 case BINDSTATUS_MIMETYPEAVAILABLE:
547 CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
548 if(tested_protocol != FILE_TEST && !mimefilter_test && (pi & PI_MIMEVERIFICATION)) {
549 if(!short_read || !direct_read)
550 CHECK_CALLED(Read); /* set in Continue */
551 else if(short_read)
552 CHECK_CALLED(Read2); /* set in Read */
553 }
554 ok(szStatusText != NULL, "szStatusText == NULL\n");
555 if(szStatusText) {
556 if(tested_protocol == BIND_TEST)
557 ok(szStatusText == expect_wsz, "unexpected szStatusText\n");
558 else if (http_post_test)
559 ok(lstrlenW(text_plain) <= lstrlenW(szStatusText) &&
560 !memcmp(szStatusText, text_plain, lstrlenW(text_plain)*sizeof(WCHAR)),
561 "szStatusText != text/plain\n");
562 else if(!mimefilter_test)
563 ok(lstrlenW(text_htmlW) <= lstrlenW(szStatusText) &&
564 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
565 "szStatusText != text/html\n");
566 }
567 break;
568 case BINDSTATUS_DIRECTBIND:
569 CHECK_EXPECT2(ReportProgress_DIRECTBIND);
570 ok(szStatusText == NULL, "szStatusText != NULL\n");
571 break;
572 case BINDSTATUS_RAWMIMETYPE:
573 CHECK_EXPECT2(ReportProgress_RAWMIMETYPE);
574 ok(szStatusText != NULL, "szStatusText == NULL\n");
575 if(szStatusText)
576 ok(lstrlenW(szStatusText) < lstrlenW(text_htmlW) ||
577 !memcmp(szStatusText, text_htmlW, lstrlenW(text_htmlW)*sizeof(WCHAR)),
578 "szStatusText != text/html\n");
579 break;
580 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
581 CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
582 ok(szStatusText != NULL, "szStatusText == NULL\n");
583 if(szStatusText) {
584 if(binding_test)
585 ok(!strcmp_ww(szStatusText, expect_wsz), "unexpected szStatusText\n");
586 else if(tested_protocol == FILE_TEST)
587 ok(!strcmp_ww(szStatusText, file_name), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
588 else
589 ok(szStatusText != NULL, "szStatusText == NULL\n");
590 }
591 break;
592 case BINDSTATUS_FINDINGRESOURCE:
593 CHECK_EXPECT2(ReportProgress_FINDINGRESOURCE);
594 ok(szStatusText != NULL, "szStatusText == NULL\n");
595 break;
596 case BINDSTATUS_CONNECTING:
597 CHECK_EXPECT2(ReportProgress_CONNECTING);
598 ok(szStatusText != NULL, "szStatusText == NULL\n");
599 break;
600 case BINDSTATUS_SENDINGREQUEST:
601 CHECK_EXPECT2(ReportProgress_SENDINGREQUEST);
602 if(tested_protocol == FILE_TEST) {
603 ok(szStatusText != NULL, "szStatusText == NULL\n");
604 if(szStatusText)
605 ok(!*szStatusText, "wrong szStatusText\n");
606 }
607 break;
608 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
609 CHECK_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
610 ok(szStatusText != NULL, "szStatusText == NULL\n");
611 if(szStatusText)
612 ok(!strcmp_ww(szStatusText, text_htmlW), "szStatusText != text/html\n");
613 break;
614 case BINDSTATUS_PROTOCOLCLASSID:
615 CHECK_EXPECT(ReportProgress_PROTOCOLCLASSID);
616 ok(szStatusText != NULL, "szStatusText == NULL\n");
617 ok(!strcmp_ww(szStatusText, null_guid), "unexpected classid %s\n", wine_dbgstr_w(szStatusText));
618 break;
619 case BINDSTATUS_COOKIE_SENT:
620 CHECK_EXPECT(ReportProgress_COOKIE_SENT);
621 ok(szStatusText == NULL, "szStatusText != NULL\n");
622 break;
623 case BINDSTATUS_REDIRECTING:
624 CHECK_EXPECT(ReportProgress_REDIRECTING);
625 if(test_redirect)
626 ok(!strcmp_wa(szStatusText, "http://test.winehq.org/hello.html"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
627 else
628 ok(szStatusText == NULL, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
629 break;
630 case BINDSTATUS_ENCODING:
631 CHECK_EXPECT(ReportProgress_ENCODING);
632 ok(!strcmp_wa(szStatusText, "gzip"), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
633 break;
634 case BINDSTATUS_ACCEPTRANGES:
635 CHECK_EXPECT(ReportProgress_ACCEPTRANGES);
636 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
637 break;
638 case BINDSTATUS_PROXYDETECTING:
639 CHECK_EXPECT(ReportProgress_PROXYDETECTING);
640 SET_EXPECT(ReportProgress_CONNECTING);
641 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
642 break;
643 case BINDSTATUS_LOADINGMIMEHANDLER:
644 CHECK_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
645 ok(!szStatusText, "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
646 break;
647 case BINDSTATUS_DECODING:
648 CHECK_EXPECT(ReportProgress_DECODING);
649 ok(!strcmp_ww(szStatusText, gzipW), "szStatusText = %s\n", wine_dbgstr_w(szStatusText));
650 break;
651 default:
652 ok(0, "Unexpected status %d\n", ulStatusCode);
653 };
654
655 return S_OK;
656 }
657
658 static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
659 ULONG ulProgress, ULONG ulProgressMax)
660 {
661 HRESULT hres;
662
663 static int rec_depth;
664 rec_depth++;
665
666 if(!mimefilter_test && tested_protocol == FILE_TEST) {
667 CHECK_EXPECT2(ReportData);
668
669 ok(ulProgress == ulProgressMax, "ulProgress (%d) != ulProgressMax (%d)\n",
670 ulProgress, ulProgressMax);
671 ok(ulProgressMax == 13, "ulProgressMax=%d, expected 13\n", ulProgressMax);
672 /* BSCF_SKIPDRAINDATAFORFILEURLS added in IE8 */
673 ok((grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION)) ||
674 (grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION | BSCF_SKIPDRAINDATAFORFILEURLS)),
675 "grcfBSCF = %08x\n", grfBSCF);
676 }else if(direct_read) {
677 BYTE buf[14096];
678 ULONG read;
679
680 if(!read_report_data && rec_depth == 1) {
681 BOOL reported_all_data = called_ReportData2;
682
683 CHECK_EXPECT2(ReportData);
684
685 if(short_read) {
686 ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE)
687 || grfBSCF == BSCF_FIRSTDATANOTIFICATION, /* < IE8 */
688 "grcfBSCF = %08x\n", grfBSCF);
689 CHECK_CALLED(Read); /* Set in Continue */
690 first_data_notif = FALSE;
691 }else if(first_data_notif) {
692 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
693 first_data_notif = FALSE;
694 }else if(reported_all_data) {
695 ok(grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION),
696 "grcfBSCF = %08x\n", grfBSCF);
697 }else if(!direct_read) {
698 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION, "grcfBSCF = %08x\n", grfBSCF);
699 }
700
701 do {
702 read = 0;
703 if(emulate_prot)
704 SET_EXPECT(Read);
705 else
706 SET_EXPECT(ReportData2);
707 SET_EXPECT(ReportResult);
708 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
709 if(hres == S_OK)
710 ok(read, "read == 0\n");
711 if(reported_all_data) {
712 ok(hres == S_FALSE, "Read failed: %08x, expected S_FALSE\n", hres);
713 }
714 if(emulate_prot)
715 CHECK_CALLED(Read);
716 if(!reported_all_data && called_ReportData2) {
717 if(!emulate_prot)
718 CHECK_CALLED(ReportData2);
719 CHECK_CALLED(ReportResult);
720 ok(hres == S_OK, "Read failed: %08x\n", hres);
721 reported_all_data = TRUE;
722 }else {
723 if(!emulate_prot)
724 CHECK_NOT_CALLED(ReportData2);
725 CHECK_NOT_CALLED(ReportResult);
726 }
727 }while(hres == S_OK);
728 if(hres == S_FALSE)
729 wait_for_switch = FALSE;
730 }else {
731 CHECK_EXPECT(ReportData2);
732
733 ok(grfBSCF & BSCF_LASTDATANOTIFICATION, "grfBSCF = %08x\n", grfBSCF);
734
735 read = 0xdeadbeef;
736 if(emulate_prot)
737 SET_EXPECT(Read2);
738 hres = IInternetProtocol_Read(binding_test ? binding_protocol : async_protocol, expect_pv = buf, sizeof(buf), &read);
739 if(emulate_prot)
740 CHECK_CALLED(Read2);
741 ok(hres == S_FALSE, "Read returned: %08x, expected E_FALSE\n", hres);
742 ok(!read, "read = %d\n", read);
743 }
744 }else if(!binding_test && (tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST
745 || tested_protocol == FTP_TEST)) {
746 if(!(grfBSCF & BSCF_LASTDATANOTIFICATION) || (grfBSCF & BSCF_DATAFULLYAVAILABLE))
747 CHECK_EXPECT(ReportData);
748 else if (http_post_test)
749 ok(ulProgress == 13, "Read %u bytes instead of 13\n", ulProgress);
750
751 ok(ulProgress, "ulProgress == 0\n");
752
753 if(first_data_notif) {
754 ok(grfBSCF == BSCF_FIRSTDATANOTIFICATION
755 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE),
756 "grcfBSCF = %08x\n", grfBSCF);
757 first_data_notif = FALSE;
758 } else {
759 ok(grfBSCF == BSCF_INTERMEDIATEDATANOTIFICATION
760 || grfBSCF == (BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION)
761 || broken(grfBSCF == (BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION)),
762 "grcfBSCF = %08x\n", grfBSCF);
763 }
764
765 if(!(bindf & BINDF_FROMURLMON) &&
766 !(grfBSCF & BSCF_LASTDATANOTIFICATION)) {
767 if(!state) {
768 state = 1;
769 if(http_is_first) {
770 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
771 CHECK_CALLED(ReportProgress_CONNECTING);
772 } else todo_wine {
773 CHECK_NOT_CALLED(ReportProgress_FINDINGRESOURCE);
774 CHECK_NOT_CALLED(ReportProgress_CONNECTING);
775 }
776 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
777 CHECK_CALLED(OnResponse);
778 CHECK_CALLED(ReportProgress_RAWMIMETYPE);
779 }
780 SetEvent(event_complete);
781 }
782 }else if(!read_report_data) {
783 BYTE buf[1000];
784 ULONG read;
785 HRESULT hres;
786
787 CHECK_EXPECT(ReportData);
788
789 if(tested_protocol != BIND_TEST) {
790 do {
791 if(mimefilter_test)
792 SET_EXPECT(MimeFilter_Read);
793 else if(rec_depth > 1)
794 SET_EXPECT(Read2);
795 else
796 SET_EXPECT(Read);
797 hres = IInternetProtocol_Read(binding_protocol, expect_pv=buf, sizeof(buf), &read);
798 if(mimefilter_test)
799 CHECK_CALLED(MimeFilter_Read);
800 else if(rec_depth > 1)
801 CHECK_CALLED(Read2);
802 else
803 CHECK_CALLED(Read);
804 }while(hres == S_OK);
805 }
806 }
807
808 rec_depth--;
809 return S_OK;
810 }
811
812 static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
813 DWORD dwError, LPCWSTR szResult)
814 {
815 CHECK_EXPECT(ReportResult);
816
817 if(tested_protocol == FTP_TEST)
818 ok(hrResult == E_PENDING || hrResult == S_OK, "hrResult = %08x, expected E_PENDING or S_OK\n", hrResult);
819 else
820 ok(hrResult == expect_hrResult, "hrResult = %08x, expected: %08x\n",
821 hrResult, expect_hrResult);
822 if(SUCCEEDED(hrResult) || tested_protocol == FTP_TEST)
823 ok(dwError == ERROR_SUCCESS, "dwError = %d, expected ERROR_SUCCESS\n", dwError);
824 else
825 ok(dwError != ERROR_SUCCESS ||
826 broken(tested_protocol == MK_TEST), /* Win9x, WinME and NT4 */
827 "dwError == ERROR_SUCCESS\n");
828 ok(!szResult, "szResult != NULL\n");
829
830 if(direct_read)
831 SET_EXPECT(ReportData); /* checked after main loop */
832
833 return S_OK;
834 }
835
836 static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
837 ProtocolSink_QueryInterface,
838 ProtocolSink_AddRef,
839 ProtocolSink_Release,
840 ProtocolSink_Switch,
841 ProtocolSink_ReportProgress,
842 ProtocolSink_ReportData,
843 ProtocolSink_ReportResult
844 };
845
846 static IInternetProtocolSink protocol_sink = { &protocol_sink_vtbl };
847
848 static HRESULT WINAPI MimeProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
849 {
850 ok(0, "unexpected call\n");
851 return E_NOTIMPL;
852 }
853
854 static ULONG WINAPI MimeProtocolSink_AddRef(IInternetProtocolSink *iface)
855 {
856 return 2;
857 }
858
859 static ULONG WINAPI MimeProtocolSink_Release(IInternetProtocolSink *iface)
860 {
861 return 1;
862 }
863
864 static HRESULT WINAPI MimeProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
865 {
866 HRESULT hres;
867
868 CHECK_EXPECT(MimeFilter_Switch);
869
870 SET_EXPECT(Switch);
871 hres = IInternetProtocolSink_Switch(filtered_sink, pProtocolData);
872 ok(hres == S_OK, "Switch failed: %08x\n", hres);
873 CHECK_CALLED(Switch);
874
875 return S_OK;
876 }
877
878 static HRESULT WINAPI MimeProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
879 LPCWSTR szStatusText)
880 {
881 CHECK_EXPECT(MimeFilter_ReportProgress);
882 return S_OK;
883 }
884
885 static HRESULT WINAPI MimeProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF,
886 ULONG ulProgress, ULONG ulProgressMax)
887 {
888 DWORD read = 0;
889 BYTE buf[8192];
890 HRESULT hres;
891
892 CHECK_EXPECT(MimeFilter_ReportData);
893
894 if(!filter_state) {
895 SET_EXPECT(Read);
896 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
897 if(tested_protocol == HTTP_TEST)
898 ok(hres == S_OK || hres == E_PENDING || hres == S_FALSE, "Read failed: %08x\n", hres);
899 else
900 ok(hres == S_OK, "Read failed: %08x\n", hres);
901 CHECK_CALLED(Read);
902
903 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
904 hres = IInternetProtocolSink_ReportProgress(filtered_sink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, text_htmlW);
905 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
906 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
907
908 /* FIXME: test BINDSTATUS_CACHEFILENAMEAVAILABLE */
909 }
910
911 if(!read_report_data)
912 SET_EXPECT(ReportData);
913 hres = IInternetProtocolSink_ReportData(filtered_sink, grfBSCF, ulProgress, ulProgressMax);
914 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
915 if(!read_report_data)
916 CHECK_CALLED(ReportData);
917
918 if(!filter_state)
919 filter_state = 1;
920
921 return S_OK;
922 }
923
924 static HRESULT WINAPI MimeProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
925 DWORD dwError, LPCWSTR szResult)
926 {
927 HRESULT hres;
928
929 CHECK_EXPECT(MimeFilter_ReportResult);
930
931 ok(hrResult == S_OK, "hrResult = %08x\n", hrResult);
932 ok(dwError == ERROR_SUCCESS, "dwError = %u\n", dwError);
933 ok(!szResult, "szResult = %s\n", wine_dbgstr_w(szResult));
934
935 SET_EXPECT(ReportResult);
936 hres = IInternetProtocolSink_ReportResult(filtered_sink, hrResult, dwError, szResult);
937 ok(SUCCEEDED(hres), "ReportResult failed: %08x\n", hres);
938 CHECK_CALLED(ReportResult);
939
940 return S_OK;
941 }
942
943 static IInternetProtocolSinkVtbl mime_protocol_sink_vtbl = {
944 MimeProtocolSink_QueryInterface,
945 MimeProtocolSink_AddRef,
946 MimeProtocolSink_Release,
947 MimeProtocolSink_Switch,
948 MimeProtocolSink_ReportProgress,
949 MimeProtocolSink_ReportData,
950 MimeProtocolSink_ReportResult
951 };
952
953 static IInternetProtocolSink mime_protocol_sink = { &mime_protocol_sink_vtbl };
954
955 static HRESULT QueryInterface(REFIID riid, void **ppv)
956 {
957 static const IID IID_undocumented = {0x58DFC7D0,0x5381,0x43E5,{0x9D,0x72,0x4C,0xDD,0xE4,0xCB,0x0F,0x1A}};
958
959 *ppv = NULL;
960
961 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid))
962 *ppv = &protocol_sink;
963 if(IsEqualGUID(&IID_IServiceProvider, riid))
964 *ppv = &service_provider;
965 if(IsEqualGUID(&IID_IUriContainer, riid))
966 return E_NOINTERFACE; /* TODO */
967
968 /* NOTE: IE8 queries for undocumented {58DFC7D0-5381-43E5-9D72-4CDDE4CB0F1A} interface. */
969 if(IsEqualGUID(&IID_undocumented, riid))
970 return E_NOINTERFACE;
971
972 if(*ppv)
973 return S_OK;
974
975 ok(0, "unexpected call %s\n", debugstr_guid(riid));
976 return E_NOINTERFACE;
977 }
978
979 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
980 {
981 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
982 *ppv = iface;
983 return S_OK;
984 }
985 return E_NOINTERFACE;
986 }
987
988 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
989 {
990 return 2;
991 }
992
993 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
994 {
995 return 1;
996 }
997
998 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
999 {
1000 DWORD cbSize;
1001
1002 static const CHAR szPostData[] = "mode=Test";
1003
1004 CHECK_EXPECT(GetBindInfo);
1005
1006 ok(grfBINDF != NULL, "grfBINDF == NULL\n");
1007 ok(pbindinfo != NULL, "pbindinfo == NULL\n");
1008 ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
1009
1010 *grfBINDF = bindf;
1011 if(binding_test)
1012 *grfBINDF |= BINDF_FROMURLMON;
1013 cbSize = pbindinfo->cbSize;
1014 memset(pbindinfo, 0, cbSize);
1015 pbindinfo->cbSize = cbSize;
1016
1017 if (http_post_test)
1018 {
1019 /* Must be GMEM_FIXED, GMEM_MOVABLE does not work properly
1020 * with urlmon on native (Win98 and WinXP) */
1021 U(pbindinfo->stgmedData).hGlobal = GlobalAlloc(GPTR, sizeof(szPostData));
1022 if (!U(pbindinfo->stgmedData).hGlobal)
1023 {
1024 http_post_test = FALSE;
1025 skip("Out of memory\n");
1026 return E_OUTOFMEMORY;
1027 }
1028 lstrcpy((LPSTR)U(pbindinfo->stgmedData).hGlobal, szPostData);
1029 pbindinfo->cbstgmedData = sizeof(szPostData)-1;
1030 pbindinfo->dwBindVerb = BINDVERB_POST;
1031 pbindinfo->stgmedData.tymed = TYMED_HGLOBAL;
1032 }
1033
1034 return S_OK;
1035 }
1036
1037 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType,
1038 LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
1039 {
1040 ok(ppwzStr != NULL, "ppwzStr == NULL\n");
1041 ok(pcElFetched != NULL, "pcElFetched == NULL\n");
1042
1043 switch(ulStringType) {
1044 case BINDSTRING_ACCEPT_MIMES:
1045 CHECK_EXPECT(GetBindString_ACCEPT_MIMES);
1046 ok(cEl == 256, "cEl=%d, expected 256\n", cEl);
1047 if(pcElFetched) {
1048 ok(*pcElFetched == 256, "*pcElFetched=%d, expected 256\n", *pcElFetched);
1049 *pcElFetched = 1;
1050 }
1051 if(ppwzStr) {
1052 *ppwzStr = CoTaskMemAlloc(sizeof(acc_mimeW));
1053 memcpy(*ppwzStr, acc_mimeW, sizeof(acc_mimeW));
1054 }
1055 return S_OK;
1056 case BINDSTRING_USER_AGENT:
1057 CHECK_EXPECT(GetBindString_USER_AGENT);
1058 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1059 if(pcElFetched) {
1060 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1061 *pcElFetched = 1;
1062 }
1063 if(ppwzStr) {
1064 *ppwzStr = CoTaskMemAlloc(sizeof(user_agentW));
1065 memcpy(*ppwzStr, user_agentW, sizeof(user_agentW));
1066 }
1067 return S_OK;
1068 case BINDSTRING_POST_COOKIE:
1069 CHECK_EXPECT(GetBindString_POST_COOKIE);
1070 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1071 if(pcElFetched)
1072 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1073 return S_OK;
1074 case BINDSTRING_URL: {
1075 DWORD size;
1076
1077 CHECK_EXPECT(GetBindString_URL);
1078 ok(cEl == 1, "cEl=%d, expected 1\n", cEl);
1079 ok(*pcElFetched == 0, "*pcElFetch=%d, expectd 0\n", *pcElFetched);
1080 *pcElFetched = 1;
1081
1082 size = (lstrlenW(binding_urls[tested_protocol])+1)*sizeof(WCHAR);
1083 *ppwzStr = CoTaskMemAlloc(size);
1084 memcpy(*ppwzStr, binding_urls[tested_protocol], size);
1085 return S_OK;
1086 }
1087 default:
1088 ok(0, "unexpected call\n");
1089 }
1090
1091 return E_NOTIMPL;
1092 }
1093
1094 static IInternetBindInfoVtbl bind_info_vtbl = {
1095 BindInfo_QueryInterface,
1096 BindInfo_AddRef,
1097 BindInfo_Release,
1098 BindInfo_GetBindInfo,
1099 BindInfo_GetBindString
1100 };
1101
1102 static IInternetBindInfo bind_info = { &bind_info_vtbl };
1103
1104 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
1105 REFIID riid, void **ppv)
1106 {
1107 ok(0, "unexpected call\n");
1108 return E_NOINTERFACE;
1109 }
1110
1111 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
1112 {
1113 return 2;
1114 }
1115
1116 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
1117 {
1118 return 1;
1119 }
1120
1121 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
1122 {
1123 CHECK_EXPECT(SetPriority);
1124 ok(nPriority == ex_priority, "nPriority=%d\n", nPriority);
1125 return S_OK;
1126 }
1127
1128 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
1129 {
1130 ok(0, "unexpected call\n");
1131 return E_NOTIMPL;
1132 }
1133
1134
1135 static const IInternetPriorityVtbl InternetPriorityVtbl = {
1136 InternetPriority_QueryInterface,
1137 InternetPriority_AddRef,
1138 InternetPriority_Release,
1139 InternetPriority_SetPriority,
1140 InternetPriority_GetPriority
1141 };
1142
1143 static IInternetPriority InternetPriority = { &InternetPriorityVtbl };
1144
1145 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
1146 {
1147 return 2;
1148 }
1149
1150 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
1151 {
1152 return 1;
1153 }
1154
1155 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
1156 DWORD dwOptions)
1157 {
1158 ok(0, "unexpected call\n");
1159 return E_NOTIMPL;
1160 }
1161
1162 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
1163 {
1164 ok(0, "unexpected call\n");
1165 return E_NOTIMPL;
1166 }
1167
1168 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
1169 {
1170 ok(0, "unexpected call\n");
1171 return E_NOTIMPL;
1172 }
1173
1174 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
1175 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1176 {
1177 ok(0, "unexpected call\n");
1178 return E_NOTIMPL;
1179 }
1180
1181 static HRESULT WINAPI ProtocolEmul_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1182 {
1183 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1184 *ppv = iface;
1185 return S_OK;
1186 }
1187
1188 if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
1189 trace("IID_IInternetProtocolEx not supported\n");
1190 *ppv = NULL;
1191 return E_NOINTERFACE;
1192 }
1193
1194 if(IsEqualGUID(&IID_IInternetPriority, riid)) {
1195 *ppv = &InternetPriority;
1196 return S_OK;
1197 }
1198
1199 if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
1200 CHECK_EXPECT(QueryInterface_IWinInetInfo);
1201 *ppv = NULL;
1202 return E_NOINTERFACE;
1203 }
1204
1205 if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1206 CHECK_EXPECT(QueryInterface_IWinInetHttpInfo);
1207 *ppv = NULL;
1208 return E_NOINTERFACE;
1209 }
1210
1211 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1212 *ppv = NULL;
1213 return E_NOINTERFACE;
1214 }
1215
1216 static DWORD WINAPI thread_proc(PVOID arg)
1217 {
1218 HRESULT hres;
1219
1220 memset(&protocoldata, -1, sizeof(protocoldata));
1221
1222 prot_state = 0;
1223
1224 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
1225 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1226 BINDSTATUS_FINDINGRESOURCE, hostW);
1227 CHECK_CALLED(ReportProgress_FINDINGRESOURCE);
1228 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1229
1230 SET_EXPECT(ReportProgress_CONNECTING);
1231 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1232 BINDSTATUS_CONNECTING, winehq_ipW);
1233 CHECK_CALLED(ReportProgress_CONNECTING);
1234 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1235
1236 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1237 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1238 BINDSTATUS_SENDINGREQUEST, NULL);
1239 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1240 ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
1241
1242 prot_state = 1;
1243 SET_EXPECT(Switch);
1244 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1245 CHECK_CALLED(Switch);
1246 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1247
1248 if(!short_read) {
1249 prot_state = 2;
1250 if(mimefilter_test)
1251 SET_EXPECT(MimeFilter_Switch);
1252 else
1253 SET_EXPECT(Switch);
1254 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1255 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1256 if(mimefilter_test)
1257 CHECK_CALLED(MimeFilter_Switch);
1258 else
1259 CHECK_CALLED(Switch);
1260
1261 prot_state = 2;
1262 if(mimefilter_test)
1263 SET_EXPECT(MimeFilter_Switch);
1264 else
1265 SET_EXPECT(Switch);
1266 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1267 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1268 if(mimefilter_test)
1269 CHECK_CALLED(MimeFilter_Switch);
1270 else
1271 CHECK_CALLED(Switch);
1272
1273 prot_state = 3;
1274 if(mimefilter_test)
1275 SET_EXPECT(MimeFilter_Switch);
1276 else
1277 SET_EXPECT(Switch);
1278 hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
1279 ok(hres == S_OK, "Switch failed: %08x\n", hres);
1280 if(mimefilter_test)
1281 CHECK_CALLED(MimeFilter_Switch);
1282 else
1283 CHECK_CALLED(Switch);
1284 }
1285
1286 SetEvent(event_complete);
1287
1288 return 0;
1289 }
1290
1291 static HRESULT WINAPI ProtocolEmul_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1292 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1293 DWORD grfPI, HANDLE_PTR dwReserved)
1294 {
1295 BINDINFO bindinfo, exp_bindinfo;
1296 DWORD cbindf = 0;
1297 HRESULT hres;
1298
1299 CHECK_EXPECT(Start);
1300
1301 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1302 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1303 ok(pOIProtSink != &protocol_sink, "unexpected pOIProtSink\n");
1304 ok(pOIBindInfo != &bind_info, "unexpected pOIBindInfo\n");
1305 ok(!grfPI, "grfPI = %x\n", grfPI);
1306 ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
1307
1308 if(binding_test)
1309 ok(pOIProtSink == binding_sink, "pOIProtSink != binding_sink\n");
1310
1311 memset(&bindinfo, 0, sizeof(bindinfo));
1312 bindinfo.cbSize = sizeof(bindinfo);
1313 memcpy(&exp_bindinfo, &bindinfo, sizeof(bindinfo));
1314 SET_EXPECT(GetBindInfo);
1315 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1316 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1317 CHECK_CALLED(GetBindInfo);
1318 ok(cbindf == (bindf|BINDF_FROMURLMON), "bindf = %x, expected %x\n",
1319 cbindf, (bindf|BINDF_FROMURLMON));
1320 ok(!memcmp(&exp_bindinfo, &bindinfo, sizeof(bindinfo)), "unexpected bindinfo\n");
1321 ReleaseBindInfo(&bindinfo);
1322
1323 SET_EXPECT(ReportProgress_SENDINGREQUEST);
1324 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, emptyW);
1325 ok(hres == S_OK, "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
1326 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
1327
1328 if(tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST) {
1329 IServiceProvider *service_provider;
1330 IHttpNegotiate *http_negotiate;
1331 IHttpNegotiate2 *http_negotiate2;
1332 LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
1333 LPWSTR additional_headers = NULL;
1334 BYTE sec_id[100];
1335 DWORD fetched = 0, size = 100;
1336 DWORD tid;
1337
1338 SET_EXPECT(GetBindString_USER_AGENT);
1339 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
1340 &ua, 1, &fetched);
1341 CHECK_CALLED(GetBindString_USER_AGENT);
1342 ok(hres == S_OK, "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
1343 ok(fetched == 1, "fetched = %d, expected 254\n", fetched);
1344 ok(ua != NULL, "ua = %p\n", ua);
1345 ok(!strcmp_ww(ua, user_agentW), "unexpected user agent %s\n", wine_dbgstr_w(ua));
1346 CoTaskMemFree(ua);
1347
1348 fetched = 256;
1349 SET_EXPECT(GetBindString_ACCEPT_MIMES);
1350 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
1351 accept_mimes, 256, &fetched);
1352 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
1353
1354 ok(hres == S_OK,
1355 "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
1356 ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
1357 ok(!strcmp_ww(acc_mimeW, accept_mimes[0]), "unexpected mimes %s\n", wine_dbgstr_w(accept_mimes[0]));
1358 CoTaskMemFree(accept_mimes[0]);
1359
1360 hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
1361 (void**)&service_provider);
1362 ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
1363
1364 SET_EXPECT(QueryService_HttpNegotiate);
1365 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1366 &IID_IHttpNegotiate, (void**)&http_negotiate);
1367 CHECK_CALLED(QueryService_HttpNegotiate);
1368 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1369
1370 SET_EXPECT(BeginningTransaction);
1371 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, binding_urls[tested_protocol],
1372 NULL, 0, &additional_headers);
1373 CHECK_CALLED(BeginningTransaction);
1374 IHttpNegotiate_Release(http_negotiate);
1375 ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
1376 ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);
1377
1378 SET_EXPECT(QueryService_HttpNegotiate);
1379 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
1380 &IID_IHttpNegotiate2, (void**)&http_negotiate2);
1381 CHECK_CALLED(QueryService_HttpNegotiate);
1382 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1383
1384 size = 512;
1385 SET_EXPECT(GetRootSecurityId);
1386 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
1387 CHECK_CALLED(GetRootSecurityId);
1388 IHttpNegotiate2_Release(http_negotiate2);
1389 ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
1390 ok(size == 13, "size=%d\n", size);
1391
1392 IServiceProvider_Release(service_provider);
1393
1394 CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
1395
1396 return S_OK;
1397 }
1398
1399 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
1400 hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
1401 BINDSTATUS_CACHEFILENAMEAVAILABLE, expect_wsz = emptyW);
1402 ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
1403 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
1404
1405 if(mimefilter_test) {
1406 SET_EXPECT(MimeFilter_CreateInstance);
1407 SET_EXPECT(MimeFilter_Start);
1408 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1409 }
1410 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1411 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE,
1412 mimefilter_test ? gzipW : (expect_wsz = text_htmlW));
1413 ok(hres == S_OK,
1414 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
1415 if(mimefilter_test) {
1416 CHECK_CALLED(MimeFilter_CreateInstance);
1417 CHECK_CALLED(MimeFilter_Start);
1418 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1419 todo_wine CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1420 }else {
1421 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1422 }
1423
1424 if(mimefilter_test)
1425 SET_EXPECT(MimeFilter_ReportData);
1426 else
1427 SET_EXPECT(ReportData);
1428 hres = IInternetProtocolSink_ReportData(pOIProtSink,
1429 BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
1430 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1431 if(mimefilter_test)
1432 CHECK_CALLED(MimeFilter_ReportData);
1433 else
1434 CHECK_CALLED(ReportData);
1435
1436 if(tested_protocol == BIND_TEST) {
1437 hres = IInternetProtocol_Terminate(binding_protocol, 0);
1438 ok(hres == E_FAIL, "Termiante failed: %08x\n", hres);
1439 }
1440
1441 if(mimefilter_test)
1442 SET_EXPECT(MimeFilter_ReportResult);
1443 else
1444 SET_EXPECT(ReportResult);
1445 hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
1446 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1447 if(mimefilter_test)
1448 CHECK_CALLED(MimeFilter_ReportResult);
1449 else
1450 CHECK_CALLED(ReportResult);
1451
1452 return S_OK;
1453 }
1454
1455 static HRESULT WINAPI ProtocolEmul_Continue(IInternetProtocol *iface,
1456 PROTOCOLDATA *pProtocolData)
1457 {
1458 DWORD bscf = 0, pr;
1459 HRESULT hres;
1460
1461 CHECK_EXPECT(Continue);
1462
1463 ok(pProtocolData != NULL, "pProtocolData == NULL\n");
1464 if(!pProtocolData || tested_protocol == BIND_TEST)
1465 return S_OK;
1466 if(binding_test) {
1467 ok(pProtocolData != &protocoldata, "pProtocolData == &protocoldata\n");
1468 ok(pProtocolData->grfFlags == protocoldata.grfFlags, "grfFlags wrong %x/%x\n",
1469 pProtocolData->grfFlags, protocoldata.grfFlags );
1470 ok(pProtocolData->dwState == protocoldata.dwState, "dwState wrong %x/%x\n",
1471 pProtocolData->dwState, protocoldata.dwState );
1472 ok(pProtocolData->pData == protocoldata.pData, "pData wrong %p/%p\n",
1473 pProtocolData->pData, protocoldata.pData );
1474 ok(pProtocolData->cbData == protocoldata.cbData, "cbData wrong %x/%x\n",
1475 pProtocolData->cbData, protocoldata.cbData );
1476 }
1477
1478 switch(prot_state) {
1479 case 1: {
1480 IServiceProvider *service_provider;
1481 IHttpNegotiate *http_negotiate;
1482 static WCHAR header[] = {'?',0};
1483
1484 hres = IInternetProtocolSink_QueryInterface(binding_sink, &IID_IServiceProvider,
1485 (void**)&service_provider);
1486 ok(hres == S_OK, "Could not get IServiceProvicder\n");
1487
1488 SET_EXPECT(QueryService_HttpNegotiate);
1489 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
1490 &IID_IHttpNegotiate, (void**)&http_negotiate);
1491 IServiceProvider_Release(service_provider);
1492 CHECK_CALLED(QueryService_HttpNegotiate);
1493 ok(hres == S_OK, "Could not get IHttpNegotiate\n");
1494
1495 SET_EXPECT(OnResponse);
1496 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
1497 IHttpNegotiate_Release(http_negotiate);
1498 CHECK_CALLED(OnResponse);
1499 IHttpNegotiate_Release(http_negotiate);
1500 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
1501
1502 if(mimefilter_test) {
1503 SET_EXPECT(MimeFilter_CreateInstance);
1504 SET_EXPECT(MimeFilter_Start);
1505 SET_EXPECT(ReportProgress_LOADINGMIMEHANDLER);
1506 }else if(!(pi & PI_MIMEVERIFICATION)) {
1507 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1508 }
1509 hres = IInternetProtocolSink_ReportProgress(binding_sink,
1510 BINDSTATUS_MIMETYPEAVAILABLE, mimefilter_test ? gzipW : text_htmlW);
1511 if(mimefilter_test) {
1512 CHECK_CALLED(MimeFilter_CreateInstance);
1513 CHECK_CALLED(MimeFilter_Start);
1514 CHECK_CALLED(ReportProgress_LOADINGMIMEHANDLER);
1515 }else if(!(pi & PI_MIMEVERIFICATION)) {
1516 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1517 }
1518 ok(hres == S_OK,
1519 "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1520
1521 bscf |= BSCF_FIRSTDATANOTIFICATION;
1522 break;
1523 }
1524 case 2:
1525 case 3:
1526 bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
1527 break;
1528 }
1529
1530 pr = prot_read;
1531 if(mimefilter_test) {
1532 SET_EXPECT(MimeFilter_ReportData);
1533 }else if(pi & PI_MIMEVERIFICATION) {
1534 if(pr < 200)
1535 SET_EXPECT(Read); /* checked in ReportData for short_read */
1536 if(pr == 200) {
1537 if(!mimefilter_test)
1538 SET_EXPECT(Read); /* checked in BINDSTATUS_MIMETYPEAVAILABLE or ReportData */
1539 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1540 }
1541 if(pr >= 200)
1542 SET_EXPECT(ReportData);
1543 }else {
1544 SET_EXPECT(ReportData);
1545 }
1546
1547 hres = IInternetProtocolSink_ReportData(binding_sink, bscf, pr, 400);
1548 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1549
1550 if(mimefilter_test) {
1551 SET_EXPECT(MimeFilter_ReportData);
1552 }else if(pi & PI_MIMEVERIFICATION) {
1553 if(!short_read && pr < 200)
1554 CHECK_CALLED(Read);
1555 if(pr == 200) {
1556 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1557 }
1558 }else {
1559 CHECK_CALLED(ReportData);
1560 }
1561
1562 if(prot_state == 3)
1563 prot_state = 4;
1564
1565 return S_OK;
1566 }
1567
1568 static HRESULT WINAPI ProtocolEmul_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1569 {
1570 CHECK_EXPECT(Terminate);
1571 ok(!dwOptions, "dwOptions=%d\n", dwOptions);
1572 return S_OK;
1573 }
1574
1575 static HRESULT WINAPI ProtocolEmul_Read(IInternetProtocol *iface, void *pv,
1576 ULONG cb, ULONG *pcbRead)
1577 {
1578 if(read_report_data)
1579 CHECK_EXPECT2(Read2);
1580
1581 if(mimefilter_test || short_read) {
1582 if(!read_report_data)
1583 CHECK_EXPECT2(Read);
1584 }else if((pi & PI_MIMEVERIFICATION)) {
1585 if(!read_report_data)
1586 CHECK_EXPECT2(Read);
1587
1588 if(prot_read < 300) {
1589 ok(pv != expect_pv, "pv == expect_pv\n");
1590 if(prot_read < 300)
1591 ok(cb == 2048-prot_read, "cb=%d\n", cb);
1592 else
1593 ok(cb == 700, "cb=%d\n", cb);
1594 }else {
1595 ok(expect_pv <= pv && (BYTE*)pv < (BYTE*)expect_pv + cb, "pv != expect_pv\n");
1596 }
1597 }else {
1598 if(!read_report_data)
1599 CHECK_EXPECT(Read);
1600
1601 ok(pv == expect_pv, "pv != expect_pv\n");
1602 ok(cb == 1000, "cb=%d\n", cb);
1603 ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1604 }
1605 ok(pcbRead != NULL, "pcbRead == NULL\n");
1606
1607 if(prot_state == 3 || (short_read && prot_state != 4)) {
1608 HRESULT hres;
1609
1610 prot_state = 4;
1611 if(short_read) {
1612 SET_EXPECT(Read2); /* checked in BINDSTATUS_MIMETYPEAVAILABLE */
1613 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
1614 }
1615 if(mimefilter_test)
1616 SET_EXPECT(MimeFilter_ReportData);
1617 else if(direct_read)
1618 SET_EXPECT(ReportData2);
1619 read_report_data++;
1620 hres = IInternetProtocolSink_ReportData(binding_sink,
1621 BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 0, 0);
1622 read_report_data--;
1623 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
1624 if(short_read)
1625 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
1626 if(mimefilter_test)
1627 CHECK_CALLED(MimeFilter_ReportData);
1628 else if(direct_read)
1629 CHECK_CALLED(ReportData2);
1630
1631 if(mimefilter_test)
1632 SET_EXPECT(MimeFilter_ReportResult);
1633 else
1634 SET_EXPECT(ReportResult);
1635 hres = IInternetProtocolSink_ReportResult(binding_sink, S_OK, ERROR_SUCCESS, NULL);
1636 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
1637 if(mimefilter_test)
1638 CHECK_CALLED(MimeFilter_ReportResult);
1639 else
1640 CHECK_CALLED(ReportResult);
1641
1642 memset(pv, 'x', 100);
1643 prot_read += *pcbRead = 100;
1644 return S_OK;
1645 }if(prot_state == 4) {
1646 *pcbRead = 0;
1647 return S_FALSE;
1648 }
1649
1650 if((async_read_pending = !async_read_pending)) {
1651 *pcbRead = 0;
1652 return tested_protocol == HTTP_TEST || tested_protocol == HTTPS_TEST ? E_PENDING : S_FALSE;
1653 }
1654
1655 memset(pv, 'x', 100);
1656 prot_read += *pcbRead = 100;
1657 return S_OK;
1658 }
1659
1660 static HRESULT WINAPI ProtocolEmul_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1661 {
1662 CHECK_EXPECT(LockRequest);
1663 ok(dwOptions == 0, "dwOptions=%x\n", dwOptions);
1664 return S_OK;
1665 }
1666
1667 static HRESULT WINAPI ProtocolEmul_UnlockRequest(IInternetProtocol *iface)
1668 {
1669 CHECK_EXPECT(UnlockRequest);
1670 return S_OK;
1671 }
1672
1673 static const IInternetProtocolVtbl ProtocolVtbl = {
1674 ProtocolEmul_QueryInterface,
1675 Protocol_AddRef,
1676 Protocol_Release,
1677 ProtocolEmul_Start,
1678 ProtocolEmul_Continue,
1679 Protocol_Abort,
1680 ProtocolEmul_Terminate,
1681 Protocol_Suspend,
1682 Protocol_Resume,
1683 ProtocolEmul_Read,
1684 Protocol_Seek,
1685 ProtocolEmul_LockRequest,
1686 ProtocolEmul_UnlockRequest
1687 };
1688
1689 static IInternetProtocol Protocol = { &ProtocolVtbl };
1690
1691 static HRESULT WINAPI MimeProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
1692 {
1693 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
1694 *ppv = iface;
1695 return S_OK;
1696 }
1697
1698 if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
1699 *ppv = &mime_protocol_sink;
1700 return S_OK;
1701 }
1702
1703 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1704 *ppv = NULL;
1705 return E_NOINTERFACE;
1706 }
1707
1708 static HRESULT WINAPI MimeProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
1709 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
1710 DWORD grfPI, HANDLE_PTR dwReserved)
1711 {
1712 PROTOCOLFILTERDATA *data;
1713 LPOLESTR url_str = NULL;
1714 DWORD fetched = 0;
1715 BINDINFO bindinfo;
1716 DWORD cbindf = 0;
1717 HRESULT hres;
1718
1719 CHECK_EXPECT(MimeFilter_Start);
1720
1721 ok(!strcmp_ww(szUrl, gzipW), "wrong url %s\n", wine_dbgstr_w(szUrl));
1722 ok(grfPI == (PI_FILTER_MODE|PI_FORCE_ASYNC), "grfPI=%x, expected PI_FILTER_MODE|PI_FORCE_ASYNC\n", grfPI);
1723 ok(dwReserved, "dwReserved == 0\n");
1724 ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
1725 ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
1726
1727 if(binding_test) {
1728 ok(pOIProtSink != binding_sink, "pOIProtSink == protocol_sink\n");
1729 ok(pOIBindInfo == prot_bind_info, "pOIBindInfo != bind_info\n");
1730 }else {
1731 ok(pOIProtSink == &protocol_sink, "pOIProtSink != protocol_sink\n");
1732 ok(pOIBindInfo == &bind_info, "pOIBindInfo != bind_info\n");
1733 }
1734
1735 data = (void*)dwReserved;
1736 ok(data->cbSize == sizeof(*data), "data->cbSize = %d\n", data->cbSize);
1737 ok(!data->pProtocolSink, "data->pProtocolSink != NULL\n");
1738 ok(data->pProtocol != NULL, "data->pProtocol == NULL\n");
1739 ok(!data->pUnk, "data->pUnk != NULL\n");
1740 ok(!data->dwFilterFlags, "data->dwProtocolFlags = %x\n", data->dwFilterFlags);
1741 if(binding_test) {
1742 IInternetProtocolSink *prot_sink;
1743
1744 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocolSink, (void**)&prot_sink);
1745 ok(prot_sink == pOIProtSink, "QI(data->pProtocol, IID_IInternetProtocolSink) != pOIProtSink\n");
1746 IInternetProtocolSink_Release(prot_sink);
1747
1748 ok(data->pProtocol != binding_protocol, "data->pProtocol == binding_protocol\n");
1749
1750 filtered_protocol = data->pProtocol;
1751 IInternetProtocol_AddRef(filtered_protocol);
1752 }else {
1753 IInternetProtocol *prot;
1754
1755 IInternetProtocol_QueryInterface(data->pProtocol, &IID_IInternetProtocol, (void**)&prot);
1756 ok(prot == async_protocol, "QI(data->pProtocol, IID_IInternetProtocol) != async_protocol\n");
1757 IInternetProtocol_Release(prot);
1758
1759 ok(data->pProtocol != async_protocol, "data->pProtocol == async_protocol\n");
1760 }
1761
1762 filtered_sink = pOIProtSink;
1763
1764 SET_EXPECT(ReportProgress_DECODING);
1765 hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DECODING, gzipW);
1766 ok(hres == S_OK, "ReportProgress(BINDSTATUS_DECODING) failed: %08x\n", hres);
1767 CHECK_CALLED(ReportProgress_DECODING);
1768
1769 SET_EXPECT(GetBindInfo);
1770 memset(&bindinfo, 0, sizeof(bindinfo));
1771 bindinfo.cbSize = sizeof(bindinfo);
1772 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &cbindf, &bindinfo);
1773 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1774 ok(cbindf == (bindf|BINDF_FROMURLMON), "cbindf = %x, expected %x\n", cbindf, bindf);
1775 CHECK_CALLED(GetBindInfo);
1776
1777 SET_EXPECT(GetBindString_URL);
1778 hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_URL, &url_str, 1, &fetched);
1779 ok(hres == S_OK, "GetBindString(BINDSTRING_URL) failed: %08x\n", hres);
1780 ok(fetched == 1, "fetched = %d\n", fetched);
1781 ok(!strcmp_ww(url_str, binding_urls[tested_protocol]), "wrong url_str %s\n", wine_dbgstr_w(url_str));
1782 CoTaskMemFree(url_str);
1783 CHECK_CALLED(GetBindString_URL);
1784
1785 return S_OK;
1786 }
1787
1788 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
1789 PROTOCOLDATA *pProtocolData)
1790 {
1791 CHECK_EXPECT(MimeFilter_Continue);
1792 return E_NOTIMPL;
1793 }
1794
1795 static HRESULT WINAPI MimeProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
1796 {
1797 HRESULT hres;
1798
1799 CHECK_EXPECT(MimeFilter_Terminate);
1800
1801 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1802
1803 SET_EXPECT(Terminate);
1804 hres = IInternetProtocol_Terminate(filtered_protocol, dwOptions);
1805 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
1806 CHECK_CALLED(Terminate);
1807
1808 return S_OK;
1809 }
1810
1811 static HRESULT WINAPI MimeProtocol_Read(IInternetProtocol *iface, void *pv,
1812 ULONG cb, ULONG *pcbRead)
1813 {
1814 BYTE buf[2096];
1815 DWORD read = 0;
1816 HRESULT hres;
1817
1818 CHECK_EXPECT(MimeFilter_Read);
1819
1820 ok(pv != NULL, "pv == NULL\n");
1821 ok(cb != 0, "cb == 0\n");
1822 ok(pcbRead != NULL, "pcbRead == NULL\n");
1823
1824 if(read_report_data)
1825 SET_EXPECT(Read2);
1826 else
1827 SET_EXPECT(Read);
1828 hres = IInternetProtocol_Read(filtered_protocol, buf, sizeof(buf), &read);
1829 ok(hres == S_OK || hres == S_FALSE || hres == E_PENDING, "Read failed: %08x\n", hres);
1830 if(read_report_data)
1831 CHECK_CALLED(Read2);
1832 else
1833 CHECK_CALLED(Read);
1834
1835 if(pcbRead) {
1836 ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
1837 *pcbRead = read;
1838 }
1839
1840 memset(pv, 'x', read);
1841 return hres;
1842 }
1843
1844 static HRESULT WINAPI MimeProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
1845 {
1846 HRESULT hres;
1847
1848 CHECK_EXPECT(MimeFilter_LockRequest);
1849
1850 ok(!dwOptions, "dwOptions = %x\n", dwOptions);
1851
1852 SET_EXPECT(LockRequest);
1853 hres = IInternetProtocol_LockRequest(filtered_protocol, dwOptions);
1854 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
1855 CHECK_CALLED(LockRequest);
1856
1857 return S_OK;
1858 }
1859
1860 static HRESULT WINAPI MimeProtocol_UnlockRequest(IInternetProtocol *iface)
1861 {
1862 HRESULT hres;
1863
1864 CHECK_EXPECT(MimeFilter_UnlockRequest);
1865
1866 SET_EXPECT(UnlockRequest);
1867 hres = IInternetProtocol_UnlockRequest(filtered_protocol);
1868 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
1869 CHECK_CALLED(UnlockRequest);
1870
1871 return S_OK;
1872 }
1873
1874 static const IInternetProtocolVtbl MimeProtocolVtbl = {
1875 MimeProtocol_QueryInterface,
1876 Protocol_AddRef,
1877 Protocol_Release,
1878 MimeProtocol_Start,
1879 Protocol_Continue,
1880 Protocol_Abort,
1881 MimeProtocol_Terminate,
1882 Protocol_Suspend,
1883 Protocol_Resume,
1884 MimeProtocol_Read,
1885 Protocol_Seek,
1886 MimeProtocol_LockRequest,
1887 MimeProtocol_UnlockRequest
1888 };
1889
1890 static IInternetProtocol MimeProtocol = { &MimeProtocolVtbl };
1891
1892 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1893 {
1894 ok(0, "unexpected call\n");
1895 return E_NOINTERFACE;
1896 }
1897
1898 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1899 {
1900 return 2;
1901 }
1902
1903 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1904 {
1905 return 1;
1906 }
1907
1908 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1909 REFIID riid, void **ppv)
1910 {
1911 CHECK_EXPECT(CreateInstance);
1912
1913 ok(pOuter == (IUnknown*)prot_bind_info, "pOuter != protocol_unk\n");
1914 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
1915 ok(ppv != NULL, "ppv == NULL\n");
1916
1917 *ppv = &Protocol;
1918 return S_OK;
1919 }
1920
1921 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1922 {
1923 ok(0, "unexpected call\n");
1924 return S_OK;
1925 }
1926
1927 static const IClassFactoryVtbl ClassFactoryVtbl = {
1928 ClassFactory_QueryInterface,
1929 ClassFactory_AddRef,
1930 ClassFactory_Release,
1931 ClassFactory_CreateInstance,
1932 ClassFactory_LockServer
1933 };
1934
1935 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
1936
1937 static HRESULT WINAPI MimeFilter_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1938 {
1939 CHECK_EXPECT(MimeFilter_CreateInstance);
1940
1941 ok(!outer, "outer = %p\n", outer);
1942 ok(IsEqualGUID(&IID_IInternetProtocol, riid), "unexpected riid %s\n", debugstr_guid(riid));
1943
1944 *ppv = &MimeProtocol;
1945 return S_OK;
1946 }
1947
1948 static const IClassFactoryVtbl MimeFilterCFVtbl = {
1949 ClassFactory_QueryInterface,
1950 ClassFactory_AddRef,
1951 ClassFactory_Release,
1952 MimeFilter_CreateInstance,
1953 ClassFactory_LockServer
1954 };
1955
1956 static IClassFactory mimefilter_cf = { &MimeFilterCFVtbl };
1957
1958 #define TEST_BINDING 0x01
1959 #define TEST_FILTER 0x02
1960 #define TEST_FIRST_HTTP 0x04
1961 #define TEST_DIRECT_READ 0x08
1962 #define TEST_POST 0x10
1963 #define TEST_EMULATEPROT 0x20
1964 #define TEST_SHORT_READ 0x40
1965 #define TEST_REDIRECT 0x80
1966
1967 static void init_test(int prot, DWORD flags)
1968 {
1969 tested_protocol = prot;
1970 binding_test = (flags & TEST_BINDING) != 0;
1971 first_data_notif = TRUE;
1972 prot_read = 0;
1973 prot_state = 0;
1974 async_read_pending = TRUE;
1975 mimefilter_test = (flags & TEST_FILTER) != 0;
1976 filter_state = 0;
1977 ResetEvent(event_complete);
1978 ResetEvent(event_complete2);
1979 ResetEvent(event_continue);
1980 ResetEvent(event_continue_done);
1981 async_protocol = binding_protocol = filtered_protocol = NULL;
1982 filtered_sink = NULL;
1983 http_is_first = (flags & TEST_FIRST_HTTP) != 0;
1984 first_data_notif = TRUE;
1985 state = 0;
1986 direct_read = (flags & TEST_DIRECT_READ) != 0;
1987 http_post_test = (flags & TEST_POST) != 0;
1988 emulate_prot = (flags & TEST_EMULATEPROT) != 0;
1989 wait_for_switch = TRUE;
1990 short_read = (flags & TEST_SHORT_READ) != 0;
1991 test_redirect = (flags & TEST_REDIRECT) != 0;
1992 }
1993
1994 static void test_priority(IInternetProtocol *protocol)
1995 {
1996 IInternetPriority *priority;
1997 LONG pr;
1998 HRESULT hres;
1999
2000 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority,
2001 (void**)&priority);
2002 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2003 if(FAILED(hres))
2004 return;
2005
2006 hres = IInternetPriority_GetPriority(priority, &pr);
2007 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2008 ok(pr == 0, "pr=%d, expected 0\n", pr);
2009
2010 hres = IInternetPriority_SetPriority(priority, 1);
2011 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2012
2013 hres = IInternetPriority_GetPriority(priority, &pr);
2014 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2015 ok(pr == 1, "pr=%d, expected 1\n", pr);
2016
2017 IInternetPriority_Release(priority);
2018 }
2019
2020 static BOOL file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL is_first)
2021 {
2022 HRESULT hres;
2023
2024 SET_EXPECT(GetBindInfo);
2025 if(!(bindf & BINDF_FROMURLMON))
2026 SET_EXPECT(ReportProgress_DIRECTBIND);
2027 if(is_first) {
2028 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2029 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2030 if(bindf & BINDF_FROMURLMON)
2031 SET_EXPECT(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2032 else
2033 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2034 }
2035 SET_EXPECT(ReportData);
2036 if(is_first)
2037 SET_EXPECT(ReportResult);
2038
2039 expect_hrResult = S_OK;
2040
2041 hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
2042 if(hres == INET_E_RESOURCE_NOT_FOUND) {
2043 win_skip("Start failed\n");
2044 return FALSE;
2045 }
2046 ok(hres == S_OK, "Start failed: %08x\n", hres);
2047
2048 CHECK_CALLED(GetBindInfo);
2049 if(!(bindf & BINDF_FROMURLMON))
2050 CHECK_CALLED(ReportProgress_DIRECTBIND);
2051 if(is_first) {
2052 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2053 CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
2054 if(bindf & BINDF_FROMURLMON)
2055 CHECK_CALLED(ReportProgress_VERIFIEDMIMETYPEAVAILABLE);
2056 else
2057 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2058 }
2059 CHECK_CALLED(ReportData);
2060 if(is_first)
2061 CHECK_CALLED(ReportResult);
2062
2063 return TRUE;
2064 }
2065
2066 static void test_file_protocol_url(LPCWSTR url)
2067 {
2068 IInternetProtocolInfo *protocol_info;
2069 IUnknown *unk;
2070 IClassFactory *factory;
2071 HRESULT hres;
2072
2073 hres = CoGetClassObject(&CLSID_FileProtocol, CLSCTX_INPROC_SERVER, NULL,
2074 &IID_IUnknown, (void**)&unk);
2075 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2076 if(FAILED(hres))
2077 return;
2078
2079 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2080 ok(hres == E_NOINTERFACE,
2081 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2082
2083 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2084 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2085 if(SUCCEEDED(hres)) {
2086 IInternetProtocol *protocol;
2087 BYTE buf[512];
2088 ULONG cb;
2089 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2090 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2091
2092 if(SUCCEEDED(hres)) {
2093 if(file_protocol_start(protocol, url, TRUE)) {
2094 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2095 ok(hres == S_OK, "Read failed: %08x\n", hres);
2096 ok(cb == 2, "cb=%u expected 2\n", cb);
2097 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2098 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2099 hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
2100 ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
2101 ok(cb == 0, "cb=%u expected 0\n", cb);
2102 hres = IInternetProtocol_UnlockRequest(protocol);
2103 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2104 }
2105
2106 if(file_protocol_start(protocol, url, FALSE)) {
2107 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2108 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2109 hres = IInternetProtocol_LockRequest(protocol, 0);
2110 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2111 hres = IInternetProtocol_UnlockRequest(protocol);
2112 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2113 }
2114
2115 IInternetProtocol_Release(protocol);
2116 }
2117
2118 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2119 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2120
2121 if(SUCCEEDED(hres)) {
2122 if(file_protocol_start(protocol, url, TRUE)) {
2123 hres = IInternetProtocol_LockRequest(protocol, 0);
2124 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2125 hres = IInternetProtocol_Terminate(protocol, 0);
2126 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2127 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2128 ok(hres == S_OK, "Read failed: %08x\n\n", hres);
2129 hres = IInternetProtocol_UnlockRequest(protocol);
2130 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2131 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2132 ok(hres == S_OK, "Read failed: %08x\n", hres);
2133 hres = IInternetProtocol_Terminate(protocol, 0);
2134 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2135 }
2136
2137 IInternetProtocol_Release(protocol);
2138 }
2139
2140 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
2141 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2142
2143 if(SUCCEEDED(hres)) {
2144 if(file_protocol_start(protocol, url, TRUE)) {
2145 hres = IInternetProtocol_Terminate(protocol, 0);
2146 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2147 hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
2148 ok(hres == S_OK, "Read failed: %08x\n", hres);
2149 ok(cb == 2, "cb=%u expected 2\n", cb);
2150 }
2151
2152 IInternetProtocol_Release(protocol);
2153 }
2154
2155 IClassFactory_Release(factory);
2156 }
2157
2158 IUnknown_Release(unk);
2159 }
2160
2161 static void test_file_protocol_fail(void)
2162 {
2163 IInternetProtocol *protocol;
2164 HRESULT hres;
2165
2166 static const WCHAR index_url2[] =
2167 {'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
2168
2169 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2170 &IID_IInternetProtocol, (void**)&protocol);
2171 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2172 if(FAILED(hres))
2173 return;
2174
2175 SET_EXPECT(GetBindInfo);
2176 expect_hrResult = MK_E_SYNTAX;
2177 hres = IInternetProtocol_Start(protocol, wszIndexHtml, &protocol_sink, &bind_info, 0, 0);
2178 ok(hres == MK_E_SYNTAX ||
2179 hres == E_INVALIDARG,
2180 "Start failed: %08x, expected MK_E_SYNTAX or E_INVALIDARG\n", hres);
2181 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2182
2183 SET_EXPECT(GetBindInfo);
2184 if(!(bindf & BINDF_FROMURLMON))
2185 SET_EXPECT(ReportProgress_DIRECTBIND);
2186 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2187 SET_EXPECT(ReportResult);
2188 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2189 hres = IInternetProtocol_Start(protocol, index_url, &protocol_sink, &bind_info, 0, 0);
2190 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2191 "Start failed: %08x expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2192 CHECK_CALLED(GetBindInfo);
2193 if(!(bindf & BINDF_FROMURLMON))
2194 CHECK_CALLED(ReportProgress_DIRECTBIND);
2195 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2196 CHECK_CALLED(ReportResult);
2197
2198 IInternetProtocol_Release(protocol);
2199
2200 hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2201 &IID_IInternetProtocol, (void**)&protocol);
2202 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2203 if(FAILED(hres))
2204 return;
2205
2206 SET_EXPECT(GetBindInfo);
2207 if(!(bindf & BINDF_FROMURLMON))
2208 SET_EXPECT(ReportProgress_DIRECTBIND);
2209 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2210 SET_EXPECT(ReportResult);
2211 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2212
2213 hres = IInternetProtocol_Start(protocol, index_url2, &protocol_sink, &bind_info, 0, 0);
2214 ok(hres == INET_E_RESOURCE_NOT_FOUND,
2215 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND\n", hres);
2216 CHECK_CALLED(GetBindInfo);
2217 if(!(bindf & BINDF_FROMURLMON))
2218 CHECK_CALLED(ReportProgress_DIRECTBIND);
2219 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2220 CHECK_CALLED(ReportResult);
2221
2222 SET_EXPECT(GetBindInfo);
2223 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2224 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2225 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2226
2227 SET_EXPECT(GetBindInfo);
2228 hres = IInternetProtocol_Start(protocol, emptyW, &protocol_sink, &bind_info, 0, 0);
2229 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2230 CLEAR_CALLED(GetBindInfo); /* GetBindInfo not called in IE7 */
2231
2232 IInternetProtocol_Release(protocol);
2233 }
2234
2235 static void test_file_protocol(void) {
2236 WCHAR buf[INTERNET_MAX_URL_LENGTH], file_name_buf[MAX_PATH];
2237 DWORD size;
2238 ULONG len;
2239 HANDLE file;
2240
2241 static const WCHAR wszFile[] = {'f','i','l','e',':',0};
2242 static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/',0};
2243 static const WCHAR wszFile3[] = {'f','i','l','e',':','/','/','/',0};
2244 static const char html_doc[] = "<HTML></HTML>";
2245
2246 trace("Testing file protocol...\n");
2247 init_test(FILE_TEST, 0);
2248
2249 SetLastError(0xdeadbeef);
2250 file = CreateFileW(wszIndexHtml, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2251 FILE_ATTRIBUTE_NORMAL, NULL);
2252 if(!file && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
2253 {
2254 win_skip("Detected Win9x or WinMe\n");
2255 return;
2256 }
2257 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2258 if(file == INVALID_HANDLE_VALUE)
2259 return;
2260 WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
2261 CloseHandle(file);
2262
2263 file_name = wszIndexHtml;
2264 bindf = 0;
2265 test_file_protocol_url(index_url);
2266 bindf = BINDF_FROMURLMON;
2267 test_file_protocol_url(index_url);
2268 bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
2269 test_file_protocol_url(index_url);
2270
2271 memcpy(buf, wszFile, sizeof(wszFile));
2272 len = sizeof(wszFile)/sizeof(WCHAR)-1;
2273 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2274 buf[len++] = '\\';
2275 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2276
2277 file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
2278 bindf = 0;
2279 test_file_protocol_url(buf);
2280 bindf = BINDF_FROMURLMON;
2281 test_file_protocol_url(buf);
2282
2283 memcpy(buf, wszFile2, sizeof(wszFile2));
2284 len = GetCurrentDirectoryW(sizeof(file_name_buf)/sizeof(WCHAR), file_name_buf);
2285 file_name_buf[len++] = '\\';
2286 memcpy(file_name_buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2287 lstrcpyW(buf+sizeof(wszFile2)/sizeof(WCHAR)-1, file_name_buf);
2288 file_name = file_name_buf;
2289 bindf = 0;
2290 test_file_protocol_url(buf);
2291 bindf = BINDF_FROMURLMON;
2292 test_file_protocol_url(buf);
2293
2294 buf[sizeof(wszFile2)/sizeof(WCHAR)] = '|';
2295 test_file_protocol_url(buf);
2296
2297 memcpy(buf, wszFile3, sizeof(wszFile3));
2298 len = sizeof(wszFile3)/sizeof(WCHAR)-1;
2299 len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
2300 buf[len++] = '\\';
2301 memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
2302
2303 file_name = buf + sizeof(wszFile3)/sizeof(WCHAR)-1;
2304 bindf = 0;
2305 test_file_protocol_url(buf);
2306 bindf = BINDF_FROMURLMON;
2307 test_file_protocol_url(buf);
2308
2309 DeleteFileW(wszIndexHtml);
2310
2311 bindf = 0;
2312 test_file_protocol_fail();
2313 bindf = BINDF_FROMURLMON;
2314 test_file_protocol_fail();
2315 }
2316
2317 static BOOL http_protocol_start(LPCWSTR url)
2318 {
2319 static BOOL got_user_agent = FALSE;
2320 HRESULT hres;
2321
2322 SET_EXPECT(GetBindInfo);
2323 if (!(bindf & BINDF_FROMURLMON))
2324 SET_EXPECT(ReportProgress_DIRECTBIND);
2325 if(!got_user_agent)
2326 SET_EXPECT(GetBindString_USER_AGENT);
2327 SET_EXPECT(GetBindString_ACCEPT_MIMES);
2328 SET_EXPECT(QueryService_HttpNegotiate);
2329 SET_EXPECT(BeginningTransaction);
2330 SET_EXPECT(GetRootSecurityId);
2331 if (http_post_test)
2332 SET_EXPECT(GetBindString_POST_COOKIE);
2333
2334 hres = IInternetProtocol_Start(async_protocol, url, &protocol_sink, &bind_info, 0, 0);
2335 ok(hres == S_OK, "Start failed: %08x\n", hres);
2336 if(FAILED(hres))
2337 return FALSE;
2338
2339 CHECK_CALLED(GetBindInfo);
2340 if (!(bindf & BINDF_FROMURLMON))
2341 CHECK_CALLED(ReportProgress_DIRECTBIND);
2342 if (!got_user_agent)
2343 {
2344 CHECK_CALLED(GetBindString_USER_AGENT);
2345 got_user_agent = TRUE;
2346 }
2347 CHECK_CALLED(GetBindString_ACCEPT_MIMES);
2348 CHECK_CALLED(QueryService_HttpNegotiate);
2349 CHECK_CALLED(BeginningTransaction);
2350 /* GetRootSecurityId called on WinXP but not on Win98 */
2351 CLEAR_CALLED(GetRootSecurityId);
2352 if (http_post_test)
2353 CHECK_CALLED(GetBindString_POST_COOKIE);
2354
2355 return TRUE;
2356 }
2357
2358 static void test_protocol_terminate(IInternetProtocol *protocol)
2359 {
2360 BYTE buf[3600];
2361 DWORD cb;
2362 HRESULT hres;
2363
2364 hres = IInternetProtocol_LockRequest(protocol, 0);
2365 ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
2366
2367 hres = IInternetProtocol_Read(protocol, buf, 1, &cb);
2368 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2369
2370 hres = IInternetProtocol_Terminate(protocol, 0);
2371 ok(hres == S_OK, "Terminate failed: %08x\n", hres);
2372
2373 /* This wait is to give the internet handles being freed in Terminate
2374 * enough time to actually terminate in all cases. Internet handles
2375 * terminate asynchronously and native reuses the main InternetOpen
2376 * handle. The only case in which this seems to be necessary is on
2377 * wine with native wininet and urlmon, resulting in the next time
2378 * test_http_protocol_url being called the first data notification actually
2379 * being an extra last data notification from the previous connection
2380 * about once out of every ten times. */
2381 Sleep(100);
2382
2383 hres = IInternetProtocol_UnlockRequest(protocol);
2384 ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
2385 }
2386
2387 static void test_http_info(IInternetProtocol *protocol)
2388 {
2389 IWinInetHttpInfo *info;
2390 HRESULT hres;
2391
2392 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetHttpInfo, (void**)&info);
2393 ok(hres == S_OK, "Could not get IWinInterHttpInfo iface: %08x\n", hres);
2394
2395 /* TODO */
2396
2397 IWinInetHttpInfo_Release(info);
2398 }
2399
2400 /* is_first refers to whether this is the first call to this function
2401 * _for this url_ */
2402 static void test_http_protocol_url(LPCWSTR url, int prot, DWORD flags)
2403 {
2404 IInternetProtocolInfo *protocol_info;
2405 IClassFactory *factory;
2406 IUnknown *unk;
2407 HRESULT hres;
2408
2409 init_test(prot, flags);
2410 http_url = url;
2411
2412 hres = CoGetClassObject(prot == HTTPS_TEST ? &CLSID_HttpSProtocol : &CLSID_HttpProtocol,
2413 CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2414 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2415 if(FAILED(hres))
2416 return;
2417
2418 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2419 ok(hres == E_NOINTERFACE,
2420 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2421 hres);
2422
2423 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2424 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2425 IUnknown_Release(unk);
2426 if(FAILED(hres))
2427 return;
2428
2429 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2430 (void**)&async_protocol);
2431 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2432 if(SUCCEEDED(hres)) {
2433 BYTE buf[3600];
2434 DWORD cb;
2435 ULONG ref;
2436
2437 test_priority(async_protocol);
2438 test_http_info(async_protocol);
2439
2440 SET_EXPECT(ReportProgress_COOKIE_SENT);
2441 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2442 SET_EXPECT(ReportProgress_CONNECTING);
2443 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2444 if(test_redirect)
2445 SET_EXPECT(ReportProgress_REDIRECTING);
2446 SET_EXPECT(ReportProgress_PROXYDETECTING);
2447 if(prot == HTTP_TEST)
2448 SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
2449 else
2450 SET_EXPECT(QueryService_HttpSecurity);
2451 if(!(bindf & BINDF_FROMURLMON)) {
2452 SET_EXPECT(OnResponse);
2453 SET_EXPECT(ReportProgress_RAWMIMETYPE);
2454 SET_EXPECT(ReportData);
2455 } else {
2456 SET_EXPECT(Switch);
2457 }
2458
2459 if(!http_protocol_start(url))
2460 return;
2461
2462 if(!direct_read)
2463 SET_EXPECT(ReportResult);
2464 expect_hrResult = S_OK;
2465
2466 if(direct_read) {
2467 while(wait_for_switch) {
2468 SET_EXPECT(Switch);
2469 WaitForSingleObject(event_continue, INFINITE);
2470 CHECK_CALLED(Switch);
2471 call_continue(&continue_protdata);
2472 SetEvent(event_continue_done);
2473 }
2474 }else {
2475 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2476 ok((hres == E_PENDING && cb==0) ||
2477 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2478
2479 WaitForSingleObject(event_complete, INFINITE);
2480 if(bindf & BINDF_FROMURLMON)
2481 CHECK_CALLED(Switch);
2482 else
2483 CHECK_CALLED(ReportData);
2484 if(prot == HTTPS_TEST)
2485 CLEAR_CALLED(QueryService_HttpSecurity);
2486
2487 while(1) {
2488 if(bindf & BINDF_FROMURLMON)
2489 SET_EXPECT(Switch);
2490 else
2491 SET_EXPECT(ReportData);
2492 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2493 if(hres == E_PENDING) {
2494 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2495 ok((hres == E_PENDING && cb==0) ||
2496 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2497 WaitForSingleObject(event_complete, INFINITE);
2498 if(bindf & BINDF_FROMURLMON)
2499 CHECK_CALLED(Switch);
2500 else
2501 CHECK_CALLED(ReportData);
2502 }else {
2503 if(bindf & BINDF_FROMURLMON)
2504 CHECK_NOT_CALLED(Switch);
2505 else
2506 CHECK_NOT_CALLED(ReportData);
2507 if(cb == 0) break;
2508 }
2509 }
2510 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2511 CHECK_CALLED(ReportResult);
2512 }
2513 if(prot == HTTPS_TEST)
2514 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2515
2516 test_protocol_terminate(async_protocol);
2517 ref = IInternetProtocol_Release(async_protocol);
2518 ok(!ref, "ref=%x\n", hres);
2519 }
2520
2521 IClassFactory_Release(factory);
2522 }
2523
2524 static void test_http_protocol(void)
2525 {
2526 static const WCHAR winehq_url[] =
2527 {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
2528 'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
2529 static const WCHAR posttest_url[] =
2530 {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
2531 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
2532 'p','o','s','t','t','e','s','t','.','p','h','p',0};
2533 static const WCHAR redirect_url[] =
2534 {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/',
2535 't','e','s','t','r','e','d','i','r','e','c','t',0};
2536
2537 trace("Testing http protocol (not from urlmon)...\n");
2538 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2539 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_FIRST_HTTP);
2540
2541 trace("Testing http protocol (from urlmon)...\n");
2542 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2543 test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2544
2545 trace("Testing http protocol (to file)...\n");
2546 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NEEDFILE;
2547 test_http_protocol_url(winehq_url, HTTP_TEST, 0);
2548
2549 trace("Testing http protocol (post data)...\n");
2550 /* Without this flag we get a ReportProgress_CACHEFILENAMEAVAILABLE
2551 * notification with BINDVERB_POST */
2552 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2553 test_http_protocol_url(posttest_url, HTTP_TEST, TEST_FIRST_HTTP|TEST_POST);
2554
2555 trace("Testing http protocol (direct read)...\n");
2556 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2557 test_http_protocol_url(winehq_url, HTTP_TEST, TEST_DIRECT_READ);
2558
2559 trace("Testing http protocol (redirected)...\n");
2560 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON;
2561 test_http_protocol_url(redirect_url, HTTP_TEST, TEST_REDIRECT);
2562 }
2563
2564 static void test_https_protocol(void)
2565 {
2566 static const WCHAR codeweavers_url[] =
2567 {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s',
2568 '.','c','o','m','/','t','e','s','t','.','h','t','m','l',0};
2569
2570 trace("Testing https protocol (from urlmon)...\n");
2571 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2572 test_http_protocol_url(codeweavers_url, HTTPS_TEST, TEST_FIRST_HTTP);
2573 }
2574
2575
2576 static void test_ftp_protocol(void)
2577 {
2578 IInternetProtocolInfo *protocol_info;
2579 IClassFactory *factory;
2580 IUnknown *unk;
2581 BYTE buf[4096];
2582 ULONG ref;
2583 DWORD cb;
2584 HRESULT hres;
2585
2586 static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
2587 '/','p','u','b','/','o','t','h','e','r','/',
2588 'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
2589
2590 trace("Testing ftp protocol...\n");
2591
2592 bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA | BINDF_FROMURLMON | BINDF_NOWRITECACHE;
2593 state = 0;
2594 tested_protocol = FTP_TEST;
2595 first_data_notif = TRUE;
2596 expect_hrResult = E_PENDING;
2597
2598 hres = CoGetClassObject(&CLSID_FtpProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2599 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2600 if(FAILED(hres))
2601 return;
2602
2603 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2604 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2605
2606 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2607 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2608 IUnknown_Release(unk);
2609 if(FAILED(hres))
2610 return;
2611
2612 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2613 (void**)&async_protocol);
2614 IClassFactory_Release(factory);
2615 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2616
2617 test_priority(async_protocol);
2618 test_http_info(async_protocol);
2619
2620 SET_EXPECT(GetBindInfo);
2621 SET_EXPECT(ReportProgress_FINDINGRESOURCE);
2622 SET_EXPECT(ReportProgress_CONNECTING);
2623 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2624 SET_EXPECT(Switch);
2625
2626 hres = IInternetProtocol_Start(async_protocol, ftp_urlW, &protocol_sink, &bind_info, 0, 0);
2627 ok(hres == S_OK, "Start failed: %08x\n", hres);
2628 CHECK_CALLED(GetBindInfo);
2629
2630 SET_EXPECT(ReportResult);
2631
2632 hres = IInternetProtocol_Read(async_protocol, buf, 1, &cb);
2633 ok((hres == E_PENDING && cb==0) ||
2634 (hres == S_OK && cb==1), "Read failed: %08x (%d bytes)\n", hres, cb);
2635
2636 WaitForSingleObject(event_complete, INFINITE);
2637
2638 while(1) {
2639
2640 hres = IInternetProtocol_Read(async_protocol, buf, sizeof(buf), &cb);
2641 if(hres == E_PENDING)
2642 WaitForSingleObject(event_complete, INFINITE);
2643 else
2644 if(cb == 0) break;
2645 }
2646
2647 ok(hres == S_FALSE, "Read failed: %08x\n", hres);
2648 CHECK_CALLED(ReportResult);
2649 CHECK_CALLED(Switch);
2650
2651 test_protocol_terminate(async_protocol);
2652
2653 ref = IInternetProtocol_Release(async_protocol);
2654 ok(!ref, "ref=%d\n", ref);
2655 }
2656
2657 static void test_gopher_protocol(void)
2658 {
2659 IInternetProtocolInfo *protocol_info;
2660 IClassFactory *factory;
2661 IUnknown *unk;
2662 HRESULT hres;
2663
2664 trace("Testing gopher protocol...\n");
2665
2666 hres = CoGetClassObject(&CLSID_GopherProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
2667 ok(hres == S_OK ||
2668 hres == REGDB_E_CLASSNOTREG, /* Gopher protocol has been removed as of Vista */
2669 "CoGetClassObject failed: %08x\n", hres);
2670 if(FAILED(hres))
2671 return;
2672
2673 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2674 ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n", hres);
2675
2676 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2677 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2678 IUnknown_Release(unk);
2679 if(FAILED(hres))
2680 return;
2681
2682 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2683 (void**)&async_protocol);
2684 IClassFactory_Release(factory);
2685 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2686
2687 test_priority(async_protocol);
2688
2689 IInternetProtocol_Release(async_protocol);
2690 }
2691
2692 static void test_mk_protocol(void)
2693 {
2694 IInternetProtocolInfo *protocol_info;
2695 IInternetProtocol *protocol;
2696 IClassFactory *factory;
2697 IUnknown *unk;
2698 HRESULT hres;
2699
2700 static const WCHAR wrong_url1[] = {'t','e','s','t',':','@','M','S','I','T','S','t','o','r','e',
2701 ':',':','/','t','e','s','t','.','h','t','m','l',0};
2702 static const WCHAR wrong_url2[] = {'m','k',':','/','t','e','s','t','.','h','t','m','l',0};
2703
2704 trace("Testing mk protocol...\n");
2705 init_test(MK_TEST, 0);
2706
2707 hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL,
2708 &IID_IUnknown, (void**)&unk);
2709 ok(hres == S_OK, "CoGetClassObject failed: %08x\n", hres);
2710
2711 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&protocol_info);
2712 ok(hres == E_NOINTERFACE,
2713 "Could not get IInternetProtocolInfo interface: %08x, expected E_NOINTERFACE\n",
2714 hres);
2715
2716 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
2717 ok(hres == S_OK, "Could not get IClassFactory interface\n");
2718 IUnknown_Release(unk);
2719 if(FAILED(hres))
2720 return;
2721
2722 hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol,
2723 (void**)&protocol);
2724 IClassFactory_Release(factory);
2725 ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
2726
2727 SET_EXPECT(GetBindInfo);
2728 hres = IInternetProtocol_Start(protocol, wrong_url1, &protocol_sink, &bind_info, 0, 0);
2729 ok(hres == MK_E_SYNTAX || hres == INET_E_INVALID_URL,
2730 "Start failed: %08x, expected MK_E_SYNTAX or INET_E_INVALID_URL\n", hres);
2731 CLEAR_CALLED(GetBindInfo);
2732
2733 SET_EXPECT(GetBindInfo);
2734 SET_EXPECT(ReportProgress_DIRECTBIND);
2735 SET_EXPECT(ReportProgress_SENDINGREQUEST);
2736 SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
2737 SET_EXPECT(ReportResult);
2738 expect_hrResult = INET_E_RESOURCE_NOT_FOUND;
2739
2740 hres = IInternetProtocol_Start(protocol, wrong_url2, &protocol_sink, &bind_info, 0, 0);
2741 ok(hres == INET_E_RESOURCE_NOT_FOUND ||
2742 hres == INET_E_INVALID_URL, /* win2k3 */
2743 "Start failed: %08x, expected INET_E_RESOURCE_NOT_FOUND or INET_E_INVALID_URL\n", hres);
2744
2745 if (hres == INET_E_RESOURCE_NOT_FOUND) {
2746 CHECK_CALLED(GetBindInfo);
2747 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2748 CHECK_CALLED(ReportProgress_SENDINGREQUEST);
2749 CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2750 CHECK_CALLED(ReportResult);
2751 }else {
2752 CLEAR_CALLED(GetBindInfo);
2753 CLEAR_CALLED(ReportProgress_DIRECTBIND);
2754 CLEAR_CALLED(ReportProgress_SENDINGREQUEST);
2755 CLEAR_CALLED(ReportProgress_MIMETYPEAVAILABLE);
2756 CLEAR_CALLED(ReportResult);
2757 }
2758
2759 IInternetProtocol_Release(protocol);
2760 }
2761
2762 static void test_CreateBinding(void)
2763 {
2764 IInternetProtocol *protocol;
2765 IInternetPriority *priority;
2766 IInternetSession *session;
2767 IWinInetHttpInfo *http_info;
2768 IWinInetInfo *inet_info;
2769 LONG p;
2770 BYTE buf[1000];
2771 DWORD read;
2772 HRESULT hres;
2773
2774 static const WCHAR test_url[] =
2775 {'t','e','s','t',':','/','/','f','i','l','e','.','h','t','m','l',0};
2776 static const WCHAR wsz_test[] = {'t','e','s','t',0};
2777
2778 trace("Testing CreateBinding...\n");
2779 init_test(BIND_TEST, TEST_BINDING);
2780
2781 hres = CoInternetGetSession(0, &session, 0);
2782 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
2783
2784 hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL, wsz_test, 0, NULL, 0);
2785 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
2786
2787 hres = IInternetSession_CreateBinding(session, NULL, test_url, NULL, NULL, &protocol, 0);
2788 binding_protocol = protocol;
2789 ok(hres == S_OK, "CreateBinding failed: %08x\n", hres);
2790 ok(protocol != NULL, "protocol == NULL\n");
2791
2792 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetBindInfo, (void**)&prot_bind_info);
2793 ok(hres == S_OK, "QueryInterface(IID_IInternetBindInfo) failed: %08x\n", hres);
2794
2795 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolSink, (void**)&binding_sink);
2796 ok(hres == S_OK, "Could not get IInternetProtocolSink: %08x\n", hres);
2797
2798 hres = IInternetProtocol_Start(protocol, test_url, NULL, &bind_info, 0, 0);
2799 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2800 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, NULL, 0, 0);
2801 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2802 hres = IInternetProtocol_Start(protocol, NULL, &protocol_sink, &bind_info, 0, 0);
2803 ok(hres == E_INVALIDARG, "Start failed: %08x, expected E_INVALIDARG\n", hres);
2804
2805 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
2806 ok(hres == S_OK, "QueryInterface(IID_IInternetPriority) failed: %08x\n", hres);
2807
2808 p = 0xdeadbeef;
2809 hres = IInternetPriority_GetPriority(priority, &p);
2810 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2811 ok(!p, "p=%d\n", p);
2812
2813 ex_priority = 100;
2814 hres = IInternetPriority_SetPriority(priority, 100);
2815 ok(hres == S_OK, "SetPriority failed: %08x\n", hres);
2816
2817 p = 0xdeadbeef;
2818 hres = IInternetPriority_GetPriority(priority, &p);
2819 ok(hres == S_OK, "GetPriority failed: %08x\n", hres);
2820 ok(p == 100, "p=%d\n", p);
2821
2822 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2823 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2824
2825 SET_EXPECT(QueryService_InternetProtocol);
2826 SET_EXPECT(CreateInstance);
2827 SET_EXPECT(ReportProgress_PROTOCOLCLASSID);
2828 SET_EXPECT(SetPriority);
2829 SET_EXPECT(Start);
2830
2831 expect_hrResult = S_OK;
2832 hres = IInternetProtocol_Start(protocol, test_url, &protocol_sink, &bind_info, 0, 0);
2833 ok(hres == S_OK, "Start failed: %08x\n", hres);
2834
2835 CHECK_CALLED(QueryService_InternetProtocol);
2836 CHECK_CALLED(CreateInstance);
2837 CHECK_CALLED(ReportProgress_PROTOCOLCLASSID);
2838 CHECK_CALLED(SetPriority);
2839 CHECK_CALLED(Start);
2840
2841 SET_EXPECT(QueryInterface_IWinInetInfo);
2842 hres = IInternetProtocol_QueryInterface(protocol, &IID_IWinInetInfo, (void**)&inet_info);
2843 ok(hres == E_NOINTERFACE, "Could not get IWinInetInfo protocol: %08x\n", hres);
2844 CHECK_CALLED(QueryInterface_IWinInetInfo);
2845
2846 SET_EXPECT(QueryInterface_IWinInetInfo);
2847 hres = IInterne