Zhenbo Li : mshtml: Add IHTMLOptionElement:: defaultSelected property implementation.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Aug 25 09:38:02 CDT 2015
Module: wine
Branch: master
Commit: 85c31979de75ad25932d7305d2eaef9148afad5b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=85c31979de75ad25932d7305d2eaef9148afad5b
Author: Zhenbo Li <litimetal at gmail.com>
Date: Sat Aug 22 21:16:35 2015 +0800
mshtml: Add IHTMLOptionElement::defaultSelected property implementation.
---
dlls/mshtml/htmloption.c | 46 ++++++++++++++++++++++++++++++++++++----
dlls/mshtml/tests/dom.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+), 4 deletions(-)
diff --git a/dlls/mshtml/htmloption.c b/dlls/mshtml/htmloption.c
index 54d872c..802e85a 100644
--- a/dlls/mshtml/htmloption.c
+++ b/dlls/mshtml/htmloption.c
@@ -166,15 +166,53 @@ static HRESULT WINAPI HTMLOptionElement_get_value(IHTMLOptionElement *iface, BST
static HRESULT WINAPI HTMLOptionElement_put_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL v)
{
HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
- FIXME("(%p)->(%x)\n", This, v);
- return E_NOTIMPL;
+ cpp_bool val, selected;
+ nsresult nsres;
+
+ TRACE("(%p)->(%x)\n", This, v);
+
+ val = (v == VARIANT_TRUE);
+
+ nsres = nsIDOMHTMLOptionElement_GetSelected(This->nsoption, &selected);
+ if(NS_FAILED(nsres)) {
+ ERR("GetSelected failed: %08x\n", nsres);
+ return E_FAIL;
+ }
+
+ nsres = nsIDOMHTMLOptionElement_SetDefaultSelected(This->nsoption, val);
+ if(NS_FAILED(nsres)) {
+ ERR("SetDefaultSelected failed: %08x\n", nsres);
+ return E_FAIL;
+ }
+
+ if(val != selected) {
+ nsres = nsIDOMHTMLOptionElement_SetSelected(This->nsoption, selected); /* WinAPI will reserve selected property */
+ if(NS_FAILED(nsres)) {
+ ERR("SetSelected failed: %08x\n", nsres);
+ return E_FAIL;
+ }
+ }
+
+ return S_OK;
}
static HRESULT WINAPI HTMLOptionElement_get_defaultSelected(IHTMLOptionElement *iface, VARIANT_BOOL *p)
{
HTMLOptionElement *This = impl_from_IHTMLOptionElement(iface);
- FIXME("(%p)->(%p)\n", This, p);
- return E_NOTIMPL;
+ cpp_bool val;
+ nsresult nsres;
+
+ TRACE("(%p)->(%p)\n", This, p);
+ if(!p)
+ return E_POINTER;
+ nsres = nsIDOMHTMLOptionElement_GetDefaultSelected(This->nsoption, &val);
+ if(NS_FAILED(nsres)) {
+ ERR("GetDefaultSelected failed: %08x\n", nsres);
+ return E_FAIL;
+ }
+
+ *p = val ? VARIANT_TRUE : VARIANT_FALSE;
+ return S_OK;
}
static HRESULT WINAPI HTMLOptionElement_put_index(IHTMLOptionElement *iface, LONG v)
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index 55b64ef..c7e5e7c 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -1692,6 +1692,60 @@ static void _test_option_get_index(unsigned line, IHTMLOptionElement *option, LO
"value = %d, expected = %d\n", val, exval);
}
+#define test_option_put_defaultSelected(o,d) _test_option_put_defaultSelected(__LINE__,o,d)
+static void _test_option_put_defaultSelected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL b)
+{
+ HRESULT hres;
+
+ hres = IHTMLOptionElement_put_defaultSelected(option, b);
+ ok_(__FILE__,line)(hres == S_OK, "put_defaultSelected %08x\n", hres);
+}
+
+#define test_option_defaultSelected(o,e) _test_option_defaultSelected(__LINE__,o,e)
+static void _test_option_defaultSelected(unsigned line, IHTMLOptionElement *option, VARIANT_BOOL ex)
+{
+ HRESULT hres;
+ VARIANT_BOOL b;
+
+ hres = IHTMLOptionElement_get_defaultSelected(option, NULL);
+ ok_(__FILE__,line)(hres == E_POINTER, "Expect E_POINTER, got %08x\n", hres);
+
+ b = 0x100;
+ hres = IHTMLOptionElement_get_defaultSelected(option, &b);
+ ok_(__FILE__,line)(hres == S_OK, "get_defaultSelected failed: %08x\n", hres);
+ ok_(__FILE__,line)(b == ex, "b = %x, expected = %x\n", b, ex);
+}
+
+static void test_option_defaultSelected_property(IHTMLOptionElement *option)
+{
+ test_option_defaultSelected(option, VARIANT_FALSE);
+ test_option_selected(option, VARIANT_FALSE);
+
+ test_option_put_defaultSelected(option, 0x100); /* Invalid value */
+ test_option_defaultSelected(option, VARIANT_FALSE);
+ test_option_selected(option, VARIANT_FALSE);
+
+ test_option_put_defaultSelected(option, VARIANT_TRUE);
+ test_option_defaultSelected(option, VARIANT_TRUE);
+ test_option_selected(option, VARIANT_FALSE);
+
+ test_option_put_defaultSelected(option, 0x100); /* Invalid value */
+ test_option_defaultSelected(option, VARIANT_FALSE);
+ test_option_selected(option, VARIANT_FALSE);
+
+ test_option_put_selected(option, VARIANT_TRUE);
+ test_option_selected(option, VARIANT_TRUE);
+ test_option_defaultSelected(option, VARIANT_FALSE);
+
+ test_option_put_defaultSelected(option, VARIANT_TRUE);
+ test_option_defaultSelected(option, VARIANT_TRUE);
+ test_option_selected(option, VARIANT_TRUE);
+
+ /* Restore defaultSelected */
+ test_option_put_defaultSelected(option, VARIANT_TRUE);
+ test_option_put_selected(option, VARIANT_FALSE);
+}
+
#define test_textarea_value(t,v) _test_textarea_value(__LINE__,t,v)
static void _test_textarea_value(unsigned line, IUnknown *unk, const char *exval)
{
@@ -5085,6 +5139,7 @@ static void test_create_option_elem(IHTMLDocument2 *doc)
test_option_put_text(option, "new text");
test_option_put_value(option, "new value");
test_option_get_index(option, 0);
+ test_option_defaultSelected_property(option);
test_option_put_selected(option, VARIANT_TRUE);
test_option_put_selected(option, VARIANT_FALSE);
More information about the wine-cvs
mailing list