mshtml: Added support for getElementsByTagName in document fragment nodes.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2015-11-19 12:14:59 +01:00 committed by Alexandre Julliard
parent ef127caef2
commit 808c2d6c7f
2 changed files with 72 additions and 24 deletions

View File

@ -2371,18 +2371,44 @@ static HRESULT WINAPI HTMLDocument3_getElementsByTagName(IHTMLDocument3 *iface,
TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl); TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pelColl);
if(!This->doc_node->nsdoc) { if(This->doc_node->nsdoc) {
WARN("NULL nsdoc\n"); nsAString_InitDepend(&id_str, v);
return E_UNEXPECTED; nsres = nsIDOMHTMLDocument_GetElementsByTagName(This->doc_node->nsdoc, &id_str, &nslist);
nsAString_Finish(&id_str);
if(FAILED(nsres)) {
ERR("GetElementByName failed: %08x\n", nsres);
return E_FAIL;
}
}else {
nsIDOMDocumentFragment *docfrag;
nsAString nsstr;
if(v) {
const WCHAR *ptr;
for(ptr=v; *ptr; ptr++) {
if(!isalnumW(*ptr)) {
FIXME("Unsupported invalid tag %s\n", debugstr_w(v));
return E_NOTIMPL;
}
}
}
nsres = nsIDOMNode_QueryInterface(This->doc_node->node.nsnode, &IID_nsIDOMDocumentFragment, (void**)&docfrag);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMDocumentFragment iface: %08x\n", nsres);
return E_UNEXPECTED;
}
nsAString_InitDepend(&nsstr, v);
nsres = nsIDOMDocumentFragment_QuerySelectorAll(docfrag, &nsstr, &nslist);
nsAString_Finish(&nsstr);
nsIDOMDocumentFragment_Release(docfrag);
if(NS_FAILED(nsres)) {
ERR("QuerySelectorAll failed: %08x\n", nsres);
return E_FAIL;
}
} }
nsAString_InitDepend(&id_str, v);
nsres = nsIDOMHTMLDocument_GetElementsByTagName(This->doc_node->nsdoc, &id_str, &nslist);
nsAString_Finish(&id_str);
if(FAILED(nsres)) {
ERR("GetElementByName failed: %08x\n", nsres);
return E_FAIL;
}
*pelColl = create_collection_from_nodelist(This->doc_node, nslist); *pelColl = create_collection_from_nodelist(This->doc_node, nslist);
nsIDOMNodeList_Release(nslist); nsIDOMNodeList_Release(nslist);

View File

@ -2693,6 +2693,35 @@ static void _test_elem_getelembytag(unsigned line, IUnknown *unk, elem_type_t ty
IHTMLElementCollection_Release(col); IHTMLElementCollection_Release(col);
} }
#define test_doc_getelembytag(a,b,c,d) _test_doc_getelembytag(__LINE__,a,b,c,d)
static void _test_doc_getelembytag(unsigned line, IHTMLDocument2 *unk, const char *tag, elem_type_t type, LONG exlen)
{
IHTMLDocument3 *doc = _get_doc3_iface(line, unk);
IHTMLElementCollection *col = NULL;
elem_type_t *types = NULL;
BSTR tmp;
int i;
HRESULT hres;
tmp = a2bstr(elem_type_infos[type].tag);
hres = IHTMLDocument3_getElementsByTagName(doc, tmp, &col);
SysFreeString(tmp);
ok_(__FILE__,line) (hres == S_OK, "getElementByTagName failed: %08x\n", hres);
ok_(__FILE__,line) (col != NULL, "col == NULL\n");
if(exlen) {
types = HeapAlloc(GetProcessHeap(), 0, exlen*sizeof(elem_type_t));
for(i=0; i<exlen; i++)
types[i] = type;
}
_test_elem_collection(line, (IUnknown*)col, types, exlen);
HeapFree(GetProcessHeap(), 0, types);
IHTMLElementCollection_Release(col);
IHTMLDocument3_Release(doc);
}
#define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t) #define test_elem_innertext(e,t) _test_elem_innertext(__LINE__,e,t)
static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext) static void _test_elem_innertext(unsigned line, IHTMLElement *elem, const char *extext)
{ {
@ -8283,20 +8312,7 @@ static void test_elems(IHTMLDocument2 *doc)
} }
IDispatch_Release(disp); IDispatch_Release(disp);
hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3); test_doc_getelembytag(doc, "Img", ET_IMG, 1);
ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
str = a2bstr("Img");
hres = IHTMLDocument3_getElementsByTagName(doc3, str, &col);
ok(hres == S_OK, "getElementsByTagName(%s) failed: %08x\n", wine_dbgstr_w(str), hres);
SysFreeString(str);
if(hres == S_OK)
{
static const elem_type_t img_types[] = { ET_IMG };
test_elem_collection((IUnknown*)col, img_types, sizeof(img_types)/sizeof(img_types[0]));
IHTMLElementCollection_Release(col);
}
elem = get_doc_elem_by_id(doc, "y"); elem = get_doc_elem_by_id(doc, "y");
test_elem_set_innerhtml((IUnknown*)elem, "inner html"); test_elem_set_innerhtml((IUnknown*)elem, "inner html");
@ -8313,6 +8329,9 @@ static void test_elems(IHTMLDocument2 *doc)
IHTMLElement_Release(elem2); IHTMLElement_Release(elem2);
IHTMLElement_Release(elem); IHTMLElement_Release(elem);
hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
hres = IHTMLDocument3_recalc(doc3, VARIANT_TRUE); hres = IHTMLDocument3_recalc(doc3, VARIANT_TRUE);
ok(hres == S_OK, "recalc failed: %08x\n", hres); ok(hres == S_OK, "recalc failed: %08x\n", hres);
@ -9263,6 +9282,9 @@ static void test_docfrag(IHTMLDocument2 *doc)
test_elem_source_index(br, 0); test_elem_source_index(br, 0);
IHTMLElement_Release(br); IHTMLElement_Release(br);
test_doc_getelembytag(frag, "a", ET_A, 0);
test_doc_getelembytag(frag, "Br", ET_BR, 1);
div = get_elem_by_id(doc, "divid", TRUE); div = get_elem_by_id(doc, "divid", TRUE);
test_node_append_child((IUnknown*)div, (IUnknown*)frag); test_node_append_child((IUnknown*)div, (IUnknown*)frag);
IHTMLElement_Release(div); IHTMLElement_Release(div);