mshtml/tests: Added addEventListener tests.
[wine.git] / dlls / mshtml / tests / events.c
blob4f577459c9f1eb847e16f858a64ffec1c58780ea
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmdid.h"
31 #include "docobj.h"
32 #include "hlink.h"
33 #include "dispex.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) \
42 do { \
43 trace(#func "\n"); \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
46 }while(0)
48 #define CHECK_EXPECT(func) \
49 do { \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
52 }while(0)
54 #define CHECK_CALLED(func) \
55 do { \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
58 }while(0)
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(div_onclick_capture);
66 DEFINE_EXPECT(div_onclick_bubble);
67 DEFINE_EXPECT(timeout);
68 DEFINE_EXPECT(doccp_onclick);
69 DEFINE_EXPECT(doccp_onclick_cancel);
70 DEFINE_EXPECT(div_onclick_disp);
71 DEFINE_EXPECT(invoke_onclick);
72 DEFINE_EXPECT(iframe_onreadystatechange_loading);
73 DEFINE_EXPECT(iframe_onreadystatechange_interactive);
74 DEFINE_EXPECT(iframe_onreadystatechange_complete);
75 DEFINE_EXPECT(iframedoc_onreadystatechange);
76 DEFINE_EXPECT(img_onload);
77 DEFINE_EXPECT(img_onerror);
78 DEFINE_EXPECT(link_onload);
79 DEFINE_EXPECT(input_onfocus);
80 DEFINE_EXPECT(input_onblur);
81 DEFINE_EXPECT(div_onfocusin);
82 DEFINE_EXPECT(div_onfocusout);
83 DEFINE_EXPECT(form_onsubmit);
84 DEFINE_EXPECT(form_onclick);
85 DEFINE_EXPECT(submit_onclick);
86 DEFINE_EXPECT(submit_onclick_cancel);
87 DEFINE_EXPECT(submit_onclick_attached);
88 DEFINE_EXPECT(submit_onclick_attached_check_cancel);
89 DEFINE_EXPECT(submit_onclick_setret);
90 DEFINE_EXPECT(elem2_cp_onclick);
91 DEFINE_EXPECT(iframe_onload);
93 static HWND container_hwnd = NULL;
94 static IHTMLWindow2 *window;
95 static IOleDocumentView *view;
96 static BOOL is_ie9plus;
97 static int document_mode;
98 static unsigned in_fire_event;
100 typedef struct {
101 LONG x;
102 LONG y;
103 LONG offset_x;
104 LONG offset_y;
105 } xy_test_t;
107 static const xy_test_t no_xy = {-10,-10,-10,-10};
109 static const char empty_doc_str[] =
110 "<html></html>";
112 static const char empty_doc_ie9_str[] =
113 "<html>"
114 "<head><meta http-equiv=\"x-ua-compatible\" content=\"IE=9\" /></head>"
115 "</html>";
117 static const char readystate_doc_str[] =
118 "<html><body><iframe id=\"iframe\"></iframe></body></html>";
120 static const char readystate_doc_ie9_str[] =
121 "<html>"
122 "<head><meta http-equiv=\"x-ua-compatible\" content=\"IE=9\" /></head>"
123 "<body><iframe id=\"iframe\"></iframe></body></html>";
125 static const char img_doc_str[] =
126 "<html><body><img id=\"imgid\"></img></body></html>";
128 static const char link_doc_str[] =
129 "<html><body><link id=\"linkid\" rel=\"stylesheet\" type=\"text/css\"></link></body></html>";
131 static const char input_doc_str[] =
132 "<html><body><div id=\"divid\"><input id=\"inputid\"></input></div></body></html>";
134 static const char iframe_doc_str[] =
135 "<html><body><iframe id=\"ifr\">Testing</iframe></body></html>";
137 static int strcmp_wa(LPCWSTR strw, const char *stra)
139 CHAR buf[512];
140 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
141 return lstrcmpA(stra, buf);
144 static BSTR a2bstr(const char *str)
146 BSTR ret;
147 int len;
149 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
150 ret = SysAllocStringLen(NULL, len-1);
151 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
153 return ret;
156 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
158 IUnknown *unk1, *unk2;
160 if(iface1 == iface2)
161 return TRUE;
163 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
164 IUnknown_Release(unk1);
165 IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
166 IUnknown_Release(unk2);
168 return unk1 == unk2;
171 #define test_disp(u,id) _test_disp(__LINE__,u,id)
172 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
174 IDispatchEx *dispex;
175 ITypeInfo *typeinfo;
176 UINT ticnt;
177 HRESULT hres;
179 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
180 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
181 if(FAILED(hres))
182 return;
184 ticnt = 0xdeadbeef;
185 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
186 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
187 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
189 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
190 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
192 if(SUCCEEDED(hres)) {
193 TYPEATTR *type_attr;
195 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
196 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
197 if(diid)
198 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
199 wine_dbgstr_guid(&type_attr->guid));
201 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
202 ITypeInfo_Release(typeinfo);
205 IDispatchEx_Release(dispex);
208 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
209 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
211 IHTMLDocument3 *doc3;
212 HRESULT hres;
214 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
215 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
217 return doc3;
220 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
221 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
223 IHTMLElement *elem;
224 HRESULT hres;
226 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
227 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
229 return elem;
232 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
233 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
235 IHTMLElement2 *elem2;
236 HRESULT hres;
238 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
239 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
241 return elem2;
244 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
245 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
247 IHTMLElement3 *elem3;
248 HRESULT hres;
250 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
251 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
253 return elem3;
256 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
257 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
259 IHTMLElement4 *elem4;
260 HRESULT hres;
262 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem4);
263 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4 iface: %08x\n", hres);
265 return elem4;
268 #define get_iframe_iface(u) _get_iframe_iface(__LINE__,u)
269 static IHTMLIFrameElement *_get_iframe_iface(unsigned line, IUnknown *unk)
271 IHTMLIFrameElement *iframe;
272 HRESULT hres;
274 hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement, (void**)&iframe);
275 ok_(__FILE__,line)(hres == S_OK, "QueryInterface(IID_IHTMLIFrameElement) failed: %08x\n", hres);
277 return iframe;
280 #define doc_get_body(d) _doc_get_body(__LINE__,d)
281 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
283 IHTMLElement *body = NULL;
284 HRESULT hres;
286 hres = IHTMLDocument2_get_body(doc, &body);
287 ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
288 ok_(__FILE__,line) (body != NULL, "body == NULL\n");
290 return body;
293 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
294 static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
296 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
297 IHTMLElement *elem;
298 BSTR str;
299 HRESULT hres;
301 str = a2bstr(id);
302 hres = IHTMLDocument3_getElementById(doc3, str, &elem);
303 SysFreeString(str);
304 IHTMLDocument3_Release(doc3);
305 ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
306 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
308 return elem;
311 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
312 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
314 IHTMLElement *elem = _get_elem_iface(line, unk);
315 BSTR tag;
316 HRESULT hres;
318 hres = IHTMLElement_get_tagName(elem, &tag);
319 IHTMLElement_Release(elem);
320 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
321 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
323 SysFreeString(tag);
326 #define get_event_obj() _get_event_obj(__LINE__)
327 static IHTMLEventObj *_get_event_obj(unsigned line)
329 IHTMLEventObj *event = NULL;
330 HRESULT hres;
332 hres = IHTMLWindow2_get_event(window, &event);
333 ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
334 ok_(__FILE__,line) (event != NULL, "event = NULL\n");
336 /* Native IE uses an undocumented DIID in IE9+ mode */
337 _test_disp(line, (IUnknown*)event, document_mode < 9 ? &DIID_DispCEventObj : NULL);
339 return event;
342 #define set_elem_innerhtml(e,t) _set_elem_innerhtml(__LINE__,e,t)
343 static void _set_elem_innerhtml(unsigned line, IHTMLElement *elem, const char *inner_html)
345 BSTR html;
346 HRESULT hres;
348 html = a2bstr(inner_html);
349 hres = IHTMLElement_put_innerHTML(elem, html);
350 ok_(__FILE__,line)(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
351 SysFreeString(html);
354 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
355 static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
357 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
358 VARIANT_BOOL b;
359 BSTR str;
360 HRESULT hres;
362 b = 100;
363 str = a2bstr(event);
364 in_fire_event++;
365 hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
366 in_fire_event--;
367 SysFreeString(str);
368 ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
369 ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
372 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
373 static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
374 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
376 ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
377 ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
378 ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
379 ok_(__FILE__,line) (pdp->cArgs == (document_mode < 9 ? 1 : 2), "pdp->cArgs = %d\n", pdp->cArgs);
380 ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
381 ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
382 pdp->rgdispidNamedArgs[0]);
383 ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
384 if(pdp->cArgs > 1)
385 ok_(__FILE__,line) (V_VT(pdp->rgvarg+1) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg+1));
386 ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
387 ok_(__FILE__,line) (pei != NULL, "pei == NULL");
388 ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
390 if(dispiid)
391 _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
393 if(pdp->cArgs > 1) {
394 IHTMLEventObj *window_event, *event_obj;
395 IDOMEvent *event;
396 HRESULT hres;
398 hres = IDispatch_QueryInterface(V_DISPATCH(pdp->rgvarg+1), &IID_IDOMEvent, (void**)&event);
399 if(in_fire_event)
400 ok(hres == E_NOINTERFACE, "QI(IID_IDOMEvent) returned %08x\n", hres);
401 else
402 ok(hres == S_OK, "Could not get IDOMEvent iface: %08x\n", hres);
404 hres = IDispatch_QueryInterface(V_DISPATCH(pdp->rgvarg+1), &IID_IHTMLEventObj, (void**)&event_obj);
405 if(in_fire_event)
406 ok(hres == S_OK, "Could not get IDOMEventObj iface: %08x\n", hres);
407 else
408 ok(hres == E_NOINTERFACE, "QI(IID_IHTMLEventObj) returned %08x\n", hres);
410 if(event)
411 IDOMEvent_Release(event);
412 if(event_obj)
413 IHTMLEventObj_Release(event_obj);
415 hres = IHTMLWindow2_get_event(window, &window_event);
416 ok(hres == S_OK, "get_event failed: %08x\n", hres);
417 if(window_event) {
418 todo_wine_if(in_fire_event)
419 ok(!iface_cmp((IUnknown*)V_DISPATCH(pdp->rgvarg+1), (IUnknown*)window_event),
420 "window_event != event arg\n");
421 IHTMLEventObj_Release(window_event);
426 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
427 static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
428 VARIANT *pvarRes, EXCEPINFO *pei)
430 IHTMLEventObj *event;
432 ok(id == DISPID_VALUE, "id = %d\n", id);
433 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
434 ok(pdp != NULL, "pDispParams == NULL\n");
435 ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
436 ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
437 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
438 ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
439 ok(pvarRes != NULL, "pvarRes = NULL\n");
440 ok(pei != NULL, "pei = NULL\n");
441 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
442 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
443 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
445 event = _get_event_obj(line);
446 todo_wine
447 ok(!iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
448 IHTMLEventObj_Release(event);
451 #define get_event_src() _get_event_src(__LINE__)
452 static IHTMLElement *_get_event_src(unsigned line)
454 IHTMLEventObj *event = _get_event_obj(line);
455 IHTMLElement *src_elem = NULL;
456 HRESULT hres;
458 hres = IHTMLEventObj_get_srcElement(event, &src_elem);
459 IHTMLEventObj_Release(event);
460 ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
462 return src_elem;
465 #define test_event_src(t) _test_event_src(__LINE__,t)
466 static void _test_event_src(unsigned line, const char *src_tag)
468 IHTMLElement *src_elem = _get_event_src(line);
470 if(src_tag) {
471 ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
472 _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
473 IHTMLElement_Release(src_elem);
474 }else {
475 ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
479 static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
481 VARIANT_BOOL b;
482 HRESULT hres;
484 hres = IHTMLEventObj_get_altKey(event, &b);
485 ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
486 ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
489 static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
491 VARIANT_BOOL b;
492 HRESULT hres;
494 hres = IHTMLEventObj_get_ctrlKey(event, &b);
495 ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
496 ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
499 static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
501 VARIANT_BOOL b;
502 HRESULT hres;
504 hres = IHTMLEventObj_get_shiftKey(event, &b);
505 ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
506 ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
509 #define test_event_cancelbubble(a,b) _test_event_cancelbubble(__LINE__,a,b)
510 static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
512 VARIANT_BOOL b;
513 HRESULT hres;
515 hres = IHTMLEventObj_get_cancelBubble(event, &b);
516 ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
517 ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
520 static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
522 IHTMLElement *elem;
523 HRESULT hres;
525 hres = IHTMLEventObj_get_fromElement(event, &elem);
526 ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
527 if(from_tag)
528 _test_elem_tag(line, (IUnknown*)elem, from_tag);
529 else
530 ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
531 if(elem)
532 IHTMLElement_Release(elem);
535 static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
537 IHTMLElement *elem;
538 HRESULT hres;
540 hres = IHTMLEventObj_get_toElement(event, &elem);
541 ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
542 if(to_tag)
543 _test_elem_tag(line, (IUnknown*)elem, to_tag);
544 else
545 ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
546 if(elem)
547 IHTMLElement_Release(elem);
550 static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
552 LONG l;
553 HRESULT hres;
555 hres = IHTMLEventObj_get_keyCode(event, &l);
556 ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
557 ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
560 static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
562 LONG l;
563 HRESULT hres;
565 hres = IHTMLEventObj_get_button(event, &l);
566 ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
567 ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
570 static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
572 LONG l;
573 HRESULT hres;
575 hres = IHTMLEventObj_get_reason(event, &l);
576 ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
577 ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
580 static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
582 LONG l;
583 HRESULT hres;
585 hres = IHTMLEventObj_get_x(event, &l);
586 ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
587 if(exl != -10) /* don't test the exact value */
588 ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
591 static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
593 LONG l;
594 HRESULT hres;
596 hres = IHTMLEventObj_get_y(event, &l);
597 ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
598 if(exl != -10) /* don't test the exact value */
599 ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
602 static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
604 LONG l;
605 HRESULT hres;
607 hres = IHTMLEventObj_get_clientX(event, &l);
608 ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
609 if(exl != -10) /* don't test the exact value */
610 ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
613 static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
615 LONG l;
616 HRESULT hres;
618 hres = IHTMLEventObj_get_clientY(event, &l);
619 ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
620 if(exl != -10) /* don't test the exact value */
621 ok_(__FILE__,line)(l == exl, "clientY = %d, expected %d\n", l, exl);
624 static void _test_event_offsetx(unsigned line, IHTMLEventObj *event, LONG exl)
626 LONG l;
627 HRESULT hres;
629 hres = IHTMLEventObj_get_offsetX(event, &l);
630 ok_(__FILE__,line)(hres == S_OK, "get_offsetX failed: %08x\n", hres);
631 if(exl != -10) /* don't test the exact value */
632 ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
635 static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
637 LONG l;
638 HRESULT hres;
640 hres = IHTMLEventObj_get_offsetY(event, &l);
641 ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
642 if(exl != -10) /* don't test the exact value */
643 ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
646 static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
648 LONG l;
649 HRESULT hres;
651 hres = IHTMLEventObj_get_screenX(event, &l);
652 ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
653 if(exl != -10) /* don't test the exact value */
654 ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
657 static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
659 LONG l;
660 HRESULT hres;
662 hres = IHTMLEventObj_get_screenY(event, &l);
663 ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
664 if(exl != -10) /* don't test the exact value for -10 */
665 ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
668 static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
670 BSTR str;
671 HRESULT hres;
673 hres = IHTMLEventObj_get_type(event, &str);
674 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
675 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
678 static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
680 BSTR str;
681 HRESULT hres;
683 hres = IHTMLEventObj_get_qualifier(event, &str);
684 ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
685 if(exstr)
686 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
687 else
688 ok_(__FILE__,line)(!str, "qualifier != NULL\n");
691 static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
693 IDispatch *disp;
694 HRESULT hres;
696 hres = IHTMLEventObj_get_srcFilter(event, &disp);
697 ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
698 ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
701 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
702 static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
704 IHTMLEventObj *event = _get_event_obj(line);
705 IDOMEvent *dom_event;
706 VARIANT v;
707 HRESULT hres;
709 _test_event_altkey(line, event, VARIANT_FALSE);
710 _test_event_ctrlkey(line, event, VARIANT_FALSE);
711 _test_event_shiftkey(line, event, VARIANT_FALSE);
712 _test_event_cancelbubble(line, event, VARIANT_FALSE);
713 _test_event_fromelem(line, event, NULL);
714 _test_event_toelem(line, event, NULL);
715 _test_event_keycode(line, event, 0);
716 _test_event_button(line, event, 0);
717 _test_event_type(line, event, type);
718 _test_event_qualifier(line, event, NULL);
719 _test_event_reason(line, event, 0);
720 _test_event_srcfilter(line, event);
721 _test_event_x(line, event, xy->x);
722 _test_event_y(line, event, xy->y);
723 _test_event_clientx(line, event, -10);
724 _test_event_clienty(line, event, -10);
725 _test_event_offsetx(line, event, xy->offset_x);
726 _test_event_offsety(line, event, xy->offset_y);
727 _test_event_screenx(line, event, -10);
728 _test_event_screeny(line, event, -10);
730 V_VT(&v) = VT_NULL;
731 hres = IHTMLEventObj_get_returnValue(event, &v);
732 ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
733 /* Depending on source of event, returnValue may be true bool in IE9+ mode */
734 ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY || (document_mode >= 9 && V_VT(&v) == VT_BOOL),
735 "V_VT(returnValue) = %d\n", V_VT(&v));
736 if(V_VT(&v) == VT_BOOL)
737 ok_(__FILE__,line)(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(returnValue) = %x\n", V_BOOL(&v));
739 hres = IHTMLEventObj_QueryInterface(event, &IID_IDOMEvent, (void**)&dom_event);
740 ok(hres == E_NOINTERFACE, "Could not get IDOMEvent iface: %08x\n", hres);
742 IHTMLEventObj_Release(event);
745 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
746 static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
748 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
749 VARIANT_BOOL res;
750 BSTR name;
751 HRESULT hres;
753 name = a2bstr(namea);
754 hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
755 IHTMLElement2_Release(elem);
756 SysFreeString(name);
757 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
758 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
761 #define add_event_listener(a,b,c,d) _add_event_listener(__LINE__,a,b,c,d)
762 static void _add_event_listener(unsigned line, IUnknown *unk, const char *type, IDispatch *listener, VARIANT_BOOL use_capture)
764 IEventTarget *event_target;
765 BSTR str;
766 HRESULT hres;
768 hres = IUnknown_QueryInterface(unk, &IID_IEventTarget, (void**)&event_target);
769 ok_(__FILE__,line)(hres == S_OK, "Could not get IEventTarget iface: %08x\n", hres);
771 str = a2bstr(type);
772 hres = IEventTarget_addEventListener(event_target, str, listener, use_capture);
773 SysFreeString(str);
774 ok_(__FILE__,line)(hres == S_OK, "addEventListener failed: %08x\n", hres);
776 IEventTarget_Release(event_target);
779 #define remove_event_listener(a,b,c,d) _remove_event_listener(__LINE__,a,b,c,d)
780 static void _remove_event_listener(unsigned line, IUnknown *unk, const char *type, IDispatch *listener, VARIANT_BOOL use_capture)
782 IEventTarget *event_target;
783 BSTR str;
784 HRESULT hres;
786 hres = IUnknown_QueryInterface(unk, &IID_IEventTarget, (void**)&event_target);
787 ok_(__FILE__,line)(hres == S_OK, "Could not get IEventTarget iface: %08x\n", hres);
789 str = a2bstr(type);
790 hres = IEventTarget_removeEventListener(event_target, str, listener, use_capture);
791 SysFreeString(str);
792 ok_(__FILE__,line)(hres == S_OK, "removeEventListener failed: %08x\n", hres);
794 IEventTarget_Release(event_target);
797 #define elem_detach_event(a,b,c) _elem_detach_event(__LINE__,a,b,c)
798 static void _elem_detach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
800 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
801 BSTR name;
802 HRESULT hres;
804 name = a2bstr(namea);
805 hres = IHTMLElement2_detachEvent(elem, name, disp);
806 IHTMLElement2_Release(elem);
807 SysFreeString(name);
808 ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
811 #define doc_attach_event(a,b,c) _doc_attach_event(__LINE__,a,b,c)
812 static void _doc_attach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
814 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
815 VARIANT_BOOL res;
816 BSTR name;
817 HRESULT hres;
819 name = a2bstr(namea);
820 hres = IHTMLDocument3_attachEvent(doc3, name, disp, &res);
821 IHTMLDocument3_Release(doc3);
822 SysFreeString(name);
823 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
824 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
827 #define doc_detach_event(a,b,c) _doc_detach_event(__LINE__,a,b,c)
828 static void _doc_detach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
830 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
831 BSTR name;
832 HRESULT hres;
834 name = a2bstr(namea);
835 hres = IHTMLDocument3_detachEvent(doc3, name, disp);
836 IHTMLDocument3_Release(doc3);
837 SysFreeString(name);
838 ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
841 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
843 if(IsEqualGUID(riid, &IID_IUnknown)
844 || IsEqualGUID(riid, &IID_IDispatch)
845 || IsEqualGUID(riid, &IID_IDispatchEx))
846 *ppv = iface;
847 else {
848 *ppv = NULL;
849 return E_NOINTERFACE;
852 return S_OK;
855 static HRESULT WINAPI Dispatch_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
857 if(IsEqualGUID(riid, &IID_IUnknown)
858 || IsEqualGUID(riid, &IID_IDispatch)) {
859 *ppv = iface;
860 }else {
861 *ppv = NULL;
862 return E_NOINTERFACE;
865 return S_OK;
868 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
870 return 2;
873 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
875 return 1;
878 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
880 ok(0, "unexpected call\n");
881 return E_NOTIMPL;
884 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
885 LCID lcid, ITypeInfo **ppTInfo)
887 ok(0, "unexpected call\n");
888 return E_NOTIMPL;
891 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
892 LPOLESTR *rgszNames, UINT cNames,
893 LCID lcid, DISPID *rgDispId)
895 ok(0, "unexpected call\n");
896 return E_NOTIMPL;
899 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
900 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
901 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
903 ok(0, "unexpected call\n");
904 return E_NOTIMPL;
907 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
909 ok(0, "unexpected call\n");
910 return E_NOTIMPL;
913 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
914 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
916 ok(0, "unexpected call\n");
917 return E_NOTIMPL;
920 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
922 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
923 return E_NOTIMPL;
926 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
928 ok(0, "unexpected call\n");
929 return E_NOTIMPL;
932 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
934 ok(0, "unexpected call\n");
935 return E_NOTIMPL;
938 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
940 ok(0, "unexpected call\n");
941 return E_NOTIMPL;
944 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
946 ok(0, "unexpected call\n");
947 return E_NOTIMPL;
950 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
952 ok(0, "unexpected call\n");
953 return E_NOTIMPL;
956 #define EVENT_HANDLER_FUNC_OBJ(event) \
957 static IDispatchExVtbl event ## FuncVtbl = { \
958 DispatchEx_QueryInterface, \
959 DispatchEx_AddRef, \
960 DispatchEx_Release, \
961 DispatchEx_GetTypeInfoCount, \
962 DispatchEx_GetTypeInfo, \
963 DispatchEx_GetIDsOfNames, \
964 DispatchEx_Invoke, \
965 DispatchEx_GetDispID, \
966 event, \
967 DispatchEx_DeleteMemberByName, \
968 DispatchEx_DeleteMemberByDispID, \
969 DispatchEx_GetMemberProperties, \
970 DispatchEx_GetMemberName, \
971 DispatchEx_GetNextDispID, \
972 DispatchEx_GetNameSpaceParent \
973 }; \
974 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
976 static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
977 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
979 IHTMLDocument3 *doc3;
980 CHECK_EXPECT(document_onclick);
981 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
982 doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
983 IHTMLDocument3_Release(doc3);
984 test_event_src("DIV");
985 test_event_obj("click", &no_xy);
986 return S_OK;
989 EVENT_HANDLER_FUNC_OBJ(document_onclick);
991 static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
992 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
994 CHECK_EXPECT(div_onclick);
995 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
996 test_event_src("DIV");
997 test_event_obj("click", &no_xy);
998 return S_OK;
1001 EVENT_HANDLER_FUNC_OBJ(div_onclick);
1003 static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1004 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1006 CHECK_EXPECT(div_onclick_attached);
1008 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1009 test_event_src("DIV");
1010 return S_OK;
1013 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
1015 static HRESULT WINAPI doc_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1016 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1018 CHECK_EXPECT(doc_onclick_attached);
1020 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1021 test_event_src("DIV");
1022 return S_OK;
1025 EVENT_HANDLER_FUNC_OBJ(doc_onclick_attached);
1027 static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1028 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1030 CHECK_EXPECT(body_onclick);
1031 /* Native IE returns undocumented DIID in IE9+ mode */
1032 test_event_args(document_mode < 9 ? &DIID_DispHTMLBody : NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1033 test_event_src("DIV");
1034 return S_OK;
1037 EVENT_HANDLER_FUNC_OBJ(body_onclick);
1039 static HRESULT WINAPI div_onclick_capture(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1040 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1042 CHECK_EXPECT(div_onclick_capture);
1044 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1045 test_event_src("DIV");
1046 return S_OK;
1049 EVENT_HANDLER_FUNC_OBJ(div_onclick_capture);
1051 static HRESULT WINAPI div_onclick_bubble(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1052 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1054 CHECK_EXPECT(div_onclick_bubble);
1056 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1057 test_event_src("DIV");
1058 return S_OK;
1061 EVENT_HANDLER_FUNC_OBJ(div_onclick_bubble);
1063 static HRESULT WINAPI img_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1064 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1066 CHECK_EXPECT(img_onload);
1067 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
1068 test_event_src("IMG");
1069 return S_OK;
1072 EVENT_HANDLER_FUNC_OBJ(img_onload);
1074 static HRESULT WINAPI link_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1075 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1077 CHECK_EXPECT(link_onload);
1078 test_event_args(&DIID_DispHTMLLinkElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
1079 test_event_src("LINK");
1080 return S_OK;
1083 EVENT_HANDLER_FUNC_OBJ(link_onload);
1085 static HRESULT WINAPI unattached_img_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1086 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1088 IHTMLElement *event_src;
1090 CHECK_EXPECT(img_onload);
1092 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
1093 event_src = get_event_src();
1094 todo_wine
1095 ok(!event_src, "event_src != NULL\n");
1096 if(event_src)
1097 IHTMLElement_Release(event_src);
1098 return S_OK;
1101 EVENT_HANDLER_FUNC_OBJ(unattached_img_onload);
1103 static HRESULT WINAPI img_onerror(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1104 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1106 CHECK_EXPECT(img_onerror);
1107 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
1108 test_event_src("IMG");
1109 return S_OK;
1112 EVENT_HANDLER_FUNC_OBJ(img_onerror);
1114 static HRESULT WINAPI input_onfocus(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1115 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1117 CHECK_EXPECT(input_onfocus);
1118 test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
1119 test_event_src("INPUT");
1120 return S_OK;
1123 EVENT_HANDLER_FUNC_OBJ(input_onfocus);
1125 static HRESULT WINAPI div_onfocusin(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1126 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1128 CHECK_EXPECT(div_onfocusin);
1129 test_event_args(NULL /* FIXME: &DIID_DispHTMLDivElement */, id, wFlags, pdp, pvarRes, pei, pspCaller);
1130 test_event_src("INPUT");
1131 return S_OK;
1134 EVENT_HANDLER_FUNC_OBJ(div_onfocusin);
1136 static HRESULT WINAPI div_onfocusout(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1137 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1139 CHECK_EXPECT(div_onfocusout);
1140 test_event_args(NULL /* FIXME: &DIID_DispHTMLDivElement */, id, wFlags, pdp, pvarRes, pei, pspCaller);
1141 test_event_src("INPUT");
1142 return S_OK;
1145 EVENT_HANDLER_FUNC_OBJ(div_onfocusout);
1147 static HRESULT WINAPI input_onblur(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1148 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1150 CHECK_EXPECT(input_onblur);
1151 test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
1152 test_event_src("INPUT");
1153 return S_OK;
1156 EVENT_HANDLER_FUNC_OBJ(input_onblur);
1158 static HRESULT WINAPI form_onsubmit(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1159 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1161 CHECK_EXPECT(form_onsubmit);
1162 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1163 test_event_src("FORM");
1165 V_VT(pvarRes) = VT_BOOL;
1166 V_BOOL(pvarRes) = VARIANT_FALSE;
1167 return S_OK;
1170 EVENT_HANDLER_FUNC_OBJ(form_onsubmit);
1172 static HRESULT WINAPI form_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1173 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1175 CHECK_EXPECT(form_onclick);
1176 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1178 return S_OK;
1181 EVENT_HANDLER_FUNC_OBJ(form_onclick);
1183 static HRESULT WINAPI submit_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1184 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1186 CHECK_EXPECT(submit_onclick);
1187 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1188 test_event_src("INPUT");
1190 V_VT(pvarRes) = VT_BOOL;
1191 V_BOOL(pvarRes) = VARIANT_FALSE;
1192 return S_OK;
1195 EVENT_HANDLER_FUNC_OBJ(submit_onclick);
1197 static HRESULT WINAPI iframe_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1198 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1200 CHECK_EXPECT(iframe_onload);
1201 test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
1202 test_event_src("IFRAME");
1203 return S_OK;
1206 EVENT_HANDLER_FUNC_OBJ(iframe_onload);
1208 static HRESULT WINAPI submit_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1209 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1211 CHECK_EXPECT(submit_onclick_attached);
1212 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1213 test_event_src("INPUT");
1215 V_VT(pvarRes) = VT_BOOL;
1216 V_BOOL(pvarRes) = VARIANT_FALSE;
1217 return S_OK;
1220 EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached);
1222 static HRESULT WINAPI submit_onclick_attached_check_cancel(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1223 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1225 IHTMLEventObj *event;
1226 HRESULT hres;
1228 CHECK_EXPECT(submit_onclick_attached_check_cancel);
1229 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1230 test_event_src("INPUT");
1232 event = NULL;
1233 hres = IHTMLWindow2_get_event(window, &event);
1234 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1235 ok(event != NULL, "event == NULL\n");
1237 test_event_cancelbubble(event, VARIANT_TRUE);
1238 return S_OK;
1241 EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached_check_cancel);
1243 static VARIANT onclick_retval, onclick_event_retval;
1245 static HRESULT WINAPI submit_onclick_setret(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1246 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1248 IHTMLEventObj *event;
1249 VARIANT v;
1250 HRESULT hres;
1252 CHECK_EXPECT(submit_onclick_setret);
1253 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1254 test_event_src("INPUT");
1256 event = NULL;
1257 hres = IHTMLWindow2_get_event(window, &event);
1258 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1259 ok(event != NULL, "event == NULL\n");
1261 V_VT(&v) = VT_ERROR;
1262 hres = IHTMLEventObj_get_returnValue(event, &v);
1263 ok(hres == S_OK, "get_returnValue failed: %08x\n", hres);
1264 if(document_mode < 9) {
1265 ok(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
1266 }else todo_wine {
1267 ok(V_VT(&v) == VT_BOOL, "V_VT(returnValue) = %d\n", V_VT(&v));
1268 ok(V_BOOL(&v) == VARIANT_TRUE, "V_BOOL(returnValue) = %x\n", V_BOOL(&v));
1271 hres = IHTMLEventObj_put_returnValue(event, onclick_event_retval);
1272 ok(hres == S_OK, "put_returnValue failed: %08x\n", hres);
1274 V_VT(&v) = VT_ERROR;
1275 hres = IHTMLEventObj_get_returnValue(event, &v);
1276 ok(hres == S_OK, "get_returnValue failed: %08x\n", hres);
1277 ok(VarCmp(&v, &onclick_event_retval, 0, 0) == VARCMP_EQ, "unexpected returnValue\n");
1279 IHTMLEventObj_Release(event);
1280 *pvarRes = onclick_retval;
1281 return S_OK;
1284 EVENT_HANDLER_FUNC_OBJ(submit_onclick_setret);
1286 static HRESULT WINAPI submit_onclick_cancel(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1287 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1289 IHTMLEventObj *event;
1290 HRESULT hres;
1292 CHECK_EXPECT(submit_onclick_cancel);
1293 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1294 test_event_src("INPUT");
1296 event = NULL;
1297 hres = IHTMLWindow2_get_event(window, &event);
1298 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1299 ok(event != NULL, "event == NULL\n");
1301 test_event_cancelbubble(event, VARIANT_FALSE);
1303 hres = IHTMLEventObj_put_cancelBubble(event, VARIANT_TRUE);
1304 ok(hres == S_OK, "put_returnValue failed: %08x\n", hres);
1306 test_event_cancelbubble(event, VARIANT_TRUE);
1307 IHTMLEventObj_Release(event);
1308 return S_OK;
1311 EVENT_HANDLER_FUNC_OBJ(submit_onclick_cancel);
1313 static HRESULT WINAPI iframedoc_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1314 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1316 IHTMLEventObj *event = NULL;
1317 HRESULT hres;
1319 CHECK_EXPECT2(iframedoc_onreadystatechange);
1320 test_event_args(document_mode < 9 ? &DIID_DispHTMLDocument : NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1322 event = (void*)0xdeadbeef;
1323 hres = IHTMLWindow2_get_event(window, &event);
1324 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1325 ok(!event, "event = %p\n", event);
1327 return S_OK;
1330 EVENT_HANDLER_FUNC_OBJ(iframedoc_onreadystatechange);
1332 static HRESULT WINAPI iframe_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1333 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1335 IHTMLWindow2 *iframe_window;
1336 IHTMLDocument2 *iframe_doc;
1337 IHTMLFrameBase2 *iframe;
1338 IHTMLElement2 *elem2;
1339 IHTMLElement *elem;
1340 VARIANT v;
1341 BSTR str, str2;
1342 HRESULT hres;
1344 test_event_args(document_mode < 9 ? &DIID_DispHTMLIFrame : NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1345 test_event_src("IFRAME");
1347 elem = get_event_src();
1348 elem2 = get_elem2_iface((IUnknown*)elem);
1349 IHTMLElement_Release(elem);
1351 V_VT(&v) = VT_EMPTY;
1352 hres = IHTMLElement2_get_readyState(elem2, &v);
1353 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1354 ok(V_VT(&v) == VT_BSTR, "V_VT(readyState) = %d\n", V_VT(&v));
1356 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase2, (void**)&iframe);
1357 IHTMLElement2_Release(elem2);
1358 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
1360 str = NULL;
1361 hres = IHTMLFrameBase2_get_readyState(iframe, &str);
1362 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1363 ok(str != NULL, "readyState == NULL\n");
1364 ok(!lstrcmpW(str, V_BSTR(&v)), "ready states differ\n");
1365 VariantClear(&v);
1367 hres = IHTMLFrameBase2_get_contentWindow(iframe, &iframe_window);
1368 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
1370 hres = IHTMLWindow2_get_document(iframe_window, &iframe_doc);
1371 IHTMLWindow2_Release(iframe_window);
1372 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1374 hres = IHTMLDocument2_get_readyState(iframe_doc, &str2);
1375 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1376 ok(!lstrcmpW(str, str2), "unexpected document readyState %s\n", wine_dbgstr_w(str2));
1377 SysFreeString(str2);
1379 if(!strcmp_wa(str, "loading")) {
1380 CHECK_EXPECT(iframe_onreadystatechange_loading);
1382 V_VT(&v) = VT_DISPATCH;
1383 V_DISPATCH(&v) = (IDispatch*)&iframedoc_onreadystatechange_obj;
1384 hres = IHTMLDocument2_put_onreadystatechange(iframe_doc, v);
1385 ok(hres == S_OK, "put_onreadystatechange: %08x\n", hres);
1386 }else if(!strcmp_wa(str, "interactive"))
1387 CHECK_EXPECT(iframe_onreadystatechange_interactive);
1388 else if(!strcmp_wa(str, "complete"))
1389 CHECK_EXPECT(iframe_onreadystatechange_complete);
1390 else
1391 ok(0, "unexpected state %s\n", wine_dbgstr_w(str));
1393 SysFreeString(str);
1394 IHTMLDocument2_Release(iframe_doc);
1395 IHTMLFrameBase2_Release(iframe);
1396 return S_OK;
1399 EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange);
1401 static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1402 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1404 ok(0, "unexpected call\n");
1405 return S_OK;
1408 EVENT_HANDLER_FUNC_OBJ(nocall);
1410 #define CONNECTION_POINT_OBJ(cpname, diid) \
1411 static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
1413 *ppv = NULL; \
1414 if(IsEqualGUID(riid, &IID_IUnknown) \
1415 || IsEqualGUID(riid, &IID_IDispatch) \
1416 || IsEqualGUID(riid, &diid)) \
1417 *ppv = iface; \
1418 else { \
1419 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid)); \
1420 return E_NOINTERFACE; \
1422 return S_OK; \
1424 static IDispatchExVtbl cpname ## Vtbl = { \
1425 cpname ## _QueryInterface, \
1426 DispatchEx_AddRef, \
1427 DispatchEx_Release, \
1428 DispatchEx_GetTypeInfoCount, \
1429 DispatchEx_GetTypeInfo, \
1430 DispatchEx_GetIDsOfNames, \
1431 cpname, \
1432 DispatchEx_GetDispID, \
1433 DispatchEx_InvokeEx, \
1434 DispatchEx_DeleteMemberByName, \
1435 DispatchEx_DeleteMemberByDispID, \
1436 DispatchEx_GetMemberProperties, \
1437 DispatchEx_GetMemberName, \
1438 DispatchEx_GetNextDispID, \
1439 DispatchEx_GetNameSpaceParent \
1440 }; \
1441 static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
1443 #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
1444 static void _test_cp_args(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1446 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1447 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1448 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1449 ok_(__FILE__,line)(!dp->cArgs, "dp->cArgs = %d\n", dp->cArgs);
1450 ok_(__FILE__,line)(!dp->rgvarg, "dp->rgvarg = %p\n", dp->rgvarg);
1451 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1452 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1453 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1454 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1455 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1456 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1459 #define test_cp_eventarg(a,b,c,d,e,f) _test_cp_eventarg(__LINE__,a,b,c,d,e,f)
1460 static void _test_cp_eventarg(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1462 IHTMLEventObj *event;
1464 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1465 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1466 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1467 ok_(__FILE__,line)(dp->cArgs == 1, "dp->cArgs = %d\n", dp->cArgs);
1468 ok_(__FILE__,line)(dp->rgvarg != NULL, "dp->rgvarg = %p\n", dp->rgvarg);
1469 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1470 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1471 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1472 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1473 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1474 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1476 ok(V_VT(dp->rgvarg) == VT_DISPATCH, "V_VT(dp->rgvarg) = %d\n", V_VT(dp->rgvarg));
1477 ok(V_DISPATCH(dp->rgvarg) != NULL, "V_DISPATCH(dp->rgvarg) = %p\n", V_DISPATCH(dp->rgvarg));
1479 event = _get_event_obj(line);
1480 todo_wine
1481 ok(!iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(dp->rgvarg)), "event != arg0\n");
1482 IHTMLEventObj_Release(event);
1485 static HRESULT WINAPI doccp(IDispatchEx *iface, DISPID dispIdMember,
1486 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1487 VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1489 switch(dispIdMember) {
1490 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1491 CHECK_EXPECT(doccp_onclick);
1492 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1493 break;
1494 default:
1495 ok(0, "unexpected call %d\n", dispIdMember);
1496 return E_NOTIMPL;
1499 return S_OK;
1502 CONNECTION_POINT_OBJ(doccp, DIID_HTMLDocumentEvents);
1504 static HRESULT WINAPI doccp_onclick_cancel(IDispatchEx *iface, DISPID dispIdMember,
1505 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1507 switch(dispIdMember) {
1508 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1509 CHECK_EXPECT(doccp_onclick_cancel);
1510 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1511 V_VT(pVarResult) = VT_BOOL;
1512 V_BOOL(pVarResult) = VARIANT_FALSE;
1513 break;
1514 default:
1515 ok(0, "unexpected call %d\n", dispIdMember);
1516 return E_NOTIMPL;
1519 return S_OK;
1522 CONNECTION_POINT_OBJ(doccp_onclick_cancel, DIID_HTMLDocumentEvents);
1524 static HRESULT WINAPI elem2_cp(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1525 WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1527 switch(dispIdMember) {
1528 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1529 CHECK_EXPECT(elem2_cp_onclick);
1530 test_cp_eventarg(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1531 break;
1532 default:
1533 ok(0, "unexpected call %d\n", dispIdMember);
1534 return E_NOTIMPL;
1537 return S_OK;
1540 CONNECTION_POINT_OBJ(elem2_cp, DIID_HTMLElementEvents2);
1542 static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1543 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1544 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1546 CHECK_EXPECT(timeout);
1548 ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
1549 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1550 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
1551 ok(!lcid, "lcid = %x\n", lcid);
1552 ok(pDispParams != NULL, "pDispParams == NULL\n");
1553 ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
1554 ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
1555 ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
1556 ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
1557 ok(pVarResult != NULL, "pVarResult = NULL\n");
1558 ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
1559 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1560 ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1562 return S_OK;
1565 static const IDispatchExVtbl timeoutFuncVtbl = {
1566 DispatchEx_QueryInterface,
1567 DispatchEx_AddRef,
1568 DispatchEx_Release,
1569 DispatchEx_GetTypeInfoCount,
1570 DispatchEx_GetTypeInfo,
1571 DispatchEx_GetIDsOfNames,
1572 timeoutFunc_Invoke,
1573 DispatchEx_GetDispID,
1574 DispatchEx_InvokeEx,
1575 DispatchEx_DeleteMemberByName,
1576 DispatchEx_DeleteMemberByDispID,
1577 DispatchEx_GetMemberProperties,
1578 DispatchEx_GetMemberName,
1579 DispatchEx_GetNextDispID,
1580 DispatchEx_GetNameSpaceParent
1583 static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
1585 static HRESULT WINAPI timeoutFunc2_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1586 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1587 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1589 ok(0, "unexpected call\n");
1590 return E_FAIL;
1593 static const IDispatchExVtbl timeoutFunc2Vtbl = {
1594 DispatchEx_QueryInterface,
1595 DispatchEx_AddRef,
1596 DispatchEx_Release,
1597 DispatchEx_GetTypeInfoCount,
1598 DispatchEx_GetTypeInfo,
1599 DispatchEx_GetIDsOfNames,
1600 timeoutFunc2_Invoke,
1601 DispatchEx_GetDispID,
1602 DispatchEx_InvokeEx,
1603 DispatchEx_DeleteMemberByName,
1604 DispatchEx_DeleteMemberByDispID,
1605 DispatchEx_GetMemberProperties,
1606 DispatchEx_GetMemberName,
1607 DispatchEx_GetNextDispID,
1608 DispatchEx_GetNameSpaceParent
1611 static IDispatchEx timeoutFunc2 = { &timeoutFunc2Vtbl };
1613 static HRESULT WINAPI div_onclick_disp_Invoke(IDispatchEx *iface, DISPID id,
1614 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1615 VARIANT *pvarRes, EXCEPINFO *pei, UINT *puArgErr)
1617 CHECK_EXPECT(div_onclick_disp);
1619 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1621 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1622 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1624 return S_OK;
1627 static const IDispatchExVtbl div_onclick_dispVtbl = {
1628 Dispatch_QueryInterface,
1629 DispatchEx_AddRef,
1630 DispatchEx_Release,
1631 DispatchEx_GetTypeInfoCount,
1632 DispatchEx_GetTypeInfo,
1633 DispatchEx_GetIDsOfNames,
1634 div_onclick_disp_Invoke,
1637 static IDispatchEx div_onclick_disp = { &div_onclick_dispVtbl };
1639 static void pump_msgs(BOOL *b)
1641 MSG msg;
1643 if(b) {
1644 while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
1645 TranslateMessage(&msg);
1646 DispatchMessageW(&msg);
1648 }else {
1649 while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
1650 TranslateMessage(&msg);
1651 DispatchMessageW(&msg);
1656 static IConnectionPoint *get_cp(IUnknown *unk, REFIID riid)
1658 IConnectionPointContainer *cp_container;
1659 IConnectionPoint *cp;
1660 HRESULT hres;
1662 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1663 ok(hres == S_OK, "Could not get IConnectionPointContainer: %08x\n", hres);
1665 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, riid, &cp);
1666 IConnectionPointContainer_Release(cp_container);
1667 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1669 return cp;
1672 static DWORD register_cp(IUnknown *unk, REFIID riid, IUnknown *sink)
1674 IConnectionPoint *cp;
1675 DWORD cookie;
1676 HRESULT hres;
1678 cp = get_cp(unk, riid);
1679 hres = IConnectionPoint_Advise(cp, sink, &cookie);
1680 IConnectionPoint_Release(cp);
1681 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1683 return cookie;
1686 static void unregister_cp(IUnknown *unk, REFIID riid, DWORD cookie)
1688 IConnectionPoint *cp;
1689 HRESULT hres;
1691 cp = get_cp(unk, riid);
1692 hres = IConnectionPoint_Unadvise(cp, cookie);
1693 IConnectionPoint_Release(cp);
1694 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
1697 static HRESULT WINAPI EventDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
1699 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
1700 *ppv = iface;
1701 return S_OK;
1704 ok(0, "Unexpected call\n");
1705 return E_NOINTERFACE;
1708 static DWORD WINAPI EventDispatch_AddRef(IDispatch *iface)
1710 return 2;
1713 static DWORD WINAPI EventDispatch_Release(IDispatch *iface)
1715 return 1;
1718 static HRESULT WINAPI EventDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
1720 ok(0, "Unexpected call\n");
1721 return E_NOTIMPL;
1724 static HRESULT WINAPI EventDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1726 ok(0, "Unexpected call\n");
1727 return E_NOTIMPL;
1730 static HRESULT WINAPI EventDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
1731 UINT cNames, LCID lcid, DISPID *rgDispId)
1733 ok(0, "Unexpected call\n");
1734 return E_NOTIMPL;
1737 static HRESULT WINAPI EventDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
1738 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1739 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1741 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1742 ok(pDispParams != NULL, "pDispParams == NULL\n");
1743 ok(pExcepInfo != NULL, "pExcepInfo == NULL\n");
1744 ok(puArgErr != NULL, "puArgErr == NULL\n");
1745 ok(V_VT(pVarResult) == 0, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1746 ok(wFlags == DISPATCH_METHOD, "wFlags = %d\n", wFlags);
1748 switch(dispIdMember) {
1749 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1750 CHECK_EXPECT2(invoke_onclick);
1751 break;
1752 case DISPID_HTMLDOCUMENTEVENTS2_ONPROPERTYCHANGE:
1753 case DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE:
1754 case 1027:
1755 case 1034:
1756 case 1037:
1757 case 1044:
1758 case 1045:
1759 case 1047:
1760 case 1048:
1761 case 1049:
1762 break; /* TODO */
1763 default:
1764 ok(0, "Unexpected call: %d\n", dispIdMember);
1767 return S_OK;
1770 static const IDispatchVtbl EventDispatchVtbl = {
1771 EventDispatch_QueryInterface,
1772 EventDispatch_AddRef,
1773 EventDispatch_Release,
1774 EventDispatch_GetTypeInfoCount,
1775 EventDispatch_GetTypeInfo,
1776 EventDispatch_GetIDsOfNames,
1777 EventDispatch_Invoke
1780 static IDispatch EventDispatch = { &EventDispatchVtbl };
1782 static void set_body_html(IHTMLDocument2 *doc, const char *html)
1784 IHTMLElement *body = doc_get_body(doc);
1785 set_elem_innerhtml(body, html);
1786 IHTMLElement_Release(body);
1789 static void test_onclick(IHTMLDocument2 *doc)
1791 DWORD cp_cookie, elem2_cp_cookie;
1792 IHTMLElement *div, *body;
1793 VARIANT v;
1794 HRESULT hres;
1796 trace("onclick tests in document mode %d\n", document_mode);
1798 set_body_html(doc, "<div id=\"clickdiv\""
1799 " style=\"text-align: center; background: red; font-size: 32\">"
1800 "click here"
1801 "</div>");
1803 register_cp((IUnknown*)doc, &IID_IDispatch, (IUnknown*)&EventDispatch);
1805 div = get_elem_id(doc, "clickdiv");
1807 elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
1808 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
1810 V_VT(&v) = VT_EMPTY;
1811 hres = IHTMLElement_get_onclick(div, &v);
1812 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1813 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1815 V_VT(&v) = VT_EMPTY;
1816 hres = IHTMLElement_put_onclick(div, v);
1817 ok(hres == (document_mode < 9 ? E_NOTIMPL : S_OK), "put_onclick failed: %08x\n", hres);
1819 V_VT(&v) = VT_EMPTY;
1820 hres = IHTMLElement_get_onclick(div, &v);
1821 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1822 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1824 V_VT(&v) = VT_BSTR;
1825 V_BSTR(&v) = a2bstr("function();");
1826 hres = IHTMLElement_put_onclick(div, v);
1827 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1828 SysFreeString(V_BSTR(&v));
1830 V_VT(&v) = VT_EMPTY;
1831 hres = IHTMLElement_get_onclick(div, &v);
1832 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1833 if(document_mode < 9) {
1834 ok(V_VT(&v) == VT_BSTR, "V_VT(onclick) = %d\n", V_VT(&v));
1835 ok(!strcmp_wa(V_BSTR(&v), "function();"), "V_BSTR(onclick) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
1836 }else {
1837 todo_wine
1838 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1840 VariantClear(&v);
1842 V_VT(&v) = VT_DISPATCH;
1843 V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
1844 hres = IHTMLElement_put_onclick(div, v);
1845 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1847 V_VT(&v) = VT_NULL;
1848 hres = IHTMLElement_put_ondblclick(div, v);
1849 ok(hres == S_OK, "put_ondblclick failed: %08x\n", hres);
1851 V_VT(&v) = VT_EMPTY;
1852 hres = IHTMLElement_get_onclick(div, &v);
1853 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1854 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1855 ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1856 VariantClear(&v);
1858 V_VT(&v) = VT_EMPTY;
1859 hres = IHTMLDocument2_get_onclick(doc, &v);
1860 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1861 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1863 V_VT(&v) = VT_DISPATCH;
1864 V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
1865 hres = IHTMLDocument2_put_onclick(doc, v);
1866 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1868 V_VT(&v) = VT_EMPTY;
1869 hres = IHTMLDocument2_get_onclick(doc, &v);
1870 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1871 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1872 ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1873 VariantClear(&v);
1875 if(document_mode >= 9) {
1876 add_event_listener((IUnknown*)div, "click", (IDispatch*)&div_onclick_capture_obj, VARIANT_TRUE);
1877 add_event_listener((IUnknown*)div, "click", (IDispatch*)&div_onclick_bubble_obj, VARIANT_FALSE);
1880 body = doc_get_body(doc);
1882 V_VT(&v) = VT_DISPATCH;
1883 V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
1884 hres = IHTMLElement_put_onclick(body, v);
1885 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1887 if(winetest_interactive && document_mode < 9) {
1888 SET_EXPECT(div_onclick);
1889 SET_EXPECT(div_onclick_attached);
1890 SET_EXPECT(body_onclick);
1891 SET_EXPECT(document_onclick);
1892 SET_EXPECT(invoke_onclick);
1893 pump_msgs(&called_document_onclick);
1894 CHECK_CALLED(div_onclick);
1895 CHECK_CALLED(div_onclick_attached);
1896 CHECK_CALLED(body_onclick);
1897 CHECK_CALLED(document_onclick);
1898 CHECK_CALLED(invoke_onclick);
1901 SET_EXPECT(div_onclick);
1902 SET_EXPECT(div_onclick_attached);
1903 if(document_mode >= 9) {
1904 SET_EXPECT(div_onclick_capture);
1905 SET_EXPECT(div_onclick_bubble);
1907 SET_EXPECT(body_onclick);
1908 SET_EXPECT(document_onclick);
1909 SET_EXPECT(invoke_onclick);
1911 hres = IHTMLElement_click(div);
1912 ok(hres == S_OK, "click failed: %08x\n", hres);
1914 CHECK_CALLED(div_onclick);
1915 CHECK_CALLED(div_onclick_attached);
1916 if(document_mode >= 9) {
1917 CHECK_CALLED(div_onclick_capture);
1918 CHECK_CALLED(div_onclick_bubble);
1920 CHECK_CALLED(body_onclick);
1921 CHECK_CALLED(document_onclick);
1922 CHECK_CALLED(invoke_onclick);
1924 SET_EXPECT(div_onclick);
1925 SET_EXPECT(div_onclick_attached);
1926 SET_EXPECT(body_onclick);
1927 SET_EXPECT(document_onclick);
1928 SET_EXPECT(invoke_onclick);
1930 V_VT(&v) = VT_EMPTY;
1931 elem_fire_event((IUnknown*)div, "onclick", &v);
1933 CHECK_CALLED(div_onclick);
1934 CHECK_CALLED(div_onclick_attached);
1935 CHECK_CALLED(body_onclick);
1936 CHECK_CALLED(document_onclick);
1937 CHECK_CALLED(invoke_onclick);
1939 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_obj);
1940 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1941 doc_attach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1943 SET_EXPECT(div_onclick);
1944 SET_EXPECT(div_onclick_disp);
1945 SET_EXPECT(div_onclick_attached);
1946 if(document_mode >= 9) {
1947 SET_EXPECT(div_onclick_capture);
1948 SET_EXPECT(div_onclick_bubble);
1950 SET_EXPECT(body_onclick);
1951 SET_EXPECT(document_onclick);
1952 SET_EXPECT(doc_onclick_attached);
1953 SET_EXPECT(doccp_onclick);
1954 SET_EXPECT(invoke_onclick);
1956 hres = IHTMLElement_click(div);
1957 ok(hres == S_OK, "click failed: %08x\n", hres);
1959 CHECK_CALLED(div_onclick);
1960 CHECK_CALLED(div_onclick_disp);
1961 CHECK_CALLED(div_onclick_attached);
1962 if(document_mode >= 9) {
1963 CHECK_CALLED(div_onclick_capture);
1964 CHECK_CALLED(div_onclick_bubble);
1966 CHECK_CALLED(body_onclick);
1967 CHECK_CALLED(document_onclick);
1968 CHECK_CALLED(doc_onclick_attached);
1969 CHECK_CALLED(doccp_onclick);
1970 CHECK_CALLED(invoke_onclick);
1972 elem2_cp_cookie = register_cp((IUnknown*)div, &DIID_HTMLElementEvents2, (IUnknown*)&elem2_cp_obj);
1974 SET_EXPECT(div_onclick);
1975 SET_EXPECT(div_onclick_disp);
1976 SET_EXPECT(div_onclick_attached);
1977 if(document_mode >= 9) {
1978 SET_EXPECT(div_onclick_capture);
1979 SET_EXPECT(div_onclick_bubble);
1981 SET_EXPECT(elem2_cp_onclick);
1982 SET_EXPECT(body_onclick);
1983 SET_EXPECT(document_onclick);
1984 SET_EXPECT(doc_onclick_attached);
1985 SET_EXPECT(doccp_onclick);
1986 SET_EXPECT(invoke_onclick);
1988 trace("click >>>\n");
1989 hres = IHTMLElement_click(div);
1990 ok(hres == S_OK, "click failed: %08x\n", hres);
1991 trace("click <<<\n");
1993 CHECK_CALLED(div_onclick);
1994 CHECK_CALLED(div_onclick_disp);
1995 CHECK_CALLED(div_onclick_attached);
1996 if(document_mode >= 9) {
1997 CHECK_CALLED(div_onclick_capture);
1998 CHECK_CALLED(div_onclick_bubble);
2000 CHECK_CALLED(elem2_cp_onclick);
2001 CHECK_CALLED(body_onclick);
2002 CHECK_CALLED(document_onclick);
2003 CHECK_CALLED(doc_onclick_attached);
2004 CHECK_CALLED(doccp_onclick);
2005 CHECK_CALLED(invoke_onclick);
2007 unregister_cp((IUnknown*)div, &DIID_HTMLElementEvents2, elem2_cp_cookie);
2008 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
2010 V_VT(&v) = VT_NULL;
2011 hres = IHTMLElement_put_onclick(div, v);
2012 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2014 hres = IHTMLElement_get_onclick(div, &v);
2015 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
2016 ok(V_VT(&v) == VT_NULL, "get_onclick returned vt %d\n", V_VT(&v));
2018 elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
2019 elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
2020 elem_detach_event((IUnknown*)div, "test", (IDispatch*)&div_onclick_disp);
2021 doc_detach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
2023 if(document_mode >= 9) {
2024 remove_event_listener((IUnknown*)div, "click", (IDispatch*)&div_onclick_capture_obj, VARIANT_TRUE);
2025 remove_event_listener((IUnknown*)div, "click", (IDispatch*)&div_onclick_bubble_obj, VARIANT_FALSE);
2028 SET_EXPECT(div_onclick_attached);
2029 SET_EXPECT(body_onclick);
2030 SET_EXPECT(document_onclick);
2031 SET_EXPECT(invoke_onclick);
2033 hres = IHTMLElement_click(div);
2034 ok(hres == S_OK, "click failed: %08x\n", hres);
2036 CHECK_CALLED(div_onclick_attached);
2037 CHECK_CALLED(body_onclick);
2038 CHECK_CALLED(document_onclick);
2039 CHECK_CALLED(invoke_onclick);
2041 IHTMLElement_Release(div);
2042 IHTMLElement_Release(body);
2045 static void test_onreadystatechange(IHTMLDocument2 *doc)
2047 IHTMLFrameBase *iframe;
2048 IHTMLElement2 *elem2;
2049 IHTMLElement *elem;
2050 VARIANT v;
2051 BSTR str;
2052 HRESULT hres;
2054 elem = get_elem_id(doc, "iframe");
2055 elem2 = get_elem2_iface((IUnknown*)elem);
2056 IHTMLElement_Release(elem);
2058 V_VT(&v) = VT_EMPTY;
2059 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
2060 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
2061 ok(V_VT(&v) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
2063 V_VT(&v) = VT_DISPATCH;
2064 V_DISPATCH(&v) = (IDispatch*)&iframe_onreadystatechange_obj;
2065 hres = IHTMLElement2_put_onreadystatechange(elem2, v);
2066 ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
2068 V_VT(&v) = VT_EMPTY;
2069 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
2070 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
2071 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
2072 ok(V_DISPATCH(&v) == (IDispatch*)&iframe_onreadystatechange_obj, "unexpected onreadystatechange value\n");
2074 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase, (void**)&iframe);
2075 IHTMLElement2_Release(elem2);
2076 ok(hres == S_OK, "Could not get IHTMLFrameBase iface: %08x\n", hres);
2078 hres = IHTMLFrameBase_put_src(iframe, (str = a2bstr("about:blank")));
2079 SysFreeString(str);
2080 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2082 SET_EXPECT(iframe_onreadystatechange_loading);
2083 SET_EXPECT(iframedoc_onreadystatechange);
2084 SET_EXPECT(iframe_onreadystatechange_interactive);
2085 SET_EXPECT(iframe_onreadystatechange_complete);
2086 pump_msgs(&called_iframe_onreadystatechange_complete);
2087 CHECK_CALLED(iframe_onreadystatechange_loading);
2088 CHECK_CALLED(iframedoc_onreadystatechange);
2089 CHECK_CALLED(iframe_onreadystatechange_interactive);
2090 CHECK_CALLED(iframe_onreadystatechange_complete);
2092 IHTMLFrameBase_Release(iframe);
2095 static void test_imgload(IHTMLDocument2 *doc)
2097 IHTMLImgElement *img;
2098 IHTMLElement *elem;
2099 VARIANT v;
2100 BSTR str;
2101 HRESULT hres;
2103 elem = get_elem_id(doc, "imgid");
2104 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLImgElement, (void**)&img);
2105 IHTMLElement_Release(elem);
2106 ok(hres == S_OK, "Could not get IHTMLImgElement iface: %08x\n", hres);
2108 V_VT(&v) = VT_EMPTY;
2109 hres = IHTMLImgElement_get_onload(img, &v);
2110 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2111 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
2113 V_VT(&v) = VT_DISPATCH;
2114 V_DISPATCH(&v) = (IDispatch*)&img_onload_obj;
2115 hres = IHTMLImgElement_put_onload(img, v);
2116 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2118 V_VT(&v) = VT_EMPTY;
2119 hres = IHTMLImgElement_get_onload(img, &v);
2120 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2121 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
2122 ok(V_DISPATCH(&v) == (IDispatch*)&img_onload_obj, "V_DISPATCH(onload) != onloadkFunc\n");
2123 VariantClear(&v);
2125 V_VT(&v) = VT_DISPATCH;
2126 V_DISPATCH(&v) = (IDispatch*)&img_onerror_obj;
2127 hres = IHTMLImgElement_put_onerror(img, v);
2128 ok(hres == S_OK, "put_onerror failed: %08x\n", hres);
2130 V_VT(&v) = VT_EMPTY;
2131 hres = IHTMLImgElement_get_onerror(img, &v);
2132 ok(hres == S_OK, "get_onerror failed: %08x\n", hres);
2133 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onerror) = %d\n", V_VT(&v));
2134 ok(V_DISPATCH(&v) == (IDispatch*)&img_onerror_obj, "V_DISPATCH(onerror) != onerrorFunc\n");
2135 VariantClear(&v);
2137 str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_text.png");
2138 hres = IHTMLImgElement_put_src(img, str);
2139 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2140 SysFreeString(str);
2142 SET_EXPECT(img_onload);
2143 pump_msgs(&called_img_onload);
2144 CHECK_CALLED(img_onload);
2146 SET_EXPECT(img_onerror);
2148 str = a2bstr("about:blank");
2149 hres = IHTMLImgElement_put_src(img, str);
2150 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2151 SysFreeString(str);
2153 pump_msgs(&called_img_onerror); /* FIXME: should not be needed */
2155 CHECK_CALLED(img_onerror);
2157 IHTMLImgElement_Release(img);
2159 /* test onload on unattached image */
2160 hres = IHTMLDocument2_createElement(doc, (str = a2bstr("img")), &elem);
2161 SysFreeString(str);
2162 ok(hres == S_OK, "createElement(img) failed: %08x\n", hres);
2164 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLImgElement, (void**)&img);
2165 IHTMLElement_Release(elem);
2166 ok(hres == S_OK, "Could not get IHTMLImgElement iface: %08x\n", hres);
2168 V_VT(&v) = VT_EMPTY;
2169 hres = IHTMLImgElement_get_onload(img, &v);
2170 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2171 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
2173 V_VT(&v) = VT_DISPATCH;
2174 V_DISPATCH(&v) = (IDispatch*)&unattached_img_onload_obj;
2175 hres = IHTMLImgElement_put_onload(img, v);
2176 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2178 V_VT(&v) = VT_EMPTY;
2179 hres = IHTMLImgElement_get_onload(img, &v);
2180 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2181 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
2182 ok(V_DISPATCH(&v) == (IDispatch*)&unattached_img_onload_obj, "incorrect V_DISPATCH(onload)\n");
2183 VariantClear(&v);
2185 str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_text.png?v=1");
2186 hres = IHTMLImgElement_put_src(img, str);
2187 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2188 SysFreeString(str);
2190 SET_EXPECT(img_onload);
2191 pump_msgs(&called_img_onload);
2192 CHECK_CALLED(img_onload);
2194 IHTMLImgElement_Release(img);
2197 static void test_link_load(IHTMLDocument2 *doc)
2199 IHTMLLinkElement *link;
2200 IHTMLElement *elem;
2201 VARIANT v;
2202 BSTR str;
2203 HRESULT hres;
2205 elem = get_elem_id(doc, "linkid");
2206 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLLinkElement, (void**)&link);
2207 IHTMLElement_Release(elem);
2208 ok(hres == S_OK, "Could not get IHTMLLinkElement iface: %08x\n", hres);
2210 V_VT(&v) = VT_EMPTY;
2211 hres = IHTMLLinkElement_get_onload(link, &v);
2212 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2213 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
2215 V_VT(&v) = VT_DISPATCH;
2216 V_DISPATCH(&v) = (IDispatch*)&link_onload_obj;
2217 hres = IHTMLLinkElement_put_onload(link, v);
2218 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2220 V_VT(&v) = VT_EMPTY;
2221 hres = IHTMLLinkElement_get_onload(link, &v);
2222 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2223 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
2224 ok(V_DISPATCH(&v) == (IDispatch*)&link_onload_obj, "V_DISPATCH(onload) != onloadkFunc\n");
2225 VariantClear(&v);
2227 str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/styles.css");
2228 hres = IHTMLLinkElement_put_href(link, str);
2229 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2230 SysFreeString(str);
2232 SET_EXPECT(link_onload);
2233 pump_msgs(&called_link_onload);
2234 CHECK_CALLED(link_onload);
2236 IHTMLLinkElement_Release(link);
2239 static void test_focus(IHTMLDocument2 *doc)
2241 IHTMLElement2 *elem2;
2242 IHTMLElement4 *div;
2243 IHTMLElement *elem;
2244 VARIANT v;
2245 HRESULT hres;
2247 elem = get_elem_id(doc, "inputid");
2248 elem2 = get_elem2_iface((IUnknown*)elem);
2249 IHTMLElement_Release(elem);
2251 elem = get_elem_id(doc, "divid");
2252 div = get_elem4_iface((IUnknown*)elem);
2253 IHTMLElement_Release(elem);
2255 V_VT(&v) = VT_EMPTY;
2256 hres = IHTMLElement2_get_onfocus(elem2, &v);
2257 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
2258 ok(V_VT(&v) == VT_NULL, "V_VT(onfocus) = %d\n", V_VT(&v));
2260 V_VT(&v) = VT_DISPATCH;
2261 V_DISPATCH(&v) = (IDispatch*)&input_onfocus_obj;
2262 hres = IHTMLElement2_put_onfocus(elem2, v);
2263 ok(hres == S_OK, "put_onfocus failed: %08x\n", hres);
2265 V_VT(&v) = VT_EMPTY;
2266 hres = IHTMLElement2_get_onfocus(elem2, &v);
2267 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
2268 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocus) = %d\n", V_VT(&v));
2269 ok(V_DISPATCH(&v) == (IDispatch*)&input_onfocus_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
2270 VariantClear(&v);
2272 V_VT(&v) = VT_DISPATCH;
2273 V_DISPATCH(&v) = (IDispatch*)&div_onfocusin_obj;
2274 hres = IHTMLElement4_put_onfocusin(div, v);
2275 ok(hres == S_OK, "put_onfocusin failed: %08x\n", hres);
2277 V_VT(&v) = VT_EMPTY;
2278 hres = IHTMLElement4_get_onfocusin(div, &v);
2279 ok(hres == S_OK, "get_onfocusin failed: %08x\n", hres);
2280 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocusin) = %d\n", V_VT(&v));
2281 ok(V_DISPATCH(&v) == (IDispatch*)&div_onfocusin_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
2282 VariantClear(&v);
2284 V_VT(&v) = VT_EMPTY;
2285 hres = IHTMLElement2_get_onfocus(elem2, &v);
2286 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
2287 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocus) = %d\n", V_VT(&v));
2288 ok(V_DISPATCH(&v) == (IDispatch*)&input_onfocus_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
2289 VariantClear(&v);
2291 if(!winetest_interactive)
2292 ShowWindow(container_hwnd, SW_SHOW);
2294 SetFocus(NULL);
2295 ok(!IsChild(container_hwnd, GetFocus()), "focus belongs to document window\n");
2297 hres = IHTMLWindow2_focus(window);
2298 ok(hres == S_OK, "focus failed: %08x\n", hres);
2300 ok(IsChild(container_hwnd, GetFocus()), "focus does not belong to document window\n");
2301 pump_msgs(NULL);
2303 SET_EXPECT(div_onfocusin);
2304 SET_EXPECT(input_onfocus);
2305 hres = IHTMLElement2_focus(elem2);
2306 ok(hres == S_OK, "focus failed: %08x\n", hres);
2307 pump_msgs(NULL);
2308 CHECK_CALLED(div_onfocusin);
2309 CHECK_CALLED(input_onfocus);
2311 SET_EXPECT(div_onfocusin);
2312 V_VT(&v) = VT_EMPTY;
2313 elem_fire_event((IUnknown*)elem2, "onfocusin", &v);
2314 CHECK_CALLED(div_onfocusin);
2316 V_VT(&v) = VT_DISPATCH;
2317 V_DISPATCH(&v) = (IDispatch*)&input_onblur_obj;
2318 hres = IHTMLElement2_put_onblur(elem2, v);
2319 ok(hres == S_OK, "put_onblur failed: %08x\n", hres);
2321 V_VT(&v) = VT_DISPATCH;
2322 V_DISPATCH(&v) = (IDispatch*)&div_onfocusout_obj;
2323 hres = IHTMLElement4_put_onfocusout(div, v);
2324 ok(hres == S_OK, "put_onfocusout failed: %08x\n", hres);
2326 SET_EXPECT(div_onfocusout);
2327 SET_EXPECT(input_onblur);
2328 hres = IHTMLElement2_blur(elem2);
2329 pump_msgs(NULL);
2330 CHECK_CALLED(input_onblur);
2331 CHECK_CALLED(div_onfocusout);
2332 ok(hres == S_OK, "blur failed: %08x\n", hres);
2334 if(!winetest_interactive)
2335 ShowWindow(container_hwnd, SW_HIDE);
2337 IHTMLElement2_Release(elem2);
2338 IHTMLElement4_Release(div);
2341 static void test_submit(IHTMLDocument2 *doc)
2343 IHTMLElement *elem, *submit;
2344 IHTMLFormElement *form;
2345 VARIANT v;
2346 DWORD cp_cookie;
2347 HRESULT hres;
2349 set_body_html(doc,
2350 "<form id=\"formid\" method=\"post\" action=\"about:blank\">"
2351 "<input type=\"text\" value=\"test\" name=\"i\"/>"
2352 "<input type=\"submit\" id=\"submitid\" />"
2353 "</form>");
2355 elem = get_elem_id(doc, "formid");
2357 V_VT(&v) = VT_DISPATCH;
2358 V_DISPATCH(&v) = (IDispatch*)&form_onclick_obj;
2359 hres = IHTMLElement_put_onclick(elem, v);
2360 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2362 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFormElement, (void**)&form);
2363 IHTMLElement_Release(elem);
2364 ok(hres == S_OK, "Could not get IHTMLFormElement iface: %08x\n", hres);
2366 V_VT(&v) = VT_DISPATCH;
2367 V_DISPATCH(&v) = (IDispatch*)&form_onsubmit_obj;
2368 hres = IHTMLFormElement_put_onsubmit(form, v);
2369 ok(hres == S_OK, "put_onsubmit failed: %08x\n", hres);
2371 IHTMLFormElement_Release(form);
2373 submit = get_elem_id(doc, "submitid");
2375 SET_EXPECT(form_onclick);
2376 SET_EXPECT(form_onsubmit);
2377 hres = IHTMLElement_click(submit);
2378 ok(hres == S_OK, "click failed: %08x\n", hres);
2379 CHECK_CALLED(form_onclick);
2380 CHECK_CALLED(form_onsubmit);
2382 V_VT(&v) = VT_DISPATCH;
2383 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_obj;
2384 hres = IHTMLElement_put_onclick(submit, v);
2385 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2387 SET_EXPECT(form_onclick);
2388 SET_EXPECT(submit_onclick);
2389 hres = IHTMLElement_click(submit);
2390 ok(hres == S_OK, "click failed: %08x\n", hres);
2391 CHECK_CALLED(form_onclick);
2392 CHECK_CALLED(submit_onclick);
2394 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2396 SET_EXPECT(form_onclick);
2397 SET_EXPECT(submit_onclick);
2398 SET_EXPECT(submit_onclick_attached);
2399 hres = IHTMLElement_click(submit);
2400 ok(hres == S_OK, "click failed: %08x\n", hres);
2401 CHECK_CALLED(form_onclick);
2402 CHECK_CALLED(submit_onclick);
2403 CHECK_CALLED(submit_onclick_attached);
2405 V_VT(&v) = VT_NULL;
2406 hres = IHTMLElement_put_onclick(submit, v);
2407 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2409 SET_EXPECT(form_onclick);
2410 SET_EXPECT(submit_onclick_attached);
2411 hres = IHTMLElement_click(submit);
2412 ok(hres == S_OK, "click failed: %08x\n", hres);
2413 CHECK_CALLED(form_onclick);
2414 CHECK_CALLED(submit_onclick_attached);
2416 elem_detach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2418 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_onclick_cancel_obj);
2420 SET_EXPECT(form_onclick);
2421 SET_EXPECT(doccp_onclick_cancel);
2422 hres = IHTMLElement_click(submit);
2423 ok(hres == S_OK, "click failed: %08x\n", hres);
2424 CHECK_CALLED(form_onclick);
2425 CHECK_CALLED(doccp_onclick_cancel);
2427 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
2429 V_VT(&v) = VT_DISPATCH;
2430 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_setret_obj;
2431 hres = IHTMLElement_put_onclick(submit, v);
2432 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2434 V_VT(&onclick_retval) = VT_BOOL;
2435 V_BOOL(&onclick_retval) = VARIANT_TRUE;
2436 V_VT(&onclick_event_retval) = VT_BOOL;
2437 V_BOOL(&onclick_event_retval) = VARIANT_TRUE;
2439 SET_EXPECT(submit_onclick_setret);
2440 SET_EXPECT(form_onclick);
2441 SET_EXPECT(form_onsubmit);
2442 hres = IHTMLElement_click(submit);
2443 ok(hres == S_OK, "click failed: %08x\n", hres);
2444 CHECK_CALLED(submit_onclick_setret);
2445 CHECK_CALLED(form_onclick);
2446 CHECK_CALLED(form_onsubmit);
2448 V_VT(&onclick_event_retval) = VT_BOOL;
2449 V_BOOL(&onclick_event_retval) = VARIANT_FALSE;
2451 SET_EXPECT(submit_onclick_setret);
2452 SET_EXPECT(form_onclick);
2453 hres = IHTMLElement_click(submit);
2454 ok(hres == S_OK, "click failed: %08x\n", hres);
2455 CHECK_CALLED(submit_onclick_setret);
2456 CHECK_CALLED(form_onclick);
2458 V_VT(&onclick_retval) = VT_BOOL;
2459 V_BOOL(&onclick_retval) = VARIANT_FALSE;
2460 V_VT(&onclick_event_retval) = VT_BOOL;
2461 V_BOOL(&onclick_event_retval) = VARIANT_TRUE;
2463 SET_EXPECT(submit_onclick_setret);
2464 SET_EXPECT(form_onclick);
2465 hres = IHTMLElement_click(submit);
2466 ok(hres == S_OK, "click failed: %08x\n", hres);
2467 CHECK_CALLED(submit_onclick_setret);
2468 CHECK_CALLED(form_onclick);
2470 V_VT(&onclick_event_retval) = VT_BOOL;
2471 V_BOOL(&onclick_event_retval) = VARIANT_FALSE;
2473 SET_EXPECT(submit_onclick_setret);
2474 SET_EXPECT(form_onclick);
2475 hres = IHTMLElement_click(submit);
2476 ok(hres == S_OK, "click failed: %08x\n", hres);
2477 CHECK_CALLED(submit_onclick_setret);
2478 CHECK_CALLED(form_onclick);
2480 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2481 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_check_cancel_obj);
2483 V_VT(&v) = VT_DISPATCH;
2484 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_cancel_obj;
2485 hres = IHTMLElement_put_onclick(submit, v);
2486 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2488 SET_EXPECT(submit_onclick_cancel);
2489 SET_EXPECT(submit_onclick_attached_check_cancel);
2490 SET_EXPECT(submit_onclick_attached);
2491 hres = IHTMLElement_click(submit);
2492 ok(hres == S_OK, "click failed: %08x\n", hres);
2493 CHECK_CALLED(submit_onclick_cancel);
2494 CHECK_CALLED(submit_onclick_attached_check_cancel);
2495 CHECK_CALLED(submit_onclick_attached);
2497 if(1)pump_msgs(NULL);
2499 IHTMLElement_Release(submit);
2502 static void test_timeout(IHTMLDocument2 *doc)
2504 IHTMLWindow3 *win3;
2505 VARIANT expr, var;
2506 LONG id;
2507 HRESULT hres;
2509 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
2510 ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
2512 V_VT(&expr) = VT_DISPATCH;
2513 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc2;
2514 V_VT(&var) = VT_EMPTY;
2515 id = 0;
2516 hres = IHTMLWindow3_setInterval(win3, &expr, 1, &var, &id);
2517 ok(hres == S_OK, "setInterval failed: %08x\n", hres);
2518 ok(id, "id = 0\n");
2520 hres = IHTMLWindow2_clearTimeout(window, id);
2521 ok(hres == S_OK, "clearTimeout failer: %08x\n", hres);
2523 V_VT(&expr) = VT_DISPATCH;
2524 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2525 V_VT(&var) = VT_EMPTY;
2526 id = 0;
2527 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
2528 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
2529 ok(id, "id = 0\n");
2531 SET_EXPECT(timeout);
2532 pump_msgs(&called_timeout);
2533 CHECK_CALLED(timeout);
2535 V_VT(&expr) = VT_DISPATCH;
2536 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2537 V_VT(&var) = VT_EMPTY;
2538 id = 0;
2539 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
2540 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
2541 ok(id, "id = 0\n");
2543 hres = IHTMLWindow2_clearTimeout(window, id);
2544 ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
2546 V_VT(&expr) = VT_DISPATCH;
2547 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2548 V_VT(&var) = VT_EMPTY;
2549 id = 0;
2550 hres = IHTMLWindow3_setInterval(win3, &expr, 1, &var, &id);
2551 ok(hres == S_OK, "setInterval failed: %08x\n", hres);
2552 ok(id, "id = 0\n");
2554 SET_EXPECT(timeout);
2555 pump_msgs(&called_timeout);
2556 CHECK_CALLED(timeout);
2558 SET_EXPECT(timeout);
2559 pump_msgs(&called_timeout);
2560 CHECK_CALLED(timeout);
2562 hres = IHTMLWindow2_clearInterval(window, id);
2563 ok(hres == S_OK, "clearTimeout failer: %08x\n", hres);
2565 IHTMLWindow3_Release(win3);
2568 static IHTMLWindow2 *get_iframe_window(IHTMLIFrameElement *iframe)
2570 IHTMLWindow2 *window;
2571 IHTMLFrameBase2 *base;
2572 HRESULT hres;
2574 hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&base);
2575 ok(hres == S_OK, "QueryInterface(IID_IHTMLFrameBase2) failed: %08x\n", hres);
2577 hres = IHTMLFrameBase2_get_contentWindow(base, &window);
2578 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
2579 ok(window != NULL, "window == NULL\n");
2581 if(base) IHTMLFrameBase2_Release(base);
2582 return window;
2585 static IHTMLDocument2 *get_iframe_doc(IHTMLIFrameElement *iframe)
2587 IHTMLDocument2 *result = NULL;
2588 IHTMLWindow2 *window;
2589 HRESULT hres;
2591 window = get_iframe_window(iframe);
2593 hres = IHTMLWindow2_get_document(window, &result);
2594 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2595 ok(result != NULL, "result == NULL\n");
2597 IHTMLWindow2_Release(window);
2598 return result;
2601 static void test_iframe_connections(IHTMLDocument2 *doc)
2603 IHTMLIFrameElement *iframe;
2604 IHTMLDocument2 *iframes_doc;
2605 DWORD cookie;
2606 IConnectionPoint *cp;
2607 IHTMLElement *element;
2608 BSTR str;
2609 HRESULT hres;
2611 trace("iframe tests...\n");
2613 element = get_elem_id(doc, "ifr");
2614 iframe = get_iframe_iface((IUnknown*)element);
2615 IHTMLElement_Release(element);
2617 iframes_doc = get_iframe_doc(iframe);
2618 IHTMLIFrameElement_Release(iframe);
2620 cookie = register_cp((IUnknown*)iframes_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
2622 cp = get_cp((IUnknown*)doc, &IID_IDispatch);
2623 hres = IConnectionPoint_Unadvise(cp, cookie);
2624 IConnectionPoint_Release(cp);
2625 ok(hres == CONNECT_E_NOCONNECTION, "Unadvise returned %08x, expected CONNECT_E_NOCONNECTION\n", hres);
2627 unregister_cp((IUnknown*)iframes_doc, &IID_IDispatch, cookie);
2629 if(is_ie9plus) {
2630 IHTMLFrameBase2 *frame_base2;
2631 VARIANT v;
2633 hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&frame_base2);
2634 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
2636 V_VT(&v) = VT_DISPATCH;
2637 V_DISPATCH(&v) = (IDispatch*)&iframe_onload_obj;
2638 hres = IHTMLFrameBase2_put_onload(frame_base2, v);
2639 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2641 IHTMLFrameBase2_Release(frame_base2);
2643 str = a2bstr("about:blank");
2644 hres = IHTMLDocument2_put_URL(iframes_doc, str);
2645 ok(hres == S_OK, "put_URL failed: %08x\n", hres);
2646 SysFreeString(str);
2648 SET_EXPECT(iframe_onload);
2649 pump_msgs(&called_iframe_onload);
2650 CHECK_CALLED(iframe_onload);
2652 str = a2bstr("about:test");
2653 hres = IHTMLDocument2_put_URL(iframes_doc, str);
2654 ok(hres == S_OK, "put_URL failed: %08x\n", hres);
2655 SysFreeString(str);
2657 SET_EXPECT(iframe_onload);
2658 pump_msgs(&called_iframe_onload);
2659 CHECK_CALLED(iframe_onload);
2660 }else {
2661 win_skip("Skipping iframe onload tests on IE older than 9.\n");
2664 IHTMLDocument2_Release(iframes_doc);
2667 static void test_create_event(IHTMLDocument2 *doc)
2669 IDocumentEvent *doc_event;
2670 IDOMEvent *event;
2671 USHORT phase;
2672 BSTR str;
2673 HRESULT hres;
2675 trace("createEvent tests...\n");
2677 hres = IHTMLDocument2_QueryInterface(doc, &IID_IDocumentEvent, (void**)&doc_event);
2678 ok(hres == S_OK, "Could not get IDocumentEvent iface: %08x\n", hres);
2680 str = a2bstr("Event");
2681 hres = IDocumentEvent_createEvent(doc_event, str, &event);
2682 SysFreeString(str);
2683 ok(hres == S_OK, "createEvent failed: %08x\n", hres);
2685 phase = 0xdead;
2686 hres = IDOMEvent_get_eventPhase(event, &phase);
2687 ok(hres == S_OK, "get_eventPhase failed: %08x\n", hres);
2688 ok(!phase, "phase = %u\n", phase);
2690 hres = IDOMEvent_preventDefault(event);
2691 ok(hres == S_OK, "preventDefault failed: %08x\n", hres);
2693 hres = IDOMEvent_stopPropagation(event);
2694 ok(hres == S_OK, "stopPropagation failed: %08x\n", hres);
2696 IDOMEvent_Release(event);
2698 IDocumentEvent_Release(doc_event);
2701 static HRESULT QueryInterface(REFIID,void**);
2703 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
2705 return E_NOINTERFACE;
2708 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
2710 return 2;
2713 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
2715 return 1;
2718 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
2720 return E_NOTIMPL;
2723 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
2725 return E_NOTIMPL;
2728 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
2730 return E_NOTIMPL;
2733 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
2734 LPCBORDERWIDTHS pborderwidths)
2736 return E_NOTIMPL;
2739 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
2740 LPCBORDERWIDTHS pborderwidths)
2742 return S_OK;
2745 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
2746 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
2748 return S_OK;
2751 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
2752 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
2754 return S_OK;
2757 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
2758 LPOLEMENUGROUPWIDTHS lpMenuWidths)
2760 return E_NOTIMPL;
2763 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
2764 HOLEMENU holemenu, HWND hwndActiveObject)
2766 ok(0, "unexpected call\n");
2767 return E_NOTIMPL;
2770 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
2772 ok(0, "unexpected call\n");
2773 return E_NOTIMPL;
2776 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
2778 return S_OK;
2781 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
2783 return E_NOTIMPL;
2786 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
2788 ok(0, "unexpected call\n");
2789 return E_NOTIMPL;
2792 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
2793 InPlaceFrame_QueryInterface,
2794 InPlaceFrame_AddRef,
2795 InPlaceFrame_Release,
2796 InPlaceFrame_GetWindow,
2797 InPlaceFrame_ContextSensitiveHelp,
2798 InPlaceFrame_GetBorder,
2799 InPlaceFrame_RequestBorderSpace,
2800 InPlaceFrame_SetBorderSpace,
2801 InPlaceFrame_SetActiveObject,
2802 InPlaceFrame_InsertMenus,
2803 InPlaceFrame_SetMenu,
2804 InPlaceFrame_RemoveMenus,
2805 InPlaceFrame_SetStatusText,
2806 InPlaceFrame_EnableModeless,
2807 InPlaceFrame_TranslateAccelerator
2810 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
2812 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
2813 InPlaceFrame_QueryInterface,
2814 InPlaceFrame_AddRef,
2815 InPlaceFrame_Release,
2816 InPlaceFrame_GetWindow,
2817 InPlaceFrame_ContextSensitiveHelp,
2818 InPlaceFrame_GetBorder,
2819 InPlaceFrame_RequestBorderSpace,
2820 InPlaceFrame_SetBorderSpace,
2821 InPlaceUIWindow_SetActiveObject,
2824 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
2826 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
2828 return QueryInterface(riid, ppv);
2831 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
2833 return 2;
2836 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
2838 return 1;
2841 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
2843 *phwnd = container_hwnd;
2844 return S_OK;
2847 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
2849 ok(0, "unexpected call\n");
2850 return E_NOTIMPL;
2853 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
2855 return S_OK;
2858 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
2860 return S_OK;
2863 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
2865 return S_OK;
2868 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
2869 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
2870 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
2872 static const RECT rect = {0,0,300,300};
2874 *ppFrame = &InPlaceFrame;
2875 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
2876 *lprcPosRect = rect;
2877 *lprcClipRect = rect;
2879 ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
2880 lpFrameInfo->fMDIApp = FALSE;
2881 lpFrameInfo->hwndFrame = container_hwnd;
2882 lpFrameInfo->haccel = NULL;
2883 lpFrameInfo->cAccelEntries = 0;
2885 return S_OK;
2888 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
2890 return E_NOTIMPL;
2893 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
2895 return S_OK;
2898 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
2900 return S_OK;
2903 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
2905 return E_NOTIMPL;
2908 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
2910 return E_NOTIMPL;
2913 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
2915 return E_NOTIMPL;
2918 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
2919 InPlaceSite_QueryInterface,
2920 InPlaceSite_AddRef,
2921 InPlaceSite_Release,
2922 InPlaceSite_GetWindow,
2923 InPlaceSite_ContextSensitiveHelp,
2924 InPlaceSite_CanInPlaceActivate,
2925 InPlaceSite_OnInPlaceActivate,
2926 InPlaceSite_OnUIActivate,
2927 InPlaceSite_GetWindowContext,
2928 InPlaceSite_Scroll,
2929 InPlaceSite_OnUIDeactivate,
2930 InPlaceSite_OnInPlaceDeactivate,
2931 InPlaceSite_DiscardUndoState,
2932 InPlaceSite_DeactivateAndUndo,
2933 InPlaceSite_OnPosRectChange,
2936 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
2938 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
2940 return QueryInterface(riid, ppv);
2943 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
2945 return 2;
2948 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
2950 return 1;
2953 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
2955 ok(0, "unexpected call\n");
2956 return E_NOTIMPL;
2959 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
2960 IMoniker **ppmon)
2962 ok(0, "unexpected call\n");
2963 return E_NOTIMPL;
2966 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
2968 return E_NOTIMPL;
2971 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
2973 ok(0, "unexpected call\n");
2974 return E_NOTIMPL;
2977 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
2979 ok(0, "unexpected call\n");
2980 return E_NOTIMPL;
2983 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
2985 ok(0, "unexpected call\n");
2986 return E_NOTIMPL;
2989 static const IOleClientSiteVtbl ClientSiteVtbl = {
2990 ClientSite_QueryInterface,
2991 ClientSite_AddRef,
2992 ClientSite_Release,
2993 ClientSite_SaveObject,
2994 ClientSite_GetMoniker,
2995 ClientSite_GetContainer,
2996 ClientSite_ShowObject,
2997 ClientSite_OnShowWindow,
2998 ClientSite_RequestNewObjectLayout
3001 static IOleClientSite ClientSite = { &ClientSiteVtbl };
3003 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
3005 return QueryInterface(riid, ppv);
3008 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
3010 return 2;
3013 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
3015 return 1;
3018 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
3020 RECT rect = {0,0,300,300};
3021 IOleDocument *document;
3022 HRESULT hres;
3024 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
3025 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
3027 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
3028 IOleDocument_Release(document);
3029 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
3031 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
3032 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
3034 hres = IOleDocumentView_UIActivate(view, TRUE);
3035 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
3037 hres = IOleDocumentView_SetRect(view, &rect);
3038 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
3040 hres = IOleDocumentView_Show(view, TRUE);
3041 ok(hres == S_OK, "Show failed: %08x\n", hres);
3043 return S_OK;
3046 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
3047 DocumentSite_QueryInterface,
3048 DocumentSite_AddRef,
3049 DocumentSite_Release,
3050 DocumentSite_ActivateMe
3053 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
3055 static HRESULT QueryInterface(REFIID riid, void **ppv)
3057 *ppv = NULL;
3059 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
3060 *ppv = &ClientSite;
3061 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
3062 *ppv = &DocumentSite;
3063 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
3064 *ppv = &InPlaceSite;
3066 return *ppv ? S_OK : E_NOINTERFACE;
3069 static IHTMLDocument2 *notif_doc;
3070 static BOOL doc_complete;
3072 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
3073 REFIID riid, void**ppv)
3075 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
3076 *ppv = iface;
3077 return S_OK;
3080 ok(0, "unexpected call\n");
3081 return E_NOINTERFACE;
3084 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
3086 return 2;
3089 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
3091 return 1;
3094 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
3096 if(dispID == DISPID_READYSTATE){
3097 BSTR state;
3098 HRESULT hres;
3100 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
3101 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
3103 if(!strcmp_wa(state, "complete"))
3104 doc_complete = TRUE;
3106 SysFreeString(state);
3109 return S_OK;
3112 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
3114 ok(0, "unexpected call\n");
3115 return E_NOTIMPL;
3118 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
3119 PropertyNotifySink_QueryInterface,
3120 PropertyNotifySink_AddRef,
3121 PropertyNotifySink_Release,
3122 PropertyNotifySink_OnChanged,
3123 PropertyNotifySink_OnRequestEdit
3126 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
3128 static void doc_load_string(IHTMLDocument2 *doc, const char *str)
3130 IPersistStreamInit *init;
3131 IStream *stream;
3132 HGLOBAL mem;
3133 SIZE_T len;
3135 notif_doc = doc;
3137 doc_complete = FALSE;
3138 len = strlen(str);
3139 mem = GlobalAlloc(0, len);
3140 memcpy(mem, str, len);
3141 CreateStreamOnHGlobal(mem, TRUE, &stream);
3143 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
3145 IPersistStreamInit_Load(init, stream);
3146 IPersistStreamInit_Release(init);
3147 IStream_Release(stream);
3150 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
3152 IConnectionPointContainer *container;
3153 IConnectionPoint *cp;
3154 DWORD cookie;
3155 HRESULT hres;
3157 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
3158 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
3160 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
3161 IConnectionPointContainer_Release(container);
3162 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
3164 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
3165 IConnectionPoint_Release(cp);
3166 ok(hres == S_OK, "Advise failed: %08x\n", hres);
3169 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
3171 IOleObject *oleobj;
3172 HRESULT hres;
3174 if(!set && view) {
3175 IOleDocumentView_Show(view, FALSE);
3176 IOleDocumentView_CloseView(view, 0);
3177 IOleDocumentView_SetInPlaceSite(view, NULL);
3178 IOleDocumentView_Release(view);
3179 view = NULL;
3182 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
3183 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
3185 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
3186 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
3188 if(set) {
3189 IHlinkTarget *hlink;
3191 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
3192 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
3194 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
3195 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
3197 IHlinkTarget_Release(hlink);
3200 IOleObject_Release(oleobj);
3202 static IHTMLDocument2 *create_document(void)
3204 IHTMLDocument2 *doc;
3205 HRESULT hres;
3207 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
3208 &IID_IHTMLDocument2, (void**)&doc);
3209 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
3210 return SUCCEEDED(hres) ? doc : NULL;
3214 typedef void (*testfunc_t)(IHTMLDocument2*);
3216 static void run_test(const char *str, testfunc_t test)
3218 IHTMLDocument2 *doc;
3219 IHTMLElement *body = NULL;
3220 MSG msg;
3221 HRESULT hres;
3223 doc = create_document();
3224 if (!doc)
3225 return;
3226 set_client_site(doc, TRUE);
3227 doc_load_string(doc, str);
3228 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3230 while(!doc_complete && GetMessageA(&msg, NULL, 0, 0)) {
3231 TranslateMessage(&msg);
3232 DispatchMessageA(&msg);
3235 hres = IHTMLDocument2_get_body(doc, &body);
3236 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3238 if(body) {
3239 IHTMLDocument6 *doc6;
3241 IHTMLElement_Release(body);
3243 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6);
3244 if(SUCCEEDED(hres)) {
3245 VARIANT v;
3246 hres = IHTMLDocument6_get_documentMode(doc6, &v);
3247 ok(hres == S_OK, "get_documentMode failed: %08x\n", hres);
3248 ok(V_VT(&v) == VT_R4, "V_VT(documentMode) = %u\n", V_VT(&v));
3249 document_mode = V_R4(&v);
3250 IHTMLDocument6_Release(doc6);
3251 }else {
3252 document_mode = 0;
3255 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3256 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3257 ok(window != NULL, "window == NULL\n");
3259 test(doc);
3261 IHTMLWindow2_Release(window);
3262 window = NULL;
3263 }else {
3264 skip("Could not get document body. Assuming no Gecko installed.\n");
3267 set_client_site(doc, FALSE);
3268 IHTMLDocument2_Release(doc);
3271 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3273 return DefWindowProcA(hwnd, msg, wParam, lParam);
3276 static HWND create_container_window(void)
3278 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
3279 static WNDCLASSEXA wndclass = {
3280 sizeof(WNDCLASSEXA),
3282 wnd_proc,
3283 0, 0, NULL, NULL, NULL, NULL, NULL,
3284 szHTMLDocumentTest,
3285 NULL
3288 RegisterClassExA(&wndclass);
3289 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
3290 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
3291 300, 300, NULL, NULL, NULL, NULL);
3294 static void test_empty_document(void)
3296 HRESULT hres;
3297 IHTMLWindow2 *window;
3298 IHTMLDocument2 *windows_doc, *doc;
3299 IConnectionPoint *cp;
3300 DWORD cookie;
3302 doc = create_document();
3303 if(!doc)
3304 return;
3306 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3307 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3309 hres = IHTMLWindow2_get_document(window, &windows_doc);
3310 IHTMLWindow2_Release(window);
3311 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3313 cookie = register_cp((IUnknown*)windows_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
3315 cp = get_cp((IUnknown*)doc, &IID_IDispatch);
3316 hres = IConnectionPoint_Unadvise(cp, cookie);
3317 IConnectionPoint_Release(cp);
3318 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
3320 IHTMLDocument2_Release(windows_doc);
3321 IHTMLDocument2_Release(doc);
3324 static BOOL check_ie(void)
3326 IHTMLDocument2 *doc;
3327 IHTMLDocument5 *doc5;
3328 IHTMLDocument7 *doc7;
3329 HRESULT hres;
3331 doc = create_document();
3332 if(!doc)
3333 return FALSE;
3335 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument7, (void**)&doc7);
3336 if(SUCCEEDED(hres)) {
3337 is_ie9plus = TRUE;
3338 IHTMLDocument7_Release(doc7);
3341 trace("is_ie9plus %x\n", is_ie9plus);
3343 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
3344 if(SUCCEEDED(hres))
3345 IHTMLDocument5_Release(doc5);
3347 IHTMLDocument2_Release(doc);
3348 return SUCCEEDED(hres);
3351 START_TEST(events)
3353 CoInitialize(NULL);
3355 if(check_ie()) {
3356 container_hwnd = create_container_window();
3358 if(winetest_interactive)
3359 ShowWindow(container_hwnd, SW_SHOW);
3361 run_test(empty_doc_str, test_timeout);
3362 run_test(empty_doc_str, test_onclick);
3363 run_test(empty_doc_ie9_str, test_onclick);
3364 run_test(readystate_doc_str, test_onreadystatechange);
3365 run_test(readystate_doc_ie9_str, test_onreadystatechange);
3366 run_test(img_doc_str, test_imgload);
3367 run_test(link_doc_str, test_link_load);
3368 run_test(input_doc_str, test_focus);
3369 run_test(empty_doc_str, test_submit);
3370 run_test(empty_doc_ie9_str, test_submit);
3371 run_test(iframe_doc_str, test_iframe_connections);
3372 if(is_ie9plus)
3373 run_test(empty_doc_ie9_str, test_create_event);
3375 test_empty_document();
3377 DestroyWindow(container_hwnd);
3378 }else {
3379 win_skip("Too old IE\n");
3382 CoUninitialize();