2 * Copyright 2008-2009 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(div_onclick);
63 DEFINE_EXPECT(div_onclick_attached);
64 DEFINE_EXPECT(timeout);
65 DEFINE_EXPECT(doccp_onclick);
66 DEFINE_EXPECT(iframe_onreadystatechange_loading);
67 DEFINE_EXPECT(iframe_onreadystatechange_interactive);
68 DEFINE_EXPECT(iframe_onreadystatechange_complete);
70 static HWND container_hwnd = NULL;
71 static IHTMLWindow2 *window;
72 static IOleDocumentView *view;
82 static const xy_test_t no_xy = {-10,-10,-10,-10};
83 static const xy_test_t zero_xy = {0,0,0,0};
85 static const char empty_doc_str[] =
88 static const char click_doc_str[] =
90 "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
93 static const char readystate_doc_str[] =
94 "<<html><body><iframe id=\"iframe\"></iframe></body></html>";
96 static const char *debugstr_guid(REFIID riid)
100 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
101 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
102 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
103 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
108 static int strcmp_wa(LPCWSTR strw, const char *stra)
111 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
112 return lstrcmpA(stra, buf);
115 static BSTR a2bstr(const char *str)
120 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
121 ret = SysAllocStringLen(NULL, len-1);
122 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
127 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
129 IUnknown *unk1, *unk2;
134 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
135 IUnknown_Release(unk1);
136 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
137 IUnknown_Release(unk2);
142 #define test_disp(u,id) _test_disp(__LINE__,u,id)
143 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
150 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
151 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
156 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
157 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
158 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
160 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
161 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
163 if(SUCCEEDED(hres)) {
166 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
167 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
168 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
169 debugstr_guid(&type_attr->guid));
171 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
172 ITypeInfo_Release(typeinfo);
175 IDispatchEx_Release(dispex);
178 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
179 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
181 IHTMLDocument3 *doc3;
184 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
185 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
190 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
191 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
196 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
197 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
202 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
203 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
205 IHTMLElement2 *elem2;
208 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
209 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
214 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
215 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
217 IHTMLElement3 *elem3;
220 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
221 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
226 #define doc_get_body(d) _doc_get_body(__LINE__,d)
227 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
229 IHTMLElement *body = NULL;
232 hres = IHTMLDocument2_get_body(doc, &body);
233 ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
234 ok_(__FILE__,line) (body != NULL, "body == NULL\n");
239 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
240 static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
242 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
248 hres = IHTMLDocument3_getElementById(doc3, str, &elem);
250 IHTMLDocument3_Release(doc3);
251 ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
256 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
257 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
259 IHTMLElement *elem = _get_elem_iface(line, unk);
263 hres = IHTMLElement_get_tagName(elem, &tag);
264 IHTMLElement_Release(elem);
265 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
266 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
271 #define get_event_obj() _get_event_obj(__LINE__)
272 static IHTMLEventObj *_get_event_obj(unsigned line)
274 IHTMLEventObj *event = NULL;
277 hres = IHTMLWindow2_get_event(window, &event);
278 ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
279 ok_(__FILE__,line) (event != NULL, "event = NULL\n");
280 _test_disp(line, (IUnknown*)event, &DIID_DispCEventObj);
285 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
286 static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
288 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
295 hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
297 ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
298 ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
301 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
302 static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
303 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
305 ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
306 ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
307 ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
308 ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
309 ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
310 ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
311 pdp->rgdispidNamedArgs[0]);
312 ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
313 ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
314 ok_(__FILE__,line) (pei != NULL, "pei == NULL");
315 ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
318 _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
321 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
322 static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
323 VARIANT *pvarRes, EXCEPINFO *pei)
325 IHTMLEventObj *event;
327 ok(id == DISPID_VALUE, "id = %d\n", id);
328 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
329 ok(pdp != NULL, "pDispParams == NULL\n");
330 ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
331 ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
332 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
333 ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
334 ok(pvarRes != NULL, "pvarRes = NULL\n");
335 ok(pei != NULL, "pei = NULL\n");
336 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
337 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
338 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
340 event = _get_event_obj(line);
341 ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
342 IHTMLEventObj_Release(event);
345 #define get_event_src() _get_event_src(__LINE__)
346 static IHTMLElement *_get_event_src(unsigned line)
348 IHTMLEventObj *event = _get_event_obj(line);
349 IHTMLElement *src_elem = NULL;
352 hres = IHTMLEventObj_get_srcElement(event, &src_elem);
353 IHTMLEventObj_Release(event);
354 ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
359 #define test_event_src(t) _test_event_src(__LINE__,t)
360 static void _test_event_src(unsigned line, const char *src_tag)
362 IHTMLElement *src_elem = _get_event_src(line);
365 ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
366 _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
367 IHTMLElement_Release(src_elem);
369 ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
373 static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
378 hres = IHTMLEventObj_get_altKey(event, &b);
379 ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
380 ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
383 static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
388 hres = IHTMLEventObj_get_ctrlKey(event, &b);
389 ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
390 ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
393 static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
398 hres = IHTMLEventObj_get_shiftKey(event, &b);
399 ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
400 ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
403 static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
408 hres = IHTMLEventObj_get_cancelBubble(event, &b);
409 ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
410 ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
413 static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
418 hres = IHTMLEventObj_get_fromElement(event, &elem);
419 ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
421 _test_elem_tag(line, (IUnknown*)elem, from_tag);
423 ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
425 IHTMLElement_Release(elem);
428 static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
433 hres = IHTMLEventObj_get_toElement(event, &elem);
434 ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
436 _test_elem_tag(line, (IUnknown*)elem, to_tag);
438 ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
440 IHTMLElement_Release(elem);
443 static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
448 hres = IHTMLEventObj_get_keyCode(event, &l);
449 ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
450 ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
453 static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
458 hres = IHTMLEventObj_get_button(event, &l);
459 ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
460 ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
463 static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
468 hres = IHTMLEventObj_get_reason(event, &l);
469 ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
470 ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
473 static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
478 hres = IHTMLEventObj_get_x(event, &l);
479 ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
480 if(exl == -10) /* don't test the exact value */
481 todo_wine ok_(__FILE__,line)(l > 0, "x = %d\n", l);
483 ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
486 static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
491 hres = IHTMLEventObj_get_y(event, &l);
492 ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
493 if(exl == -10) /* don't test the exact value */
494 todo_wine ok_(__FILE__,line)(l > 0, "y = %d\n", l);
496 ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
499 static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
504 hres = IHTMLEventObj_get_clientX(event, &l);
505 ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
506 if(exl == -10) {/* don't test the exact value */
508 todo_wine ok_(__FILE__,line)(l > 0, "clientX = %d\n", l);
510 ok_(__FILE__,line)(l > 0, "clientX = %d\n", l);
512 ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
516 static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
521 hres = IHTMLEventObj_get_clientY(event, &l);
522 ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
523 if(exl == -10) {/* don't test the exact value */
525 todo_wine ok_(__FILE__,line)(l > 0, "clientY = %d\n", l);
527 ok_(__FILE__,line)(l > 0, "clientY = %d\n", l);
529 ok_(__FILE__,line)(l == exl, "clientY = %d, expected %d\n", l, exl);
533 static void _test_event_offsetx(unsigned line, IHTMLEventObj *event, LONG exl)
538 hres = IHTMLEventObj_get_offsetX(event, &l);
539 ok_(__FILE__,line)(hres == S_OK, "get_offsetX failed: %08x\n", hres);
540 if(exl == -10) /* don't test the exact value */
541 todo_wine ok_(__FILE__,line)(l > 0, "offsetX = %d\n", l);
543 ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
546 static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
551 hres = IHTMLEventObj_get_offsetY(event, &l);
552 ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
553 if(exl == -10) /* don't test the exact value */
554 todo_wine ok_(__FILE__,line)(l > 0, "offsetY = %d\n", l);
556 ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
559 static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
564 hres = IHTMLEventObj_get_screenX(event, &l);
565 ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
566 if(exl == -10) { /* don't test the exact value */
568 todo_wine ok_(__FILE__,line)(l > 0, "screenX = %d\n", l);
570 ok_(__FILE__,line)(l > 0, "screenX = %d\n", l);
572 ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
576 static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
581 hres = IHTMLEventObj_get_screenY(event, &l);
582 ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
583 if(exl == -10) { /* don't test the exact value */
585 todo_wine ok_(__FILE__,line)(l > 0, "screenY = %d\n", l);
587 ok_(__FILE__,line)(l > 0, "screenY = %d\n", l);
589 ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
593 static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
598 hres = IHTMLEventObj_get_type(event, &str);
599 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
600 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
603 static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
608 hres = IHTMLEventObj_get_qualifier(event, &str);
609 ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
611 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
613 ok_(__FILE__,line)(!str, "qualifier != NULL\n");
616 static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
621 hres = IHTMLEventObj_get_srcFilter(event, &disp);
622 ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
623 ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
626 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
627 static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
629 IHTMLEventObj *event = _get_event_obj(line);
633 _test_event_altkey(line, event, VARIANT_FALSE);
634 _test_event_ctrlkey(line, event, VARIANT_FALSE);
635 _test_event_shiftkey(line, event, VARIANT_FALSE);
636 _test_event_cancelbubble(line, event, VARIANT_FALSE);
637 _test_event_fromelem(line, event, NULL);
638 _test_event_toelem(line, event, NULL);
639 _test_event_keycode(line, event, 0);
640 _test_event_button(line, event, 0);
641 _test_event_type(line, event, type);
642 _test_event_qualifier(line, event, NULL);
643 _test_event_reason(line, event, 0);
644 _test_event_srcfilter(line, event);
645 _test_event_x(line, event, xy->x);
646 _test_event_y(line, event, xy->y);
647 _test_event_clientx(line, event, -10);
648 _test_event_clienty(line, event, -10);
649 _test_event_offsetx(line, event, xy->offset_x);
650 _test_event_offsety(line, event, xy->offset_y);
651 _test_event_screenx(line, event, -10);
652 _test_event_screeny(line, event, -10);
654 hres = IHTMLEventObj_get_returnValue(event, &v);
655 ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
656 ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
658 IHTMLEventObj_Release(event);
661 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
662 static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
664 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
669 name = a2bstr(namea);
670 hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
671 IHTMLElement2_Release(elem);
673 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
674 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
677 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
681 if(IsEqualGUID(riid, &IID_IUnknown)
682 || IsEqualGUID(riid, &IID_IDispatch)
683 || IsEqualGUID(riid, &IID_IDispatchEx))
686 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
687 return E_NOINTERFACE;
693 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
698 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
703 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
705 ok(0, "unexpected call\n");
709 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
710 LCID lcid, ITypeInfo **ppTInfo)
712 ok(0, "unexpected call\n");
716 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
717 LPOLESTR *rgszNames, UINT cNames,
718 LCID lcid, DISPID *rgDispId)
720 ok(0, "unexpected call\n");
724 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
725 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
726 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
728 ok(0, "unexpected call\n");
732 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
734 ok(0, "unexpected call\n");
738 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
739 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
741 ok(0, "unexpected call\n");
745 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
747 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
751 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
753 ok(0, "unexpected call\n");
757 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
759 ok(0, "unexpected call\n");
763 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
765 ok(0, "unexpected call\n");
769 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
771 ok(0, "unexpected call\n");
775 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
777 ok(0, "unexpected call\n");
781 #define EVENT_HANDLER_FUNC_OBJ(event) \
782 static IDispatchExVtbl event ## FuncVtbl = { \
783 DispatchEx_QueryInterface, \
785 DispatchEx_Release, \
786 DispatchEx_GetTypeInfoCount, \
787 DispatchEx_GetTypeInfo, \
788 DispatchEx_GetIDsOfNames, \
790 DispatchEx_GetDispID, \
792 DispatchEx_DeleteMemberByName, \
793 DispatchEx_DeleteMemberByDispID, \
794 DispatchEx_GetMemberProperties, \
795 DispatchEx_GetMemberName, \
796 DispatchEx_GetNextDispID, \
797 DispatchEx_GetNameSpaceParent \
799 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
801 static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
802 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
804 IHTMLDocument3 *doc3;
805 CHECK_EXPECT(document_onclick);
806 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
807 doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
808 IHTMLDocument3_Release(doc3);
809 test_event_src("DIV");
810 test_event_obj("click", &no_xy);
814 EVENT_HANDLER_FUNC_OBJ(document_onclick);
816 static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
817 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
819 CHECK_EXPECT(div_onclick);
820 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
821 test_event_src("DIV");
825 EVENT_HANDLER_FUNC_OBJ(div_onclick);
827 static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
828 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
830 CHECK_EXPECT(div_onclick_attached);
832 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
833 test_event_src("DIV");
837 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
839 static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
840 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
842 CHECK_EXPECT(body_onclick);
843 test_event_args(&DIID_DispHTMLBody, id, wFlags, pdp, pvarRes, pei, pspCaller);
844 test_event_src("DIV");
848 EVENT_HANDLER_FUNC_OBJ(body_onclick);
850 static HRESULT WINAPI iframe_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
851 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
853 IHTMLFrameBase2 *iframe;
854 IHTMLElement2 *elem2;
860 test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
861 test_event_src("IFRAME");
863 elem = get_event_src();
864 elem2 = get_elem2_iface((IUnknown*)elem);
865 IHTMLElement_Release(elem);
868 hres = IHTMLElement2_get_readyState(elem2, &v);
869 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
870 ok(V_VT(&v) == VT_BSTR, "V_VT(readyState) = %d\n", V_VT(&v));
872 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase2, (void**)&iframe);
873 IHTMLElement2_Release(elem2);
874 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
877 hres = IHTMLFrameBase2_get_readyState(iframe, &str);
878 IHTMLFrameBase2_Release(iframe);
879 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
880 ok(str != NULL, "readyState == NULL\n");
881 ok(!lstrcmpW(str, V_BSTR(&v)), "ready states differ\n");
884 if(!strcmp_wa(str, "loading"))
885 CHECK_EXPECT(iframe_onreadystatechange_loading);
886 else if(!strcmp_wa(str, "interactive"))
887 CHECK_EXPECT(iframe_onreadystatechange_interactive);
888 else if(!strcmp_wa(str, "complete"))
889 CHECK_EXPECT(iframe_onreadystatechange_complete);
891 ok(0, "unexpected state %s\n", wine_dbgstr_w(str));
896 EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange);
898 static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
899 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
901 ok(0, "unexpected call\n");
905 EVENT_HANDLER_FUNC_OBJ(nocall);
907 #define CONNECTION_POINT_OBJ(cpname, diid) \
908 static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
911 if(IsEqualGUID(riid, &IID_IUnknown) \
912 || IsEqualGUID(riid, &IID_IDispatch) \
913 || IsEqualGUID(riid, &diid)) \
916 ok(0, "unexpected riid %s\n", debugstr_guid(riid)); \
917 return E_NOINTERFACE; \
921 static IDispatchExVtbl cpname ## Vtbl = { \
922 cpname ## _QueryInterface, \
924 DispatchEx_Release, \
925 DispatchEx_GetTypeInfoCount, \
926 DispatchEx_GetTypeInfo, \
927 DispatchEx_GetIDsOfNames, \
929 DispatchEx_GetDispID, \
930 DispatchEx_InvokeEx, \
931 DispatchEx_DeleteMemberByName, \
932 DispatchEx_DeleteMemberByDispID, \
933 DispatchEx_GetMemberProperties, \
934 DispatchEx_GetMemberName, \
935 DispatchEx_GetNextDispID, \
936 DispatchEx_GetNameSpaceParent \
938 static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
940 #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
941 static void _test_cp_args(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
943 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
944 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
945 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
946 ok_(__FILE__,line)(!dp->cArgs, "dp->cArgs = %d\n", dp->cArgs);
947 ok_(__FILE__,line)(!dp->rgvarg, "dp->rgvarg = %p\n", dp->rgvarg);
948 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
949 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
950 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
951 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
952 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
953 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
956 static HRESULT WINAPI doccp(IDispatchEx *iface, DISPID dispIdMember,
957 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
958 VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
960 switch(dispIdMember) {
961 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
962 CHECK_EXPECT(doccp_onclick);
963 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
966 ok(0, "unexpected call %d\n", dispIdMember);
973 CONNECTION_POINT_OBJ(doccp, DIID_HTMLDocumentEvents);
975 static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
976 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
977 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
979 CHECK_EXPECT(timeout);
981 ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
982 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
983 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
984 ok(!lcid, "lcid = %x\n", lcid);
985 ok(pDispParams != NULL, "pDispParams == NULL\n");
986 ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
987 ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
988 ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
989 ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
990 ok(pVarResult != NULL, "pVarResult = NULL\n");
991 ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
992 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
993 ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
998 static IDispatchExVtbl timeoutFuncVtbl = {
999 DispatchEx_QueryInterface,
1002 DispatchEx_GetTypeInfoCount,
1003 DispatchEx_GetTypeInfo,
1004 DispatchEx_GetIDsOfNames,
1006 DispatchEx_GetDispID,
1007 DispatchEx_InvokeEx,
1008 DispatchEx_DeleteMemberByName,
1009 DispatchEx_DeleteMemberByDispID,
1010 DispatchEx_GetMemberProperties,
1011 DispatchEx_GetMemberName,
1012 DispatchEx_GetNextDispID,
1013 DispatchEx_GetNameSpaceParent
1016 static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
1018 static void pump_msgs(BOOL *b)
1021 while(!*b && GetMessage(&msg, NULL, 0, 0)) {
1022 TranslateMessage(&msg);
1023 DispatchMessage(&msg);
1027 static IConnectionPoint *get_cp(IUnknown *unk, REFIID riid)
1029 IConnectionPointContainer *cp_container;
1030 IConnectionPoint *cp;
1033 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1034 ok(hres == S_OK, "Could not get IConnectionPointContainer: %08x\n", hres);
1036 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, riid, &cp);
1037 IConnectionPointContainer_Release(cp_container);
1038 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1043 static DWORD register_cp(IUnknown *unk, REFIID riid, IUnknown *sink)
1045 IConnectionPoint *cp;
1049 cp = get_cp(unk, riid);
1050 hres = IConnectionPoint_Advise(cp, sink, &cookie);
1051 IConnectionPoint_Release(cp);
1052 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1057 static void unregister_cp(IUnknown *unk, REFIID riid, DWORD cookie)
1059 IConnectionPoint *cp;
1062 cp = get_cp(unk, riid);
1063 hres = IConnectionPoint_Unadvise(cp, cookie);
1064 IConnectionPoint_Release(cp);
1065 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
1068 static void test_onclick(IHTMLDocument2 *doc)
1070 IHTMLElement *div, *body;
1075 div = get_elem_id(doc, "clickdiv");
1077 elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
1078 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
1080 V_VT(&v) = VT_EMPTY;
1081 hres = IHTMLElement_get_onclick(div, &v);
1082 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1083 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1085 V_VT(&v) = VT_EMPTY;
1086 hres = IHTMLElement_put_onclick(div, v);
1087 ok(hres == E_NOTIMPL, "put_onclick failed: %08x\n", hres);
1089 V_VT(&v) = VT_DISPATCH;
1090 V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
1091 hres = IHTMLElement_put_onclick(div, v);
1092 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1094 V_VT(&v) = VT_EMPTY;
1095 hres = IHTMLElement_get_onclick(div, &v);
1096 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1097 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1098 ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1101 V_VT(&v) = VT_EMPTY;
1102 hres = IHTMLDocument2_get_onclick(doc, &v);
1103 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1104 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1106 V_VT(&v) = VT_DISPATCH;
1107 V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
1108 hres = IHTMLDocument2_put_onclick(doc, v);
1109 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1111 V_VT(&v) = VT_EMPTY;
1112 hres = IHTMLDocument2_get_onclick(doc, &v);
1113 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1114 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1115 ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1118 body = doc_get_body(doc);
1120 V_VT(&v) = VT_DISPATCH;
1121 V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
1122 hres = IHTMLElement_put_onclick(body, v);
1123 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1125 if(winetest_interactive) {
1126 SET_EXPECT(div_onclick);
1127 SET_EXPECT(div_onclick_attached);
1128 SET_EXPECT(body_onclick);
1129 SET_EXPECT(document_onclick);
1130 pump_msgs(&called_document_onclick);
1131 CHECK_CALLED(div_onclick);
1132 CHECK_CALLED(div_onclick_attached);
1133 CHECK_CALLED(body_onclick);
1134 CHECK_CALLED(document_onclick);
1139 SET_EXPECT(div_onclick);
1140 SET_EXPECT(div_onclick_attached);
1141 SET_EXPECT(body_onclick);
1142 SET_EXPECT(document_onclick);
1144 hres = IHTMLElement_click(div);
1145 ok(hres == S_OK, "click failed: %08x\n", hres);
1147 CHECK_CALLED(div_onclick);
1148 CHECK_CALLED(div_onclick_attached);
1149 CHECK_CALLED(body_onclick);
1150 CHECK_CALLED(document_onclick);
1152 SET_EXPECT(div_onclick);
1153 SET_EXPECT(div_onclick_attached);
1154 SET_EXPECT(body_onclick);
1155 SET_EXPECT(document_onclick);
1157 V_VT(&v) = VT_EMPTY;
1158 elem_fire_event((IUnknown*)div, "onclick", &v);
1160 CHECK_CALLED(div_onclick);
1161 CHECK_CALLED(div_onclick_attached);
1162 CHECK_CALLED(body_onclick);
1163 CHECK_CALLED(document_onclick);
1165 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_obj);
1167 SET_EXPECT(div_onclick);
1168 SET_EXPECT(div_onclick_attached);
1169 SET_EXPECT(body_onclick);
1170 SET_EXPECT(document_onclick);
1171 SET_EXPECT(doccp_onclick);
1173 hres = IHTMLElement_click(div);
1174 ok(hres == S_OK, "click failed: %08x\n", hres);
1176 CHECK_CALLED(div_onclick);
1177 CHECK_CALLED(div_onclick_attached);
1178 CHECK_CALLED(body_onclick);
1179 CHECK_CALLED(document_onclick);
1180 CHECK_CALLED(doccp_onclick);
1182 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
1184 IHTMLElement_Release(div);
1185 IHTMLElement_Release(body);
1188 static void test_onreadystatechange(IHTMLDocument2 *doc)
1190 IHTMLFrameBase *iframe;
1191 IHTMLElement2 *elem2;
1197 elem = get_elem_id(doc, "iframe");
1198 elem2 = get_elem2_iface((IUnknown*)elem);
1199 IHTMLElement_Release(elem);
1201 V_VT(&v) = VT_EMPTY;
1202 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1203 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1204 ok(V_VT(&v) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1206 V_VT(&v) = VT_DISPATCH;
1207 V_DISPATCH(&v) = (IDispatch*)&iframe_onreadystatechange_obj;
1208 hres = IHTMLElement2_put_onreadystatechange(elem2, v);
1209 ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
1211 V_VT(&v) = VT_EMPTY;
1212 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1213 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1214 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1215 ok(V_DISPATCH(&v) == (IDispatch*)&iframe_onreadystatechange_obj, "unexpected onreadystatechange value\n");
1217 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase, (void**)&iframe);
1218 IHTMLElement2_Release(elem2);
1219 ok(hres == S_OK, "Could not get IHTMLFrameBase iface: %08x\n", hres);
1221 hres = IHTMLFrameBase_put_src(iframe, (str = a2bstr("about:blank")));
1223 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1225 SET_EXPECT(iframe_onreadystatechange_loading);
1226 SET_EXPECT(iframe_onreadystatechange_interactive);
1227 SET_EXPECT(iframe_onreadystatechange_complete);
1228 pump_msgs(&called_iframe_onreadystatechange_complete);
1230 CHECK_CALLED(iframe_onreadystatechange_loading);
1231 CHECK_CALLED(iframe_onreadystatechange_interactive);
1232 CHECK_CALLED(iframe_onreadystatechange_complete);
1234 IHTMLFrameBase_Release(iframe);
1237 static void test_timeout(IHTMLDocument2 *doc)
1244 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
1245 ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
1247 V_VT(&expr) = VT_DISPATCH;
1248 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1249 V_VT(&var) = VT_EMPTY;
1251 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1252 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1255 SET_EXPECT(timeout);
1256 pump_msgs(&called_timeout);
1257 CHECK_CALLED(timeout);
1259 V_VT(&expr) = VT_DISPATCH;
1260 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1261 V_VT(&var) = VT_EMPTY;
1263 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1264 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1267 hres = IHTMLWindow2_clearTimeout(window, id);
1268 ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
1270 IHTMLWindow3_Release(win3);
1273 static HRESULT QueryInterface(REFIID,void**);
1275 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
1277 return E_NOINTERFACE;
1280 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
1285 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
1290 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1295 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
1300 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
1305 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
1306 LPCBORDERWIDTHS pborderwidths)
1311 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
1312 LPCBORDERWIDTHS pborderwidths)
1317 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
1318 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1323 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
1324 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1329 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
1330 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1335 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
1336 HOLEMENU holemenu, HWND hwndActiveObject)
1338 ok(0, "unexpected call\n");
1342 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
1344 ok(0, "unexpected call\n");
1348 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
1353 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
1358 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
1360 ok(0, "unexpected call\n");
1364 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
1365 InPlaceFrame_QueryInterface,
1366 InPlaceFrame_AddRef,
1367 InPlaceFrame_Release,
1368 InPlaceFrame_GetWindow,
1369 InPlaceFrame_ContextSensitiveHelp,
1370 InPlaceFrame_GetBorder,
1371 InPlaceFrame_RequestBorderSpace,
1372 InPlaceFrame_SetBorderSpace,
1373 InPlaceFrame_SetActiveObject,
1374 InPlaceFrame_InsertMenus,
1375 InPlaceFrame_SetMenu,
1376 InPlaceFrame_RemoveMenus,
1377 InPlaceFrame_SetStatusText,
1378 InPlaceFrame_EnableModeless,
1379 InPlaceFrame_TranslateAccelerator
1382 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
1384 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
1385 InPlaceFrame_QueryInterface,
1386 InPlaceFrame_AddRef,
1387 InPlaceFrame_Release,
1388 InPlaceFrame_GetWindow,
1389 InPlaceFrame_ContextSensitiveHelp,
1390 InPlaceFrame_GetBorder,
1391 InPlaceFrame_RequestBorderSpace,
1392 InPlaceFrame_SetBorderSpace,
1393 InPlaceUIWindow_SetActiveObject,
1396 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
1398 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
1400 return QueryInterface(riid, ppv);
1403 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
1408 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
1413 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1415 *phwnd = container_hwnd;
1419 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1421 ok(0, "unexpected call\n");
1425 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
1430 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
1435 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
1440 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
1441 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1442 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1444 static const RECT rect = {0,0,300,300};
1446 *ppFrame = &InPlaceFrame;
1447 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
1448 *lprcPosRect = rect;
1449 *lprcClipRect = rect;
1451 lpFrameInfo->cb = sizeof(*lpFrameInfo);
1452 lpFrameInfo->fMDIApp = FALSE;
1453 lpFrameInfo->hwndFrame = container_hwnd;
1454 lpFrameInfo->haccel = NULL;
1455 lpFrameInfo->cAccelEntries = 0;
1460 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
1465 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1470 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
1475 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
1480 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
1485 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1490 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
1491 InPlaceSite_QueryInterface,
1493 InPlaceSite_Release,
1494 InPlaceSite_GetWindow,
1495 InPlaceSite_ContextSensitiveHelp,
1496 InPlaceSite_CanInPlaceActivate,
1497 InPlaceSite_OnInPlaceActivate,
1498 InPlaceSite_OnUIActivate,
1499 InPlaceSite_GetWindowContext,
1501 InPlaceSite_OnUIDeactivate,
1502 InPlaceSite_OnInPlaceDeactivate,
1503 InPlaceSite_DiscardUndoState,
1504 InPlaceSite_DeactivateAndUndo,
1505 InPlaceSite_OnPosRectChange,
1508 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
1510 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
1512 return QueryInterface(riid, ppv);
1515 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
1520 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1525 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1527 ok(0, "unexpected call\n");
1531 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1534 ok(0, "unexpected call\n");
1538 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1543 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1545 ok(0, "unexpected call\n");
1549 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1551 ok(0, "unexpected call\n");
1555 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1557 ok(0, "unexpected call\n");
1561 static const IOleClientSiteVtbl ClientSiteVtbl = {
1562 ClientSite_QueryInterface,
1565 ClientSite_SaveObject,
1566 ClientSite_GetMoniker,
1567 ClientSite_GetContainer,
1568 ClientSite_ShowObject,
1569 ClientSite_OnShowWindow,
1570 ClientSite_RequestNewObjectLayout
1573 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1575 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1577 return QueryInterface(riid, ppv);
1580 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1585 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1590 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1592 RECT rect = {0,0,300,300};
1593 IOleDocument *document;
1596 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1597 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1599 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1600 IOleDocument_Release(document);
1601 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1603 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1604 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1606 hres = IOleDocumentView_UIActivate(view, TRUE);
1607 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1609 hres = IOleDocumentView_SetRect(view, &rect);
1610 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1612 hres = IOleDocumentView_Show(view, TRUE);
1613 ok(hres == S_OK, "Show failed: %08x\n", hres);
1618 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1619 DocumentSite_QueryInterface,
1620 DocumentSite_AddRef,
1621 DocumentSite_Release,
1622 DocumentSite_ActivateMe
1625 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1627 static HRESULT QueryInterface(REFIID riid, void **ppv)
1631 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1633 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1634 *ppv = &DocumentSite;
1635 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1636 *ppv = &InPlaceSite;
1638 return *ppv ? S_OK : E_NOINTERFACE;
1641 static IHTMLDocument2 *notif_doc;
1642 static BOOL doc_complete;
1644 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1645 REFIID riid, void**ppv)
1647 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1652 ok(0, "unexpected call\n");
1653 return E_NOINTERFACE;
1656 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1661 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1666 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1668 if(dispID == DISPID_READYSTATE){
1672 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1673 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1675 if(!strcmp_wa(state, "complete"))
1676 doc_complete = TRUE;
1678 SysFreeString(state);
1684 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1686 ok(0, "unexpected call\n");
1690 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1691 PropertyNotifySink_QueryInterface,
1692 PropertyNotifySink_AddRef,
1693 PropertyNotifySink_Release,
1694 PropertyNotifySink_OnChanged,
1695 PropertyNotifySink_OnRequestEdit
1698 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1700 static void doc_load_string(IHTMLDocument2 *doc, const char *str)
1702 IPersistStreamInit *init;
1709 doc_complete = FALSE;
1711 mem = GlobalAlloc(0, len);
1712 memcpy(mem, str, len);
1713 CreateStreamOnHGlobal(mem, TRUE, &stream);
1715 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1717 IPersistStreamInit_Load(init, stream);
1718 IPersistStreamInit_Release(init);
1719 IStream_Release(stream);
1722 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1724 IConnectionPointContainer *container;
1725 IConnectionPoint *cp;
1729 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1730 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1732 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1733 IConnectionPointContainer_Release(container);
1734 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1736 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1737 IConnectionPoint_Release(cp);
1738 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1741 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1747 IOleDocumentView_Show(view, FALSE);
1748 IOleDocumentView_CloseView(view, 0);
1749 IOleDocumentView_SetInPlaceSite(view, NULL);
1750 IOleDocumentView_Release(view);
1754 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1755 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1757 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1758 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1761 IHlinkTarget *hlink;
1763 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1764 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1766 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1767 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1769 IHlinkTarget_Release(hlink);
1772 IOleObject_Release(oleobj);
1774 static IHTMLDocument2 *create_document(void)
1776 IHTMLDocument2 *doc;
1777 IHTMLDocument5 *doc5;
1780 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1781 &IID_IHTMLDocument2, (void**)&doc);
1782 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1786 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1788 win_skip("Could not get IHTMLDocument5 interface, probably too old IE\n");
1789 IHTMLDocument2_Release(doc);
1793 IHTMLDocument5_Release(doc5);
1798 typedef void (*testfunc_t)(IHTMLDocument2*);
1800 static void run_test(const char *str, testfunc_t test)
1802 IHTMLDocument2 *doc;
1803 IHTMLElement *body = NULL;
1808 doc = create_document();
1811 set_client_site(doc, TRUE);
1812 doc_load_string(doc, str);
1813 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1815 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1816 TranslateMessage(&msg);
1817 DispatchMessage(&msg);
1820 hres = IHTMLDocument2_get_body(doc, &body);
1821 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1824 IHTMLElement_Release(body);
1826 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1827 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1828 ok(window != NULL, "window == NULL\n");
1832 IHTMLWindow2_Release(window);
1835 skip("Could not get document body. Assuming no Gecko installed.\n");
1838 set_client_site(doc, FALSE);
1839 IHTMLDocument2_Release(doc);
1842 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1844 return DefWindowProc(hwnd, msg, wParam, lParam);
1847 static HWND create_container_window(void)
1849 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
1850 static WNDCLASSEXA wndclass = {
1851 sizeof(WNDCLASSEXA),
1854 0, 0, NULL, NULL, NULL, NULL, NULL,
1859 RegisterClassExA(&wndclass);
1860 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
1861 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
1862 300, 300, NULL, NULL, NULL, NULL);
1868 container_hwnd = create_container_window();
1870 if(winetest_interactive)
1871 ShowWindow(container_hwnd, SW_SHOW);
1873 run_test(empty_doc_str, test_timeout);
1874 run_test(click_doc_str, test_onclick);
1875 run_test(readystate_doc_str, test_onreadystatechange);
1877 DestroyWindow(container_hwnd);