2006-12-25 16:09:41 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2006 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include <wine/test.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2008-07-08 16:17:17 +02:00
|
|
|
#include "initguid.h"
|
2006-12-25 16:09:41 +01:00
|
|
|
#include "ole2.h"
|
|
|
|
#include "urlmon.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
|
|
|
#define DEFINE_EXPECT(func) \
|
|
|
|
static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
|
|
|
|
|
|
|
|
#define SET_EXPECT(func) \
|
|
|
|
expect_ ## func = TRUE
|
|
|
|
|
|
|
|
#define CHECK_EXPECT(func) \
|
|
|
|
do { \
|
|
|
|
ok(expect_ ##func, "unexpected call " #func "\n"); \
|
|
|
|
expect_ ## func = FALSE; \
|
|
|
|
called_ ## func = TRUE; \
|
|
|
|
}while(0)
|
|
|
|
|
2007-10-26 01:22:20 +02:00
|
|
|
#define SET_CALLED(func) \
|
|
|
|
expect_ ## func = called_ ## func = FALSE
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
#define CHECK_CALLED(func) \
|
|
|
|
do { \
|
|
|
|
ok(called_ ## func, "expected " #func "\n"); \
|
2007-10-26 01:22:20 +02:00
|
|
|
SET_CALLED(func); \
|
2006-12-25 16:09:41 +01:00
|
|
|
}while(0)
|
|
|
|
|
|
|
|
DEFINE_GUID(CLSID_ITSProtocol,0x9d148291,0xb9c8,0x11d0,0xa4,0xcc,0x00,0x00,0xf8,0x01,0x49,0xf6);
|
|
|
|
|
|
|
|
DEFINE_EXPECT(GetBindInfo);
|
|
|
|
DEFINE_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
|
|
|
|
DEFINE_EXPECT(ReportProgress_SENDINGREQUEST);
|
|
|
|
DEFINE_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
|
2011-08-01 15:48:17 +02:00
|
|
|
DEFINE_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
2007-01-13 12:47:57 +01:00
|
|
|
DEFINE_EXPECT(ReportProgress_DIRECTBIND);
|
2006-12-25 16:09:41 +01:00
|
|
|
DEFINE_EXPECT(ReportData);
|
|
|
|
DEFINE_EXPECT(ReportResult);
|
|
|
|
|
|
|
|
static HRESULT expect_hrResult;
|
2007-02-06 20:49:02 +01:00
|
|
|
static IInternetProtocol *read_protocol = NULL;
|
2008-01-31 18:19:20 +01:00
|
|
|
static DWORD bindf;
|
2006-12-25 16:09:41 +01:00
|
|
|
|
2007-02-22 21:11:21 +01:00
|
|
|
static const WCHAR blank_url1[] = {'i','t','s',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR blank_url2[] = {'m','S','-','i','T','s',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR blank_url3[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR blank_url4[] = {'i','t','s',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR blank_url5[] = {'i','t','s',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR blank_url6[] = {'i','t','s',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','%','6','2','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR blank_url7[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
|
2007-03-13 18:44:05 +01:00
|
|
|
static const WCHAR blank_url8[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
|
2012-09-21 12:28:18 +02:00
|
|
|
static const WCHAR blank_url9[] = {'i','t','s',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','d','i','r','/','.','.','/','b','l','a','n','k','.','h','t','m','l',0};
|
2007-02-22 21:11:21 +01:00
|
|
|
|
2007-01-13 12:47:57 +01:00
|
|
|
static enum {
|
|
|
|
ITS_PROTOCOL,
|
|
|
|
MK_PROTOCOL
|
|
|
|
} test_protocol;
|
|
|
|
|
2007-02-22 21:10:08 +01:00
|
|
|
static const WCHAR cache_file1[] =
|
|
|
|
{'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR cache_file2[] =
|
|
|
|
{'t','e','s','t','.','c','h','m',':',':','\\','b','l','a','n','k','.','h','t','m','l',0};
|
2007-03-13 18:44:05 +01:00
|
|
|
static const WCHAR cache_file3[] =
|
|
|
|
{'t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l','/',0};
|
2007-02-22 21:10:08 +01:00
|
|
|
static const WCHAR *cache_file = cache_file1;
|
|
|
|
|
2012-12-05 18:38:28 +01:00
|
|
|
static const WCHAR *a2w(const char *str)
|
|
|
|
{
|
|
|
|
static WCHAR bufs[8][128];
|
|
|
|
static int i;
|
|
|
|
|
|
|
|
if(!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
i = (i+1) % 8;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, str, -1, bufs[i], 128);
|
|
|
|
return bufs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int strcmp_wa(const WCHAR *str1, const char *str2)
|
|
|
|
{
|
|
|
|
return lstrcmpW(str1, a2w(str2));
|
|
|
|
}
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
static HRESULT WINAPI ProtocolSink_QueryInterface(IInternetProtocolSink *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
|
|
|
|
*ppv = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProtocolSink_AddRef(IInternetProtocolSink *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProtocolSink_Release(IInternetProtocolSink *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolSink_Switch(IInternetProtocolSink *iface, PROTOCOLDATA *pProtocolData)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode,
|
|
|
|
LPCWSTR szStatusText)
|
|
|
|
{
|
|
|
|
static const WCHAR blank_html[] = {'b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR text_html[] = {'t','e','x','t','/','h','t','m','l',0};
|
|
|
|
|
|
|
|
switch(ulStatusCode) {
|
|
|
|
case BINDSTATUS_BEGINDOWNLOADDATA:
|
|
|
|
CHECK_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
|
|
|
|
ok(!szStatusText, "szStatusText != NULL\n");
|
|
|
|
break;
|
|
|
|
case BINDSTATUS_SENDINGREQUEST:
|
|
|
|
CHECK_EXPECT(ReportProgress_SENDINGREQUEST);
|
2007-01-13 12:47:57 +01:00
|
|
|
if(test_protocol == ITS_PROTOCOL)
|
|
|
|
ok(!lstrcmpW(szStatusText, blank_html), "unexpected szStatusText\n");
|
|
|
|
else
|
|
|
|
ok(szStatusText == NULL, "szStatusText != NULL\n");
|
2006-12-25 16:09:41 +01:00
|
|
|
break;
|
|
|
|
case BINDSTATUS_MIMETYPEAVAILABLE:
|
|
|
|
CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
|
|
|
|
ok(!lstrcmpW(szStatusText, text_html), "unexpected szStatusText\n");
|
|
|
|
break;
|
2007-01-13 12:47:57 +01:00
|
|
|
case BINDSTATUS_CACHEFILENAMEAVAILABLE:
|
2011-08-01 15:48:17 +02:00
|
|
|
CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
2007-01-13 12:47:57 +01:00
|
|
|
ok(!lstrcmpW(szStatusText, cache_file), "unexpected szStatusText\n");
|
|
|
|
break;
|
|
|
|
case BINDSTATUS_DIRECTBIND:
|
|
|
|
CHECK_EXPECT(ReportProgress_DIRECTBIND);
|
|
|
|
ok(!szStatusText, "szStatusText != NULL\n");
|
|
|
|
break;
|
2006-12-25 16:09:41 +01:00
|
|
|
default:
|
|
|
|
ok(0, "unexpected ulStatusCode %d\n", ulStatusCode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolSink_ReportData(IInternetProtocolSink *iface, DWORD grfBSCF, ULONG ulProgress,
|
|
|
|
ULONG ulProgressMax)
|
|
|
|
{
|
|
|
|
CHECK_EXPECT(ReportData);
|
|
|
|
|
|
|
|
ok(ulProgress == ulProgressMax, "ulProgress != ulProgressMax\n");
|
2007-01-13 12:47:57 +01:00
|
|
|
if(test_protocol == ITS_PROTOCOL)
|
|
|
|
ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_DATAFULLYAVAILABLE), "grcf = %08x\n", grfBSCF);
|
|
|
|
else
|
|
|
|
ok(grfBSCF == (BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION), "grcf = %08x\n", grfBSCF);
|
2006-12-25 16:09:41 +01:00
|
|
|
|
2007-02-06 20:49:02 +01:00
|
|
|
if(read_protocol) {
|
|
|
|
BYTE buf[100];
|
|
|
|
DWORD cb = 0xdeadbeef;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IInternetProtocol_Read(read_protocol, buf, sizeof(buf), &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 13, "cb=%u expected 13\n", cb);
|
|
|
|
ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
|
|
|
|
}
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-06 20:49:02 +01:00
|
|
|
static HRESULT WINAPI ProtocolSink_ReportResult(IInternetProtocolSink *iface, HRESULT hrResult,
|
|
|
|
DWORD dwError, LPCWSTR szResult)
|
2006-12-25 16:09:41 +01:00
|
|
|
{
|
|
|
|
CHECK_EXPECT(ReportResult);
|
|
|
|
|
|
|
|
ok(hrResult == expect_hrResult, "expected: %08x got: %08x\n", expect_hrResult, hrResult);
|
|
|
|
ok(dwError == 0, "dwError = %d\n", dwError);
|
|
|
|
ok(!szResult, "szResult != NULL\n");
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IInternetProtocolSinkVtbl protocol_sink_vtbl = {
|
|
|
|
ProtocolSink_QueryInterface,
|
|
|
|
ProtocolSink_AddRef,
|
|
|
|
ProtocolSink_Release,
|
|
|
|
ProtocolSink_Switch,
|
|
|
|
ProtocolSink_ReportProgress,
|
|
|
|
ProtocolSink_ReportData,
|
|
|
|
ProtocolSink_ReportResult
|
|
|
|
};
|
|
|
|
|
|
|
|
static IInternetProtocolSink protocol_sink = {
|
|
|
|
&protocol_sink_vtbl
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetBindInfo, riid)) {
|
|
|
|
*ppv = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
|
|
|
|
{
|
|
|
|
CHECK_EXPECT(GetBindInfo);
|
|
|
|
|
|
|
|
ok(grfBINDF != NULL, "grfBINDF == NULL\n");
|
|
|
|
if(grfBINDF)
|
|
|
|
ok(!*grfBINDF, "*grfBINDF != 0\n");
|
|
|
|
ok(pbindinfo != NULL, "pbindinfo == NULL\n");
|
|
|
|
ok(pbindinfo->cbSize == sizeof(BINDINFO), "wrong size of pbindinfo: %d\n", pbindinfo->cbSize);
|
|
|
|
|
2008-01-31 18:19:20 +01:00
|
|
|
*grfBINDF = bindf;
|
2006-12-25 16:09:41 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface, ULONG ulStringType, LPOLESTR *ppwzStr,
|
|
|
|
ULONG cEl, ULONG *pcElFetched)
|
|
|
|
{
|
|
|
|
ok(0, "unexpected call\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IInternetBindInfoVtbl bind_info_vtbl = {
|
|
|
|
BindInfo_QueryInterface,
|
|
|
|
BindInfo_AddRef,
|
|
|
|
BindInfo_Release,
|
|
|
|
BindInfo_GetBindInfo,
|
|
|
|
BindInfo_GetBindString
|
|
|
|
};
|
|
|
|
|
|
|
|
static IInternetBindInfo bind_info = {
|
|
|
|
&bind_info_vtbl
|
|
|
|
};
|
|
|
|
|
|
|
|
static void test_protocol_fail(IInternetProtocol *protocol, LPCWSTR url, HRESULT expected_hres)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
SET_EXPECT(GetBindInfo);
|
|
|
|
SET_EXPECT(ReportResult);
|
|
|
|
|
|
|
|
expect_hrResult = expected_hres;
|
|
|
|
hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
|
|
|
|
ok(hres == expected_hres, "expected: %08x got: %08x\n", expected_hres, hres);
|
|
|
|
|
|
|
|
CHECK_CALLED(GetBindInfo);
|
|
|
|
CHECK_CALLED(ReportResult);
|
|
|
|
}
|
|
|
|
|
2007-10-26 01:22:20 +02:00
|
|
|
#define protocol_start(p,u,e) _protocol_start(__LINE__,p,u,e)
|
|
|
|
static HRESULT _protocol_start(unsigned line, IInternetProtocol *protocol, LPCWSTR url, BOOL expect_mime)
|
2006-12-25 16:09:41 +01:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
SET_EXPECT(GetBindInfo);
|
2007-01-13 12:47:57 +01:00
|
|
|
if(test_protocol == MK_PROTOCOL)
|
|
|
|
SET_EXPECT(ReportProgress_DIRECTBIND);
|
2006-12-25 16:09:41 +01:00
|
|
|
SET_EXPECT(ReportProgress_SENDINGREQUEST);
|
2007-03-13 18:44:05 +01:00
|
|
|
if(expect_mime)
|
|
|
|
SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
|
2007-01-13 12:47:57 +01:00
|
|
|
if(test_protocol == MK_PROTOCOL)
|
2011-08-01 15:48:17 +02:00
|
|
|
SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
2006-12-25 16:09:41 +01:00
|
|
|
SET_EXPECT(ReportData);
|
2007-01-13 12:47:57 +01:00
|
|
|
if(test_protocol == ITS_PROTOCOL)
|
|
|
|
SET_EXPECT(ReportProgress_BEGINDOWNLOADDATA);
|
2006-12-25 16:09:41 +01:00
|
|
|
SET_EXPECT(ReportResult);
|
|
|
|
expect_hrResult = S_OK;
|
|
|
|
|
|
|
|
hres = IInternetProtocol_Start(protocol, url, &protocol_sink, &bind_info, 0, 0);
|
2007-10-26 01:22:20 +02:00
|
|
|
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
SET_CALLED(GetBindInfo);
|
|
|
|
if(test_protocol == MK_PROTOCOL)
|
|
|
|
SET_CALLED(ReportProgress_DIRECTBIND);
|
|
|
|
SET_CALLED(ReportProgress_SENDINGREQUEST);
|
|
|
|
if(expect_mime)
|
|
|
|
SET_CALLED(ReportProgress_MIMETYPEAVAILABLE);
|
|
|
|
if(test_protocol == MK_PROTOCOL)
|
2011-08-01 15:48:17 +02:00
|
|
|
SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
2007-10-26 01:22:20 +02:00
|
|
|
SET_CALLED(ReportData);
|
|
|
|
if(test_protocol == ITS_PROTOCOL)
|
|
|
|
SET_CALLED(ReportProgress_BEGINDOWNLOADDATA);
|
|
|
|
SET_CALLED(ReportResult);
|
|
|
|
}else {
|
|
|
|
CHECK_CALLED(GetBindInfo);
|
|
|
|
if(test_protocol == MK_PROTOCOL)
|
2007-10-30 11:44:12 +01:00
|
|
|
SET_CALLED(ReportProgress_DIRECTBIND);
|
2007-10-26 01:22:20 +02:00
|
|
|
CHECK_CALLED(ReportProgress_SENDINGREQUEST);
|
|
|
|
if(expect_mime)
|
|
|
|
CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
|
|
|
|
if(test_protocol == MK_PROTOCOL)
|
2011-08-01 15:48:17 +02:00
|
|
|
SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
2007-10-26 01:22:20 +02:00
|
|
|
CHECK_CALLED(ReportData);
|
|
|
|
if(test_protocol == ITS_PROTOCOL)
|
|
|
|
CHECK_CALLED(ReportProgress_BEGINDOWNLOADDATA);
|
|
|
|
CHECK_CALLED(ReportResult);
|
|
|
|
}
|
2006-12-25 16:09:41 +01:00
|
|
|
|
2007-10-26 01:22:20 +02:00
|
|
|
return hres;
|
2006-12-25 16:09:41 +01:00
|
|
|
}
|
|
|
|
|
2007-03-13 18:44:05 +01:00
|
|
|
static void test_protocol_url(IClassFactory *factory, LPCWSTR url, BOOL expect_mime)
|
2006-12-25 16:09:41 +01:00
|
|
|
{
|
|
|
|
IInternetProtocol *protocol;
|
|
|
|
BYTE buf[512];
|
|
|
|
ULONG cb, ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2007-10-26 01:22:20 +02:00
|
|
|
hres = protocol_start(protocol, url, expect_mime);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
IInternetProtocol_Release(protocol);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 13, "cb=%u expected 13\n", cb);
|
|
|
|
ok(!memcmp(buf, "<html></html>", 13), "unexpected data\n");
|
|
|
|
ref = IInternetProtocol_Release(protocol);
|
|
|
|
ok(!ref, "protocol ref=%d\n", ref);
|
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cb = 0xdeadbeef;
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
|
2007-01-13 12:47:57 +01:00
|
|
|
ok(hres == (test_protocol == ITS_PROTOCOL ? INET_E_DATA_NOT_AVAILABLE : E_FAIL),
|
|
|
|
"Read returned %08x\n", hres);
|
2006-12-25 16:09:41 +01:00
|
|
|
ok(cb == 0xdeadbeef, "cb=%u expected 0xdeadbeef\n", cb);
|
|
|
|
|
2007-03-13 18:44:05 +01:00
|
|
|
protocol_start(protocol, url, expect_mime);
|
2006-12-25 16:09:41 +01:00
|
|
|
hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 2, "cb=%u expected 2\n", cb);
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 11, "cb=%u, expected 11\n", cb);
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
|
|
|
|
ok(hres == S_FALSE, "Read failed: %08x expected S_FALSE\n", hres);
|
|
|
|
ok(cb == 0, "cb=%u expected 0\n", cb);
|
|
|
|
hres = IInternetProtocol_UnlockRequest(protocol);
|
|
|
|
ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
|
|
|
|
ref = IInternetProtocol_Release(protocol);
|
|
|
|
ok(!ref, "protocol ref=%d\n", ref);
|
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2007-03-13 18:44:05 +01:00
|
|
|
protocol_start(protocol, url, expect_mime);
|
2006-12-25 16:09:41 +01:00
|
|
|
hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_LockRequest(protocol, 0);
|
|
|
|
ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_UnlockRequest(protocol);
|
|
|
|
ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, sizeof(buf), &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 11, "cb=%u, expected 11\n", cb);
|
|
|
|
ref = IInternetProtocol_Release(protocol);
|
|
|
|
ok(!ref, "protocol ref=%d\n", ref);
|
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2007-03-13 18:44:05 +01:00
|
|
|
protocol_start(protocol, url, expect_mime);
|
2006-12-25 16:09:41 +01:00
|
|
|
hres = IInternetProtocol_LockRequest(protocol, 0);
|
|
|
|
ok(hres == S_OK, "LockRequest failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_Terminate(protocol, 0);
|
|
|
|
ok(hres == S_OK, "Terminate failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 2, "cb=%u, expected 2\n", cb);
|
|
|
|
hres = IInternetProtocol_UnlockRequest(protocol);
|
|
|
|
ok(hres == S_OK, "UnlockRequest failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 2, "cb=%u, expected 2\n", cb);
|
|
|
|
hres = IInternetProtocol_Terminate(protocol, 0);
|
|
|
|
ok(hres == S_OK, "Terminate failed: %08x\n", hres);
|
|
|
|
hres = IInternetProtocol_Read(protocol, buf, 2, &cb);
|
|
|
|
ok(hres == S_OK, "Read failed: %08x\n", hres);
|
|
|
|
ok(cb == 2, "cb=%u expected 2\n", cb);
|
|
|
|
ref = IInternetProtocol_Release(protocol);
|
|
|
|
ok(!ref, "protocol ref=%d\n", ref);
|
2007-02-06 20:49:02 +01:00
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&read_protocol);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2007-03-13 18:44:05 +01:00
|
|
|
protocol_start(read_protocol, url, expect_mime);
|
2007-02-06 20:49:02 +01:00
|
|
|
ref = IInternetProtocol_Release(read_protocol);
|
|
|
|
ok(!ref, "protocol ref=%d\n", ref);
|
|
|
|
read_protocol = NULL;
|
2006-12-25 16:09:41 +01:00
|
|
|
}
|
|
|
|
|
2007-02-22 21:12:19 +01:00
|
|
|
static const struct {
|
2012-12-05 18:38:28 +01:00
|
|
|
const char *base_url;
|
|
|
|
const char *rel_url;
|
2007-02-22 21:12:19 +01:00
|
|
|
DWORD flags;
|
|
|
|
HRESULT hres;
|
2012-12-05 18:38:28 +01:00
|
|
|
const char *combined_url;
|
2007-02-22 21:12:19 +01:00
|
|
|
} combine_tests[] = {
|
2012-12-05 18:38:28 +01:00
|
|
|
{"its:test.chm::/blank.html", "its:test.chm::/blank.html", 0, STG_E_INVALIDNAME, NULL},
|
|
|
|
{"mS-iTs:test.chm::/blank.html", "mS-iTs:test.chm::/blank.html", 0, STG_E_INVALIDNAME, NULL},
|
|
|
|
{"its:test.chm::/blank.html", "test.html", 0, S_OK, "its:test.chm::/test.html"},
|
|
|
|
{"its:test.chm::/blank.html", "test.chm::/test.html", 0, STG_E_INVALIDNAME, NULL},
|
|
|
|
{"its:test.chm::/blank.html", "/test.html", 0, S_OK, "its:test.chm::/test.html"},
|
|
|
|
{"its:test.chm::/blank.html", "te:t.html", 0, STG_E_INVALIDNAME, NULL},
|
|
|
|
{"its:test.chm::/blank.html", "/test.html", URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO, S_OK, "its:test.chm::/test.html"},
|
|
|
|
{"its:test.chm::/blank.html", "dir/test.html", 0, S_OK, "its:test.chm::/dir/test.html"},
|
|
|
|
{"test.html", "test.chm::/test.html", 0, 0x80041001, NULL},
|
|
|
|
{"its:test:.chm::/blank.html", "test.html", 0, S_OK, "its:test:.chm::/test.html"},
|
|
|
|
{"its:test.chm::/dir/blank.html", "test.html", 0, S_OK, "its:test.chm::/dir/test.html"},
|
|
|
|
{"its:test.chm::blank.html", "test.html", 0, S_OK, "its:test.chm::blank.htmltest.html"},
|
|
|
|
{"ms-its:test.chm::/dir/blank.html", "test.html", 0, S_OK, "ms-its:test.chm::/dir/test.html"},
|
|
|
|
{"mk:@MSITStore:test.chm::/dir/blank.html", "test.html", 0, S_OK, "mk:@MSITStore:test.chm::/dir/test.html"},
|
|
|
|
{"xxx:test.chm::/dir/blank.html", "test.html", 0, INET_E_USE_DEFAULT_PROTOCOLHANDLER, NULL},
|
|
|
|
{"its:test.chm::/dir/blank.html", "/test.html", 0, S_OK, "its:test.chm::/test.html"},
|
2012-12-05 18:38:40 +01:00
|
|
|
{"its:test.chm::/blank.html", "#frag", 0, S_OK, "its:test.chm::/blank.html#frag"},
|
|
|
|
{"its:test.chm::/blank.html#hash", "#frag", 0, S_OK, "its:test.chm::/blank.html#hash#frag"},
|
|
|
|
{"its:test.chm::/blank.html", "test.html#frag", 0, S_OK, "its:test.chm::/test.html#frag"},
|
|
|
|
{"its:test.chm::/blank.html", "/test.html#frag", 0, S_OK, "its:test.chm::/test.html#frag"},
|
|
|
|
{"its:test.chm::/blank.html", "?query", 0, S_OK, "its:test.chm::/?query"},
|
|
|
|
{"its:test.chm::/blank.html#frag/blank", "test.html", 0, S_OK, "its:test.chm::/blank.html#frag/test.html"},
|
2007-02-22 21:12:19 +01:00
|
|
|
};
|
|
|
|
|
2007-02-22 21:10:42 +01:00
|
|
|
static void test_its_protocol_info(IInternetProtocol *protocol)
|
|
|
|
{
|
|
|
|
IInternetProtocolInfo *info;
|
2007-02-22 21:11:21 +01:00
|
|
|
WCHAR buf[1024];
|
|
|
|
DWORD size, i;
|
2007-02-22 21:10:42 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetProtocolInfo, (void**)&info);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocolInfo interface: %08x\n", hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2007-02-22 21:11:21 +01:00
|
|
|
for(i = PARSE_CANONICALIZE; i <= PARSE_UNESCAPE; i++) {
|
|
|
|
if(i != PARSE_CANONICALIZE && i != PARSE_SECURITY_URL) {
|
|
|
|
hres = IInternetProtocolInfo_ParseUrl(info, blank_url1, i, 0, buf,
|
|
|
|
sizeof(buf)/sizeof(buf[0]), &size, 0);
|
|
|
|
ok(hres == INET_E_DEFAULT_ACTION,
|
|
|
|
"[%d] failed: %08x, expected INET_E_DEFAULT_ACTION\n", i, hres);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-22 21:12:19 +01:00
|
|
|
for(i=0; i < sizeof(combine_tests)/sizeof(combine_tests[0]); i++) {
|
|
|
|
size = 0xdeadbeef;
|
|
|
|
memset(buf, 0xfe, sizeof(buf));
|
2012-12-05 18:38:28 +01:00
|
|
|
hres = IInternetProtocolInfo_CombineUrl(info, a2w(combine_tests[i].base_url),
|
|
|
|
a2w(combine_tests[i].rel_url), combine_tests[i].flags, buf,
|
2007-02-22 21:12:19 +01:00
|
|
|
sizeof(buf)/sizeof(WCHAR), &size, 0);
|
|
|
|
ok(hres == combine_tests[i].hres, "[%d] CombineUrl returned %08x, expected %08x\n",
|
|
|
|
i, hres, combine_tests[i].hres);
|
2012-12-05 18:38:28 +01:00
|
|
|
ok(size == (combine_tests[i].combined_url ? strlen(combine_tests[i].combined_url)+1
|
2007-02-22 21:12:19 +01:00
|
|
|
: 0xdeadbeef), "[%d] unexpected size=%d\n", i, size);
|
|
|
|
if(combine_tests[i].combined_url)
|
2012-12-05 18:38:28 +01:00
|
|
|
ok(!strcmp_wa(buf, combine_tests[i].combined_url), "[%d] unexpected result: %s\n", i, wine_dbgstr_w(buf));
|
2007-02-22 21:12:19 +01:00
|
|
|
else
|
|
|
|
ok(buf[0] == 0xfefe, "buf changed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
size = 0xdeadbeef;
|
|
|
|
memset(buf, 0xfe, sizeof(buf));
|
2012-12-05 18:38:28 +01:00
|
|
|
hres = IInternetProtocolInfo_CombineUrl(info, a2w("its:test.chm::/blank.html"), a2w("test.html"), 0, buf,
|
2007-02-22 21:12:19 +01:00
|
|
|
1, &size, 0);
|
|
|
|
ok(hres == E_OUTOFMEMORY, "CombineUrl failed: %08x\n", hres);
|
2012-12-05 18:38:28 +01:00
|
|
|
ok(size == 25, "size=%d\n", size);
|
2007-02-22 21:12:19 +01:00
|
|
|
ok(buf[0] == 0xfefe, "buf changed\n");
|
|
|
|
|
2007-02-22 21:10:42 +01:00
|
|
|
IInternetProtocolInfo_Release(info);
|
|
|
|
}
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
static void test_its_protocol(void)
|
|
|
|
{
|
2007-02-22 21:10:08 +01:00
|
|
|
IInternetProtocolInfo *info;
|
2006-12-25 16:09:41 +01:00
|
|
|
IClassFactory *factory;
|
|
|
|
IUnknown *unk;
|
|
|
|
ULONG ref;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR wrong_url1[] =
|
|
|
|
{'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','.','h','t','m','l',0};
|
|
|
|
static const WCHAR wrong_url2[] =
|
|
|
|
{'i','t','s',':','t','e','s','.','c','h','m',':',':','b','/','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR wrong_url3[] =
|
|
|
|
{'i','t','s',':','t','e','s','t','.','c','h','m','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR wrong_url4[] = {'m','k',':','@','M','S','I','T','S','t','o','r',':',
|
|
|
|
't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
static const WCHAR wrong_url5[] = {'f','i','l','e',':',
|
|
|
|
't','e','s','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
|
|
|
|
|
2007-01-13 12:47:57 +01:00
|
|
|
test_protocol = ITS_PROTOCOL;
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
hres = CoGetClassObject(&CLSID_ITSProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void**)&unk);
|
2009-02-20 12:39:30 +01:00
|
|
|
ok(hres == S_OK ||
|
|
|
|
broken(hres == REGDB_E_CLASSNOTREG), /* Some W95 and NT4 */
|
|
|
|
"CoGetClassObject failed: %08x\n", hres);
|
2008-10-08 01:35:16 +02:00
|
|
|
if(FAILED(hres))
|
2006-12-25 16:09:41 +01:00
|
|
|
return;
|
|
|
|
|
2007-02-22 21:10:08 +01:00
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocolInfo, (void**)&info);
|
|
|
|
ok(hres == E_NOINTERFACE, "Could not get IInternetProtocolInfo: %08x\n", hres);
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&factory);
|
|
|
|
ok(hres == S_OK, "Could not get IClassFactory interface\n");
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
IInternetProtocol *protocol;
|
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(factory, NULL, &IID_IInternetProtocol, (void**)&protocol);
|
|
|
|
ok(hres == S_OK, "Could not get IInternetProtocol: %08x\n", hres);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2007-02-22 21:10:42 +01:00
|
|
|
test_its_protocol_info(protocol);
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
test_protocol_fail(protocol, wrong_url1, STG_E_FILENOTFOUND);
|
|
|
|
test_protocol_fail(protocol, wrong_url2, STG_E_FILENOTFOUND);
|
|
|
|
test_protocol_fail(protocol, wrong_url3, STG_E_FILENOTFOUND);
|
|
|
|
|
|
|
|
hres = IInternetProtocol_Start(protocol, wrong_url4, &protocol_sink, &bind_info, 0, 0);
|
|
|
|
ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
|
|
|
|
"Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
|
|
|
|
|
|
|
|
hres = IInternetProtocol_Start(protocol, wrong_url5, &protocol_sink, &bind_info, 0, 0);
|
|
|
|
ok(hres == INET_E_USE_DEFAULT_PROTOCOLHANDLER,
|
|
|
|
"Start failed: %08x, expected INET_E_USE_DEFAULT_PROTOCOLHANDLER\n", hres);
|
|
|
|
|
|
|
|
ref = IInternetProtocol_Release(protocol);
|
|
|
|
ok(!ref, "protocol ref=%d\n", ref);
|
|
|
|
|
2007-03-13 18:44:05 +01:00
|
|
|
test_protocol_url(factory, blank_url1, TRUE);
|
|
|
|
test_protocol_url(factory, blank_url2, TRUE);
|
|
|
|
test_protocol_url(factory, blank_url3, TRUE);
|
|
|
|
test_protocol_url(factory, blank_url4, TRUE);
|
|
|
|
test_protocol_url(factory, blank_url5, TRUE);
|
|
|
|
test_protocol_url(factory, blank_url6, TRUE);
|
|
|
|
test_protocol_url(factory, blank_url8, TRUE);
|
2012-09-21 12:28:18 +02:00
|
|
|
test_protocol_url(factory, blank_url9, TRUE);
|
2008-01-31 18:19:20 +01:00
|
|
|
bindf = BINDF_FROMURLMON | BINDF_NEEDFILE;
|
|
|
|
test_protocol_url(factory, blank_url1, TRUE);
|
2006-12-25 16:09:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IClassFactory_Release(factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
}
|
|
|
|
|
2007-01-13 12:47:57 +01:00
|
|
|
static void test_mk_protocol(void)
|
|
|
|
{
|
|
|
|
IClassFactory *cf;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
test_protocol = MK_PROTOCOL;
|
|
|
|
|
|
|
|
hres = CoGetClassObject(&CLSID_MkProtocol, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory,
|
|
|
|
(void**)&cf);
|
2009-02-20 12:39:30 +01:00
|
|
|
ok(hres == S_OK ||
|
|
|
|
broken(hres == REGDB_E_CLASSNOTREG), /* Some W95 and NT4 */
|
|
|
|
"CoGetClassObject failed: %08x\n", hres);
|
2008-10-08 01:35:16 +02:00
|
|
|
if(FAILED(hres))
|
2007-01-13 12:47:57 +01:00
|
|
|
return;
|
|
|
|
|
2007-02-22 21:10:08 +01:00
|
|
|
cache_file = cache_file1;
|
2007-03-13 18:44:05 +01:00
|
|
|
test_protocol_url(cf, blank_url3, TRUE);
|
2007-02-22 21:10:08 +01:00
|
|
|
cache_file = cache_file2;
|
2007-03-13 18:44:05 +01:00
|
|
|
test_protocol_url(cf, blank_url7, TRUE);
|
|
|
|
cache_file = cache_file3;
|
|
|
|
test_protocol_url(cf, blank_url8, FALSE);
|
2007-01-13 12:47:57 +01:00
|
|
|
|
|
|
|
IClassFactory_Release(cf);
|
|
|
|
}
|
|
|
|
|
2006-12-25 16:09:41 +01:00
|
|
|
static BOOL create_chm(void)
|
|
|
|
{
|
|
|
|
HANDLE file;
|
|
|
|
HRSRC src;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
file = CreateFileA("test.chm", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
ok(file != INVALID_HANDLE_VALUE, "Could not create test.chm file\n");
|
|
|
|
if(file == INVALID_HANDLE_VALUE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
src = FindResourceA(NULL, MAKEINTRESOURCEA(60), MAKEINTRESOURCEA(60));
|
|
|
|
|
|
|
|
WriteFile(file, LoadResource(NULL, src), SizeofResource(NULL, src), &size, NULL);
|
|
|
|
CloseHandle(file);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void delete_chm(void)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = DeleteFileA("test.chm");
|
|
|
|
ok(ret, "DeleteFileA failed: %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(protocol)
|
|
|
|
{
|
|
|
|
OleInitialize(NULL);
|
|
|
|
|
|
|
|
if(!create_chm())
|
|
|
|
return;
|
|
|
|
|
|
|
|
test_its_protocol();
|
2007-01-13 12:47:57 +01:00
|
|
|
test_mk_protocol();
|
2006-12-25 16:09:41 +01:00
|
|
|
|
|
|
|
delete_chm();
|
|
|
|
OleUninitialize();
|
|
|
|
}
|