diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index f8d62a37a02..c5c2e784ff3 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -438,15 +438,49 @@ static HRESULT WINAPI HTMLWindow2_get_navigator(IHTMLWindow2 *iface, IOmNavigato static HRESULT WINAPI HTMLWindow2_put_name(IHTMLWindow2 *iface, BSTR v) { HTMLWindow *This = HTMLWINDOW2_THIS(iface); - FIXME("(%p)->(%s)\n", This, debugstr_w(v)); - return E_NOTIMPL; + nsAString name_str; + nsresult nsres; + + TRACE("(%p)->(%s)\n", This, debugstr_w(v)); + + nsAString_Init(&name_str, v); + nsres = nsIDOMWindow_SetName(This->nswindow, &name_str); + nsAString_Finish(&name_str); + if(NS_FAILED(nsres)) + ERR("SetName failed: %08x\n", nsres); + + return S_OK; } static HRESULT WINAPI HTMLWindow2_get_name(IHTMLWindow2 *iface, BSTR *p) { HTMLWindow *This = HTMLWINDOW2_THIS(iface); - FIXME("(%p)->(%p)\n", This, p); - return E_NOTIMPL; + nsAString name_str; + nsresult nsres; + HRESULT hres; + + TRACE("(%p)->(%p)\n", This, p); + + nsAString_Init(&name_str, NULL); + nsres = nsIDOMWindow_GetName(This->nswindow, &name_str); + if(NS_SUCCEEDED(nsres)) { + const PRUnichar *name; + + nsAString_GetData(&name_str, &name); + if(*name) { + *p = SysAllocString(name); + hres = *p ? S_OK : E_OUTOFMEMORY; + }else { + *p = NULL; + hres = S_OK; + } + }else { + ERR("GetName failed: %08x\n", nsres); + hres = E_FAIL; + } + nsAString_Finish(&name_str); + + return hres; } static HRESULT WINAPI HTMLWindow2_get_parent(IHTMLWindow2 *iface, IHTMLWindow2 **p) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index c13c0a8c606..bb974295971 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -656,6 +656,20 @@ static IHTMLDocument2 *_get_owner_doc(unsigned line, IUnknown *unk) return doc; } +#define get_doc_window(d) _get_doc_window(__LINE__,d) +static IHTMLWindow2 *_get_doc_window(unsigned line, IHTMLDocument2 *doc) +{ + IHTMLWindow2 *window; + HRESULT hres; + + window = NULL; + hres = IHTMLDocument2_get_parentWindow(doc, &window); + ok_(__FILE__,line)(hres == S_OK, "get_parentWindow failed: %08x\n", hres); + ok_(__FILE__,line)(window != NULL, "window == NULL\n"); + + return window; +} + #define clone_node(n,d) _clone_node(__LINE__,n,d) static IHTMLDOMNode *_clone_node(unsigned line, IUnknown *unk, VARIANT_BOOL deep) { @@ -809,6 +823,35 @@ static IHTMLDocument2 *_get_doc_node(unsigned line, IHTMLDocument2 *doc) return ret; } +#define test_window_name(d,e) _test_window_name(__LINE__,d,e) +static void _test_window_name(unsigned line, IHTMLWindow2 *window, const char *exname) +{ + BSTR name; + HRESULT hres; + + hres = IHTMLWindow2_get_name(window, &name); + ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres); + if(exname) + ok_(__FILE__,line)(!strcmp_wa(name, exname), "name = %s\n", wine_dbgstr_w(name)); + else + ok_(__FILE__,line)(!name, "name = %s\n", wine_dbgstr_w(name)); +} + +#define set_window_name(w,n) _set_window_name(__LINE__,w,n) +static void _set_window_name(unsigned line, IHTMLWindow2 *window, const char *name) +{ + BSTR str; + HRESULT hres; + + str = a2bstr(name); + hres = IHTMLWindow2_put_name(window, str); + SysFreeString(str); + ok_(__FILE__,line)(hres == S_OK, "put_name failed: %08x\n", hres); + + _test_window_name(line, window, name); +} + + static void test_get_set_attr(IHTMLDocument2 *doc) { IHTMLElement *elem; @@ -4369,6 +4412,9 @@ static void test_window(IHTMLDocument2 *doc) ok(!strcmp_wa(str, "[object]"), "toString returned %s\n", wine_dbgstr_w(str)); SysFreeString(str); + test_window_name(window, NULL); + set_window_name(window, "test"); + IHTMLWindow2_Release(window); } @@ -4738,6 +4784,7 @@ static void test_elems(IHTMLDocument2 *doc) IHTMLDOMChildrenCollection *child_col; IHTMLElement *elem, *elem2, *elem3; IHTMLDOMNode *node, *node2; + IHTMLWindow2 *window; IDispatch *disp; LONG type; HRESULT hres; @@ -5151,6 +5198,11 @@ static void test_elems(IHTMLDocument2 *doc) IHTMLElement_Release(elem); IHTMLDocument3_Release(doc3); + + window = get_doc_window(doc); + test_window_name(window, NULL); + set_window_name(window, "test name"); + IHTMLWindow2_Release(window); } static void test_create_elems(IHTMLDocument2 *doc)