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>
32 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define CHECK_EXPECT(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 expect_ ## func = FALSE; \
42 called_ ## func = TRUE; \
45 #define CHECK_EXPECT2(func) \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
51 #define CHECK_CALLED(func) \
53 ok(called_ ## func, "expected " #func "\n"); \
54 expect_ ## func = called_ ## func = FALSE; \
57 DEFINE_GUID(CLSID_ResProtocol
, 0x3050F3BC, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
58 DEFINE_GUID(CLSID_AboutProtocol
, 0x3050F406, 0x98B5, 0x11CF, 0xBB,0x82, 0x00,0xAA,0x00,0xBD,0xCE,0x0B);
60 DEFINE_EXPECT(GetBindInfo
);
61 DEFINE_EXPECT(ReportProgress
);
62 DEFINE_EXPECT(ReportData
);
63 DEFINE_EXPECT(ReportResult
);
65 static HRESULT expect_hrResult
;
66 static BOOL expect_hr_win32err
= FALSE
;
69 static const WCHAR about_blank_url
[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
70 static const WCHAR about_test_url
[] = {'a','b','o','u','t',':','t','e','s','t',0};
71 static const WCHAR about_res_url
[] = {'r','e','s',':','b','l','a','n','k',0};
73 static const char *debugstr_w(LPCWSTR str
)
75 static char buf
[1024];
76 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
80 static HRESULT WINAPI
ProtocolSink_QueryInterface(IInternetProtocolSink
*iface
, REFIID riid
, void **ppv
)
82 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
89 static ULONG WINAPI
ProtocolSink_AddRef(IInternetProtocolSink
*iface
)
94 static ULONG WINAPI
ProtocolSink_Release(IInternetProtocolSink
*iface
)
99 static HRESULT WINAPI
ProtocolSink_Switch(IInternetProtocolSink
*iface
, PROTOCOLDATA
*pProtocolData
)
101 ok(0, "unexpected call\n");
105 static HRESULT WINAPI
ProtocolSink_ReportProgress(IInternetProtocolSink
*iface
, ULONG ulStatusCode
,
106 LPCWSTR szStatusText
)
108 static const WCHAR text_html
[] = {'t','e','x','t','/','h','t','m','l',0};
110 CHECK_EXPECT(ReportProgress
);
112 ok(ulStatusCode
== BINDSTATUS_MIMETYPEAVAILABLE
113 || ulStatusCode
== BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
,
114 "ulStatusCode=%d\n", ulStatusCode
);
115 ok(!lstrcmpW(szStatusText
, text_html
), "szStatusText != text/html\n");
120 static HRESULT WINAPI
ProtocolSink_ReportData(IInternetProtocolSink
*iface
, DWORD grfBSCF
, ULONG ulProgress
,
123 CHECK_EXPECT(ReportData
);
125 ok(ulProgress
== ulProgressMax
, "ulProgress != ulProgressMax\n");
126 ok(grfBSCF
== (BSCF_FIRSTDATANOTIFICATION
| BSCF_LASTDATANOTIFICATION
| BSCF_DATAFULLYAVAILABLE
),
127 "grcf = %08x\n", grfBSCF
);
132 static HRESULT WINAPI
ProtocolSink_ReportResult(IInternetProtocolSink
*iface
, HRESULT hrResult
, DWORD dwError
,
135 CHECK_EXPECT(ReportResult
);
137 if(expect_hr_win32err
)
138 ok((hrResult
&0xffff0000) == ((FACILITY_WIN32
<< 16)|0x80000000) || expect_hrResult
,
139 "expected win32 err or %08x got: %08x\n", expect_hrResult
, hrResult
);
141 ok(hrResult
== expect_hrResult
|| ((expect_hrResult
== E_INVALIDARG
||
142 expect_hrResult
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
)) &&
143 hrResult
== MK_E_SYNTAX
), "expected: %08x got: %08x\n", expect_hrResult
, hrResult
);
144 ok(dwError
== 0, "dwError = %d\n", dwError
);
145 ok(!szResult
, "szResult != NULL\n");
150 static IInternetProtocolSinkVtbl protocol_sink_vtbl
= {
151 ProtocolSink_QueryInterface
,
153 ProtocolSink_Release
,
155 ProtocolSink_ReportProgress
,
156 ProtocolSink_ReportData
,
157 ProtocolSink_ReportResult
160 static IInternetProtocolSink protocol_sink
= {
164 static HRESULT WINAPI
BindInfo_QueryInterface(IInternetBindInfo
*iface
, REFIID riid
, void **ppv
)
166 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
170 return E_NOINTERFACE
;
173 static ULONG WINAPI
BindInfo_AddRef(IInternetBindInfo
*iface
)
178 static ULONG WINAPI
BindInfo_Release(IInternetBindInfo
*iface
)
183 static HRESULT WINAPI
BindInfo_GetBindInfo(IInternetBindInfo
*iface
, DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
185 CHECK_EXPECT(GetBindInfo
);
187 ok(grfBINDF
!= NULL
, "grfBINDF == NULL\n");
188 ok(pbindinfo
!= NULL
, "pbindinfo == NULL\n");
189 ok(pbindinfo
->cbSize
== sizeof(BINDINFO
), "wrong size of pbindinfo: %d\n", pbindinfo
->cbSize
);
195 static HRESULT WINAPI
BindInfo_GetBindString(IInternetBindInfo
*iface
, ULONG ulStringType
, LPOLESTR
*ppwzStr
,
196 ULONG cEl
, ULONG
*pcElFetched
)
198 ok(0, "unexpected call\n");
202 static IInternetBindInfoVtbl bind_info_vtbl
= {
203 BindInfo_QueryInterface
,
206 BindInfo_GetBindInfo
,
207 BindInfo_GetBindString
210 static IInternetBindInfo bind_info
= {
214 static void test_protocol_fail(IInternetProtocol
*protocol
, LPCWSTR url
, HRESULT expected_hres
,
215 BOOL expect_win32err
)
219 SET_EXPECT(GetBindInfo
);
220 SET_EXPECT(ReportResult
);
222 expect_hrResult
= expected_hres
;
223 expect_hr_win32err
= expect_win32err
;
224 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
226 ok((hres
&0xffff0000) == ((FACILITY_WIN32
<< 16)|0x80000000) || hres
== expect_hrResult
,
227 "expected win32 err or %08x got: %08x\n", expected_hres
, hres
);
229 ok(hres
== expected_hres
|| ((expected_hres
== E_INVALIDARG
||
230 expected_hres
== HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
)) && hres
== MK_E_SYNTAX
),
231 "expected: %08x got: %08x\n", expected_hres
, hres
);
233 CHECK_CALLED(GetBindInfo
);
234 CHECK_CALLED(ReportResult
);
237 static void protocol_start(IInternetProtocol
*protocol
, LPCWSTR url
)
241 SET_EXPECT(GetBindInfo
);
242 SET_EXPECT(ReportResult
);
243 SET_EXPECT(ReportProgress
);
244 SET_EXPECT(ReportData
);
245 expect_hrResult
= S_OK
;
246 expect_hr_win32err
= FALSE
;
248 hres
= IInternetProtocol_Start(protocol
, url
, &protocol_sink
, &bind_info
, 0, 0);
249 ok(hres
== S_OK
, "Start failed: %08x\n", hres
);
251 CHECK_CALLED(GetBindInfo
);
252 CHECK_CALLED(ReportProgress
);
253 CHECK_CALLED(ReportData
);
254 CHECK_CALLED(ReportResult
);
257 static void res_sec_url_cmp(LPCWSTR url
, DWORD size
, LPCWSTR file
)
262 static const WCHAR fileW
[] = {'f','i','l','e',':','/','/'};
264 if(size
< sizeof(fileW
)/sizeof(WCHAR
) || memcmp(url
, fileW
, sizeof(fileW
))) {
265 ok(0, "wrong URL protocol\n");
269 SetLastError(0xdeadbeef);
270 len
= SearchPathW(NULL
, file
, NULL
, sizeof(buf
)/sizeof(WCHAR
), buf
, NULL
);
272 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
273 win_skip("SearchPathW is not implemented\n");
275 ok(0, "SearchPath failed: %u\n", GetLastError());
279 len
+= sizeof(fileW
)/sizeof(WCHAR
)+1;
280 ok(len
== size
, "wrong size %u, expected %u\n", size
, len
);
281 ok(!lstrcmpW(url
+ sizeof(fileW
)/sizeof(WCHAR
), buf
), "wrong file part %s\n", debugstr_w(url
));
284 static void test_res_protocol(void)
286 IInternetProtocolInfo
*protocol_info
;
288 IClassFactory
*factory
;
291 static const WCHAR blank_url
[] =
292 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
293 static const WCHAR test_part_url
[] = {'r','e','s',':','/','/','C','S','S','/','t','e','s','t',0};
294 static const WCHAR wrong_url1
[] =
295 {'m','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','m','t','h',0};
296 static const WCHAR wrong_url2
[] =
297 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',0};
298 static const WCHAR wrong_url3
[] =
299 {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l','/','x','x','.','h','t','m',0};
300 static const WCHAR wrong_url4
[] =
301 {'r','e','s',':','/','/','x','x','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
302 static const WCHAR wrong_url5
[] =
303 {'r','e','s',':','/','/','s','h','t','m','l','.','d','l','l','/','b','l','a','n','k','.','h','t','m',0};
304 static const WCHAR mshtml_dllW
[] = {'m','s','h','t','m','l','.','d','l','l',0};
306 hres
= CoGetClassObject(&CLSID_ResProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
307 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
311 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
312 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
313 if(SUCCEEDED(hres
)) {
318 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
319 if(i
!= PARSE_SECURITY_URL
&& i
!= PARSE_DOMAIN
) {
320 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, i
, 0, buf
,
321 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
322 ok(hres
== INET_E_DEFAULT_ACTION
,
323 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
327 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_SECURITY_URL
, 0, buf
,
328 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
329 ok(hres
== S_OK
, "ParseUrl failed: %08x\n", hres
);
330 res_sec_url_cmp(buf
, size
, mshtml_dllW
);
333 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_SECURITY_URL
, 0, buf
,
335 ok(hres
== S_FALSE
, "ParseUrl failed: %08x, expected S_FALSE\n", hres
);
336 ok(size
, "size=0\n");
338 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, wrong_url1
, PARSE_SECURITY_URL
, 0, buf
,
339 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
340 ok(hres
== MK_E_SYNTAX
|| hres
== E_INVALIDARG
,
341 "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres
);
343 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, wrong_url5
, PARSE_SECURITY_URL
, 0, buf
,
344 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
345 ok(hres
== MK_E_SYNTAX
, "ParseUrl failed: %08x, expected MK_E_SYNTAX\n", hres
);
349 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_DOMAIN
, 0, buf
,
350 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
351 ok(hres
== S_OK
|| hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
352 ok(buf
[0] == '?', "buf changed\n");
353 ok(size
== sizeof(blank_url
)/sizeof(WCHAR
), "size=%d\n", size
);
356 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, wrong_url1
, PARSE_DOMAIN
, 0, buf
,
357 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
358 ok(hres
== S_OK
|| hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
359 ok(buf
[0] == '?', "buf changed\n");
360 ok(size
== sizeof(wrong_url1
)/sizeof(WCHAR
), "size=%d\n", size
);
364 /* Crashes on win9x */
367 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
368 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
369 ok(hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
370 ok(buf
[0] == '?', "buf changed\n");
371 ok(size
== 1, "size=%u, expected 1\n", size
);
374 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_DOMAIN
, 0, buf
,
375 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
376 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
377 ok(buf
[0] == '?', "buf changed\n");
380 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
381 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
382 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
383 ok(buf
[0] == '?', "buf changed\n");
387 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, blank_url
, PARSE_UNESCAPE
+1, 0, buf
,
388 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
389 ok(hres
== INET_E_DEFAULT_ACTION
,
390 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres
);
391 ok(buf
[0] == '?', "buf changed\n");
394 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, blank_url
, test_part_url
,
395 0, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
396 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
397 ok(size
== 0xdeadbeef, "size=%d\n", size
);
400 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, blank_url
, test_part_url
,
401 URL_FILE_USE_PATHURL
, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
402 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
403 ok(size
== 0xdeadbeef, "size=%d\n", size
);
406 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, NULL
, NULL
,
407 URL_FILE_USE_PATHURL
, NULL
, 0xdeadbeef, NULL
, 0);
408 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
409 ok(size
== 0xdeadbeef, "size=%d\n", size
);
411 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, blank_url
, blank_url
, 0);
412 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
414 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, NULL
, NULL
, 0xdeadbeef);
415 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
417 for(i
=0; i
<30; i
++) {
418 if(i
== QUERY_USES_NETWORK
|| i
== QUERY_IS_SECURE
|| i
== QUERY_IS_SAFE
)
421 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, i
, 0,
422 buf
, sizeof(buf
), &size
, 0);
423 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
424 "QueryInfo(%d) returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", i
, hres
);
428 memset(buf
, '?', sizeof(buf
));
429 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
430 buf
, sizeof(buf
), &size
, 0);
431 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
432 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
433 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
435 memset(buf
, '?', sizeof(buf
));
436 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
437 buf
, sizeof(buf
), NULL
, 0);
438 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
439 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
441 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
443 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
446 memset(buf
, '?', sizeof(buf
));
447 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, NULL
, QUERY_USES_NETWORK
, 0,
448 buf
, sizeof(buf
), &size
, 0);
449 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
450 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
451 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
452 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
454 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, QUERY_USES_NETWORK
, 0,
455 NULL
, sizeof(buf
), &size
, 0);
456 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
458 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, blank_url
, 60, 0,
459 NULL
, sizeof(buf
), &size
, 0);
460 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
,
461 "QueryInfo failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres
);
463 IInternetProtocolInfo_Release(protocol_info
);
466 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
467 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
468 if(SUCCEEDED(hres
)) {
469 IInternetProtocol
*protocol
;
472 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
473 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
475 if(SUCCEEDED(hres
)) {
476 IInternetPriority
*priority
;
478 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
479 ok(hres
== E_NOINTERFACE
,
480 "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres
);
482 test_protocol_fail(protocol
, wrong_url1
, E_INVALIDARG
, FALSE
);
483 test_protocol_fail(protocol
, wrong_url2
,
484 HRESULT_FROM_WIN32(ERROR_RESOURCE_TYPE_NOT_FOUND
), FALSE
);
485 test_protocol_fail(protocol
, wrong_url3
, E_FAIL
, TRUE
);
486 test_protocol_fail(protocol
, wrong_url4
, E_FAIL
, TRUE
);
489 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
490 ok(hres
== E_FAIL
, "Read returned %08x expected E_FAIL\n", hres
);
491 ok(cb
== 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb
);
493 protocol_start(protocol
, blank_url
);
494 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
495 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
496 ok(cb
== 2, "cb=%u expected 2\n", cb
);
497 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
498 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
499 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
500 ok(hres
== S_FALSE
, "Read failed: %08x expected S_FALSE\n", hres
);
501 ok(cb
== 0, "cb=%u expected 0\n", cb
);
502 hres
= IInternetProtocol_UnlockRequest(protocol
);
503 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
505 protocol_start(protocol
, blank_url
);
506 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
507 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
508 hres
= IInternetProtocol_LockRequest(protocol
, 0);
509 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
510 hres
= IInternetProtocol_UnlockRequest(protocol
);
511 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
512 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
513 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
515 protocol_start(protocol
, blank_url
);
516 hres
= IInternetProtocol_LockRequest(protocol
, 0);
517 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
518 hres
= IInternetProtocol_Terminate(protocol
, 0);
519 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
520 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
521 ok(hres
== S_OK
, "Read failed: %08x\n\n", hres
);
522 hres
= IInternetProtocol_UnlockRequest(protocol
);
523 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
524 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
525 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
526 hres
= IInternetProtocol_Terminate(protocol
, 0);
527 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
528 hres
= IInternetProtocol_Read(protocol
, buf
, 2, &cb
);
529 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
530 ok(cb
== 2, "cb=%u expected 2\n", cb
);
532 protocol_start(protocol
, blank_url
);
533 hres
= IInternetProtocol_LockRequest(protocol
, 0);
534 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
535 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
536 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
537 protocol_start(protocol
, blank_url
);
538 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
539 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
540 hres
= IInternetProtocol_Terminate(protocol
, 0);
541 ok(hres
== S_OK
, "Terminate failed: %08x\n", hres
);
543 IInternetProtocol_Release(protocol
);
546 IClassFactory_Release(factory
);
549 IUnknown_Release(unk
);
552 static void do_test_about_protocol(IClassFactory
*factory
, DWORD bf
)
554 IInternetProtocol
*protocol
;
555 IInternetPriority
*priority
;
560 static const WCHAR blank_html
[] = {0xfeff,'<','H','T','M','L','>','<','/','H','T','M','L','>',0};
561 static const WCHAR test_html
[] =
562 {0xfeff,'<','H','T','M','L','>','t','e','s','t','<','/','H','T','M','L','>',0};
566 hres
= IClassFactory_CreateInstance(factory
, NULL
, &IID_IInternetProtocol
, (void**)&protocol
);
567 ok(hres
== S_OK
, "Could not get IInternetProtocol: %08x\n", hres
);
571 hres
= IInternetProtocol_QueryInterface(protocol
, &IID_IInternetPriority
, (void**)&priority
);
572 ok(hres
== E_NOINTERFACE
,
573 "QueryInterface(IInternetPriority) returned %08x, expected E_NOINTEFACE\n", hres
);
575 protocol_start(protocol
, about_blank_url
);
576 hres
= IInternetProtocol_LockRequest(protocol
, 0);
577 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
578 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
579 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
580 ok(cb
== sizeof(blank_html
), "cb=%d\n", cb
);
581 ok(!memcmp(buf
, blank_html
, cb
), "Readed wrong data\n");
582 hres
= IInternetProtocol_UnlockRequest(protocol
);
583 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
585 protocol_start(protocol
, about_test_url
);
586 hres
= IInternetProtocol_LockRequest(protocol
, 0);
587 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
588 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
589 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
590 ok(cb
== sizeof(test_html
), "cb=%d\n", cb
);
591 ok(!memcmp(buf
, test_html
, cb
), "Readed wrong data\n");
592 hres
= IInternetProtocol_UnlockRequest(protocol
);
593 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
595 protocol_start(protocol
, about_res_url
);
596 hres
= IInternetProtocol_LockRequest(protocol
, 0);
597 ok(hres
== S_OK
, "LockRequest failed: %08x\n", hres
);
598 hres
= IInternetProtocol_Read(protocol
, buf
, sizeof(buf
), &cb
);
599 ok(hres
== S_OK
, "Read failed: %08x\n", hres
);
600 ok(cb
== sizeof(blank_html
), "cb=%d\n", cb
);
601 ok(!memcmp(buf
, blank_html
, cb
), "Readed wrong data\n");
602 hres
= IInternetProtocol_UnlockRequest(protocol
);
603 ok(hres
== S_OK
, "UnlockRequest failed: %08x\n", hres
);
605 IInternetProtocol_Release(protocol
);
608 static void test_about_protocol(void)
610 IInternetProtocolInfo
*protocol_info
;
612 IClassFactory
*factory
;
615 hres
= CoGetClassObject(&CLSID_AboutProtocol
, CLSCTX_INPROC_SERVER
, NULL
, &IID_IUnknown
, (void**)&unk
);
616 ok(hres
== S_OK
, "CoGetClassObject failed: %08x\n", hres
);
620 hres
= IUnknown_QueryInterface(unk
, &IID_IInternetProtocolInfo
, (void**)&protocol_info
);
621 ok(hres
== S_OK
, "Could not get IInternetProtocolInfo interface: %08x\n", hres
);
622 if(SUCCEEDED(hres
)) {
627 for(i
= PARSE_CANONICALIZE
; i
<= PARSE_UNESCAPE
; i
++) {
628 if(i
!= PARSE_SECURITY_URL
&& i
!= PARSE_DOMAIN
) {
629 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, i
, 0, buf
,
630 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
631 ok(hres
== INET_E_DEFAULT_ACTION
,
632 "[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i
, hres
);
636 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_SECURITY_URL
, 0, buf
,
637 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
638 ok(hres
== S_OK
, "ParseUrl failed: %08x\n", hres
);
639 ok(!lstrcmpW(about_blank_url
, buf
), "buf != blank_url\n");
641 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_SECURITY_URL
, 0, buf
,
643 ok(hres
== S_FALSE
, "ParseUrl failed: %08x, expected S_FALSE\n", hres
);
645 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_test_url
, PARSE_SECURITY_URL
, 0, buf
,
646 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
647 ok(hres
== S_OK
, "ParseUrl failed: %08x\n", hres
);
648 ok(!lstrcmpW(about_test_url
, buf
), "buf != test_url\n");
652 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_DOMAIN
, 0, buf
,
653 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
654 ok(hres
== S_OK
|| hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
655 ok(buf
[0] == '?', "buf changed\n");
656 ok(size
== sizeof(about_blank_url
)/sizeof(WCHAR
), "size=%d\n", size
);
660 /* Crashes on win9x */
663 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
664 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
665 ok(hres
== E_FAIL
, "ParseUrl failed: %08x\n", hres
);
666 ok(buf
[0] == '?', "buf changed\n");
667 ok(size
== 1, "size=%u, expected 1\n", size
);
670 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_DOMAIN
, 0, buf
,
671 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
672 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
673 ok(buf
[0] == '?', "buf changed\n");
676 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, NULL
, PARSE_DOMAIN
, 0, buf
,
677 sizeof(buf
)/sizeof(buf
[0]), NULL
, 0);
678 ok(hres
== E_POINTER
, "ParseUrl failed: %08x\n", hres
);
679 ok(buf
[0] == '?', "buf changed\n");
682 hres
= IInternetProtocolInfo_ParseUrl(protocol_info
, about_blank_url
, PARSE_UNESCAPE
+1, 0, buf
,
683 sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
684 ok(hres
== INET_E_DEFAULT_ACTION
,
685 "ParseUrl failed: %08x, expected INET_E_DEFAULT_ACTION\n", hres
);
688 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, about_blank_url
, about_test_url
,
689 0, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
690 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
691 ok(size
== 0xdeadbeef, "size=%d\n", size
);
694 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, about_blank_url
, about_test_url
,
695 URL_FILE_USE_PATHURL
, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
696 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
697 ok(size
== 0xdeadbeef, "size=%d\n", size
);
700 hres
= IInternetProtocolInfo_CombineUrl(protocol_info
, NULL
, NULL
,
701 URL_FILE_USE_PATHURL
, buf
, sizeof(buf
)/sizeof(buf
[0]), &size
, 0);
702 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
, "CombineUrl failed: %08x\n", hres
);
703 ok(size
== 0xdeadbeef, "size=%d\n", size
);
705 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, about_blank_url
, about_blank_url
, 0);
706 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
708 hres
= IInternetProtocolInfo_CompareUrl(protocol_info
, NULL
, NULL
, 0xdeadbeef);
709 ok(hres
== E_NOTIMPL
, "CompareUrl failed: %08x\n", hres
);
711 for(i
=0; i
<30; i
++) {
713 case QUERY_CAN_NAVIGATE
:
714 case QUERY_USES_NETWORK
:
715 case QUERY_IS_CACHED
:
716 case QUERY_IS_INSTALLEDENTRY
:
717 case QUERY_IS_CACHED_OR_MAPPED
:
718 case QUERY_IS_SECURE
:
720 case QUERY_USES_HISTORYFOLDER
:
723 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, i
, 0,
724 buf
, sizeof(buf
), &size
, 0);
725 ok(hres
== E_FAIL
, "QueryInfo(%d) returned: %08x, expected E_FAIL\n", i
, hres
);
729 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_CAN_NAVIGATE
, 0,
730 buf
, sizeof(buf
), &size
, 0);
731 ok(hres
== INET_E_USE_DEFAULT_PROTOCOLHANDLER
||
732 hres
== E_FAIL
, /* win2k */
733 "QueryInfo returned: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER or E_FAIL\n", hres
);
736 memset(buf
, '?', sizeof(buf
));
737 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
738 buf
, sizeof(buf
), &size
, 0);
739 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
740 ok(size
== sizeof(DWORD
), "size=%d\n", size
);
741 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
743 memset(buf
, '?', sizeof(buf
));
744 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
745 buf
, sizeof(buf
), NULL
, 0);
746 ok(hres
== S_OK
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x\n", hres
);
747 ok(!*(DWORD
*)buf
, "buf=%d\n", *(DWORD
*)buf
);
749 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
751 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
753 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, QUERY_USES_NETWORK
, 0,
754 NULL
, sizeof(buf
), &size
, 0);
755 ok(hres
== E_FAIL
, "QueryInfo(QUERY_USES_NETWORK) failed: %08x, expected E_FAIL\n", hres
);
757 hres
= IInternetProtocolInfo_QueryInfo(protocol_info
, about_blank_url
, 60, 0,
758 NULL
, sizeof(buf
), &size
, 0);
759 ok(hres
== E_FAIL
, "QueryInfo failed: %08x, expected E_FAIL\n", hres
);
761 IInternetProtocolInfo_Release(protocol_info
);
764 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&factory
);
765 ok(hres
== S_OK
, "Could not get IClassFactory interface\n");
766 if(SUCCEEDED(hres
)) {
767 do_test_about_protocol(factory
, 0);
768 do_test_about_protocol(factory
,
769 BINDF_ASYNCHRONOUS
| BINDF_ASYNCSTORAGE
| BINDF_PULLDATA
| BINDF_FROMURLMON
| BINDF_NEEDFILE
);
771 IClassFactory_Release(factory
);
774 IUnknown_Release(unk
);
782 test_about_protocol();