2009-10-14 23:33:03 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Andrew Eikum 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
|
|
|
|
#define CONST_VTABLE
|
|
|
|
|
|
|
|
#include <wine/test.h>
|
|
|
|
|
|
|
|
#include "mshtml.h"
|
2010-01-24 21:39:30 +01:00
|
|
|
#include "wininet.h"
|
2009-10-14 23:33:03 +02:00
|
|
|
|
|
|
|
struct location_test {
|
|
|
|
const char *name;
|
2010-01-24 21:39:30 +01:00
|
|
|
const char *url;
|
2009-10-14 23:33:03 +02:00
|
|
|
|
|
|
|
const char *href;
|
|
|
|
const char *protocol;
|
|
|
|
const char *host;
|
|
|
|
const char *hostname;
|
|
|
|
const char *port;
|
|
|
|
const char *pathname;
|
|
|
|
const char *search;
|
|
|
|
const char *hash;
|
|
|
|
};
|
|
|
|
|
2010-01-24 21:39:30 +01:00
|
|
|
static const struct location_test location_tests[] = {
|
|
|
|
{
|
|
|
|
"HTTP",
|
|
|
|
"http://www.winehq.org?search#hash",
|
|
|
|
"http://www.winehq.org/?search#hash",
|
|
|
|
"http:",
|
|
|
|
"www.winehq.org:80",
|
|
|
|
"www.winehq.org",
|
|
|
|
"80",
|
2019-05-28 17:33:44 +02:00
|
|
|
"/",
|
2010-01-24 21:39:30 +01:00
|
|
|
"?search",
|
|
|
|
"#hash"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"HTTP with file",
|
|
|
|
"http://www.winehq.org/file?search#hash",
|
|
|
|
"http://www.winehq.org/file?search#hash",
|
|
|
|
"http:",
|
|
|
|
"www.winehq.org:80",
|
|
|
|
"www.winehq.org",
|
|
|
|
"80",
|
2019-05-28 17:33:44 +02:00
|
|
|
"/file",
|
2010-01-24 21:39:30 +01:00
|
|
|
"?search",
|
|
|
|
"#hash"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"FTP",
|
|
|
|
"ftp://ftp.winehq.org/",
|
|
|
|
"ftp://ftp.winehq.org/",
|
|
|
|
"ftp:",
|
|
|
|
"ftp.winehq.org:21",
|
|
|
|
"ftp.winehq.org",
|
|
|
|
"21",
|
2019-05-28 17:33:44 +02:00
|
|
|
"/",
|
2010-01-24 21:39:30 +01:00
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"FTP with file",
|
|
|
|
"ftp://ftp.winehq.org/file",
|
|
|
|
"ftp://ftp.winehq.org/file",
|
|
|
|
"ftp:",
|
|
|
|
"ftp.winehq.org:21",
|
|
|
|
"ftp.winehq.org",
|
|
|
|
"21",
|
2019-05-28 17:33:44 +02:00
|
|
|
"/file",
|
2010-01-24 21:39:30 +01:00
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
};
|
2009-10-14 23:33:03 +02:00
|
|
|
|
|
|
|
static int str_eq_wa(LPCWSTR strw, const char *stra)
|
|
|
|
{
|
|
|
|
CHAR buf[512];
|
|
|
|
|
2012-03-29 15:05:43 +02:00
|
|
|
if(!strw || !stra)
|
|
|
|
return (void*)strw == (void*)stra;
|
2009-10-14 23:33:03 +02:00
|
|
|
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
|
|
|
|
return !lstrcmpA(stra, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_href(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_href(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_href should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_href(loc, &str);
|
|
|
|
ok(hres == S_OK, "%s: get_href failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
|
|
|
ok(str_eq_wa(str, test->href),
|
|
|
|
"%s: expected retrieved href to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->href, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2012-10-22 11:59:27 +02:00
|
|
|
|
|
|
|
hres = IHTMLLocation_toString(loc, &str);
|
|
|
|
ok(hres == S_OK, "%s: toString failed: 0x%08x\n", test->name, hres);
|
|
|
|
ok(str_eq_wa(str, test->href), "%s: toString returned %s, expected %s\n",
|
|
|
|
test->name, wine_dbgstr_w(str), test->href);
|
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_protocol(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_protocol(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_protocol should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_protocol(loc, &str);
|
2009-10-15 23:17:17 +02:00
|
|
|
ok(hres == S_OK, "%s: get_protocol failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
|
|
|
ok(str_eq_wa(str, test->protocol),
|
|
|
|
"%s: expected retrieved protocol to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->protocol, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_host(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_host(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_host should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_host(loc, &str);
|
2009-10-15 23:17:28 +02:00
|
|
|
ok(hres == S_OK, "%s: get_host failed: 0x%08x\n", test->name, hres);
|
2017-11-22 15:55:07 +01:00
|
|
|
if(hres == S_OK){
|
|
|
|
int len = test->host ? strlen(test->host) : 0;
|
2009-10-19 18:18:21 +02:00
|
|
|
ok(str_eq_wa(str, test->host),
|
|
|
|
"%s: expected retrieved host to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->host, wine_dbgstr_w(str));
|
2017-11-22 15:55:07 +01:00
|
|
|
ok(SysStringLen(str) == len, "%s: unexpected string length %u, expected %u\n",
|
|
|
|
test->name, SysStringLen(str), len);
|
|
|
|
}
|
|
|
|
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
2012-03-29 15:05:43 +02:00
|
|
|
static void test_hostname(IHTMLLocation *loc, IHTMLDocument2 *doc, const struct location_test *test)
|
2009-10-14 23:33:03 +02:00
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_hostname(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_hostname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_hostname(loc, &str);
|
2009-10-15 23:17:39 +02:00
|
|
|
ok(hres == S_OK, "%s: get_hostname failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
|
|
|
ok(str_eq_wa(str, test->hostname),
|
|
|
|
"%s: expected retrieved hostname to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->hostname, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2012-03-29 15:05:43 +02:00
|
|
|
|
|
|
|
hres = IHTMLDocument2_get_domain(doc, &str);
|
|
|
|
ok(hres == S_OK, "%s: get_domain failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(hres == S_OK)
|
|
|
|
ok(str_eq_wa(str, test->hostname ? test->hostname : ""),
|
|
|
|
"%s: expected retrieved domain to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->hostname, wine_dbgstr_w(str));
|
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_port(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_port(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_port should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_port(loc, &str);
|
2009-10-14 23:33:37 +02:00
|
|
|
ok(hres == S_OK, "%s: get_port failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
2016-01-13 16:32:28 +01:00
|
|
|
ok(str_eq_wa(str, test->port)
|
|
|
|
|| (!str && !*test->port), /* IE11 */
|
2009-10-19 18:18:21 +02:00
|
|
|
"%s: expected retrieved port to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->port, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_pathname(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_pathname(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_pathname should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_pathname(loc, &str);
|
|
|
|
ok(hres == S_OK, "%s: get_pathname failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
2019-05-28 17:33:58 +02:00
|
|
|
/* FIXME: We seem to be testing location in a buggy state. Path names do not
|
|
|
|
* include leading slash, while other tests confirm that it should be there */
|
|
|
|
todo_wine_if(*test->pathname == '/')
|
2019-05-28 17:33:44 +02:00
|
|
|
ok(str_eq_wa(str, *test->pathname == '/' ? test->pathname + 1 : test->pathname),
|
2009-10-19 18:18:21 +02:00
|
|
|
"%s: expected retrieved pathname to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->pathname, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_search(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_search(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_search should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_search(loc, &str);
|
2009-10-19 18:18:18 +02:00
|
|
|
ok(hres == S_OK, "%s: get_search failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
|
|
|
ok(str_eq_wa(str, test->search),
|
|
|
|
"%s: expected retrieved search to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->search, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_hash(IHTMLLocation *loc, const struct location_test *test)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
BSTR str;
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_hash(loc, NULL);
|
|
|
|
ok(hres == E_POINTER,
|
|
|
|
"%s: get_hash should have failed with E_POINTER (0x%08x), was: 0x%08x\n",
|
|
|
|
test->name, E_POINTER, hres);
|
|
|
|
|
|
|
|
hres = IHTMLLocation_get_hash(loc, &str);
|
2009-10-19 18:18:15 +02:00
|
|
|
ok(hres == S_OK, "%s: get_hash failed: 0x%08x\n", test->name, hres);
|
2009-10-19 18:18:21 +02:00
|
|
|
if(hres == S_OK)
|
|
|
|
ok(str_eq_wa(str, test->hash),
|
|
|
|
"%s: expected retrieved hash to be L\"%s\", was: %s\n",
|
|
|
|
test->name, test->hash, wine_dbgstr_w(str));
|
2011-01-21 14:16:20 +01:00
|
|
|
SysFreeString(str);
|
2009-10-14 23:33:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void perform_test(const struct location_test* test)
|
|
|
|
{
|
2010-01-24 21:39:30 +01:00
|
|
|
WCHAR url[INTERNET_MAX_URL_LENGTH];
|
2009-10-14 23:33:03 +02:00
|
|
|
HRESULT hres;
|
|
|
|
IBindCtx *bc;
|
|
|
|
IMoniker *url_mon;
|
|
|
|
IPersistMoniker *persist_mon;
|
|
|
|
IHTMLDocument2 *doc;
|
|
|
|
IHTMLDocument6 *doc6;
|
|
|
|
IHTMLLocation *location;
|
|
|
|
|
|
|
|
hres = CreateBindCtx(0, &bc);
|
|
|
|
ok(hres == S_OK, "%s: CreateBindCtx failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return;
|
|
|
|
|
2018-06-07 23:44:40 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, test->url, -1, url, ARRAY_SIZE(url));
|
2010-01-24 21:39:30 +01:00
|
|
|
hres = CreateURLMoniker(NULL, url, &url_mon);
|
2009-10-14 23:33:03 +02:00
|
|
|
ok(hres == S_OK, "%s: CreateURLMoniker failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = CoCreateInstance(&CLSID_HTMLDocument, NULL,
|
|
|
|
CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, &IID_IHTMLDocument2,
|
|
|
|
(void**)&doc);
|
2020-05-13 10:33:54 +02:00
|
|
|
#if !defined(__i386__) && !defined(__x86_64__)
|
|
|
|
todo_wine
|
|
|
|
#endif
|
2009-10-14 23:33:03 +02:00
|
|
|
ok(hres == S_OK, "%s: CoCreateInstance failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IMoniker_Release(url_mon);
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6);
|
|
|
|
if(hres == S_OK){
|
|
|
|
IHTMLDocument6_Release(doc6);
|
|
|
|
}else{
|
|
|
|
win_skip("%s: Could not get IHTMLDocument6, probably too old IE. Requires IE 8+\n", test->name);
|
|
|
|
IMoniker_Release(url_mon);
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker,
|
|
|
|
(void**)&persist_mon);
|
|
|
|
ok(hres == S_OK, "%s: IHTMlDocument2_QueryInterface failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IHTMLDocument2_Release(doc);
|
|
|
|
IMoniker_Release(url_mon);
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IPersistMoniker_Load(persist_mon, FALSE, url_mon, bc,
|
|
|
|
STGM_SHARE_EXCLUSIVE | STGM_READWRITE);
|
|
|
|
ok(hres == S_OK, "%s: IPersistMoniker_Load failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IPersistMoniker_Release(persist_mon);
|
|
|
|
IHTMLDocument2_Release(doc);
|
|
|
|
IMoniker_Release(url_mon);
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IHTMLDocument2_get_location(doc, &location);
|
|
|
|
ok(hres == S_OK, "%s: IHTMLDocument2_get_location failed: 0x%08x\n", test->name, hres);
|
|
|
|
if(FAILED(hres)){
|
|
|
|
IPersistMoniker_Release(persist_mon);
|
|
|
|
IHTMLDocument2_Release(doc);
|
|
|
|
IMoniker_Release(url_mon);
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_href(location, test);
|
|
|
|
test_protocol(location, test);
|
|
|
|
test_host(location, test);
|
2012-03-29 15:05:43 +02:00
|
|
|
test_hostname(location, doc, test);
|
2009-10-14 23:33:03 +02:00
|
|
|
test_port(location, test);
|
|
|
|
test_pathname(location, test);
|
|
|
|
test_search(location, test);
|
|
|
|
test_hash(location, test);
|
|
|
|
|
|
|
|
IHTMLLocation_Release(location);
|
|
|
|
IPersistMoniker_Release(persist_mon);
|
|
|
|
IHTMLDocument2_Release(doc);
|
|
|
|
IMoniker_Release(url_mon);
|
|
|
|
IBindCtx_Release(bc);
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(htmllocation)
|
|
|
|
{
|
2010-01-24 21:39:30 +01:00
|
|
|
int i;
|
|
|
|
|
2009-10-14 23:33:03 +02:00
|
|
|
CoInitialize(NULL);
|
|
|
|
|
2018-06-07 23:44:40 +02:00
|
|
|
for(i=0; i < ARRAY_SIZE(location_tests); i++)
|
2010-01-24 21:39:30 +01:00
|
|
|
perform_test(location_tests+i);
|
2009-10-14 23:33:03 +02:00
|
|
|
|
|
|
|
CoUninitialize();
|
|
|
|
}
|