Zhenbo Li : mshtml: Add IHTMLXMLHttpRequest::responseXML() method implementation.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jan 5 12:18:32 CST 2016


Module: wine
Branch: master
Commit: 798b1e06f38328121e0f201a9a44ba020e07e1f2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=798b1e06f38328121e0f201a9a44ba020e07e1f2

Author: Zhenbo Li <litimetal at gmail.com>
Date:   Fri Dec 25 15:30:06 2015 +0800

mshtml: Add IHTMLXMLHttpRequest::responseXML() method implementation.

Signed-off-by: Zhenbo Li <litimetal at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/tests/xmlhttprequest.c | 111 +++++++++++++++++++++++++++++++++++++
 dlls/mshtml/xmlhttprequest.c       |  41 +++++++++++++-
 2 files changed, 150 insertions(+), 2 deletions(-)

diff --git a/dlls/mshtml/tests/xmlhttprequest.c b/dlls/mshtml/tests/xmlhttprequest.c
index 0997206..b402aeb 100644
--- a/dlls/mshtml/tests/xmlhttprequest.c
+++ b/dlls/mshtml/tests/xmlhttprequest.c
@@ -20,11 +20,13 @@
 
 #include <wine/test.h>
 #include <stdarg.h>
+#include <stdio.h>
 
 #include "windef.h"
 #include "winbase.h"
 #include "ole2.h"
 #include "mshtml.h"
+#include "objsafe.h"
 
 static BSTR a2bstr(const char *str)
 {
@@ -454,6 +456,109 @@ static void test_header(const struct HEADER_TYPE expect[], int num)
     }
 }
 
+static const char *debugstr_variant(const VARIANT *var)
+{
+    static char buf[400];
+
+    if (!var)
+        return "(null)";
+
+    switch (V_VT(var))
+    {
+    case VT_EMPTY:
+        return "{VT_EMPTY}";
+    case VT_BSTR:
+        sprintf(buf, "{VT_BSTR: %s}", wine_dbgstr_w(V_BSTR(var)));
+        break;
+    case VT_BOOL:
+        sprintf(buf, "{VT_BOOL: %x}", V_BOOL(var));
+        break;
+    case VT_UI4:
+        sprintf(buf, "{VT_UI4: %u}", V_UI4(var));
+        break;
+    default:
+        sprintf(buf, "{vt %d}", V_VT(var));
+        break;
+    }
+
+    return buf;
+}
+
+static void test_illegal_xml(IXMLDOMDocument *xmldom)
+{
+    IXMLDOMNode *first, *last;
+    VARIANT variant;
+    HRESULT hres;
+    BSTR bstr;
+
+    hres = IXMLDOMDocument_get_baseName(xmldom, NULL);
+    ok(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
+    hres = IXMLDOMDocument_get_baseName(xmldom, &bstr);
+    ok(hres == S_FALSE, "get_baseName failed: %08x\n", hres);
+    ok(bstr == NULL, "bstr(%p): %s\n", bstr, wine_dbgstr_w(bstr));
+    SysFreeString(bstr);
+
+    hres = IXMLDOMDocument_get_dataType(xmldom, NULL);
+    ok(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
+    hres = IXMLDOMDocument_get_dataType(xmldom, &variant);
+    ok(hres == S_FALSE, "get_dataType failed: %08x\n", hres);
+    ok(V_VT(&variant) == VT_NULL, "got %s\n", debugstr_variant(&variant));
+    VariantClear(&variant);
+
+    hres = IXMLDOMDocument_get_text(xmldom, &bstr);
+    ok(!strcmp_wa(bstr, ""), "text = %s\n", wine_dbgstr_w(bstr));
+    SysFreeString(bstr);
+
+    hres = IXMLDOMDocument_get_firstChild(xmldom, NULL);
+    ok(hres == E_INVALIDARG, "Expect E_INVALIDARG, got %08x\n", hres);
+
+    first = (void*)0xdeadbeef;
+    hres = IXMLDOMDocument_get_firstChild(xmldom, &first);
+    ok(hres == S_FALSE, "get_firstChild failed: %08x\n", hres);
+    ok(first == NULL, "first != NULL\n");
+
+    last = (void*)0xdeadbeef;
+    hres = IXMLDOMDocument_get_lastChild(xmldom, &last);
+    ok(hres == S_FALSE, "get_lastChild failed: %08x\n", hres);
+    ok(last == NULL, "last != NULL\n");
+}
+
+static void test_responseXML(const char *expect_text)
+{
+    IDispatch *disp;
+    IXMLDOMDocument *xmldom;
+    IObjectSafety *safety;
+    DWORD enabled = 0, supported = 0;
+    HRESULT hres;
+
+    disp = NULL;
+    hres = IHTMLXMLHttpRequest_get_responseXML(xhr, &disp);
+    ok(hres == S_OK, "get_responseXML failed: %08x\n", hres);
+    ok(disp != NULL, "disp == NULL\n");
+
+    xmldom = NULL;
+    hres = IDispatch_QueryInterface(disp, &IID_IXMLDOMDocument, (void**)&xmldom);
+    ok(hres == S_OK, "QueryInterface(IXMLDOMDocument) failed: %08x\n", hres);
+    ok(xmldom != NULL, "xmldom == NULL\n");
+
+    hres = IXMLDOMDocument_QueryInterface(xmldom, &IID_IObjectSafety, (void**)&safety);
+    ok(hres == S_OK, "QueryInterface IObjectSafety failed: %08x\n", hres);
+    hres = IObjectSafety_GetInterfaceSafetyOptions(safety, NULL, &supported, &enabled);
+    ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
+    ok(broken(supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA)) ||
+       supported == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER) /* msxml3 SP8+ */,
+        "Expected supported: (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), got %08x\n", supported);
+    ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER),
+        "Expected enabled: (INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER), got 0x%08x\n", enabled);
+    IObjectSafety_Release(safety);
+
+    if(!expect_text)
+        test_illegal_xml(xmldom);
+
+    IXMLDOMDocument_Release(xmldom);
+    IDispatch_Release(disp);
+}
+
 static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *expect_text)
 {
     VARIANT vbool, vempty, var;
@@ -468,6 +573,8 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *
         {"Content-Type", "application/xml"}
     };
 
+    trace("test_sync_xhr\n");
+
     create_xmlhttprequest(doc);
     if(!xhr)
         return;
@@ -612,6 +719,8 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const char *
             expect_text, wine_dbgstr_w(text));
     SysFreeString(text);
 
+    test_responseXML(expect_text);
+
     IHTMLXMLHttpRequest_Release(xhr);
     xhr = NULL;
 }
@@ -786,6 +895,8 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const char
             expect_text, wine_dbgstr_w(text));
     SysFreeString(text);
 
+    test_responseXML(expect_text);
+
     IHTMLXMLHttpRequest_Release(xhr);
     xhr = NULL;
 }
diff --git a/dlls/mshtml/xmlhttprequest.c b/dlls/mshtml/xmlhttprequest.c
index fdfa31f..d188478 100644
--- a/dlls/mshtml/xmlhttprequest.c
+++ b/dlls/mshtml/xmlhttprequest.c
@@ -30,6 +30,9 @@
 
 #include "mshtml_private.h"
 #include "htmlevent.h"
+#include "initguid.h"
+#include "msxml6.h"
+#include "objsafe.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 
@@ -334,8 +337,42 @@ static HRESULT WINAPI HTMLXMLHttpRequest_get_responseText(IHTMLXMLHttpRequest *i
 static HRESULT WINAPI HTMLXMLHttpRequest_get_responseXML(IHTMLXMLHttpRequest *iface, IDispatch **p)
 {
     HTMLXMLHttpRequest *This = impl_from_IHTMLXMLHttpRequest(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    IXMLDOMDocument *xmldoc = NULL;
+    BSTR str;
+    HRESULT hres;
+    VARIANT_BOOL vbool;
+    IObjectSafety *safety;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    hres = CoCreateInstance(&CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (void**)&xmldoc);
+    if(FAILED(hres)) {
+        ERR("CoCreateInstance failed: %08x\n", hres);
+        return hres;
+    }
+
+    hres = IHTMLXMLHttpRequest_get_responseText(iface, &str);
+    if(FAILED(hres)) {
+        IXMLDOMDocument_Release(xmldoc);
+        ERR("get_responseText failed: %08x\n", hres);
+        return hres;
+    }
+
+    hres = IXMLDOMDocument_loadXML(xmldoc, str, &vbool);
+    SysFreeString(str);
+    if(hres != S_OK || vbool != VARIANT_TRUE)
+        WARN("loadXML failed: %08x, returning an empty xmldoc\n", hres);
+
+    hres = IXMLDOMDocument_QueryInterface(xmldoc, &IID_IObjectSafety, (void**)&safety);
+    assert(SUCCEEDED(hres));
+    hres = IObjectSafety_SetInterfaceSafetyOptions(safety, NULL,
+        INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER,
+        INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACE_USES_SECURITY_MANAGER);
+    assert(SUCCEEDED(hres));
+    IObjectSafety_Release(safety);
+
+    *p = (IDispatch*)xmldoc;
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLXMLHttpRequest_get_status(IHTMLXMLHttpRequest *iface, LONG *p)




More information about the wine-cvs mailing list