[MSHTML_WINETEST]
[reactos.git] / rostests / winetests / mshtml / dom.c
index 5c7380e..25bf764 100644 (file)
@@ -99,7 +99,8 @@ typedef enum {
     ET_TR,
     ET_TD,
     ET_IFRAME,
-    ET_FORM
+    ET_FORM,
+    ET_FRAME
 } elem_type_t;
 
 static const IID * const none_iids[] = {
@@ -310,6 +311,19 @@ static const IID * const td_iids[] = {
     NULL
 };
 
+static const IID * const frame_iids[] = {
+    &IID_IHTMLDOMNode,
+    &IID_IHTMLDOMNode2,
+    &IID_IHTMLElement,
+    &IID_IHTMLElement2,
+    &IID_IHTMLElement3,
+    &IID_IHTMLFrameBase,
+    &IID_IHTMLFrameBase2,
+    &IID_IDispatchEx,
+    &IID_IConnectionPointContainer,
+    NULL
+};
+
 static const IID * const iframe_iids[] = {
     &IID_IHTMLDOMNode,
     &IID_IHTMLDOMNode2,
@@ -318,6 +332,7 @@ static const IID * const iframe_iids[] = {
     &IID_IHTMLElement3,
     &IID_IHTMLFrameBase,
     &IID_IHTMLFrameBase2,
+    &IID_IHTMLIFrameElement,
     &IID_IDispatchEx,
     &IID_IConnectionPointContainer,
     NULL
@@ -389,7 +404,7 @@ static const elem_type_info_t elem_type_infos[] = {
     {"A",         anchor_iids,      &DIID_DispHTMLAnchorElement},
     {"INPUT",     input_iids,       &DIID_DispHTMLInputElement},
     {"SELECT",    select_iids,      &DIID_DispHTMLSelectElement},
-    {"TEXTAREA",  textarea_iids,    NULL},
+    {"TEXTAREA",  textarea_iids,    &DIID_DispHTMLTextAreaElement},
     {"OPTION",    option_iids,      &DIID_DispHTMLOptionElement},
     {"STYLE",     elem_iids,        NULL},
     {"BLOCKQUOTE",elem_iids,        NULL},
@@ -397,7 +412,7 @@ static const elem_type_info_t elem_type_infos[] = {
     {"BR",        elem_iids,        NULL},
     {"TABLE",     table_iids,       &DIID_DispHTMLTable},
     {"TBODY",     elem_iids,        NULL},
-    {"SCRIPT",    script_iids,      NULL},
+    {"SCRIPT",    script_iids,      &DIID_DispHTMLScriptElement},
     {"TEST",      elem_iids,        &DIID_DispHTMLUnknownElement},
     {"TEST",      generic_iids,     &DIID_DispHTMLGenericElement},
     {"!",         comment_iids,     &DIID_DispHTMLCommentElement},
@@ -405,7 +420,8 @@ static const elem_type_info_t elem_type_infos[] = {
     {"TR",        tr_iids,          &DIID_DispHTMLTableRow},
     {"TD",        td_iids,          NULL},
     {"IFRAME",    iframe_iids,      &DIID_DispHTMLIFrame},
-    {"FORM",      form_iids,        &DIID_DispHTMLFormElement}
+    {"FORM",      form_iids,        &DIID_DispHTMLFormElement},
+    {"FRAME",     frame_iids,       &DIID_DispHTMLFrameElement}
 };
 
 static const char *dbgstr_guid(REFIID riid)
@@ -668,6 +684,17 @@ static IHTMLDOMTextNode *_get_text_iface(unsigned line, IUnknown *unk)
     return text;
 }
 
+#define get_comment_iface(u) _get_comment_iface(__LINE__,u)
+static IHTMLCommentElement *_get_comment_iface(unsigned line, IUnknown *unk)
+{
+    IHTMLCommentElement *comment;
+    HRESULT hres;
+
+    hres = IUnknown_QueryInterface(unk, &IID_IHTMLCommentElement, (void**)&comment);
+    ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLCommentElement: %08x\n", hres);
+    return comment;
+}
+
 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
 {
@@ -1086,6 +1113,22 @@ static void _test_option_put_value(unsigned line, IHTMLOptionElement *option, co
     _test_option_value(line, option, value);
 }
 
+#define test_comment_text(c,t) _test_comment_text(__LINE__,c,t)
+static void _test_comment_text(unsigned line, IUnknown *unk, const char *extext)
+{
+    IHTMLCommentElement *comment = _get_comment_iface(__LINE__,unk);
+    BSTR text;
+    HRESULT hres;
+
+    text = a2bstr(extext);
+    hres = IHTMLCommentElement_get_text(comment, &text);
+    ok_(__FILE__,line)(hres == S_OK, "get_text failed: %08x\n", hres);
+    ok_(__FILE__,line)(!strcmp_wa(text, extext), "text = \"%s\", expected \"%s\"\n", wine_dbgstr_w(text), extext);
+
+    IHTMLCommentElement_Release(comment);
+    SysFreeString(text);
+}
+
 #define create_option_elem(d,t,v) _create_option_elem(__LINE__,d,t,v)
 static IHTMLOptionElement *_create_option_elem(unsigned line, IHTMLDocument2 *doc,
         const char *txt, const char *val)
@@ -1129,8 +1172,8 @@ static void _test_img_width(unsigned line, IHTMLImgElement *img, const long exp)
     HRESULT hres;
 
     hres = IHTMLImgElement_get_width(img, &found);
-    todo_wine ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
-    todo_wine ok_(__FILE__,line) (found == exp, "width=%d\n", found);
+    ok_(__FILE__,line) (hres == S_OK, "get_width failed: %08x\n", hres);
+    ok_(__FILE__,line) (found == exp, "width=%d\n", found);
 }
 
 #define test_img_put_width(o,w) _test_img_put_width(__LINE__,o,w)
@@ -1139,7 +1182,7 @@ static void _test_img_put_width(unsigned line, IHTMLImgElement *img, const long
     HRESULT hres;
 
     hres = IHTMLImgElement_put_width(img, width);
-    todo_wine ok(hres == S_OK, "put_width failed: %08x\n", hres);
+    ok(hres == S_OK, "put_width failed: %08x\n", hres);
 
     _test_img_width(line, img, width);
 }
@@ -1151,8 +1194,8 @@ static void _test_img_height(unsigned line, IHTMLImgElement *img, const long exp
     HRESULT hres;
 
     hres = IHTMLImgElement_get_height(img, &found);
-    todo_wine ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
-    todo_wine ok_(__FILE__,line) (found == exp, "height=%d\n", found);
+    ok_(__FILE__,line) (hres == S_OK, "get_height failed: %08x\n", hres);
+    ok_(__FILE__,line) (found == exp, "height=%d\n", found);
 }
 
 #define test_img_put_height(o,w) _test_img_put_height(__LINE__,o,w)
@@ -1161,7 +1204,7 @@ static void _test_img_put_height(unsigned line, IHTMLImgElement *img, const long
     HRESULT hres;
 
     hres = IHTMLImgElement_put_height(img, height);
-    todo_wine ok(hres == S_OK, "put_height failed: %08x\n", hres);
+    ok(hres == S_OK, "put_height failed: %08x\n", hres);
 
     _test_img_height(line, img, height);
 }
@@ -1638,6 +1681,21 @@ static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *o
     SysFreeString(html);
 }
 
+#define test_elem_outerhtml(e,t) _test_elem_outerhtml(__LINE__,e,t)
+static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
+{
+    IHTMLElement *elem = _get_elem_iface(line, unk);
+    BSTR html;
+    HRESULT hres;
+
+    hres = IHTMLElement_get_outerHTML(elem, &html);
+    ok_(__FILE__,line)(hres == S_OK, "get_outerHTML failed: %08x\n", hres);
+    ok_(__FILE__,line)(!strcmp_wa(html, outer_html), "outerHTML = '%s', expected '%s'\n", wine_dbgstr_w(html), outer_html);
+
+    IHTMLElement_Release(elem);
+    SysFreeString(html);
+}
+
 #define get_first_child(n) _get_first_child(__LINE__,n)
 static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
 {
@@ -3853,6 +3911,18 @@ static void test_default_style(IHTMLStyle *style)
     ok(!strcmp_wa(V_BSTR(&v), "auto"), "V_BSTR(v)=%s\n", wine_dbgstr_w(V_BSTR(&v)));
     VariantClear(&v);
 
+    V_VT(&v) = VT_I4;
+    V_I4(&v) = 100;
+    hres = IHTMLStyle_put_width(style, v);
+    ok(hres == S_OK, "put_width failed: %08x\n", hres);
+
+    V_VT(&v) = VT_EMPTY;
+    hres = IHTMLStyle_get_width(style, &v);
+    ok(hres == S_OK, "get_width failed: %08x\n", hres);
+    ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v));
+    ok(!strcmp_wa(V_BSTR(&v), "100px"), "V_BSTR(v)=%s\n", wine_dbgstr_w(V_BSTR(&v)));
+    VariantClear(&v);
+
     /* margin tests */
     str = (void*)0xdeadbeef;
     hres = IHTMLStyle_get_margin(style, &str);
@@ -4418,8 +4488,8 @@ static void test_default_style(IHTMLStyle *style)
      */
     V_BSTR(&v) = NULL;
     hres = IHTMLStyle_get_borderRightColor(style, &v);
-    todo_wine ok(hres == S_OK, "get_borderRightColor failed: %08x\n", hres);
-    todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
+    ok(hres == S_OK, "get_borderRightColor failed: %08x\n", hres);
+    ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
     VariantClear(&v);
 
     V_BSTR(&v) = NULL;
@@ -4452,8 +4522,8 @@ static void test_default_style(IHTMLStyle *style)
      */
     V_BSTR(&v) = NULL;
     hres = IHTMLStyle_get_borderTopColor(style, &v);
-    todo_wine ok(hres == S_OK, "get_borderTopColor failed: %08x\n", hres);
-    todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
+    ok(hres == S_OK, "get_borderTopColor failed: %08x\n", hres);
+    ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
     VariantClear(&v);
 
     V_BSTR(&v) = NULL;
@@ -4486,8 +4556,8 @@ static void test_default_style(IHTMLStyle *style)
      */
     V_BSTR(&v) = NULL;
     hres = IHTMLStyle_get_borderBottomColor(style, &v);
-    todo_wine ok(hres == S_OK, "get_borderBottomColor failed: %08x\n", hres);
-    todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
+    ok(hres == S_OK, "get_borderBottomColor failed: %08x\n", hres);
+    ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
     VariantClear(&v);
 
     V_BSTR(&v) = NULL;
@@ -4520,8 +4590,8 @@ static void test_default_style(IHTMLStyle *style)
      */
     V_BSTR(&v) = NULL;
     hres = IHTMLStyle_get_borderLeftColor(style, &v);
-    todo_wine ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
-    todo_wine ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
+    ok(hres == S_OK, "get_borderLeftColor failed: %08x\n", hres);
+    ok(!strcmp_wa(V_BSTR(&v), "red"), "str=%s\n", wine_dbgstr_w(V_BSTR(&v)));
     VariantClear(&v);
 
     V_BSTR(&v) = NULL;
@@ -5142,10 +5212,12 @@ static void doc_write(IHTMLDocument2 *doc, BOOL ln, const char *text)
     SafeArrayDestroy(sa);
 }
 
-static void test_frame_doc(IUnknown *frame_elem)
+static void test_frame_doc(IUnknown *frame_elem, BOOL iframe)
 {
     IHTMLDocument2 *window_doc, *elem_doc;
+    IHTMLFrameElement3 *frame_elem3;
     IHTMLWindow2 *content_window;
+    HRESULT hres;
 
     content_window = get_frame_content_window(frame_elem);
     window_doc = get_window_doc(content_window);
@@ -5154,6 +5226,23 @@ static void test_frame_doc(IUnknown *frame_elem)
     elem_doc = get_elem_doc(frame_elem);
     ok(iface_cmp((IUnknown*)window_doc, (IUnknown*)elem_doc), "content_doc != elem_doc\n");
 
+    if(!iframe) {
+        hres = IUnknown_QueryInterface(frame_elem, &IID_IHTMLFrameElement3, (void**)&frame_elem3);
+        if(SUCCEEDED(hres)) {
+            IDispatch *disp = NULL;
+
+            hres = IHTMLFrameElement3_get_contentDocument(frame_elem3, &disp);
+            ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
+            ok(disp != NULL, "contentDocument == NULL\n");
+            ok(iface_cmp((IUnknown*)disp, (IUnknown*)window_doc), "contentDocument != contentWindow.document\n");
+
+            IDispatch_Release(disp);
+            IHTMLFrameElement3_Release(frame_elem3);
+        }else {
+            win_skip("IHTMLFrameElement3 not supported\n");
+        }
+    }
+
     IHTMLDocument2_Release(elem_doc);
     IHTMLDocument2_Release(window_doc);
 }
@@ -5176,7 +5265,7 @@ static void test_iframe_elem(IHTMLElement *elem)
         ET_BR
     };
 
-    test_frame_doc((IUnknown*)elem);
+    test_frame_doc((IUnknown*)elem, TRUE);
 
     content_window = get_frame_content_window((IUnknown*)elem);
     test_window_length(content_window, 0);
@@ -5503,9 +5592,18 @@ static void test_elems(IHTMLDocument2 *doc)
         {
             VARIANT_BOOL vb;
 
+            hres = IHTMLScriptElement_put_type (script, NULL);
+            ok(hres == S_OK, "put_type failed: %08x\n", hres);
+            hres = IHTMLScriptElement_get_type(script, &type);
+            ok(hres == S_OK, "get_type failed: %08x\n", hres);
+            ok(type == NULL, "Unexpected type %s\n", wine_dbgstr_w(type));
+
+            hres = IHTMLScriptElement_put_type (script, a2bstr ("text/javascript"));
+            ok(hres == S_OK, "put_type failed: %08x\n", hres);
             hres = IHTMLScriptElement_get_type(script, &type);
             ok(hres == S_OK, "get_type failed: %08x\n", hres);
             ok(!strcmp_wa(type, "text/javascript"), "Unexpected type %s\n", wine_dbgstr_w(type));
+
             SysFreeString(type);
 
             /* test defer */
@@ -5861,6 +5959,11 @@ static void test_create_elems(IHTMLDocument2 *doc)
             ok(type == 8, "type=%d, expected 8\n", type);
 
             test_node_get_value_str((IUnknown*)comment, "testing");
+            test_elem_title((IUnknown*)comment, NULL);
+            test_elem_set_title((IUnknown*)comment, "comment title");
+            test_elem_title((IUnknown*)comment, "comment title");
+            test_comment_text((IUnknown*)comment, "<!--testing-->");
+            test_elem_outerhtml((IUnknown*)comment, "<!--testing-->");
 
             IHTMLDOMNode_Release(comment);
         }
@@ -5871,6 +5974,22 @@ static void test_create_elems(IHTMLDocument2 *doc)
     IHTMLElement_Release(body);
 }
 
+static void test_null_write(IHTMLDocument2 *doc)
+{
+    HRESULT hres;
+
+    doc_write(doc, FALSE, NULL);
+    doc_write(doc, TRUE, NULL);
+
+    hres = IHTMLDocument2_write(doc, NULL);
+    ok(hres == S_OK,
+       "Expected IHTMLDocument2::write to return S_OK, got 0x%08x\n", hres);
+
+    hres = IHTMLDocument2_writeln(doc, NULL);
+    ok(hres == S_OK,
+       "Expected IHTMLDocument2::writeln to return S_OK, got 0x%08x\n", hres);
+}
+
 static void test_exec(IUnknown *unk, const GUID *grpid, DWORD cmdid, VARIANT *in, VARIANT *out)
 {
     IOleCommandTarget *cmdtrg;
@@ -5964,7 +6083,8 @@ static void test_frame(IDispatch *disp, const char *exp_id)
     if(FAILED(hres))
         return;
 
-    test_frame_doc((IUnknown*)frame_elem);
+    test_elem_type((IUnknown*)frame_elem, ET_FRAME);
+    test_frame_doc((IUnknown*)frame_elem, FALSE);
     test_elem_id((IUnknown*)frame_elem, exp_id);
     IHTMLElement_Release(frame_elem);
 
@@ -6344,6 +6464,7 @@ START_TEST(dom)
     run_domtest(elem_test2_str, test_elems2);
     run_domtest(doc_blank, test_create_elems);
     run_domtest(doc_blank, test_defaults);
+    run_domtest(doc_blank, test_null_write);
     run_domtest(indent_test_str, test_indent);
     run_domtest(cond_comment_str, test_cond_comment);
     run_domtest(frameset_str, test_frameset);