2 * Copyright 2008-2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
35 #define DEFINE_EXPECT(func) \
36 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38 #define SET_EXPECT(func) \
39 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
41 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 DEFINE_EXPECT(document_onclick);
61 DEFINE_EXPECT(body_onclick);
62 DEFINE_EXPECT(doc_onclick_attached);
63 DEFINE_EXPECT(div_onclick);
64 DEFINE_EXPECT(div_onclick_attached);
65 DEFINE_EXPECT(timeout);
66 DEFINE_EXPECT(doccp_onclick);
67 DEFINE_EXPECT(doccp_onclick_cancel);
68 DEFINE_EXPECT(div_onclick_disp);
69 DEFINE_EXPECT(iframe_onreadystatechange_loading);
70 DEFINE_EXPECT(iframe_onreadystatechange_interactive);
71 DEFINE_EXPECT(iframe_onreadystatechange_complete);
72 DEFINE_EXPECT(iframedoc_onreadystatechange);
73 DEFINE_EXPECT(img_onload);
74 DEFINE_EXPECT(input_onfocus);
75 DEFINE_EXPECT(form_onsubmit);
76 DEFINE_EXPECT(form_onclick);
77 DEFINE_EXPECT(submit_onclick);
78 DEFINE_EXPECT(submit_onclick_attached);
80 static HWND container_hwnd = NULL;
81 static IHTMLWindow2 *window;
82 static IOleDocumentView *view;
92 static const xy_test_t no_xy = {-10,-10,-10,-10};
93 static const xy_test_t zero_xy = {0,0,0,0};
95 static const char empty_doc_str[] =
98 static const char click_doc_str[] =
100 "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
103 static const char readystate_doc_str[] =
104 "<html><body><iframe id=\"iframe\"></iframe></body></html>";
106 static const char img_doc_str[] =
107 "<html><body><img id=\"imgid\"></img></body></html>";
109 static const char input_doc_str[] =
110 "<html><body><input id=\"inputid\"></input></body></html>";
112 static const char iframe_doc_str[] =
113 "<html><body><iframe id=\"ifr\">Testing</iframe></body></html>";
115 static const char form_doc_str[] =
116 "<html><body><form id=\"formid\" method=\"post\" action=\"about:blank\">"
117 "<input type=\"text\" value=\"test\" name=\"i\"/>"
118 "<input type=\"submit\" id=\"submitid\" />"
119 "</form></body></html>";
121 static const char *debugstr_guid(REFIID riid)
125 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
126 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
127 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
128 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
133 static int strcmp_wa(LPCWSTR strw, const char *stra)
136 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
137 return lstrcmpA(stra, buf);
140 static BSTR a2bstr(const char *str)
145 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
146 ret = SysAllocStringLen(NULL, len-1);
147 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
152 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
154 IUnknown *unk1, *unk2;
159 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
160 IUnknown_Release(unk1);
161 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
162 IUnknown_Release(unk2);
167 #define test_disp(u,id) _test_disp(__LINE__,u,id)
168 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
175 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
176 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
181 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
182 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
183 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
185 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
186 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
188 if(SUCCEEDED(hres)) {
191 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
192 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
193 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
194 debugstr_guid(&type_attr->guid));
196 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
197 ITypeInfo_Release(typeinfo);
200 IDispatchEx_Release(dispex);
203 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
204 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
206 IHTMLDocument3 *doc3;
209 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
210 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
215 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
216 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
221 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
222 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
227 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
228 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
230 IHTMLElement2 *elem2;
233 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
234 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
239 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
240 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
242 IHTMLElement3 *elem3;
245 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
246 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
251 #define doc_get_body(d) _doc_get_body(__LINE__,d)
252 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
254 IHTMLElement *body = NULL;
257 hres = IHTMLDocument2_get_body(doc, &body);
258 ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
259 ok_(__FILE__,line) (body != NULL, "body == NULL\n");
264 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
265 static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
267 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
273 hres = IHTMLDocument3_getElementById(doc3, str, &elem);
275 IHTMLDocument3_Release(doc3);
276 ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
281 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
282 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
284 IHTMLElement *elem = _get_elem_iface(line, unk);
288 hres = IHTMLElement_get_tagName(elem, &tag);
289 IHTMLElement_Release(elem);
290 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
291 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
296 #define get_event_obj() _get_event_obj(__LINE__)
297 static IHTMLEventObj *_get_event_obj(unsigned line)
299 IHTMLEventObj *event = NULL;
302 hres = IHTMLWindow2_get_event(window, &event);
303 ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
304 ok_(__FILE__,line) (event != NULL, "event = NULL\n");
305 _test_disp(line, (IUnknown*)event, &DIID_DispCEventObj);
310 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
311 static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
313 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
320 hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
322 ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
323 ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
326 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
327 static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
328 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
330 ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
331 ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
332 ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
333 ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
334 ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
335 ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
336 pdp->rgdispidNamedArgs[0]);
337 ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
338 ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
339 ok_(__FILE__,line) (pei != NULL, "pei == NULL");
340 ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
343 _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
346 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
347 static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
348 VARIANT *pvarRes, EXCEPINFO *pei)
350 IHTMLEventObj *event;
352 ok(id == DISPID_VALUE, "id = %d\n", id);
353 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
354 ok(pdp != NULL, "pDispParams == NULL\n");
355 ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
356 ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
357 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
358 ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
359 ok(pvarRes != NULL, "pvarRes = NULL\n");
360 ok(pei != NULL, "pei = NULL\n");
361 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
362 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
363 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
365 event = _get_event_obj(line);
366 ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
367 IHTMLEventObj_Release(event);
370 #define get_event_src() _get_event_src(__LINE__)
371 static IHTMLElement *_get_event_src(unsigned line)
373 IHTMLEventObj *event = _get_event_obj(line);
374 IHTMLElement *src_elem = NULL;
377 hres = IHTMLEventObj_get_srcElement(event, &src_elem);
378 IHTMLEventObj_Release(event);
379 ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
384 #define test_event_src(t) _test_event_src(__LINE__,t)
385 static void _test_event_src(unsigned line, const char *src_tag)
387 IHTMLElement *src_elem = _get_event_src(line);
390 ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
391 _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
392 IHTMLElement_Release(src_elem);
394 ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
398 static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
403 hres = IHTMLEventObj_get_altKey(event, &b);
404 ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
405 ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
408 static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
413 hres = IHTMLEventObj_get_ctrlKey(event, &b);
414 ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
415 ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
418 static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
423 hres = IHTMLEventObj_get_shiftKey(event, &b);
424 ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
425 ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
428 static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
433 hres = IHTMLEventObj_get_cancelBubble(event, &b);
434 ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
435 ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
438 static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
443 hres = IHTMLEventObj_get_fromElement(event, &elem);
444 ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
446 _test_elem_tag(line, (IUnknown*)elem, from_tag);
448 ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
450 IHTMLElement_Release(elem);
453 static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
458 hres = IHTMLEventObj_get_toElement(event, &elem);
459 ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
461 _test_elem_tag(line, (IUnknown*)elem, to_tag);
463 ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
465 IHTMLElement_Release(elem);
468 static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
473 hres = IHTMLEventObj_get_keyCode(event, &l);
474 ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
475 ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
478 static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
483 hres = IHTMLEventObj_get_button(event, &l);
484 ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
485 ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
488 static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
493 hres = IHTMLEventObj_get_reason(event, &l);
494 ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
495 ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
498 static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
503 hres = IHTMLEventObj_get_x(event, &l);
504 ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
505 if(exl != -10) /* don't test the exact value */
506 ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
509 static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
514 hres = IHTMLEventObj_get_y(event, &l);
515 ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
516 if(exl != -10) /* don't test the exact value */
517 ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
520 static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
525 hres = IHTMLEventObj_get_clientX(event, &l);
526 ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
527 if(exl != -10) /* don't test the exact value */
528 ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
531 static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
536 hres = IHTMLEventObj_get_clientY(event, &l);
537 ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
538 if(exl != -10) /* don't test the exact value */
539 ok_(__FILE__,line)(l == exl, "clientY = %d, expected %d\n", l, exl);
542 static void _test_event_offsetx(unsigned line, IHTMLEventObj *event, LONG exl)
547 hres = IHTMLEventObj_get_offsetX(event, &l);
548 ok_(__FILE__,line)(hres == S_OK, "get_offsetX failed: %08x\n", hres);
549 if(exl != -10) /* don't test the exact value */
550 ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
553 static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
558 hres = IHTMLEventObj_get_offsetY(event, &l);
559 ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
560 if(exl != -10) /* don't test the exact value */
561 ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
564 static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
569 hres = IHTMLEventObj_get_screenX(event, &l);
570 ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
571 if(exl != -10) /* don't test the exact value */
572 ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
575 static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
580 hres = IHTMLEventObj_get_screenY(event, &l);
581 ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
582 if(exl != -10) /* don't test the exact value for -10 */
583 ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
586 static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
591 hres = IHTMLEventObj_get_type(event, &str);
592 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
593 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
596 static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
601 hres = IHTMLEventObj_get_qualifier(event, &str);
602 ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
604 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
606 ok_(__FILE__,line)(!str, "qualifier != NULL\n");
609 static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
614 hres = IHTMLEventObj_get_srcFilter(event, &disp);
615 ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
616 ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
619 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
620 static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
622 IHTMLEventObj *event = _get_event_obj(line);
626 _test_event_altkey(line, event, VARIANT_FALSE);
627 _test_event_ctrlkey(line, event, VARIANT_FALSE);
628 _test_event_shiftkey(line, event, VARIANT_FALSE);
629 _test_event_cancelbubble(line, event, VARIANT_FALSE);
630 _test_event_fromelem(line, event, NULL);
631 _test_event_toelem(line, event, NULL);
632 _test_event_keycode(line, event, 0);
633 _test_event_button(line, event, 0);
634 _test_event_type(line, event, type);
635 _test_event_qualifier(line, event, NULL);
636 _test_event_reason(line, event, 0);
637 _test_event_srcfilter(line, event);
638 _test_event_x(line, event, xy->x);
639 _test_event_y(line, event, xy->y);
640 _test_event_clientx(line, event, -10);
641 _test_event_clienty(line, event, -10);
642 _test_event_offsetx(line, event, xy->offset_x);
643 _test_event_offsety(line, event, xy->offset_y);
644 _test_event_screenx(line, event, -10);
645 _test_event_screeny(line, event, -10);
647 hres = IHTMLEventObj_get_returnValue(event, &v);
648 ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
649 ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
651 IHTMLEventObj_Release(event);
654 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
655 static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
657 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
662 name = a2bstr(namea);
663 hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
664 IHTMLElement2_Release(elem);
666 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
667 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
670 #define elem_detach_event(a,b,c) _elem_detach_event(__LINE__,a,b,c)
671 static void _elem_detach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
673 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
677 name = a2bstr(namea);
678 hres = IHTMLElement2_detachEvent(elem, name, disp);
679 IHTMLElement2_Release(elem);
681 ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
684 #define doc_attach_event(a,b,c) _doc_attach_event(__LINE__,a,b,c)
685 static void _doc_attach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
687 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
692 name = a2bstr(namea);
693 hres = IHTMLDocument3_attachEvent(doc3, name, disp, &res);
694 IHTMLDocument3_Release(doc3);
696 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
697 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
700 #define doc_detach_event(a,b,c) _doc_detach_event(__LINE__,a,b,c)
701 static void _doc_detach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
703 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
707 name = a2bstr(namea);
708 hres = IHTMLDocument3_detachEvent(doc3, name, disp);
709 IHTMLDocument3_Release(doc3);
711 ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
714 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
718 if(IsEqualGUID(riid, &IID_IUnknown)
719 || IsEqualGUID(riid, &IID_IDispatch)
720 || IsEqualGUID(riid, &IID_IDispatchEx))
723 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
724 return E_NOINTERFACE;
730 static HRESULT WINAPI Dispatch_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
734 if(IsEqualGUID(riid, &IID_IUnknown)
735 || IsEqualGUID(riid, &IID_IDispatch)) {
737 }else if(IsEqualGUID(riid, &IID_IDispatchEx)) {
738 return E_NOINTERFACE;
740 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
741 return E_NOINTERFACE;
747 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
752 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
757 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
759 ok(0, "unexpected call\n");
763 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
764 LCID lcid, ITypeInfo **ppTInfo)
766 ok(0, "unexpected call\n");
770 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
771 LPOLESTR *rgszNames, UINT cNames,
772 LCID lcid, DISPID *rgDispId)
774 ok(0, "unexpected call\n");
778 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
779 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
780 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
782 ok(0, "unexpected call\n");
786 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
788 ok(0, "unexpected call\n");
792 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
793 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
795 ok(0, "unexpected call\n");
799 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
801 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
805 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
807 ok(0, "unexpected call\n");
811 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
813 ok(0, "unexpected call\n");
817 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
819 ok(0, "unexpected call\n");
823 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
825 ok(0, "unexpected call\n");
829 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
831 ok(0, "unexpected call\n");
835 #define EVENT_HANDLER_FUNC_OBJ(event) \
836 static IDispatchExVtbl event ## FuncVtbl = { \
837 DispatchEx_QueryInterface, \
839 DispatchEx_Release, \
840 DispatchEx_GetTypeInfoCount, \
841 DispatchEx_GetTypeInfo, \
842 DispatchEx_GetIDsOfNames, \
844 DispatchEx_GetDispID, \
846 DispatchEx_DeleteMemberByName, \
847 DispatchEx_DeleteMemberByDispID, \
848 DispatchEx_GetMemberProperties, \
849 DispatchEx_GetMemberName, \
850 DispatchEx_GetNextDispID, \
851 DispatchEx_GetNameSpaceParent \
853 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
855 static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
856 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
858 IHTMLDocument3 *doc3;
859 CHECK_EXPECT(document_onclick);
860 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
861 doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
862 IHTMLDocument3_Release(doc3);
863 test_event_src("DIV");
864 test_event_obj("click", &no_xy);
868 EVENT_HANDLER_FUNC_OBJ(document_onclick);
870 static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
871 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
873 CHECK_EXPECT(div_onclick);
874 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
875 test_event_src("DIV");
879 EVENT_HANDLER_FUNC_OBJ(div_onclick);
881 static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
882 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
884 CHECK_EXPECT(div_onclick_attached);
886 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
887 test_event_src("DIV");
891 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
893 static HRESULT WINAPI doc_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
894 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
896 CHECK_EXPECT(doc_onclick_attached);
898 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
899 test_event_src("DIV");
903 EVENT_HANDLER_FUNC_OBJ(doc_onclick_attached);
905 static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
906 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
908 CHECK_EXPECT(body_onclick);
909 test_event_args(&DIID_DispHTMLBody, id, wFlags, pdp, pvarRes, pei, pspCaller);
910 test_event_src("DIV");
914 EVENT_HANDLER_FUNC_OBJ(body_onclick);
916 static HRESULT WINAPI img_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
917 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
919 CHECK_EXPECT(img_onload);
920 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
921 test_event_src("IMG");
925 EVENT_HANDLER_FUNC_OBJ(img_onload);
927 static HRESULT WINAPI input_onfocus(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
928 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
930 CHECK_EXPECT(input_onfocus);
931 test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
932 test_event_src("INPUT");
936 EVENT_HANDLER_FUNC_OBJ(input_onfocus);
938 static HRESULT WINAPI form_onsubmit(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
939 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
941 CHECK_EXPECT(form_onsubmit);
942 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
943 test_event_src("FORM");
945 V_VT(pvarRes) = VT_BOOL;
946 V_BOOL(pvarRes) = VARIANT_FALSE;
950 EVENT_HANDLER_FUNC_OBJ(form_onsubmit);
952 static HRESULT WINAPI form_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
953 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
955 CHECK_EXPECT(form_onclick);
956 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
961 EVENT_HANDLER_FUNC_OBJ(form_onclick);
963 static HRESULT WINAPI submit_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
964 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
966 CHECK_EXPECT(submit_onclick);
967 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
968 test_event_src("INPUT");
970 V_VT(pvarRes) = VT_BOOL;
971 V_BOOL(pvarRes) = VARIANT_FALSE;
975 EVENT_HANDLER_FUNC_OBJ(submit_onclick);
977 static HRESULT WINAPI submit_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
978 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
980 CHECK_EXPECT(submit_onclick_attached);
981 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
982 test_event_src("INPUT");
984 V_VT(pvarRes) = VT_BOOL;
985 V_BOOL(pvarRes) = VARIANT_FALSE;
989 EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached);
991 static HRESULT WINAPI iframedoc_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
992 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
994 IHTMLEventObj *event = NULL;
997 CHECK_EXPECT2(iframedoc_onreadystatechange);
998 test_event_args(&DIID_DispHTMLDocument, id, wFlags, pdp, pvarRes, pei, pspCaller);
1000 event = (void*)0xdeadbeef;
1001 hres = IHTMLWindow2_get_event(window, &event);
1002 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1003 ok(!event, "event = %p\n", event);
1008 EVENT_HANDLER_FUNC_OBJ(iframedoc_onreadystatechange);
1010 static HRESULT WINAPI iframe_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1011 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1013 IHTMLWindow2 *iframe_window;
1014 IHTMLDocument2 *iframe_doc;
1015 IHTMLFrameBase2 *iframe;
1016 IHTMLElement2 *elem2;
1022 test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
1023 test_event_src("IFRAME");
1025 elem = get_event_src();
1026 elem2 = get_elem2_iface((IUnknown*)elem);
1027 IHTMLElement_Release(elem);
1029 V_VT(&v) = VT_EMPTY;
1030 hres = IHTMLElement2_get_readyState(elem2, &v);
1031 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1032 ok(V_VT(&v) == VT_BSTR, "V_VT(readyState) = %d\n", V_VT(&v));
1034 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase2, (void**)&iframe);
1035 IHTMLElement2_Release(elem2);
1036 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
1039 hres = IHTMLFrameBase2_get_readyState(iframe, &str);
1040 IHTMLFrameBase2_Release(iframe);
1041 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1042 ok(str != NULL, "readyState == NULL\n");
1043 ok(!lstrcmpW(str, V_BSTR(&v)), "ready states differ\n");
1046 hres = IHTMLFrameBase2_get_contentWindow(iframe, &iframe_window);
1047 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
1049 hres = IHTMLWindow2_get_document(iframe_window, &iframe_doc);
1050 IHTMLWindow2_Release(iframe_window);
1051 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1053 hres = IHTMLDocument2_get_readyState(iframe_doc, &str2);
1054 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1055 ok(!lstrcmpW(str, str2), "unexpected document readyState %s\n", wine_dbgstr_w(str2));
1056 SysFreeString(str2);
1058 if(!strcmp_wa(str, "loading")) {
1059 CHECK_EXPECT(iframe_onreadystatechange_loading);
1061 V_VT(&v) = VT_DISPATCH;
1062 V_DISPATCH(&v) = (IDispatch*)&iframedoc_onreadystatechange_obj;
1063 hres = IHTMLDocument2_put_onreadystatechange(iframe_doc, v);
1064 ok(hres == S_OK, "put_onreadystatechange: %08x\n", hres);
1065 }else if(!strcmp_wa(str, "interactive"))
1066 CHECK_EXPECT(iframe_onreadystatechange_interactive);
1067 else if(!strcmp_wa(str, "complete"))
1068 CHECK_EXPECT(iframe_onreadystatechange_complete);
1070 ok(0, "unexpected state %s\n", wine_dbgstr_w(str));
1073 IHTMLDocument2_Release(iframe_doc);
1074 IHTMLFrameBase2_Release(iframe);
1078 EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange);
1080 static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1081 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1083 ok(0, "unexpected call\n");
1087 EVENT_HANDLER_FUNC_OBJ(nocall);
1089 #define CONNECTION_POINT_OBJ(cpname, diid) \
1090 static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
1093 if(IsEqualGUID(riid, &IID_IUnknown) \
1094 || IsEqualGUID(riid, &IID_IDispatch) \
1095 || IsEqualGUID(riid, &diid)) \
1098 ok(0, "unexpected riid %s\n", debugstr_guid(riid)); \
1099 return E_NOINTERFACE; \
1103 static IDispatchExVtbl cpname ## Vtbl = { \
1104 cpname ## _QueryInterface, \
1105 DispatchEx_AddRef, \
1106 DispatchEx_Release, \
1107 DispatchEx_GetTypeInfoCount, \
1108 DispatchEx_GetTypeInfo, \
1109 DispatchEx_GetIDsOfNames, \
1111 DispatchEx_GetDispID, \
1112 DispatchEx_InvokeEx, \
1113 DispatchEx_DeleteMemberByName, \
1114 DispatchEx_DeleteMemberByDispID, \
1115 DispatchEx_GetMemberProperties, \
1116 DispatchEx_GetMemberName, \
1117 DispatchEx_GetNextDispID, \
1118 DispatchEx_GetNameSpaceParent \
1120 static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
1122 #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
1123 static void _test_cp_args(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1125 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
1126 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1127 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1128 ok_(__FILE__,line)(!dp->cArgs, "dp->cArgs = %d\n", dp->cArgs);
1129 ok_(__FILE__,line)(!dp->rgvarg, "dp->rgvarg = %p\n", dp->rgvarg);
1130 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1131 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1132 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1133 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1134 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1135 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1138 static HRESULT WINAPI doccp(IDispatchEx *iface, DISPID dispIdMember,
1139 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1140 VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1142 switch(dispIdMember) {
1143 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1144 CHECK_EXPECT(doccp_onclick);
1145 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1148 ok(0, "unexpected call %d\n", dispIdMember);
1155 CONNECTION_POINT_OBJ(doccp, DIID_HTMLDocumentEvents);
1157 static HRESULT WINAPI doccp_onclick_cancel(IDispatchEx *iface, DISPID dispIdMember,
1158 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1160 switch(dispIdMember) {
1161 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1162 CHECK_EXPECT(doccp_onclick_cancel);
1163 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1164 V_VT(pVarResult) = VT_BOOL;
1165 V_BOOL(pVarResult) = VARIANT_FALSE;
1168 ok(0, "unexpected call %d\n", dispIdMember);
1175 CONNECTION_POINT_OBJ(doccp_onclick_cancel, DIID_HTMLDocumentEvents);
1177 static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1178 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1179 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1181 CHECK_EXPECT(timeout);
1183 ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
1184 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
1185 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
1186 ok(!lcid, "lcid = %x\n", lcid);
1187 ok(pDispParams != NULL, "pDispParams == NULL\n");
1188 ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
1189 ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
1190 ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
1191 ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
1192 ok(pVarResult != NULL, "pVarResult = NULL\n");
1193 ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
1194 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1195 ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1200 static IDispatchExVtbl timeoutFuncVtbl = {
1201 DispatchEx_QueryInterface,
1204 DispatchEx_GetTypeInfoCount,
1205 DispatchEx_GetTypeInfo,
1206 DispatchEx_GetIDsOfNames,
1208 DispatchEx_GetDispID,
1209 DispatchEx_InvokeEx,
1210 DispatchEx_DeleteMemberByName,
1211 DispatchEx_DeleteMemberByDispID,
1212 DispatchEx_GetMemberProperties,
1213 DispatchEx_GetMemberName,
1214 DispatchEx_GetNextDispID,
1215 DispatchEx_GetNameSpaceParent
1218 static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
1220 static HRESULT WINAPI div_onclick_disp_Invoke(IDispatchEx *iface, DISPID id,
1221 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1222 VARIANT *pvarRes, EXCEPINFO *pei, UINT *puArgErr)
1224 CHECK_EXPECT(div_onclick_disp);
1226 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1228 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
1229 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1234 static IDispatchExVtbl div_onclick_dispVtbl = {
1235 Dispatch_QueryInterface,
1238 DispatchEx_GetTypeInfoCount,
1239 DispatchEx_GetTypeInfo,
1240 DispatchEx_GetIDsOfNames,
1241 div_onclick_disp_Invoke,
1244 static IDispatchEx div_onclick_disp = { &div_onclick_dispVtbl };
1246 static void pump_msgs(BOOL *b)
1251 while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
1252 TranslateMessage(&msg);
1253 DispatchMessage(&msg);
1256 while(!b && PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
1257 TranslateMessage(&msg);
1258 DispatchMessage(&msg);
1263 static IConnectionPoint *get_cp(IUnknown *unk, REFIID riid)
1265 IConnectionPointContainer *cp_container;
1266 IConnectionPoint *cp;
1269 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1270 ok(hres == S_OK, "Could not get IConnectionPointContainer: %08x\n", hres);
1272 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, riid, &cp);
1273 IConnectionPointContainer_Release(cp_container);
1274 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1279 static DWORD register_cp(IUnknown *unk, REFIID riid, IUnknown *sink)
1281 IConnectionPoint *cp;
1285 cp = get_cp(unk, riid);
1286 hres = IConnectionPoint_Advise(cp, sink, &cookie);
1287 IConnectionPoint_Release(cp);
1288 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1293 static void unregister_cp(IUnknown *unk, REFIID riid, DWORD cookie)
1295 IConnectionPoint *cp;
1298 cp = get_cp(unk, riid);
1299 hres = IConnectionPoint_Unadvise(cp, cookie);
1300 IConnectionPoint_Release(cp);
1301 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
1304 static void test_onclick(IHTMLDocument2 *doc)
1306 IHTMLElement *div, *body;
1311 div = get_elem_id(doc, "clickdiv");
1313 elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
1314 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
1316 V_VT(&v) = VT_EMPTY;
1317 hres = IHTMLElement_get_onclick(div, &v);
1318 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1319 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1321 V_VT(&v) = VT_EMPTY;
1322 hres = IHTMLElement_put_onclick(div, v);
1323 ok(hres == E_NOTIMPL, "put_onclick failed: %08x\n", hres);
1325 V_VT(&v) = VT_DISPATCH;
1326 V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
1327 hres = IHTMLElement_put_onclick(div, v);
1328 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1331 hres = IHTMLElement_put_ondblclick(div, v);
1332 ok(hres == S_OK, "put_ondblclick failed: %08x\n", hres);
1334 V_VT(&v) = VT_EMPTY;
1335 hres = IHTMLElement_get_onclick(div, &v);
1336 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1337 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1338 ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1341 V_VT(&v) = VT_EMPTY;
1342 hres = IHTMLDocument2_get_onclick(doc, &v);
1343 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1344 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1346 V_VT(&v) = VT_DISPATCH;
1347 V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
1348 hres = IHTMLDocument2_put_onclick(doc, v);
1349 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1351 V_VT(&v) = VT_EMPTY;
1352 hres = IHTMLDocument2_get_onclick(doc, &v);
1353 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1354 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1355 ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1358 body = doc_get_body(doc);
1360 V_VT(&v) = VT_DISPATCH;
1361 V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
1362 hres = IHTMLElement_put_onclick(body, v);
1363 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1365 if(winetest_interactive) {
1366 SET_EXPECT(div_onclick);
1367 SET_EXPECT(div_onclick_attached);
1368 SET_EXPECT(body_onclick);
1369 SET_EXPECT(document_onclick);
1370 pump_msgs(&called_document_onclick);
1371 CHECK_CALLED(div_onclick);
1372 CHECK_CALLED(div_onclick_attached);
1373 CHECK_CALLED(body_onclick);
1374 CHECK_CALLED(document_onclick);
1379 SET_EXPECT(div_onclick);
1380 SET_EXPECT(div_onclick_attached);
1381 SET_EXPECT(body_onclick);
1382 SET_EXPECT(document_onclick);
1384 hres = IHTMLElement_click(div);
1385 ok(hres == S_OK, "click failed: %08x\n", hres);
1387 CHECK_CALLED(div_onclick);
1388 CHECK_CALLED(div_onclick_attached);
1389 CHECK_CALLED(body_onclick);
1390 CHECK_CALLED(document_onclick);
1392 SET_EXPECT(div_onclick);
1393 SET_EXPECT(div_onclick_attached);
1394 SET_EXPECT(body_onclick);
1395 SET_EXPECT(document_onclick);
1397 V_VT(&v) = VT_EMPTY;
1398 elem_fire_event((IUnknown*)div, "onclick", &v);
1400 CHECK_CALLED(div_onclick);
1401 CHECK_CALLED(div_onclick_attached);
1402 CHECK_CALLED(body_onclick);
1403 CHECK_CALLED(document_onclick);
1405 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_obj);
1406 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1407 doc_attach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1409 SET_EXPECT(div_onclick);
1410 SET_EXPECT(div_onclick_disp);
1411 SET_EXPECT(div_onclick_attached);
1412 SET_EXPECT(body_onclick);
1413 SET_EXPECT(document_onclick);
1414 SET_EXPECT(doc_onclick_attached);
1415 SET_EXPECT(doccp_onclick);
1417 hres = IHTMLElement_click(div);
1418 ok(hres == S_OK, "click failed: %08x\n", hres);
1420 CHECK_CALLED(div_onclick);
1421 CHECK_CALLED(div_onclick_disp);
1422 CHECK_CALLED(div_onclick_attached);
1423 CHECK_CALLED(body_onclick);
1424 CHECK_CALLED(document_onclick);
1425 CHECK_CALLED(doc_onclick_attached);
1426 CHECK_CALLED(doccp_onclick);
1428 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
1431 hres = IHTMLElement_put_onclick(div, v);
1432 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1434 hres = IHTMLElement_get_onclick(div, &v);
1435 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1436 ok(V_VT(&v) == VT_NULL, "get_onclick returned vt %d\n", V_VT(&v));
1438 elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1439 elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1440 elem_detach_event((IUnknown*)div, "test", (IDispatch*)&div_onclick_disp);
1441 doc_detach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1443 SET_EXPECT(div_onclick_attached);
1444 SET_EXPECT(body_onclick);
1445 SET_EXPECT(document_onclick);
1447 hres = IHTMLElement_click(div);
1448 ok(hres == S_OK, "click failed: %08x\n", hres);
1450 CHECK_CALLED(div_onclick_attached);
1451 CHECK_CALLED(body_onclick);
1452 CHECK_CALLED(document_onclick);
1454 IHTMLElement_Release(div);
1455 IHTMLElement_Release(body);
1458 static void test_onreadystatechange(IHTMLDocument2 *doc)
1460 IHTMLFrameBase *iframe;
1461 IHTMLElement2 *elem2;
1467 elem = get_elem_id(doc, "iframe");
1468 elem2 = get_elem2_iface((IUnknown*)elem);
1469 IHTMLElement_Release(elem);
1471 V_VT(&v) = VT_EMPTY;
1472 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1473 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1474 ok(V_VT(&v) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1476 V_VT(&v) = VT_DISPATCH;
1477 V_DISPATCH(&v) = (IDispatch*)&iframe_onreadystatechange_obj;
1478 hres = IHTMLElement2_put_onreadystatechange(elem2, v);
1479 ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
1481 V_VT(&v) = VT_EMPTY;
1482 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1483 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1484 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1485 ok(V_DISPATCH(&v) == (IDispatch*)&iframe_onreadystatechange_obj, "unexpected onreadystatechange value\n");
1487 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase, (void**)&iframe);
1488 IHTMLElement2_Release(elem2);
1489 ok(hres == S_OK, "Could not get IHTMLFrameBase iface: %08x\n", hres);
1491 hres = IHTMLFrameBase_put_src(iframe, (str = a2bstr("about:blank")));
1493 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1495 SET_EXPECT(iframe_onreadystatechange_loading);
1496 SET_EXPECT(iframedoc_onreadystatechange);
1497 SET_EXPECT(iframe_onreadystatechange_interactive);
1498 SET_EXPECT(iframe_onreadystatechange_complete);
1499 pump_msgs(&called_iframe_onreadystatechange_complete);
1500 CHECK_CALLED(iframe_onreadystatechange_loading);
1501 CHECK_CALLED(iframedoc_onreadystatechange);
1502 CHECK_CALLED(iframe_onreadystatechange_interactive);
1503 CHECK_CALLED(iframe_onreadystatechange_complete);
1505 IHTMLFrameBase_Release(iframe);
1508 static void test_imgload(IHTMLDocument2 *doc)
1510 IHTMLImgElement *img;
1516 elem = get_elem_id(doc, "imgid");
1517 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLImgElement, (void**)&img);
1518 IHTMLElement_Release(elem);
1519 ok(hres == S_OK, "Could not get IHTMLImgElement iface: %08x\n", hres);
1521 V_VT(&v) = VT_EMPTY;
1522 hres = IHTMLImgElement_get_onload(img, &v);
1523 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1524 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
1526 V_VT(&v) = VT_DISPATCH;
1527 V_DISPATCH(&v) = (IDispatch*)&img_onload_obj;
1528 hres = IHTMLImgElement_put_onload(img, v);
1529 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
1531 V_VT(&v) = VT_EMPTY;
1532 hres = IHTMLImgElement_get_onload(img, &v);
1533 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1534 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
1535 ok(V_DISPATCH(&v) == (IDispatch*)&img_onload_obj, "V_DISPATCH(onload) != onloadkFunc\n");
1538 str = a2bstr("http://www.winehq.org/images/winehq_logo_text.png");
1539 hres = IHTMLImgElement_put_src(img, str);
1540 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1543 SET_EXPECT(img_onload);
1544 pump_msgs(&called_img_onload);
1545 CHECK_CALLED(img_onload);
1547 IHTMLImgElement_Release(img);
1550 static void test_focus(IHTMLDocument2 *doc)
1552 IHTMLElement2 *elem2;
1557 elem = get_elem_id(doc, "inputid");
1558 elem2 = get_elem2_iface((IUnknown*)elem);
1559 IHTMLElement_Release(elem);
1561 V_VT(&v) = VT_EMPTY;
1562 hres = IHTMLElement2_get_onfocus(elem2, &v);
1563 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
1564 ok(V_VT(&v) == VT_NULL, "V_VT(onfocus) = %d\n", V_VT(&v));
1566 V_VT(&v) = VT_DISPATCH;
1567 V_DISPATCH(&v) = (IDispatch*)&input_onfocus_obj;
1568 hres = IHTMLElement2_put_onfocus(elem2, v);
1569 ok(hres == S_OK, "put_onfocus failed: %08x\n", hres);
1571 V_VT(&v) = VT_EMPTY;
1572 hres = IHTMLElement2_get_onfocus(elem2, &v);
1573 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
1574 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocus) = %d\n", V_VT(&v));
1575 ok(V_DISPATCH(&v) == (IDispatch*)&input_onfocus_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
1578 if(!winetest_interactive)
1579 ShowWindow(container_hwnd, SW_SHOW);
1582 ok(!IsChild(container_hwnd, GetFocus()), "focus belongs to document window\n");
1584 hres = IHTMLWindow2_focus(window);
1585 ok(hres == S_OK, "focus failed: %08x\n", hres);
1587 ok(IsChild(container_hwnd, GetFocus()), "focus does not belong to document window\n");
1590 SET_EXPECT(input_onfocus);
1591 hres = IHTMLElement2_focus(elem2);
1593 CHECK_CALLED(input_onfocus);
1594 ok(hres == S_OK, "focus failed: %08x\n", hres);
1596 if(!winetest_interactive)
1597 ShowWindow(container_hwnd, SW_HIDE);
1599 IHTMLElement2_Release(elem2);
1602 static void test_submit(IHTMLDocument2 *doc)
1604 IHTMLElement *elem, *submit;
1605 IHTMLFormElement *form;
1610 elem = get_elem_id(doc, "formid");
1612 V_VT(&v) = VT_DISPATCH;
1613 V_DISPATCH(&v) = (IDispatch*)&form_onclick_obj;
1614 hres = IHTMLElement_put_onclick(elem, v);
1615 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1617 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFormElement, (void**)&form);
1618 IHTMLElement_Release(elem);
1619 ok(hres == S_OK, "Could not get IHTMLFormElement iface: %08x\n", hres);
1621 V_VT(&v) = VT_DISPATCH;
1622 V_DISPATCH(&v) = (IDispatch*)&form_onsubmit_obj;
1623 hres = IHTMLFormElement_put_onsubmit(form, v);
1624 ok(hres == S_OK, "put_onsubmit failed: %08x\n", hres);
1626 IHTMLFormElement_Release(form);
1628 submit = get_elem_id(doc, "submitid");
1630 SET_EXPECT(form_onclick);
1631 SET_EXPECT(form_onsubmit);
1632 hres = IHTMLElement_click(submit);
1633 ok(hres == S_OK, "click failed: %08x\n", hres);
1634 CHECK_CALLED(form_onclick);
1635 CHECK_CALLED(form_onsubmit);
1637 V_VT(&v) = VT_DISPATCH;
1638 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_obj;
1639 hres = IHTMLElement_put_onclick(submit, v);
1640 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1642 SET_EXPECT(form_onclick);
1643 SET_EXPECT(submit_onclick);
1644 hres = IHTMLElement_click(submit);
1645 ok(hres == S_OK, "click failed: %08x\n", hres);
1646 CHECK_CALLED(form_onclick);
1647 CHECK_CALLED(submit_onclick);
1649 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
1651 SET_EXPECT(form_onclick);
1652 SET_EXPECT(submit_onclick);
1653 SET_EXPECT(submit_onclick_attached);
1654 hres = IHTMLElement_click(submit);
1655 ok(hres == S_OK, "click failed: %08x\n", hres);
1656 CHECK_CALLED(form_onclick);
1657 CHECK_CALLED(submit_onclick);
1658 CHECK_CALLED(submit_onclick_attached);
1661 hres = IHTMLElement_put_onclick(submit, v);
1662 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1664 SET_EXPECT(form_onclick);
1665 SET_EXPECT(submit_onclick_attached);
1666 hres = IHTMLElement_click(submit);
1667 ok(hres == S_OK, "click failed: %08x\n", hres);
1668 CHECK_CALLED(form_onclick);
1669 CHECK_CALLED(submit_onclick_attached);
1671 elem_detach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
1673 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_onclick_cancel_obj);
1675 SET_EXPECT(form_onclick);
1676 SET_EXPECT(doccp_onclick_cancel);
1677 hres = IHTMLElement_click(submit);
1678 ok(hres == S_OK, "click failed: %08x\n", hres);
1679 CHECK_CALLED(form_onclick);
1680 CHECK_CALLED(doccp_onclick_cancel);
1682 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
1684 IHTMLElement_Release(submit);
1687 static void test_timeout(IHTMLDocument2 *doc)
1694 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
1695 ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
1697 V_VT(&expr) = VT_DISPATCH;
1698 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1699 V_VT(&var) = VT_EMPTY;
1701 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1702 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1705 SET_EXPECT(timeout);
1706 pump_msgs(&called_timeout);
1707 CHECK_CALLED(timeout);
1709 V_VT(&expr) = VT_DISPATCH;
1710 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1711 V_VT(&var) = VT_EMPTY;
1713 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1714 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1717 hres = IHTMLWindow2_clearTimeout(window, id);
1718 ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
1720 IHTMLWindow3_Release(win3);
1723 static IHTMLElement* find_element_by_id(IHTMLDocument2 *doc, const char *id)
1726 IHTMLDocument3 *doc3;
1727 IHTMLElement *result;
1728 BSTR idW = a2bstr(id);
1730 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
1731 ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
1733 hres = IHTMLDocument3_getElementById(doc3, idW, &result);
1734 ok(hres == S_OK, "getElementById failed: %08x\n", hres);
1735 ok(result != NULL, "result == NULL\n");
1738 IHTMLDocument3_Release(doc3);
1742 static IHTMLDocument2* get_iframe_doc(IHTMLIFrameElement *iframe)
1745 IHTMLFrameBase2 *base;
1746 IHTMLDocument2 *result = NULL;
1748 hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&base);
1749 ok(hres == S_OK, "QueryInterface(IID_IHTMLFrameBase2) failed: %08x\n", hres);
1751 IHTMLWindow2 *window;
1753 hres = IHTMLFrameBase2_get_contentWindow(base, &window);
1754 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
1755 ok(window != NULL, "window == NULL\n");
1757 hres = IHTMLWindow2_get_document(window, &result);
1758 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1759 ok(result != NULL, "result == NULL\n");
1760 IHTMLWindow2_Release(window);
1763 if(base) IHTMLFrameBase2_Release(base);
1768 static void test_iframe_connections(IHTMLDocument2 *doc)
1771 IHTMLIFrameElement *iframe;
1772 IHTMLDocument2 *iframes_doc;
1774 IConnectionPoint *cp;
1775 IHTMLElement *element = find_element_by_id(doc, "ifr");
1777 hres = IHTMLElement_QueryInterface(element, &IID_IHTMLIFrameElement, (void**)&iframe);
1778 IHTMLElement_Release(element);
1779 ok(hres == S_OK, "QueryInterface(IID_IHTMLIFrameElement) failed: %08x\n", hres);
1781 iframes_doc = get_iframe_doc(iframe);
1782 IHTMLIFrameElement_Release(iframe);
1784 cookie = register_cp((IUnknown*)iframes_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
1786 cp = get_cp((IUnknown*)doc, &IID_IDispatch);
1787 hres = IConnectionPoint_Unadvise(cp, cookie);
1788 IConnectionPoint_Release(cp);
1789 ok(hres == CONNECT_E_NOCONNECTION, "Unadvise returned %08x, expected CONNECT_E_NOCONNECTION\n", hres);
1791 IHTMLDocument2_Release(iframes_doc);
1794 static HRESULT QueryInterface(REFIID,void**);
1796 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
1798 return E_NOINTERFACE;
1801 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
1806 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
1811 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1816 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
1821 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
1826 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
1827 LPCBORDERWIDTHS pborderwidths)
1832 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
1833 LPCBORDERWIDTHS pborderwidths)
1838 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
1839 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1844 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
1845 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1850 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
1851 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1856 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
1857 HOLEMENU holemenu, HWND hwndActiveObject)
1859 ok(0, "unexpected call\n");
1863 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
1865 ok(0, "unexpected call\n");
1869 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
1874 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
1879 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
1881 ok(0, "unexpected call\n");
1885 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
1886 InPlaceFrame_QueryInterface,
1887 InPlaceFrame_AddRef,
1888 InPlaceFrame_Release,
1889 InPlaceFrame_GetWindow,
1890 InPlaceFrame_ContextSensitiveHelp,
1891 InPlaceFrame_GetBorder,
1892 InPlaceFrame_RequestBorderSpace,
1893 InPlaceFrame_SetBorderSpace,
1894 InPlaceFrame_SetActiveObject,
1895 InPlaceFrame_InsertMenus,
1896 InPlaceFrame_SetMenu,
1897 InPlaceFrame_RemoveMenus,
1898 InPlaceFrame_SetStatusText,
1899 InPlaceFrame_EnableModeless,
1900 InPlaceFrame_TranslateAccelerator
1903 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
1905 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
1906 InPlaceFrame_QueryInterface,
1907 InPlaceFrame_AddRef,
1908 InPlaceFrame_Release,
1909 InPlaceFrame_GetWindow,
1910 InPlaceFrame_ContextSensitiveHelp,
1911 InPlaceFrame_GetBorder,
1912 InPlaceFrame_RequestBorderSpace,
1913 InPlaceFrame_SetBorderSpace,
1914 InPlaceUIWindow_SetActiveObject,
1917 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
1919 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
1921 return QueryInterface(riid, ppv);
1924 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
1929 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
1934 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1936 *phwnd = container_hwnd;
1940 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1942 ok(0, "unexpected call\n");
1946 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
1951 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
1956 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
1961 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
1962 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1963 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1965 static const RECT rect = {0,0,300,300};
1967 *ppFrame = &InPlaceFrame;
1968 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
1969 *lprcPosRect = rect;
1970 *lprcClipRect = rect;
1972 lpFrameInfo->cb = sizeof(*lpFrameInfo);
1973 lpFrameInfo->fMDIApp = FALSE;
1974 lpFrameInfo->hwndFrame = container_hwnd;
1975 lpFrameInfo->haccel = NULL;
1976 lpFrameInfo->cAccelEntries = 0;
1981 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
1986 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1991 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
1996 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
2001 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
2006 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
2011 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
2012 InPlaceSite_QueryInterface,
2014 InPlaceSite_Release,
2015 InPlaceSite_GetWindow,
2016 InPlaceSite_ContextSensitiveHelp,
2017 InPlaceSite_CanInPlaceActivate,
2018 InPlaceSite_OnInPlaceActivate,
2019 InPlaceSite_OnUIActivate,
2020 InPlaceSite_GetWindowContext,
2022 InPlaceSite_OnUIDeactivate,
2023 InPlaceSite_OnInPlaceDeactivate,
2024 InPlaceSite_DiscardUndoState,
2025 InPlaceSite_DeactivateAndUndo,
2026 InPlaceSite_OnPosRectChange,
2029 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
2031 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
2033 return QueryInterface(riid, ppv);
2036 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
2041 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
2046 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
2048 ok(0, "unexpected call\n");
2052 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
2055 ok(0, "unexpected call\n");
2059 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
2064 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
2066 ok(0, "unexpected call\n");
2070 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
2072 ok(0, "unexpected call\n");
2076 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
2078 ok(0, "unexpected call\n");
2082 static const IOleClientSiteVtbl ClientSiteVtbl = {
2083 ClientSite_QueryInterface,
2086 ClientSite_SaveObject,
2087 ClientSite_GetMoniker,
2088 ClientSite_GetContainer,
2089 ClientSite_ShowObject,
2090 ClientSite_OnShowWindow,
2091 ClientSite_RequestNewObjectLayout
2094 static IOleClientSite ClientSite = { &ClientSiteVtbl };
2096 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
2098 return QueryInterface(riid, ppv);
2101 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
2106 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
2111 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
2113 RECT rect = {0,0,300,300};
2114 IOleDocument *document;
2117 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
2118 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
2120 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
2121 IOleDocument_Release(document);
2122 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
2124 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
2125 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
2127 hres = IOleDocumentView_UIActivate(view, TRUE);
2128 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
2130 hres = IOleDocumentView_SetRect(view, &rect);
2131 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
2133 hres = IOleDocumentView_Show(view, TRUE);
2134 ok(hres == S_OK, "Show failed: %08x\n", hres);
2139 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
2140 DocumentSite_QueryInterface,
2141 DocumentSite_AddRef,
2142 DocumentSite_Release,
2143 DocumentSite_ActivateMe
2146 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
2148 static HRESULT QueryInterface(REFIID riid, void **ppv)
2152 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
2154 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
2155 *ppv = &DocumentSite;
2156 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
2157 *ppv = &InPlaceSite;
2159 return *ppv ? S_OK : E_NOINTERFACE;
2162 static IHTMLDocument2 *notif_doc;
2163 static BOOL doc_complete;
2165 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2166 REFIID riid, void**ppv)
2168 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2173 ok(0, "unexpected call\n");
2174 return E_NOINTERFACE;
2177 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2182 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2187 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2189 if(dispID == DISPID_READYSTATE){
2193 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2194 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2196 if(!strcmp_wa(state, "complete"))
2197 doc_complete = TRUE;
2199 SysFreeString(state);
2205 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2207 ok(0, "unexpected call\n");
2211 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2212 PropertyNotifySink_QueryInterface,
2213 PropertyNotifySink_AddRef,
2214 PropertyNotifySink_Release,
2215 PropertyNotifySink_OnChanged,
2216 PropertyNotifySink_OnRequestEdit
2219 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2221 static void doc_load_string(IHTMLDocument2 *doc, const char *str)
2223 IPersistStreamInit *init;
2230 doc_complete = FALSE;
2232 mem = GlobalAlloc(0, len);
2233 memcpy(mem, str, len);
2234 CreateStreamOnHGlobal(mem, TRUE, &stream);
2236 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2238 IPersistStreamInit_Load(init, stream);
2239 IPersistStreamInit_Release(init);
2240 IStream_Release(stream);
2243 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2245 IConnectionPointContainer *container;
2246 IConnectionPoint *cp;
2250 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2251 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2253 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2254 IConnectionPointContainer_Release(container);
2255 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2257 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2258 IConnectionPoint_Release(cp);
2259 ok(hres == S_OK, "Advise failed: %08x\n", hres);
2262 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
2268 IOleDocumentView_Show(view, FALSE);
2269 IOleDocumentView_CloseView(view, 0);
2270 IOleDocumentView_SetInPlaceSite(view, NULL);
2271 IOleDocumentView_Release(view);
2275 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
2276 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
2278 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
2279 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
2282 IHlinkTarget *hlink;
2284 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
2285 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
2287 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
2288 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
2290 IHlinkTarget_Release(hlink);
2293 IOleObject_Release(oleobj);
2295 static IHTMLDocument2 *create_document(void)
2297 IHTMLDocument2 *doc;
2298 IHTMLDocument5 *doc5;
2301 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2302 &IID_IHTMLDocument2, (void**)&doc);
2303 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2307 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2309 win_skip("Could not get IHTMLDocument5 interface, probably too old IE\n");
2310 IHTMLDocument2_Release(doc);
2314 IHTMLDocument5_Release(doc5);
2319 typedef void (*testfunc_t)(IHTMLDocument2*);
2321 static void run_test(const char *str, testfunc_t test)
2323 IHTMLDocument2 *doc;
2324 IHTMLElement *body = NULL;
2329 doc = create_document();
2332 set_client_site(doc, TRUE);
2333 doc_load_string(doc, str);
2334 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2336 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
2337 TranslateMessage(&msg);
2338 DispatchMessage(&msg);
2341 hres = IHTMLDocument2_get_body(doc, &body);
2342 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2345 IHTMLElement_Release(body);
2347 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2348 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2349 ok(window != NULL, "window == NULL\n");
2353 IHTMLWindow2_Release(window);
2356 skip("Could not get document body. Assuming no Gecko installed.\n");
2359 set_client_site(doc, FALSE);
2360 IHTMLDocument2_Release(doc);
2363 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2365 return DefWindowProc(hwnd, msg, wParam, lParam);
2368 static HWND create_container_window(void)
2370 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
2371 static WNDCLASSEXA wndclass = {
2372 sizeof(WNDCLASSEXA),
2375 0, 0, NULL, NULL, NULL, NULL, NULL,
2380 RegisterClassExA(&wndclass);
2381 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
2382 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
2383 300, 300, NULL, NULL, NULL, NULL);
2386 static void test_empty_document(void)
2389 IHTMLWindow2 *window;
2390 IHTMLDocument2 *windows_doc, *doc;
2391 IConnectionPoint *cp;
2394 doc = create_document();
2398 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2399 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2401 hres = IHTMLWindow2_get_document(window, &windows_doc);
2402 IHTMLWindow2_Release(window);
2403 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2405 cookie = register_cp((IUnknown*)windows_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
2407 cp = get_cp((IUnknown*)doc, &IID_IDispatch);
2408 hres = IConnectionPoint_Unadvise(cp, cookie);
2409 IConnectionPoint_Release(cp);
2410 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
2412 IHTMLDocument2_Release(windows_doc);
2418 container_hwnd = create_container_window();
2420 if(winetest_interactive)
2421 ShowWindow(container_hwnd, SW_SHOW);
2423 run_test(empty_doc_str, test_timeout);
2424 run_test(click_doc_str, test_onclick);
2425 run_test(readystate_doc_str, test_onreadystatechange);
2426 run_test(img_doc_str, test_imgload);
2427 run_test(input_doc_str, test_focus);
2428 run_test(form_doc_str, test_submit);
2429 run_test(iframe_doc_str, test_iframe_connections);
2431 test_empty_document();
2433 DestroyWindow(container_hwnd);