urlmon: Added some tests and fixes of file protocol.
This commit is contained in:
parent
97c6c634d5
commit
7458d74169
|
@ -110,7 +110,9 @@ static HRESULT WINAPI FileProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl
|
|||
LARGE_INTEGER size;
|
||||
DWORD len;
|
||||
LPWSTR url, mime = NULL;
|
||||
LPCWSTR file_name;
|
||||
WCHAR null_char = 0;
|
||||
BOOL first_call = FALSE;
|
||||
HRESULT hres;
|
||||
|
||||
static const WCHAR wszFile[] = {'f','i','l','e',':'};
|
||||
|
@ -134,33 +136,39 @@ static HRESULT WINAPI FileProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl
|
|||
return hres;
|
||||
}
|
||||
|
||||
hres = FindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
|
||||
if(SUCCEEDED(hres))
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DIRECTBIND, mime);
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DIRECTBIND, NULL);
|
||||
|
||||
if(!This->file) {
|
||||
first_call = TRUE;
|
||||
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, &null_char);
|
||||
|
||||
This->file = CreateFileW(url+sizeof(wszFile)/sizeof(WCHAR), GENERIC_READ, FILE_SHARE_READ,
|
||||
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
file_name = url+sizeof(wszFile)/sizeof(WCHAR);
|
||||
if(file_name[0] == '/' && file_name[1] == '/' && file_name[2] == '/')
|
||||
file_name += 3;
|
||||
|
||||
This->file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
if(This->file == INVALID_HANDLE_VALUE) {
|
||||
This->file = NULL;
|
||||
IInternetProtocolSink_ReportResult(pOIProtSink, INET_E_RESOURCE_NOT_FOUND,
|
||||
GetLastError(), NULL);
|
||||
HeapFree(GetProcessHeap(), 0, url);
|
||||
CoTaskMemFree(mime);
|
||||
return INET_E_RESOURCE_NOT_FOUND;
|
||||
}
|
||||
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_CACHEFILENAMEAVAILABLE,
|
||||
url+sizeof(wszFile)/sizeof(WCHAR));
|
||||
if(mime)
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_MIMETYPEAVAILABLE, mime);
|
||||
IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink,
|
||||
BINDSTATUS_CACHEFILENAMEAVAILABLE, file_name);
|
||||
|
||||
hres = FindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
|
||||
if(SUCCEEDED(hres)) {
|
||||
IInternetProtocolSink_ReportProgress(pOIProtSink,
|
||||
BINDSTATUS_MIMETYPEAVAILABLE, mime);
|
||||
CoTaskMemFree(mime);
|
||||
}
|
||||
}
|
||||
|
||||
CoTaskMemFree(mime);
|
||||
HeapFree(GetProcessHeap(), 0, url);
|
||||
|
||||
if(GetFileSizeEx(This->file, &size))
|
||||
|
@ -168,6 +176,9 @@ static HRESULT WINAPI FileProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl
|
|||
BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION,
|
||||
size.u.LowPart, size.u.LowPart);
|
||||
|
||||
if(first_call)
|
||||
IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,15 +91,17 @@ static HRESULT WINAPI ProtocolSink_ReportProgress(IInternetProtocolSink *iface,
|
|||
switch(ulStatusCode) {
|
||||
case BINDSTATUS_MIMETYPEAVAILABLE:
|
||||
CHECK_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
|
||||
if(szStatusText)
|
||||
ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
|
||||
case BINDSTATUS_DIRECTBIND:
|
||||
CHECK_EXPECT2(ReportProgress_DIRECTBIND);
|
||||
ok(szStatusText != NULL, "szStatusText == NULL\n");
|
||||
if(szStatusText)
|
||||
ok(!lstrcmpW(szStatusText, text_html), "szStatusText != text/html\n");
|
||||
break;
|
||||
case BINDSTATUS_DIRECTBIND:
|
||||
CHECK_EXPECT(ReportProgress_DIRECTBIND);
|
||||
ok(szStatusText == NULL, "szStatucText != NULL\n");
|
||||
break;
|
||||
case BINDSTATUS_CACHEFILENAMEAVAILABLE:
|
||||
CHECK_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
||||
ok(szStatusText != NULL, "szStatusText == NULL\n");
|
||||
if(szStatusText)
|
||||
ok(!lstrcmpW(szStatusText, file_name), "szStatusText != file_name\n");
|
||||
break;
|
||||
|
@ -241,9 +243,10 @@ static void file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL i
|
|||
SET_EXPECT(ReportProgress_SENDINGREQUEST);
|
||||
SET_EXPECT(ReportProgress_CACHEFILENAMEAVAILABLE);
|
||||
SET_EXPECT(ReportProgress_MIMETYPEAVAILABLE);
|
||||
SET_EXPECT(ReportResult);
|
||||
}
|
||||
SET_EXPECT(ReportData);
|
||||
if(is_first)
|
||||
SET_EXPECT(ReportResult);
|
||||
|
||||
expect_hrResult = S_OK;
|
||||
|
||||
|
@ -256,9 +259,10 @@ static void file_protocol_start(IInternetProtocol *protocol, LPCWSTR url, BOOL i
|
|||
CHECK_CALLED(ReportProgress_SENDINGREQUEST);
|
||||
CHECK_CALLED(ReportProgress_CACHEFILENAMEAVAILABLE);
|
||||
CHECK_CALLED(ReportProgress_MIMETYPEAVAILABLE);
|
||||
CHECK_CALLED(ReportResult);
|
||||
}
|
||||
CHECK_CALLED(ReportData);
|
||||
if(is_first)
|
||||
CHECK_CALLED(ReportResult);
|
||||
}
|
||||
|
||||
static void test_file_protocol_url(LPCWSTR url)
|
||||
|
@ -365,6 +369,7 @@ static void test_file_protocol(void) {
|
|||
static const WCHAR index_url2[] =
|
||||
{'f','i','l','e',':','/','/','i','n','d','e','x','.','h','t','m','l',0};
|
||||
static const WCHAR wszFile[] = {'f','i','l','e',':',0};
|
||||
static const WCHAR wszFile2[] = {'f','i','l','e',':','/','/','/',0};
|
||||
static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
|
||||
static const char html_doc[] = "<HTML></HTML>";
|
||||
|
||||
|
@ -388,6 +393,15 @@ static void test_file_protocol(void) {
|
|||
file_name = buf + sizeof(wszFile)/sizeof(WCHAR)-1;
|
||||
test_file_protocol_url(buf);
|
||||
|
||||
memcpy(buf, wszFile2, sizeof(wszFile2));
|
||||
len = sizeof(wszFile2)/sizeof(WCHAR)-1;
|
||||
len += GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR)-len, buf+len);
|
||||
buf[len++] = '\\';
|
||||
memcpy(buf+len, wszIndexHtml, sizeof(wszIndexHtml));
|
||||
|
||||
file_name = buf + sizeof(wszFile2)/sizeof(WCHAR)-1;
|
||||
test_file_protocol_url(buf);
|
||||
|
||||
DeleteFileW(wszIndexHtml);
|
||||
|
||||
hres = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
||||
|
|
Loading…
Reference in New Issue