2 * Copyright 2005 Jacek Caban
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.
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.
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
21 #include <wine/test.h>
33 #define DEFINE_EXPECT(func) \
34 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
36 #define SET_EXPECT(func) \
37 expect_ ## func = TRUE
39 #define CHECK_EXPECT(func) \
41 ok(expect_ ##func, "unexpected call " #func "\n"); \
42 expect_ ## func = FALSE; \
43 called_ ## func = TRUE; \
46 #define CHECK_EXPECT2(func) \
48 ok(expect_ ##func, "unexpected call " #func "\n"); \
49 called_ ## func = TRUE; \
52 #define CHECK_CALLED(func) \
54 ok(called_ ## func, "expected " #func "\n"); \
55 expect_ ## func = called_ ## func = FALSE; \
58 DEFINE_GUID(CLSID_ResProtocol
, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
59 DEFINE_GUID(CLSID_AboutProtocol
, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
60 DEFINE_GUID(CLSID_JSProtocol
, 0x3050F3B2, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
62 DEFINE_EXPECT(GetBindInfo
);
63 DEFINE_EXPECT(ReportProgress
);
64 DEFINE_EXPECT(ReportData
);
65 DEFINE_EXPECT(ReportResult
);
67 static HRESULT expect_hrResult
;
68 static BOOL expect_hr_win32err
= FALSE
;
71 static const WCHAR about_blank_url
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
72 static const WCHAR about_test_url
[] = {'a','b','o','u','t',':','t','e','s','t',0};
73 static const WCHAR about_res_url
[] = {'r','e','s',':','b','l','a','n','k',0};
74 static const WCHAR javascript_test_url
[] = {'j','a','v','a','s','c','r','i','p','t',':','t','e','s','t','(',')',0};
76 static const char *debugstr_guid(REFIID riid
)
80 sprintf(buf
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
81 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
82 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
83 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
88 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
90 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
96 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
100 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
105 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
110 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
112 ok(0, "unexpected call\n");
116 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
117 LPCWSTR szStatusText
)
119 static const WCHAR text_html
[] = {'t','e','x','t','/','h','t','m','l',0};
121 CHECK_EXPECT(ReportProgress
);
123 ok(ulStatusCode
== BINDSTATUS_MIMETYPEAVAILABLE
124 || ulStatusCode
== BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
,
125 "ulStatusCode=%d\n", ulStatusCode
);
126 ok(!lstrcmpW(szStatusText
, text_html
), "szStatusText != text/html\n");
131 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
, ULONG ulProgress
,
134 CHECK_EXPECT(ReportData
);
136 ok(ulProgress
== ulProgressMax
, "ulProgress != ulProgressMax\n");
137 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
),
138 "grcf = %08x\n", grfBSCF
);
143 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
, DWORD dwError
,
146 CHECK_EXPECT(ReportResult
);
148 if(expect_hr_win32err
)
149 ok((hrResult
&0xffff0000) == ((FACILITY_WIN32
<< 16)|0x80000000) || expect_hrResult
,
150 "expected win32 err or %08x got: %08x\n", expect_hrResult
, hrResult
);
152 ok(hrResult
== expect_hrResult
|| ((expect_hrResult
== E_INVALIDARG
||
153 expect_hrResult
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
)) &&
154 hrResult
== MK_E_SYNTAX
), "expected: %08x got: %08x\n", expect_hrResult
, hrResult
);
155 ok(dwError
== 0, "dwError = %d\n", dwError
);
156 ok(!szResult
, "szResult != NULL\n");
161 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
162 ProtocolSink_QueryInterface
,
164 ProtocolSink_Release
,
166 ProtocolSink_ReportProgress
,
167 ProtocolSink_ReportData
,
168 ProtocolSink_ReportResult
171 static IInternetProtocolSink protocol_sink
= {
175 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
177 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
183 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
184 return E_NOINTERFACE
;
187 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
192 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
197 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
199 CHECK_EXPECT(GetBindInfo
);
201 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
202 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
203 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
209 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
, LPOLESTR
*ppwzStr
,
210 ULONG cEl
, ULONG
*pcElFetched
)
212 ok(0, "unexpected call\n");
216 static IInternetBindInfoVtbl bind_info_vtbl
= {
217 BindInfo_QueryInterface
,
220 BindInfo_GetBindInfo
,
221 BindInfo_GetBindString
224 static IInternetBindInfo bind_info
= {
228 static void test_protocol_fail(IInternetProtocol
*protocol
, LPCWSTR url
, HRESULT expected_hres
,
229 BOOL expect_win32err
)
233 SET_EXPECT(GetBindInfo
);
234 SET_EXPECT(ReportResult
);
236 expect_hrResult
= expected_hres
;
237 expect_hr_win32err
= expect_win32err
;
238 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
240 ok((hres
&0xffff0000) == ((FACILITY_WIN32
<< 16)|0x80000000) || hres
== expect_hrResult
,
241 "expected win32 err or %08x got: %08x\n", expected_hres
, hres
);
243 ok(hres
== expected_hres
|| ((expected_hres
== E_INVALIDARG
||
244 expected_hres
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
)) && hres
== MK_E_SYNTAX
),
245 "expected: %08x got: %08x\n", expected_hres
, hres
);
247 CHECK_CALLED(GetBindInfo
);
248 CHECK_CALLED(ReportResult
);
251 static void protocol_start(IInternetProtocol
*protocol
, LPCWSTR url
)
255 SET_EXPECT(GetBindInfo
);
256 SET_EXPECT(ReportResult
);
257 SET_EXPECT(ReportProgress
);
258 SET_EXPECT(ReportData
);
259 expect_hrResult
= S_OK
;
260 expect_hr_win32err
= FALSE
;
262 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
263 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
265 CHECK_CALLED(GetBindInfo
);
266 CHECK_CALLED(ReportProgress
);
267 CHECK_CALLED(ReportData
);
268 CHECK_CALLED(ReportResult
);
271 static void res_sec_url_cmp(LPCWSTR url
, DWORD size
, LPCWSTR file
)
276 static const WCHAR fileW
[] = {'f','i','l','e',':','/','/'};
278 if(size
< sizeof(fileW
)/sizeof(WCHAR
) || memcmp(url
, fileW
, sizeof(fileW
))) {
279 ok(0, "wrong URL protocol\n");
283 SetLastError(0xdeadbeef);
284 len
= SearchPathW(NULL
, file
, NULL
, sizeof(buf
)/sizeof(WCHAR
), buf
, NULL
);
286 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
287 win_skip("SearchPathW is not implemented\n");
289 ok(0, "SearchPath failed: %u\n", GetLastError());
293 len
+= sizeof(fileW
)/sizeof(WCHAR
)+1;
294 ok(len
== size
, "wrong size %u, expected %u\n", size
, len
);
295 ok(!lstrcmpW(url
+ sizeof(fileW
)/sizeof(WCHAR
), buf
), "wrong file part %s\n", wine_dbgstr_w(url
));
298 static void test_res_protocol(void)
300 IInternetProtocolInfo
*protocol_info
;
302 IClassFactory
*factory
;
305 static const WCHAR blank_url
[] =
306 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
307 static const WCHAR test_part_url
[] = {'r','e','s',':','/','/','C','S','S','/','t','e','s','t',0};
308 static const WCHAR wrong_url1
[] =
309 {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
310 static const WCHAR wrong_url2
[] =
311 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
312 static const WCHAR wrong_url3
[] =
313 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
314 static const WCHAR wrong_url4
[] =
315 {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
316 static const WCHAR wrong_url5
[] =
317 {'r','e','s',':','/','/','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
318 static const WCHAR mshtml_dllW
[] = {'m','s','h','t','m','l','.','d','l','l',0};
320 hres
= CoGetClassObject(&CLSID_ResProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
321 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
325 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
326 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
327 if(SUCCEEDED(hres
)) {
332 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
333 if(i
!= PARSE_SECURITY_URL
&& i
!= PARSE_DOMAIN
) {
334 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, i
, 0, buf
,
335 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
336 ok(hres
== INET_E_DEFAULT_ACTION
,
337 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
341 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_SECURITY_URL
, 0, buf
,
342 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
343 ok(hres
== S_OK
, "ParseUrl failed: %08x\n", hres
);
344 res_sec_url_cmp(buf
, size
, mshtml_dllW
);
347 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_SECURITY_URL
, 0, buf
,
349 ok(hres
== S_FALSE
, "ParseUrl failed: %08x, expected S_FALSE\n", hres
);
350 ok(size
, "size=0\n");
352 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, wrong_url1
, PARSE_SECURITY_URL
, 0, buf
,
353 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
354 ok(hres
== MK_E_SYNTAX
|| hres
== E_INVALIDARG
,
355 "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres
);
357 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, wrong_url5
, PARSE_SECURITY_URL
, 0, buf
,
358 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
359 ok(hres
== MK_E_SYNTAX
, "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres
);
363 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_DOMAIN
, 0, buf
,
364 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
365 ok(hres
== S_OK
|| hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
366 ok(buf
[0] == '?', "buf changed\n");
367 ok(size
== sizeof(blank_url
)/sizeof(WCHAR
) ||
368 size
== sizeof(buf
)/sizeof(buf
[0]), /* IE8 */
372 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, wrong_url1
, PARSE_DOMAIN
, 0, buf
,
373 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
374 ok(hres
== S_OK
|| hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
375 ok(buf
[0] == '?', "buf changed\n");
376 ok(size
== sizeof(wrong_url1
)/sizeof(WCHAR
) ||
377 size
== sizeof(buf
)/sizeof(buf
[0]), /* IE8 */
382 /* Crashes on win9x */
385 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
386 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
387 ok(hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
388 ok(buf
[0] == '?', "buf changed\n");
389 ok(size
== 1, "size=%u, expected 1\n", size
);
392 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_DOMAIN
, 0, buf
,
393 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
394 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
395 ok(buf
[0] == '?', "buf changed\n");
398 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
399 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
400 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
401 ok(buf
[0] == '?', "buf changed\n");
405 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_UNESCAPE
+1, 0, buf
,
406 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
407 ok(hres
== INET_E_DEFAULT_ACTION
,
408 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres
);
409 ok(buf
[0] == '?', "buf changed\n");
412 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, blank_url
, test_part_url
,
413 0, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
414 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
415 ok(size
== 0xdeadbeef, "size=%d\n", size
);
418 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, blank_url
, test_part_url
,
419 URL_FILE_USE_PATHURL
, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
420 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
421 ok(size
== 0xdeadbeef, "size=%d\n", size
);
424 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, NULL
, NULL
,
425 URL_FILE_USE_PATHURL
, NULL
, 0xdeadbeef, NULL
, 0);
426 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
427 ok(size
== 0xdeadbeef, "size=%d\n", size
);
429 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, blank_url
, blank_url
, 0);
430 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
432 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, NULL
, NULL
, 0xdeadbeef);
433 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
435 for(i
=0; i
<30; i
++) {
436 if(i
== QUERY_USES_NETWORK
|| i
== QUERY_IS_SECURE
|| i
== QUERY_IS_SAFE
)
439 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, i
, 0,
440 buf
, sizeof(buf
), &size
, 0);
441 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
442 "QueryInfo(%d) returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", i
, hres
);
446 memset(buf
, '?', sizeof(buf
));
447 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
448 buf
, sizeof(buf
), &size
, 0);
449 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
450 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
451 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
453 memset(buf
, '?', sizeof(buf
));
454 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
455 buf
, sizeof(buf
), NULL
, 0);
456 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
457 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
459 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
461 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
464 memset(buf
, '?', sizeof(buf
));
465 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, NULL
, QUERY_USES_NETWORK
, 0,
466 buf
, sizeof(buf
), &size
, 0);
467 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
468 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
469 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
470 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
472 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
473 NULL
, sizeof(buf
), &size
, 0);
474 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
476 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, 60, 0,
477 NULL
, sizeof(buf
), &size
, 0);
478 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
479 "QueryInfo failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
481 IInternetProtocolInfo_Release(protocol_info
);
484 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
485 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
486 if(SUCCEEDED(hres
)) {
487 IInternetProtocol
*protocol
;
490 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
491 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
493 if(SUCCEEDED(hres
)) {
494 IInternetPriority
*priority
;
496 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
497 ok(hres
== E_NOINTERFACE
,
498 "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres
);
500 test_protocol_fail(protocol
, wrong_url1
, E_INVALIDARG
, FALSE
);
501 test_protocol_fail(protocol
, wrong_url2
,
502 HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
), FALSE
);
503 test_protocol_fail(protocol
, wrong_url3
, E_FAIL
, TRUE
);
504 test_protocol_fail(protocol
, wrong_url4
, E_FAIL
, TRUE
);
507 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
508 ok(hres
== E_FAIL
, "Read returned %08x expected E_FAIL\n", hres
);
509 ok(cb
== 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb
);
511 protocol_start(protocol
, blank_url
);
512 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
513 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
514 ok(cb
== 2, "cb=%u expected 2\n", cb
);
515 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
516 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
517 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
518 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
519 ok(cb
== 0, "cb=%u expected 0\n", cb
);
520 hres
= IInternetProtocol_UnlockRequest(protocol
);
521 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
523 protocol_start(protocol
, blank_url
);
524 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
525 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
526 hres
= IInternetProtocol_LockRequest(protocol
, 0);
527 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
528 hres
= IInternetProtocol_UnlockRequest(protocol
);
529 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
530 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
531 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
533 protocol_start(protocol
, blank_url
);
534 hres
= IInternetProtocol_LockRequest(protocol
, 0);
535 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
536 hres
= IInternetProtocol_Terminate(protocol
, 0);
537 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
538 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
539 ok(hres
== S_OK
, "Read failed: %08x\n\n", hres
);
540 hres
= IInternetProtocol_UnlockRequest(protocol
);
541 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
542 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
543 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
544 hres
= IInternetProtocol_Terminate(protocol
, 0);
545 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
546 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
547 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
548 ok(cb
== 2, "cb=%u expected 2\n", cb
);
550 protocol_start(protocol
, blank_url
);
551 hres
= IInternetProtocol_LockRequest(protocol
, 0);
552 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
553 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
554 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
555 protocol_start(protocol
, blank_url
);
556 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
557 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
558 hres
= IInternetProtocol_Terminate(protocol
, 0);
559 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
561 IInternetProtocol_Release(protocol
);
564 IClassFactory_Release(factory
);
567 IUnknown_Release(unk
);
570 static void do_test_about_protocol(IClassFactory
*factory
, DWORD bf
)
572 IInternetProtocol
*protocol
;
573 IInternetPriority
*priority
;
578 static const WCHAR blank_html
[] = {0xfeff,'<','H','T','M','L','>','<','/','H','T','M','L','>',0};
579 static const WCHAR test_html
[] =
580 {0xfeff,'<','H','T','M','L','>','t','e','s','t','<','/','H','T','M','L','>',0};
584 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
585 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
589 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
590 ok(hres
== E_NOINTERFACE
,
591 "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres
);
593 protocol_start(protocol
, about_blank_url
);
594 hres
= IInternetProtocol_LockRequest(protocol
, 0);
595 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
596 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
597 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
598 ok(cb
== sizeof(blank_html
), "cb=%d\n", cb
);
599 ok(!memcmp(buf
, blank_html
, cb
), "Readed wrong data\n");
600 hres
= IInternetProtocol_UnlockRequest(protocol
);
601 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
603 protocol_start(protocol
, about_test_url
);
604 hres
= IInternetProtocol_LockRequest(protocol
, 0);
605 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
606 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
607 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
608 ok(cb
== sizeof(test_html
), "cb=%d\n", cb
);
609 ok(!memcmp(buf
, test_html
, cb
), "Readed wrong data\n");
610 hres
= IInternetProtocol_UnlockRequest(protocol
);
611 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
613 protocol_start(protocol
, about_res_url
);
614 hres
= IInternetProtocol_LockRequest(protocol
, 0);
615 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
616 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
617 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
618 ok(cb
== sizeof(blank_html
), "cb=%d\n", cb
);
619 ok(!memcmp(buf
, blank_html
, cb
), "Readed wrong data\n");
620 hres
= IInternetProtocol_UnlockRequest(protocol
);
621 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
623 IInternetProtocol_Release(protocol
);
626 static void test_about_protocol(void)
628 IInternetProtocolInfo
*protocol_info
;
630 IClassFactory
*factory
;
633 hres
= CoGetClassObject(&CLSID_AboutProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
634 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
638 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
639 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
640 if(SUCCEEDED(hres
)) {
645 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
646 if(i
!= PARSE_SECURITY_URL
&& i
!= PARSE_DOMAIN
) {
647 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, i
, 0, buf
,
648 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
649 ok(hres
== INET_E_DEFAULT_ACTION
,
650 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
654 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_SECURITY_URL
, 0, buf
,
655 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
656 ok(hres
== S_OK
, "ParseUrl failed: %08x\n", hres
);
657 ok(!lstrcmpW(about_blank_url
, buf
), "buf != blank_url\n");
660 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_SECURITY_URL
, 0, buf
,
662 ok(hres
== S_FALSE
, "ParseUrl failed: %08x, expected S_FALSE\n", hres
);
663 ok(size
== 12, "size = %d\n", size
);
665 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_test_url
, PARSE_SECURITY_URL
, 0, buf
,
666 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
667 ok(hres
== S_OK
, "ParseUrl failed: %08x\n", hres
);
668 ok(!lstrcmpW(about_test_url
, buf
), "buf != test_url\n");
669 ok(size
== 11, "size = %d\n", size
);
673 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_DOMAIN
, 0, buf
,
674 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
675 ok(hres
== S_OK
|| hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
676 ok(buf
[0] == '?', "buf changed\n");
677 ok(size
== sizeof(about_blank_url
)/sizeof(WCHAR
) ||
678 size
== sizeof(buf
)/sizeof(buf
[0]), /* IE8 */
683 /* Crashes on win9x */
686 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
687 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
688 ok(hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
689 ok(buf
[0] == '?', "buf changed\n");
690 ok(size
== 1, "size=%u, expected 1\n", size
);
693 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_DOMAIN
, 0, buf
,
694 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
695 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
696 ok(buf
[0] == '?', "buf changed\n");
699 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
700 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
701 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
702 ok(buf
[0] == '?', "buf changed\n");
705 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_UNESCAPE
+1, 0, buf
,
706 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
707 ok(hres
== INET_E_DEFAULT_ACTION
,
708 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres
);
711 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, about_blank_url
, about_test_url
,
712 0, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
713 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
714 ok(size
== 0xdeadbeef, "size=%d\n", size
);
717 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, about_blank_url
, about_test_url
,
718 URL_FILE_USE_PATHURL
, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
719 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
720 ok(size
== 0xdeadbeef, "size=%d\n", size
);
723 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, NULL
, NULL
,
724 URL_FILE_USE_PATHURL
, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
725 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
726 ok(size
== 0xdeadbeef, "size=%d\n", size
);
728 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, about_blank_url
, about_blank_url
, 0);
729 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
731 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, NULL
, NULL
, 0xdeadbeef);
732 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
734 for(i
=0; i
<30; i
++) {
736 case QUERY_CAN_NAVIGATE
:
737 case QUERY_USES_NETWORK
:
738 case QUERY_IS_CACHED
:
739 case QUERY_IS_INSTALLEDENTRY
:
740 case QUERY_IS_CACHED_OR_MAPPED
:
741 case QUERY_IS_SECURE
:
743 case QUERY_USES_HISTORYFOLDER
:
746 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, i
, 0,
747 buf
, sizeof(buf
), &size
, 0);
748 ok(hres
== E_FAIL
, "QueryInfo(%d) returned: %08x, expected E_FAIL\n", i
, hres
);
752 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_CAN_NAVIGATE
, 0,
753 buf
, sizeof(buf
), &size
, 0);
754 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
||
755 hres
== E_FAIL
, /* win2k */
756 "QueryInfo returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER or E_FAIL\n", hres
);
759 memset(buf
, '?', sizeof(buf
));
760 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
761 buf
, sizeof(buf
), &size
, 0);
762 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
763 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
764 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
766 memset(buf
, '?', sizeof(buf
));
767 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
768 buf
, sizeof(buf
), NULL
, 0);
769 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
770 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
772 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
774 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
776 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
777 NULL
, sizeof(buf
), &size
, 0);
778 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
780 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, 60, 0,
781 NULL
, sizeof(buf
), &size
, 0);
782 ok(hres
== E_FAIL
, "QueryInfo failed: %08x, expected E_FAIL\n", hres
);
784 IInternetProtocolInfo_Release(protocol_info
);
787 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
788 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
789 if(SUCCEEDED(hres
)) {
790 do_test_about_protocol(factory
, 0);
791 do_test_about_protocol(factory
,
792 BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NEEDFILE
);
794 IClassFactory_Release(factory
);
797 IUnknown_Release(unk
);
800 static void test_javascript_protocol(void)
802 IInternetProtocolInfo
*protocol_info
;
804 IClassFactory
*factory
;
807 hres
= CoGetClassObject(&CLSID_JSProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
808 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
812 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
813 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
814 if(SUCCEEDED(hres
)) {
819 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
820 if(i
!= PARSE_SECURITY_URL
&& i
!= PARSE_DOMAIN
) {
821 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, javascript_test_url
, i
, 0, buf
,
822 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
823 ok(hres
== INET_E_DEFAULT_ACTION
,
824 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
828 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, javascript_test_url
, PARSE_UNESCAPE
+1, 0, buf
,
829 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
830 ok(hres
== INET_E_DEFAULT_ACTION
,
831 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres
);
834 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, javascript_test_url
, javascript_test_url
,
835 0, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
836 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
837 ok(size
== 0xdeadbeef, "size=%d\n", size
);
839 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, javascript_test_url
, javascript_test_url
, 0);
840 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
842 for(i
=0; i
<30; i
++) {
844 case QUERY_USES_NETWORK
:
845 case QUERY_IS_SECURE
:
848 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, javascript_test_url
, i
, 0,
849 buf
, sizeof(buf
), &size
, 0);
850 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
851 "QueryInfo(%d) returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", i
, hres
);
856 memset(buf
, '?', sizeof(buf
));
857 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, javascript_test_url
, QUERY_USES_NETWORK
, 0,
858 buf
, sizeof(buf
), &size
, 0);
859 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
860 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
861 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
863 memset(buf
, '?', sizeof(buf
));
864 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, javascript_test_url
, QUERY_USES_NETWORK
, 0,
865 buf
, sizeof(buf
), NULL
, 0);
866 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
867 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
869 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, javascript_test_url
, QUERY_USES_NETWORK
, 0,
871 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
873 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, javascript_test_url
, QUERY_USES_NETWORK
, 0,
874 NULL
, sizeof(buf
), &size
, 0);
875 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
877 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, javascript_test_url
, 60, 0,
878 NULL
, sizeof(buf
), &size
, 0);
879 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
880 "QueryInfo failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
882 /* FIXME: test QUERY_IS_SECURE */
884 IInternetProtocolInfo_Release(protocol_info
);
887 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
888 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
890 IClassFactory_Release(factory
);
892 IUnknown_Release(unk
);
900 test_about_protocol();
901 test_javascript_protocol();