-- v3: mshtml: Implement MarkupServices_ParseString. mshtml: Implement MarkupServices_CreateMarkupContainer. mshtml/tests: Test for IMarkupServices.
From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/tests/htmldoc.c | 116 ++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+)
diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c index ad2544f189a..a691d0e085c 100644 --- a/dlls/mshtml/tests/htmldoc.c +++ b/dlls/mshtml/tests/htmldoc.c @@ -8358,6 +8358,121 @@ static void test_MHTMLDocument(void) release_document(doc); }
+static LONG get_document_elements_count(IHTMLDocument2 *doc) +{ + LONG elements_count; + IHTMLElementCollection *elements = NULL; + + IHTMLDocument2_get_all(doc, &elements); + IHTMLElementCollection_get_length(elements, &elements_count); + + IHTMLElementCollection_Release(elements); + return elements_count; +} + +static void test_MarkupContainer(IMarkupServices *markup_services) +{ + IHTMLDOMNode *doc_node; + IHTMLDocument2 *markup_container_doc; + ITargetContainer *target_container_doc; + IInternetSecurityManager *sec_manager; + IMarkupContainer *container = NULL; + ICustomDoc *custom_doc; + IHTMLLocation *location = NULL; + IHTMLElement *body = NULL; + LONG elements_count; + HRESULT hres; + + hres = IMarkupServices_CreateMarkupContainer(markup_services, &container); + todo_wine ok(hres == S_OK, "got 0x%08lx\n", hres); + todo_wine ok(container != NULL, "MarkupContainer is null.\n"); + if (!container) return; + + hres = IMarkupContainer_QueryInterface(container, &IID_IHTMLDocument2, (void**)&markup_container_doc); + ok(hres == S_OK, "got 0x%08lx\n", hres); + + hres = IHTMLDocument2_get_location(markup_container_doc, &location); + ok(hres == E_UNEXPECTED, "expected E_UNEXPECTED, got 0x%08lx\n", hres); + ok(location == NULL, "expected null location\n"); + + hres = IHTMLDocument2_get_body(markup_container_doc, &body); + ok(hres == S_OK, "got 0x%08lx\n", hres); + ok(body == NULL, "expected null body\n"); + + elements_count = get_document_elements_count(markup_container_doc); + ok(elements_count == 0, "expected document to not have elements\n"); + + hres = IMarkupContainer_QueryInterface(container, &IID_IHTMLDOMNode, (void**)&doc_node); + todo_wine ok(hres == E_NOINTERFACE, "expected to fail with E_NOINTERFACE got 0x%08lx\n", hres); + + hres = IHTMLDocument2_QueryInterface(markup_container_doc, &IID_IInternetSecurityManager, (void**)&sec_manager); + ok(hres == E_NOINTERFACE, "expected to fail with E_NOINTERFACE got 0x%08lx\n", hres); + + hres = IHTMLDocument2_QueryInterface(markup_container_doc, &IID_ITargetContainer, (void**)&target_container_doc); + ok(hres == E_NOINTERFACE, "expected to fail with E_NOINTERFACE got 0x%08lx\n", hres); + + hres = IHTMLDocument2_QueryInterface(markup_container_doc, &IID_ICustomDoc, (void**)&custom_doc); + ok(hres == E_NOINTERFACE, "expected to fail with E_NOINTERFACE got 0x%08lx\n", hres); + + IHTMLDocument2_Release(markup_container_doc); + IMarkupContainer_Release(container); +} + +static void test_MarkupServices_ParseString(IMarkupServices *markup_services, IHTMLDocument2 *doc) +{ + HRESULT hres; + LONG document_elements_count, markup_container_elements_count; + IHTMLElement *body; + BSTR inner_text; + IHTMLDocument2 *markup_container_doc = NULL; + IMarkupContainer *markup_container = NULL; + + hres = IMarkupServices_ParseString(markup_services, (OLECHAR*)L"<div>Hello World</div>", 0, &markup_container, NULL, NULL); + todo_wine ok(hres == S_OK, "got 0x%08lx\n", hres); + todo_wine ok(markup_container != NULL, "MarkupContainer is null.\n"); + if (!markup_container) return; + + hres = IMarkupContainer_QueryInterface(markup_container, &IID_IHTMLDocument2, (void**)&markup_container_doc); + ok(hres == S_OK, "failed to query interface of MarkupContainer 0x%08lx\n", hres); + + markup_container_elements_count = get_document_elements_count(markup_container_doc); + ok(markup_container_elements_count == 5, "expected markup container to have 5 elements but got %ld\n", + markup_container_elements_count); + + document_elements_count = get_document_elements_count(doc); + ok(document_elements_count != markup_container_elements_count, + "expected document to not have the same elements count of the markup container %ld == %ld\n", + document_elements_count, markup_container_elements_count); + + hres = IHTMLDocument2_get_body(markup_container_doc, &body); + ok(hres == S_OK, "got 0x%08lx\n", hres); + ok(body != NULL, "got null body\n"); + + hres = IHTMLElement_get_innerText(body, &inner_text); + ok(hres == S_OK, "failed to get inner text error 0x%08lx\n", hres); + ok(inner_text != NULL, "got a null pointer for inner text\n"); + ok(!wcscmp(inner_text, L"Hello World"), "strings don't match, got %ls\n", inner_text); + + SysFreeString(inner_text); + IHTMLElement_Release(body); + IHTMLDocument2_Release(markup_container_doc); + IMarkupContainer_Release(markup_container); +} + +static void test_MarkupServices(IHTMLDocument2 *doc) +{ + HRESULT hres; + IMarkupServices *markup_services = NULL; + + hres = IHTMLDocument2_QueryInterface(doc, &IID_IMarkupServices, (void**)&markup_services); + ok(hres == S_OK, "got 0x%08lx\n", hres); + + test_MarkupContainer(markup_services); + test_MarkupServices_ParseString(markup_services, doc); + + IMarkupServices_Release(markup_services); +} + static void test_HTMLDocument_hlink(DWORD status) { IHTMLDocument2 *doc; @@ -8524,6 +8639,7 @@ static void test_HTMLDocument_http(BOOL with_wbapp) test_travellog(doc); test_binding_ui((IUnknown*)doc); test_doc_domain(doc); + test_MarkupServices(doc);
nav_url = nav_serv_url = L"http://test.winehq.org/tests/winehq_snapshot/"; /* for valid prev nav_url */ if(support_wbapp) {
From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/htmldoc.c | 14 ++++++++++++-- dlls/mshtml/tests/htmldoc.c | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 9aa0cefc21d..bf6de461383 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -4739,8 +4739,18 @@ static HRESULT WINAPI MarkupServices_CreateMarkupPointer(IMarkupServices *iface, static HRESULT WINAPI MarkupServices_CreateMarkupContainer(IMarkupServices *iface, IMarkupContainer **ppMarkupContainer) { HTMLDocumentNode *This = impl_from_IMarkupServices(iface); - FIXME("(%p)->(%p)\n", This, ppMarkupContainer); - return E_NOTIMPL; + IHTMLDocument2 *frag; + HRESULT hres; + TRACE("(%p)->(%p)\n", This, ppMarkupContainer); + + hres = IHTMLDocument3_createDocumentFragment(&This->IHTMLDocument3_iface, &frag); + if(FAILED(hres)) + return hres; + + IHTMLDocument2_QueryInterface(frag, &IID_IMarkupContainer, (void**)ppMarkupContainer); + IHTMLDocument2_Release(frag); + + return S_OK; }
static HRESULT WINAPI MarkupServices_CreateElement(IMarkupServices *iface, diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c index a691d0e085c..384834359f9 100644 --- a/dlls/mshtml/tests/htmldoc.c +++ b/dlls/mshtml/tests/htmldoc.c @@ -8384,8 +8384,8 @@ static void test_MarkupContainer(IMarkupServices *markup_services) HRESULT hres;
hres = IMarkupServices_CreateMarkupContainer(markup_services, &container); - todo_wine ok(hres == S_OK, "got 0x%08lx\n", hres); - todo_wine ok(container != NULL, "MarkupContainer is null.\n"); + ok(hres == S_OK, "got 0x%08lx\n", hres); + ok(container != NULL, "MarkupContainer is null.\n"); if (!container) return;
hres = IMarkupContainer_QueryInterface(container, &IID_IHTMLDocument2, (void**)&markup_container_doc);
From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/htmldoc.c | 48 +++++++++++++++++++++++++++++++++++-- dlls/mshtml/tests/htmldoc.c | 4 ++-- 2 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index bf6de461383..27f9032f0de 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -4823,9 +4823,53 @@ static HRESULT WINAPI MarkupServices_ParseString(IMarkupServices *iface, OLECHAR *pchHTML, DWORD dwFlags, IMarkupContainer **ppContainerResult, IMarkupPointer *pPointerStart, IMarkupPointer *pPointerFinish) { + HRESULT hres; + IMarkupContainer *container; + IHTMLDocument2 *doc; + IHTMLDOMNode *node, *html_node, *new_html_node = NULL; + IHTMLElement *html, *body; HTMLDocumentNode *This = impl_from_IMarkupServices(iface); - FIXME("(%p)->(%s,%lx,%p,%p,%p)\n", This, debugstr_w(pchHTML), dwFlags, ppContainerResult, pPointerStart, pPointerFinish); - return E_NOTIMPL; + TRACE("(%p)->(%s,%lx,%p,%p,%p)\n", This, debugstr_w(pchHTML), dwFlags, ppContainerResult, pPointerStart, pPointerFinish); + + if(dwFlags != 0) + FIXME("flags %lx not implemented.\n", dwFlags); + if(pPointerStart || pPointerFinish) { + FIXME("Pointers not implemented.\n"); + return E_NOTIMPL; + } + + hres = IMarkupServices_CreateMarkupContainer(iface, &container); + if(FAILED(hres)) + return hres; + + IMarkupContainer_QueryInterface(container, &IID_IHTMLDocument2, (void**)&doc); + IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDOMNode, (void**)&node); + IHTMLDocument2_createElement(&This->IHTMLDocument2_iface, (BSTR)L"html", &html); + + IHTMLElement_put_innerHTML(html, (BSTR)L"<head><title></title></head><body></body>"); + IHTMLElement_QueryInterface(html, &IID_IHTMLDOMNode, (void**)&html_node); + IHTMLElement_Release(html); + + IHTMLDOMNode_appendChild(node, html_node, &new_html_node); + IHTMLDOMNode_Release(node); + IHTMLDOMNode_Release(html_node); + IHTMLDOMNode_Release(new_html_node); + + IHTMLDocument2_get_body(doc, &body); + hres = IHTMLElement_put_innerHTML(body, pchHTML); + if (FAILED(hres)) + { + ERR("Failed put_innerHTML hr %#lx\n", hres); + IMarkupContainer_Release(container); + container = NULL; + } + + IHTMLDocument2_Release(doc); + IHTMLElement_Release(body); + + *ppContainerResult = container; + + return hres; }
static HRESULT WINAPI MarkupServices_ParseGlobal(IMarkupServices *iface, diff --git a/dlls/mshtml/tests/htmldoc.c b/dlls/mshtml/tests/htmldoc.c index 384834359f9..c64ed784897 100644 --- a/dlls/mshtml/tests/htmldoc.c +++ b/dlls/mshtml/tests/htmldoc.c @@ -8428,8 +8428,8 @@ static void test_MarkupServices_ParseString(IMarkupServices *markup_services, IH IMarkupContainer *markup_container = NULL;
hres = IMarkupServices_ParseString(markup_services, (OLECHAR*)L"<div>Hello World</div>", 0, &markup_container, NULL, NULL); - todo_wine ok(hres == S_OK, "got 0x%08lx\n", hres); - todo_wine ok(markup_container != NULL, "MarkupContainer is null.\n"); + ok(hres == S_OK, "got 0x%08lx\n", hres); + ok(markup_container != NULL, "MarkupContainer is null.\n"); if (!markup_container) return;
hres = IMarkupContainer_QueryInterface(markup_container, &IID_IHTMLDocument2, (void**)&markup_container_doc);
This merge request was approved by Jacek Caban.