wined3d: Add AMD Radeon HD 6480G IGP.
[wine.git] / dlls / mshtml / tests / events.c
blob2bd85fcd1e70b1530825a28651220c2226d74e08
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(timeout);
66 DEFINE_EXPECT(doccp_onclick);
67 DEFINE_EXPECT(doccp_onclick_cancel);
68 DEFINE_EXPECT(div_onclick_disp);
69 DEFINE_EXPECT(invoke_onclick);
70 DEFINE_EXPECT(iframe_onreadystatechange_loading);
71 DEFINE_EXPECT(iframe_onreadystatechange_interactive);
72 DEFINE_EXPECT(iframe_onreadystatechange_complete);
73 DEFINE_EXPECT(iframedoc_onreadystatechange);
74 DEFINE_EXPECT(img_onload);
75 DEFINE_EXPECT(img_onerror);
76 DEFINE_EXPECT(link_onload);
77 DEFINE_EXPECT(input_onfocus);
78 DEFINE_EXPECT(input_onblur);
79 DEFINE_EXPECT(div_onfocusin);
80 DEFINE_EXPECT(div_onfocusout);
81 DEFINE_EXPECT(form_onsubmit);
82 DEFINE_EXPECT(form_onclick);
83 DEFINE_EXPECT(submit_onclick);
84 DEFINE_EXPECT(submit_onclick_cancel);
85 DEFINE_EXPECT(submit_onclick_attached);
86 DEFINE_EXPECT(submit_onclick_attached_check_cancel);
87 DEFINE_EXPECT(submit_onclick_setret);
88 DEFINE_EXPECT(elem2_cp_onclick);
89 DEFINE_EXPECT(iframe_onload);
91 static HWND container_hwnd = NULL;
92 static IHTMLWindow2 *window;
93 static IOleDocumentView *view;
94 static BOOL is_ie9plus;
96 typedef struct {
97 LONG x;
98 LONG y;
99 LONG offset_x;
100 LONG offset_y;
101 } xy_test_t;
103 static const xy_test_t no_xy = {-10,-10,-10,-10};
105 static const char empty_doc_str[] =
106 "<html></html>";
108 static const char click_doc_str[] =
109 "<html><body>"
110 "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
111 "</body></html>";
113 static const char readystate_doc_str[] =
114 "<html><body><iframe id=\"iframe\"></iframe></body></html>";
116 static const char img_doc_str[] =
117 "<html><body><img id=\"imgid\"></img></body></html>";
119 static const char link_doc_str[] =
120 "<html><body><link id=\"linkid\" rel=\"stylesheet\" type=\"text/css\"></link></body></html>";
122 static const char input_doc_str[] =
123 "<html><body><div id=\"divid\"><input id=\"inputid\"></input></div></body></html>";
125 static const char iframe_doc_str[] =
126 "<html><body><iframe id=\"ifr\">Testing</iframe></body></html>";
128 static const char form_doc_str[] =
129 "<html><body><form id=\"formid\" method=\"post\" action=\"about:blank\">"
130 "<input type=\"text\" value=\"test\" name=\"i\"/>"
131 "<input type=\"submit\" id=\"submitid\" />"
132 "</form></body></html>";
134 static int strcmp_wa(LPCWSTR strw, const char *stra)
136 CHAR buf[512];
137 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
138 return lstrcmpA(stra, buf);
141 static BSTR a2bstr(const char *str)
143 BSTR ret;
144 int len;
146 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
147 ret = SysAllocStringLen(NULL, len-1);
148 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
150 return ret;
153 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
155 IUnknown *unk1, *unk2;
157 if(iface1 == iface2)
158 return TRUE;
160 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
161 IUnknown_Release(unk1);
162 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
163 IUnknown_Release(unk2);
165 return unk1 == unk2;
168 #define test_disp(u,id) _test_disp(__LINE__,u,id)
169 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
171 IDispatchEx *dispex;
172 ITypeInfo *typeinfo;
173 UINT ticnt;
174 HRESULT hres;
176 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
177 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
178 if(FAILED(hres))
179 return;
181 ticnt = 0xdeadbeef;
182 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
183 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
184 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
186 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
187 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
189 if(SUCCEEDED(hres)) {
190 TYPEATTR *type_attr;
192 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
193 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
194 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
195 wine_dbgstr_guid(&type_attr->guid));
197 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
198 ITypeInfo_Release(typeinfo);
201 IDispatchEx_Release(dispex);
204 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
205 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
207 IHTMLDocument3 *doc3;
208 HRESULT hres;
210 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
211 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
213 return doc3;
216 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
217 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
219 IHTMLElement *elem;
220 HRESULT hres;
222 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
223 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
225 return elem;
228 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
229 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
231 IHTMLElement2 *elem2;
232 HRESULT hres;
234 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
235 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
237 return elem2;
240 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
241 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
243 IHTMLElement3 *elem3;
244 HRESULT hres;
246 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
247 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
249 return elem3;
252 #define get_elem4_iface(u) _get_elem4_iface(__LINE__,u)
253 static IHTMLElement4 *_get_elem4_iface(unsigned line, IUnknown *unk)
255 IHTMLElement4 *elem4;
256 HRESULT hres;
258 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement4, (void**)&elem4);
259 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement4 iface: %08x\n", hres);
261 return elem4;
264 #define get_iframe_iface(u) _get_iframe_iface(__LINE__,u)
265 static IHTMLIFrameElement *_get_iframe_iface(unsigned line, IUnknown *unk)
267 IHTMLIFrameElement *iframe;
268 HRESULT hres;
270 hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement, (void**)&iframe);
271 ok_(__FILE__,line)(hres == S_OK, "QueryInterface(IID_IHTMLIFrameElement) failed: %08x\n", hres);
273 return iframe;
276 #define doc_get_body(d) _doc_get_body(__LINE__,d)
277 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
279 IHTMLElement *body = NULL;
280 HRESULT hres;
282 hres = IHTMLDocument2_get_body(doc, &body);
283 ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
284 ok_(__FILE__,line) (body != NULL, "body == NULL\n");
286 return body;
289 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
290 static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
292 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
293 IHTMLElement *elem;
294 BSTR str;
295 HRESULT hres;
297 str = a2bstr(id);
298 hres = IHTMLDocument3_getElementById(doc3, str, &elem);
299 SysFreeString(str);
300 IHTMLDocument3_Release(doc3);
301 ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
302 ok_(__FILE__,line) (elem != NULL, "elem == NULL\n");
304 return elem;
307 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
308 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
310 IHTMLElement *elem = _get_elem_iface(line, unk);
311 BSTR tag;
312 HRESULT hres;
314 hres = IHTMLElement_get_tagName(elem, &tag);
315 IHTMLElement_Release(elem);
316 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
317 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
319 SysFreeString(tag);
322 #define get_event_obj() _get_event_obj(__LINE__)
323 static IHTMLEventObj *_get_event_obj(unsigned line)
325 IHTMLEventObj *event = NULL;
326 HRESULT hres;
328 hres = IHTMLWindow2_get_event(window, &event);
329 ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
330 ok_(__FILE__,line) (event != NULL, "event = NULL\n");
331 _test_disp(line, (IUnknown*)event, &DIID_DispCEventObj);
333 return event;
336 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
337 static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
339 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
340 VARIANT_BOOL b;
341 BSTR str;
342 HRESULT hres;
344 b = 100;
345 str = a2bstr(event);
346 hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
347 SysFreeString(str);
348 ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
349 ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
352 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
353 static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
354 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
356 ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
357 ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
358 ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
359 ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
360 ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
361 ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
362 pdp->rgdispidNamedArgs[0]);
363 ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
364 ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
365 ok_(__FILE__,line) (pei != NULL, "pei == NULL");
366 ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
368 if(dispiid)
369 _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
372 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
373 static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
374 VARIANT *pvarRes, EXCEPINFO *pei)
376 IHTMLEventObj *event;
378 ok(id == DISPID_VALUE, "id = %d\n", id);
379 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
380 ok(pdp != NULL, "pDispParams == NULL\n");
381 ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
382 ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
383 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
384 ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
385 ok(pvarRes != NULL, "pvarRes = NULL\n");
386 ok(pei != NULL, "pei = NULL\n");
387 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
388 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
389 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
391 event = _get_event_obj(line);
392 ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
393 IHTMLEventObj_Release(event);
396 #define get_event_src() _get_event_src(__LINE__)
397 static IHTMLElement *_get_event_src(unsigned line)
399 IHTMLEventObj *event = _get_event_obj(line);
400 IHTMLElement *src_elem = NULL;
401 HRESULT hres;
403 hres = IHTMLEventObj_get_srcElement(event, &src_elem);
404 IHTMLEventObj_Release(event);
405 ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
407 return src_elem;
410 #define test_event_src(t) _test_event_src(__LINE__,t)
411 static void _test_event_src(unsigned line, const char *src_tag)
413 IHTMLElement *src_elem = _get_event_src(line);
415 if(src_tag) {
416 ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
417 _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
418 IHTMLElement_Release(src_elem);
419 }else {
420 ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
424 static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
426 VARIANT_BOOL b;
427 HRESULT hres;
429 hres = IHTMLEventObj_get_altKey(event, &b);
430 ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
431 ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
434 static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
436 VARIANT_BOOL b;
437 HRESULT hres;
439 hres = IHTMLEventObj_get_ctrlKey(event, &b);
440 ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
441 ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
444 static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
446 VARIANT_BOOL b;
447 HRESULT hres;
449 hres = IHTMLEventObj_get_shiftKey(event, &b);
450 ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
451 ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
454 #define test_event_cancelbubble(a,b) _test_event_cancelbubble(__LINE__,a,b)
455 static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
457 VARIANT_BOOL b;
458 HRESULT hres;
460 hres = IHTMLEventObj_get_cancelBubble(event, &b);
461 ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
462 ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
465 static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
467 IHTMLElement *elem;
468 HRESULT hres;
470 hres = IHTMLEventObj_get_fromElement(event, &elem);
471 ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
472 if(from_tag)
473 _test_elem_tag(line, (IUnknown*)elem, from_tag);
474 else
475 ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
476 if(elem)
477 IHTMLElement_Release(elem);
480 static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
482 IHTMLElement *elem;
483 HRESULT hres;
485 hres = IHTMLEventObj_get_toElement(event, &elem);
486 ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
487 if(to_tag)
488 _test_elem_tag(line, (IUnknown*)elem, to_tag);
489 else
490 ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
491 if(elem)
492 IHTMLElement_Release(elem);
495 static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
497 LONG l;
498 HRESULT hres;
500 hres = IHTMLEventObj_get_keyCode(event, &l);
501 ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
502 ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
505 static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
507 LONG l;
508 HRESULT hres;
510 hres = IHTMLEventObj_get_button(event, &l);
511 ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
512 ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
515 static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
517 LONG l;
518 HRESULT hres;
520 hres = IHTMLEventObj_get_reason(event, &l);
521 ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
522 ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
525 static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
527 LONG l;
528 HRESULT hres;
530 hres = IHTMLEventObj_get_x(event, &l);
531 ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
532 if(exl != -10) /* don't test the exact value */
533 ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
536 static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
538 LONG l;
539 HRESULT hres;
541 hres = IHTMLEventObj_get_y(event, &l);
542 ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
543 if(exl != -10) /* don't test the exact value */
544 ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
547 static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
549 LONG l;
550 HRESULT hres;
552 hres = IHTMLEventObj_get_clientX(event, &l);
553 ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
554 if(exl != -10) /* don't test the exact value */
555 ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
558 static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
560 LONG l;
561 HRESULT hres;
563 hres = IHTMLEventObj_get_clientY(event, &l);
564 ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
565 if(exl != -10) /* don't test the exact value */
566 ok_(__FILE__,line)(l == exl, "clientY = %d, expected %d\n", l, exl);
569 static void _test_event_offsetx(unsigned line, IHTMLEventObj *event, LONG exl)
571 LONG l;
572 HRESULT hres;
574 hres = IHTMLEventObj_get_offsetX(event, &l);
575 ok_(__FILE__,line)(hres == S_OK, "get_offsetX failed: %08x\n", hres);
576 if(exl != -10) /* don't test the exact value */
577 ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
580 static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
582 LONG l;
583 HRESULT hres;
585 hres = IHTMLEventObj_get_offsetY(event, &l);
586 ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
587 if(exl != -10) /* don't test the exact value */
588 ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
591 static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
593 LONG l;
594 HRESULT hres;
596 hres = IHTMLEventObj_get_screenX(event, &l);
597 ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
598 if(exl != -10) /* don't test the exact value */
599 ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
602 static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
604 LONG l;
605 HRESULT hres;
607 hres = IHTMLEventObj_get_screenY(event, &l);
608 ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
609 if(exl != -10) /* don't test the exact value for -10 */
610 ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
613 static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
615 BSTR str;
616 HRESULT hres;
618 hres = IHTMLEventObj_get_type(event, &str);
619 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
620 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
623 static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
625 BSTR str;
626 HRESULT hres;
628 hres = IHTMLEventObj_get_qualifier(event, &str);
629 ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
630 if(exstr)
631 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
632 else
633 ok_(__FILE__,line)(!str, "qualifier != NULL\n");
636 static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
638 IDispatch *disp;
639 HRESULT hres;
641 hres = IHTMLEventObj_get_srcFilter(event, &disp);
642 ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
643 ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
646 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
647 static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
649 IHTMLEventObj *event = _get_event_obj(line);
650 VARIANT v;
651 HRESULT hres;
653 _test_event_altkey(line, event, VARIANT_FALSE);
654 _test_event_ctrlkey(line, event, VARIANT_FALSE);
655 _test_event_shiftkey(line, event, VARIANT_FALSE);
656 _test_event_cancelbubble(line, event, VARIANT_FALSE);
657 _test_event_fromelem(line, event, NULL);
658 _test_event_toelem(line, event, NULL);
659 _test_event_keycode(line, event, 0);
660 _test_event_button(line, event, 0);
661 _test_event_type(line, event, type);
662 _test_event_qualifier(line, event, NULL);
663 _test_event_reason(line, event, 0);
664 _test_event_srcfilter(line, event);
665 _test_event_x(line, event, xy->x);
666 _test_event_y(line, event, xy->y);
667 _test_event_clientx(line, event, -10);
668 _test_event_clienty(line, event, -10);
669 _test_event_offsetx(line, event, xy->offset_x);
670 _test_event_offsety(line, event, xy->offset_y);
671 _test_event_screenx(line, event, -10);
672 _test_event_screeny(line, event, -10);
674 V_VT(&v) = VT_NULL;
675 hres = IHTMLEventObj_get_returnValue(event, &v);
676 ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
677 ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
679 IHTMLEventObj_Release(event);
682 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
683 static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
685 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
686 VARIANT_BOOL res;
687 BSTR name;
688 HRESULT hres;
690 name = a2bstr(namea);
691 hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
692 IHTMLElement2_Release(elem);
693 SysFreeString(name);
694 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
695 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
698 #define elem_detach_event(a,b,c) _elem_detach_event(__LINE__,a,b,c)
699 static void _elem_detach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
701 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
702 BSTR name;
703 HRESULT hres;
705 name = a2bstr(namea);
706 hres = IHTMLElement2_detachEvent(elem, name, disp);
707 IHTMLElement2_Release(elem);
708 SysFreeString(name);
709 ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
712 #define doc_attach_event(a,b,c) _doc_attach_event(__LINE__,a,b,c)
713 static void _doc_attach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
715 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
716 VARIANT_BOOL res;
717 BSTR name;
718 HRESULT hres;
720 name = a2bstr(namea);
721 hres = IHTMLDocument3_attachEvent(doc3, name, disp, &res);
722 IHTMLDocument3_Release(doc3);
723 SysFreeString(name);
724 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
725 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
728 #define doc_detach_event(a,b,c) _doc_detach_event(__LINE__,a,b,c)
729 static void _doc_detach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
731 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
732 BSTR name;
733 HRESULT hres;
735 name = a2bstr(namea);
736 hres = IHTMLDocument3_detachEvent(doc3, name, disp);
737 IHTMLDocument3_Release(doc3);
738 SysFreeString(name);
739 ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
742 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
744 *ppv = NULL;
746 if(IsEqualGUID(riid, &IID_IUnknown)
747 || IsEqualGUID(riid, &IID_IDispatch)
748 || IsEqualGUID(riid, &IID_IDispatchEx))
749 *ppv = iface;
750 else {
751 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
752 return E_NOINTERFACE;
755 return S_OK;
758 static HRESULT WINAPI Dispatch_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
760 *ppv = NULL;
762 if(IsEqualGUID(riid, &IID_IUnknown)
763 || IsEqualGUID(riid, &IID_IDispatch)) {
764 *ppv = iface;
765 }else if(IsEqualGUID(riid, &IID_IDispatchEx)) {
766 return E_NOINTERFACE;
767 }else {
768 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
769 return E_NOINTERFACE;
772 return S_OK;
775 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
777 return 2;
780 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
782 return 1;
785 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
787 ok(0, "unexpected call\n");
788 return E_NOTIMPL;
791 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
792 LCID lcid, ITypeInfo **ppTInfo)
794 ok(0, "unexpected call\n");
795 return E_NOTIMPL;
798 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
799 LPOLESTR *rgszNames, UINT cNames,
800 LCID lcid, DISPID *rgDispId)
802 ok(0, "unexpected call\n");
803 return E_NOTIMPL;
806 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
807 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
808 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
810 ok(0, "unexpected call\n");
811 return E_NOTIMPL;
814 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
816 ok(0, "unexpected call\n");
817 return E_NOTIMPL;
820 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
821 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
823 ok(0, "unexpected call\n");
824 return E_NOTIMPL;
827 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
829 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
830 return E_NOTIMPL;
833 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
835 ok(0, "unexpected call\n");
836 return E_NOTIMPL;
839 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
841 ok(0, "unexpected call\n");
842 return E_NOTIMPL;
845 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
847 ok(0, "unexpected call\n");
848 return E_NOTIMPL;
851 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
853 ok(0, "unexpected call\n");
854 return E_NOTIMPL;
857 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
859 ok(0, "unexpected call\n");
860 return E_NOTIMPL;
863 #define EVENT_HANDLER_FUNC_OBJ(event) \
864 static IDispatchExVtbl event ## FuncVtbl = { \
865 DispatchEx_QueryInterface, \
866 DispatchEx_AddRef, \
867 DispatchEx_Release, \
868 DispatchEx_GetTypeInfoCount, \
869 DispatchEx_GetTypeInfo, \
870 DispatchEx_GetIDsOfNames, \
871 DispatchEx_Invoke, \
872 DispatchEx_GetDispID, \
873 event, \
874 DispatchEx_DeleteMemberByName, \
875 DispatchEx_DeleteMemberByDispID, \
876 DispatchEx_GetMemberProperties, \
877 DispatchEx_GetMemberName, \
878 DispatchEx_GetNextDispID, \
879 DispatchEx_GetNameSpaceParent \
880 }; \
881 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
883 static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
884 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
886 IHTMLDocument3 *doc3;
887 CHECK_EXPECT(document_onclick);
888 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
889 doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
890 IHTMLDocument3_Release(doc3);
891 test_event_src("DIV");
892 test_event_obj("click", &no_xy);
893 return S_OK;
896 EVENT_HANDLER_FUNC_OBJ(document_onclick);
898 static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
899 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
901 CHECK_EXPECT(div_onclick);
902 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
903 test_event_src("DIV");
904 return S_OK;
907 EVENT_HANDLER_FUNC_OBJ(div_onclick);
909 static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
910 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
912 CHECK_EXPECT(div_onclick_attached);
914 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
915 test_event_src("DIV");
916 return S_OK;
919 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
921 static HRESULT WINAPI doc_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
922 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
924 CHECK_EXPECT(doc_onclick_attached);
926 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
927 test_event_src("DIV");
928 return S_OK;
931 EVENT_HANDLER_FUNC_OBJ(doc_onclick_attached);
933 static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
934 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
936 CHECK_EXPECT(body_onclick);
937 test_event_args(&DIID_DispHTMLBody, id, wFlags, pdp, pvarRes, pei, pspCaller);
938 test_event_src("DIV");
939 return S_OK;
942 EVENT_HANDLER_FUNC_OBJ(body_onclick);
944 static HRESULT WINAPI img_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
945 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
947 CHECK_EXPECT(img_onload);
948 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
949 test_event_src("IMG");
950 return S_OK;
953 EVENT_HANDLER_FUNC_OBJ(img_onload);
955 static HRESULT WINAPI link_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
956 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
958 CHECK_EXPECT(link_onload);
959 test_event_args(&DIID_DispHTMLLinkElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
960 test_event_src("LINK");
961 return S_OK;
964 EVENT_HANDLER_FUNC_OBJ(link_onload);
966 static HRESULT WINAPI unattached_img_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
967 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
969 IHTMLElement *event_src;
971 CHECK_EXPECT(img_onload);
973 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
974 event_src = get_event_src();
975 todo_wine
976 ok(!event_src, "event_src != NULL\n");
977 if(event_src)
978 IHTMLElement_Release(event_src);
979 return S_OK;
982 EVENT_HANDLER_FUNC_OBJ(unattached_img_onload);
984 static HRESULT WINAPI img_onerror(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
985 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
987 CHECK_EXPECT(img_onerror);
988 test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
989 test_event_src("IMG");
990 return S_OK;
993 EVENT_HANDLER_FUNC_OBJ(img_onerror);
995 static HRESULT WINAPI input_onfocus(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
996 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
998 CHECK_EXPECT(input_onfocus);
999 test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
1000 test_event_src("INPUT");
1001 return S_OK;
1004 EVENT_HANDLER_FUNC_OBJ(input_onfocus);
1006 static HRESULT WINAPI div_onfocusin(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1007 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1009 CHECK_EXPECT(div_onfocusin);
1010 test_event_args(NULL /* FIXME: &DIID_DispHTMLDivElement */, id, wFlags, pdp, pvarRes, pei, pspCaller);
1011 test_event_src("INPUT");
1012 return S_OK;
1015 EVENT_HANDLER_FUNC_OBJ(div_onfocusin);
1017 static HRESULT WINAPI div_onfocusout(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1018 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1020 CHECK_EXPECT(div_onfocusout);
1021 test_event_args(NULL /* FIXME: &DIID_DispHTMLDivElement */, id, wFlags, pdp, pvarRes, pei, pspCaller);
1022 test_event_src("INPUT");
1023 return S_OK;
1026 EVENT_HANDLER_FUNC_OBJ(div_onfocusout);
1028 static HRESULT WINAPI input_onblur(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1029 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1031 CHECK_EXPECT(input_onblur);
1032 test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
1033 test_event_src("INPUT");
1034 return S_OK;
1037 EVENT_HANDLER_FUNC_OBJ(input_onblur);
1039 static HRESULT WINAPI form_onsubmit(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1040 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1042 CHECK_EXPECT(form_onsubmit);
1043 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1044 test_event_src("FORM");
1046 V_VT(pvarRes) = VT_BOOL;
1047 V_BOOL(pvarRes) = VARIANT_FALSE;
1048 return S_OK;
1051 EVENT_HANDLER_FUNC_OBJ(form_onsubmit);
1053 static HRESULT WINAPI form_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1054 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1056 CHECK_EXPECT(form_onclick);
1057 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1059 return S_OK;
1062 EVENT_HANDLER_FUNC_OBJ(form_onclick);
1064 static HRESULT WINAPI submit_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1065 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1067 CHECK_EXPECT(submit_onclick);
1068 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1069 test_event_src("INPUT");
1071 V_VT(pvarRes) = VT_BOOL;
1072 V_BOOL(pvarRes) = VARIANT_FALSE;
1073 return S_OK;
1076 EVENT_HANDLER_FUNC_OBJ(submit_onclick);
1078 static HRESULT WINAPI iframe_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1079 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1081 CHECK_EXPECT(iframe_onload);
1082 test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
1083 test_event_src("IFRAME");
1084 return S_OK;
1087 EVENT_HANDLER_FUNC_OBJ(iframe_onload);
1089 static HRESULT WINAPI submit_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1090 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1092 CHECK_EXPECT(submit_onclick_attached);
1093 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1094 test_event_src("INPUT");
1096 V_VT(pvarRes) = VT_BOOL;
1097 V_BOOL(pvarRes) = VARIANT_FALSE;
1098 return S_OK;
1101 EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached);
1103 static HRESULT WINAPI submit_onclick_attached_check_cancel(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1104 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1106 IHTMLEventObj *event;
1107 HRESULT hres;
1109 CHECK_EXPECT(submit_onclick_attached_check_cancel);
1110 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1111 test_event_src("INPUT");
1113 event = NULL;
1114 hres = IHTMLWindow2_get_event(window, &event);
1115 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1116 ok(event != NULL, "event == NULL\n");
1118 test_event_cancelbubble(event, VARIANT_TRUE);
1119 return S_OK;
1122 EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached_check_cancel);
1124 static VARIANT onclick_retval, onclick_event_retval;
1126 static HRESULT WINAPI submit_onclick_setret(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1127 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1129 IHTMLEventObj *event;
1130 VARIANT v;
1131 HRESULT hres;
1133 CHECK_EXPECT(submit_onclick_setret);
1134 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1135 test_event_src("INPUT");
1137 event = NULL;
1138 hres = IHTMLWindow2_get_event(window, &event);
1139 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1140 ok(event != NULL, "event == NULL\n");
1142 V_VT(&v) = VT_ERROR;
1143 hres = IHTMLEventObj_get_returnValue(event, &v);
1144 ok(hres == S_OK, "get_returnValue failed: %08x\n", hres);
1145 ok(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
1147 hres = IHTMLEventObj_put_returnValue(event, onclick_event_retval);
1148 ok(hres == S_OK, "put_returnValue failed: %08x\n", hres);
1150 V_VT(&v) = VT_ERROR;
1151 hres = IHTMLEventObj_get_returnValue(event, &v);
1152 ok(hres == S_OK, "get_returnValue failed: %08x\n", hres);
1153 ok(VarCmp(&v, &onclick_event_retval, 0, 0) == VARCMP_EQ, "unexpected returnValue\n");
1155 IHTMLEventObj_Release(event);
1156 *pvarRes = onclick_retval;
1157 return S_OK;
1160 EVENT_HANDLER_FUNC_OBJ(submit_onclick_setret);
1162 static HRESULT WINAPI submit_onclick_cancel(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1163 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1165 IHTMLEventObj *event;
1166 HRESULT hres;
1168 CHECK_EXPECT(submit_onclick_cancel);
1169 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1170 test_event_src("INPUT");
1172 event = NULL;
1173 hres = IHTMLWindow2_get_event(window, &event);
1174 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1175 ok(event != NULL, "event == NULL\n");
1177 test_event_cancelbubble(event, VARIANT_FALSE);
1179 hres = IHTMLEventObj_put_cancelBubble(event, VARIANT_TRUE);
1180 ok(hres == S_OK, "put_returnValue failed: %08x\n", hres);
1182 test_event_cancelbubble(event, VARIANT_TRUE);
1183 IHTMLEventObj_Release(event);
1184 return S_OK;
1187 EVENT_HANDLER_FUNC_OBJ(submit_onclick_cancel);
1189 static HRESULT WINAPI iframedoc_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1190 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1192 IHTMLEventObj *event = NULL;
1193 HRESULT hres;
1195 CHECK_EXPECT2(iframedoc_onreadystatechange);
1196 test_event_args(&DIID_DispHTMLDocument, id, wFlags, pdp, pvarRes, pei, pspCaller);
1198 event = (void*)0xdeadbeef;
1199 hres = IHTMLWindow2_get_event(window, &event);
1200 ok(hres == S_OK, "get_event failed: %08x\n", hres);
1201 ok(!event, "event = %p\n", event);
1203 return S_OK;
1206 EVENT_HANDLER_FUNC_OBJ(iframedoc_onreadystatechange);
1208 static HRESULT WINAPI iframe_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1209 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1211 IHTMLWindow2 *iframe_window;
1212 IHTMLDocument2 *iframe_doc;
1213 IHTMLFrameBase2 *iframe;
1214 IHTMLElement2 *elem2;
1215 IHTMLElement *elem;
1216 VARIANT v;
1217 BSTR str, str2;
1218 HRESULT hres;
1220 test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
1221 test_event_src("IFRAME");
1223 elem = get_event_src();
1224 elem2 = get_elem2_iface((IUnknown*)elem);
1225 IHTMLElement_Release(elem);
1227 V_VT(&v) = VT_EMPTY;
1228 hres = IHTMLElement2_get_readyState(elem2, &v);
1229 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1230 ok(V_VT(&v) == VT_BSTR, "V_VT(readyState) = %d\n", V_VT(&v));
1232 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase2, (void**)&iframe);
1233 IHTMLElement2_Release(elem2);
1234 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
1236 str = NULL;
1237 hres = IHTMLFrameBase2_get_readyState(iframe, &str);
1238 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1239 ok(str != NULL, "readyState == NULL\n");
1240 ok(!lstrcmpW(str, V_BSTR(&v)), "ready states differ\n");
1241 VariantClear(&v);
1243 hres = IHTMLFrameBase2_get_contentWindow(iframe, &iframe_window);
1244 ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
1246 hres = IHTMLWindow2_get_document(iframe_window, &iframe_doc);
1247 IHTMLWindow2_Release(iframe_window);
1248 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1250 hres = IHTMLDocument2_get_readyState(iframe_doc, &str2);
1251 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1252 ok(!lstrcmpW(str, str2), "unexpected document readyState %s\n", wine_dbgstr_w(str2));
1253 SysFreeString(str2);
1255 if(!strcmp_wa(str, "loading")) {
1256 CHECK_EXPECT(iframe_onreadystatechange_loading);
1258 V_VT(&v) = VT_DISPATCH;
1259 V_DISPATCH(&v) = (IDispatch*)&iframedoc_onreadystatechange_obj;
1260 hres = IHTMLDocument2_put_onreadystatechange(iframe_doc, v);
1261 ok(hres == S_OK, "put_onreadystatechange: %08x\n", hres);
1262 }else if(!strcmp_wa(str, "interactive"))
1263 CHECK_EXPECT(iframe_onreadystatechange_interactive);
1264 else if(!strcmp_wa(str, "complete"))
1265 CHECK_EXPECT(iframe_onreadystatechange_complete);
1266 else
1267 ok(0, "unexpected state %s\n", wine_dbgstr_w(str));
1269 SysFreeString(str);
1270 IHTMLDocument2_Release(iframe_doc);
1271 IHTMLFrameBase2_Release(iframe);
1272 return S_OK;
1275 EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange);
1277 static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1278 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1280 ok(0, "unexpected call\n");
1281 return S_OK;
1284 EVENT_HANDLER_FUNC_OBJ(nocall);
1286 #define CONNECTION_POINT_OBJ(cpname, diid) \
1287 static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
1289 *ppv = NULL; \
1290 if(IsEqualGUID(riid, &IID_IUnknown) \
1291 || IsEqualGUID(riid, &IID_IDispatch) \
1292 || IsEqualGUID(riid, &diid)) \
1293 *ppv = iface; \
1294 else { \
1295 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid)); \
1296 return E_NOINTERFACE; \
1298 return S_OK; \
1300 static IDispatchExVtbl cpname ## Vtbl = { \
1301 cpname ## _QueryInterface, \
1302 DispatchEx_AddRef, \
1303 DispatchEx_Release, \
1304 DispatchEx_GetTypeInfoCount, \
1305 DispatchEx_GetTypeInfo, \
1306 DispatchEx_GetIDsOfNames, \
1307 cpname, \
1308 DispatchEx_GetDispID, \
1309 DispatchEx_InvokeEx, \
1310 DispatchEx_DeleteMemberByName, \
1311 DispatchEx_DeleteMemberByDispID, \
1312 DispatchEx_GetMemberProperties, \
1313 DispatchEx_GetMemberName, \
1314 DispatchEx_GetNextDispID, \
1315 DispatchEx_GetNameSpaceParent \
1316 }; \
1317 static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
1319 #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
1320 static void _test_cp_args(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1322 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1323 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1324 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1325 ok_(__FILE__,line)(!dp->cArgs, "dp->cArgs = %d\n", dp->cArgs);
1326 ok_(__FILE__,line)(!dp->rgvarg, "dp->rgvarg = %p\n", dp->rgvarg);
1327 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1328 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1329 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1330 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1331 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1332 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1335 #define test_cp_eventarg(a,b,c,d,e,f) _test_cp_eventarg(__LINE__,a,b,c,d,e,f)
1336 static void _test_cp_eventarg(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1338 IHTMLEventObj *event;
1340 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1341 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1342 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1343 ok_(__FILE__,line)(dp->cArgs == 1, "dp->cArgs = %d\n", dp->cArgs);
1344 ok_(__FILE__,line)(dp->rgvarg != NULL, "dp->rgvarg = %p\n", dp->rgvarg);
1345 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1346 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1347 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1348 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1349 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1350 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1352 ok(V_VT(dp->rgvarg) == VT_DISPATCH, "V_VT(dp->rgvarg) = %d\n", V_VT(dp->rgvarg));
1353 ok(V_DISPATCH(dp->rgvarg) != NULL, "V_DISPATCH(dp->rgvarg) = %p\n", V_DISPATCH(dp->rgvarg));
1355 event = _get_event_obj(line);
1356 ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(dp->rgvarg)), "event != arg0\n");
1357 IHTMLEventObj_Release(event);
1360 static HRESULT WINAPI doccp(IDispatchEx *iface, DISPID dispIdMember,
1361 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1362 VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1364 switch(dispIdMember) {
1365 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1366 CHECK_EXPECT(doccp_onclick);
1367 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1368 break;
1369 default:
1370 ok(0, "unexpected call %d\n", dispIdMember);
1371 return E_NOTIMPL;
1374 return S_OK;
1377 CONNECTION_POINT_OBJ(doccp, DIID_HTMLDocumentEvents);
1379 static HRESULT WINAPI doccp_onclick_cancel(IDispatchEx *iface, DISPID dispIdMember,
1380 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1382 switch(dispIdMember) {
1383 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1384 CHECK_EXPECT(doccp_onclick_cancel);
1385 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1386 V_VT(pVarResult) = VT_BOOL;
1387 V_BOOL(pVarResult) = VARIANT_FALSE;
1388 break;
1389 default:
1390 ok(0, "unexpected call %d\n", dispIdMember);
1391 return E_NOTIMPL;
1394 return S_OK;
1397 CONNECTION_POINT_OBJ(doccp_onclick_cancel, DIID_HTMLDocumentEvents);
1399 static HRESULT WINAPI elem2_cp(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1400 WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1402 switch(dispIdMember) {
1403 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1404 CHECK_EXPECT(elem2_cp_onclick);
1405 test_cp_eventarg(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1406 break;
1407 default:
1408 ok(0, "unexpected call %d\n", dispIdMember);
1409 return E_NOTIMPL;
1412 return S_OK;
1415 CONNECTION_POINT_OBJ(elem2_cp, DIID_HTMLElementEvents2);
1417 static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1418 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1419 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1421 CHECK_EXPECT(timeout);
1423 ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
1424 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1425 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
1426 ok(!lcid, "lcid = %x\n", lcid);
1427 ok(pDispParams != NULL, "pDispParams == NULL\n");
1428 ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
1429 ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
1430 ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
1431 ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
1432 ok(pVarResult != NULL, "pVarResult = NULL\n");
1433 ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
1434 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1435 ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1437 return S_OK;
1440 static const IDispatchExVtbl timeoutFuncVtbl = {
1441 DispatchEx_QueryInterface,
1442 DispatchEx_AddRef,
1443 DispatchEx_Release,
1444 DispatchEx_GetTypeInfoCount,
1445 DispatchEx_GetTypeInfo,
1446 DispatchEx_GetIDsOfNames,
1447 timeoutFunc_Invoke,
1448 DispatchEx_GetDispID,
1449 DispatchEx_InvokeEx,
1450 DispatchEx_DeleteMemberByName,
1451 DispatchEx_DeleteMemberByDispID,
1452 DispatchEx_GetMemberProperties,
1453 DispatchEx_GetMemberName,
1454 DispatchEx_GetNextDispID,
1455 DispatchEx_GetNameSpaceParent
1458 static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
1460 static HRESULT WINAPI timeoutFunc2_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1461 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1462 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1464 ok(0, "unexpected call\n");
1465 return E_FAIL;
1468 static const IDispatchExVtbl timeoutFunc2Vtbl = {
1469 DispatchEx_QueryInterface,
1470 DispatchEx_AddRef,
1471 DispatchEx_Release,
1472 DispatchEx_GetTypeInfoCount,
1473 DispatchEx_GetTypeInfo,
1474 DispatchEx_GetIDsOfNames,
1475 timeoutFunc2_Invoke,
1476 DispatchEx_GetDispID,
1477 DispatchEx_InvokeEx,
1478 DispatchEx_DeleteMemberByName,
1479 DispatchEx_DeleteMemberByDispID,
1480 DispatchEx_GetMemberProperties,
1481 DispatchEx_GetMemberName,
1482 DispatchEx_GetNextDispID,
1483 DispatchEx_GetNameSpaceParent
1486 static IDispatchEx timeoutFunc2 = { &timeoutFunc2Vtbl };
1488 static HRESULT WINAPI div_onclick_disp_Invoke(IDispatchEx *iface, DISPID id,
1489 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1490 VARIANT *pvarRes, EXCEPINFO *pei, UINT *puArgErr)
1492 CHECK_EXPECT(div_onclick_disp);
1494 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1496 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1497 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1499 return S_OK;
1502 static const IDispatchExVtbl div_onclick_dispVtbl = {
1503 Dispatch_QueryInterface,
1504 DispatchEx_AddRef,
1505 DispatchEx_Release,
1506 DispatchEx_GetTypeInfoCount,
1507 DispatchEx_GetTypeInfo,
1508 DispatchEx_GetIDsOfNames,
1509 div_onclick_disp_Invoke,
1512 static IDispatchEx div_onclick_disp = { &div_onclick_dispVtbl };
1514 static void pump_msgs(BOOL *b)
1516 MSG msg;
1518 if(b) {
1519 while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
1520 TranslateMessage(&msg);
1521 DispatchMessageW(&msg);
1523 }else {
1524 while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
1525 TranslateMessage(&msg);
1526 DispatchMessageW(&msg);
1531 static IConnectionPoint *get_cp(IUnknown *unk, REFIID riid)
1533 IConnectionPointContainer *cp_container;
1534 IConnectionPoint *cp;
1535 HRESULT hres;
1537 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1538 ok(hres == S_OK, "Could not get IConnectionPointContainer: %08x\n", hres);
1540 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, riid, &cp);
1541 IConnectionPointContainer_Release(cp_container);
1542 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1544 return cp;
1547 static DWORD register_cp(IUnknown *unk, REFIID riid, IUnknown *sink)
1549 IConnectionPoint *cp;
1550 DWORD cookie;
1551 HRESULT hres;
1553 cp = get_cp(unk, riid);
1554 hres = IConnectionPoint_Advise(cp, sink, &cookie);
1555 IConnectionPoint_Release(cp);
1556 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1558 return cookie;
1561 static void unregister_cp(IUnknown *unk, REFIID riid, DWORD cookie)
1563 IConnectionPoint *cp;
1564 HRESULT hres;
1566 cp = get_cp(unk, riid);
1567 hres = IConnectionPoint_Unadvise(cp, cookie);
1568 IConnectionPoint_Release(cp);
1569 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
1572 static HRESULT WINAPI EventDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
1574 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
1575 *ppv = iface;
1576 return S_OK;
1579 ok(0, "Unexpected call\n");
1580 return E_NOINTERFACE;
1583 static DWORD WINAPI EventDispatch_AddRef(IDispatch *iface)
1585 return 2;
1588 static DWORD WINAPI EventDispatch_Release(IDispatch *iface)
1590 return 1;
1593 static HRESULT WINAPI EventDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
1595 ok(0, "Unexpected call\n");
1596 return E_NOTIMPL;
1599 static HRESULT WINAPI EventDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1601 ok(0, "Unexpected call\n");
1602 return E_NOTIMPL;
1605 static HRESULT WINAPI EventDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
1606 UINT cNames, LCID lcid, DISPID *rgDispId)
1608 ok(0, "Unexpected call\n");
1609 return E_NOTIMPL;
1612 static HRESULT WINAPI EventDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
1613 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1614 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1616 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1617 ok(pDispParams != NULL, "pDispParams == NULL\n");
1618 ok(pExcepInfo != NULL, "pExcepInfo == NULL\n");
1619 ok(puArgErr != NULL, "puArgErr == NULL\n");
1620 ok(V_VT(pVarResult) == 0, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1621 ok(wFlags == DISPATCH_METHOD, "wFlags = %d\n", wFlags);
1623 switch(dispIdMember) {
1624 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1625 CHECK_EXPECT2(invoke_onclick);
1626 break;
1627 case DISPID_HTMLDOCUMENTEVENTS2_ONPROPERTYCHANGE:
1628 case DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE:
1629 case 1027:
1630 case 1034:
1631 case 1037:
1632 case 1044:
1633 case 1045:
1634 case 1047:
1635 case 1048:
1636 case 1049:
1637 break; /* TODO */
1638 default:
1639 ok(0, "Unexpected call: %d\n", dispIdMember);
1642 return S_OK;
1645 static const IDispatchVtbl EventDispatchVtbl = {
1646 EventDispatch_QueryInterface,
1647 EventDispatch_AddRef,
1648 EventDispatch_Release,
1649 EventDispatch_GetTypeInfoCount,
1650 EventDispatch_GetTypeInfo,
1651 EventDispatch_GetIDsOfNames,
1652 EventDispatch_Invoke
1655 static IDispatch EventDispatch = { &EventDispatchVtbl };
1657 static void test_onclick(IHTMLDocument2 *doc)
1659 DWORD cp_cookie, elem2_cp_cookie;
1660 IHTMLElement *div, *body;
1661 VARIANT v;
1662 HRESULT hres;
1664 register_cp((IUnknown*)doc, &IID_IDispatch, (IUnknown*)&EventDispatch);
1666 div = get_elem_id(doc, "clickdiv");
1668 elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
1669 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
1671 V_VT(&v) = VT_EMPTY;
1672 hres = IHTMLElement_get_onclick(div, &v);
1673 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1674 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1676 V_VT(&v) = VT_EMPTY;
1677 hres = IHTMLElement_put_onclick(div, v);
1678 ok(hres == E_NOTIMPL, "put_onclick failed: %08x\n", hres);
1680 V_VT(&v) = VT_BSTR;
1681 V_BSTR(&v) = a2bstr("function();");
1682 hres = IHTMLElement_put_onclick(div, v);
1683 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1685 if(hres == S_OK) {
1686 V_VT(&v) = VT_EMPTY;
1687 hres = IHTMLElement_get_onclick(div, &v);
1688 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1689 ok(V_VT(&v) == VT_BSTR, "V_VT(onclick) = %d\n", V_VT(&v));
1690 ok(!strcmp_wa(V_BSTR(&v), "function();"), "V_BSTR(onclick) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
1692 VariantClear(&v);
1694 V_VT(&v) = VT_DISPATCH;
1695 V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
1696 hres = IHTMLElement_put_onclick(div, v);
1697 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1699 V_VT(&v) = VT_NULL;
1700 hres = IHTMLElement_put_ondblclick(div, v);
1701 ok(hres == S_OK, "put_ondblclick failed: %08x\n", hres);
1703 V_VT(&v) = VT_EMPTY;
1704 hres = IHTMLElement_get_onclick(div, &v);
1705 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1706 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1707 ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1708 VariantClear(&v);
1710 V_VT(&v) = VT_EMPTY;
1711 hres = IHTMLDocument2_get_onclick(doc, &v);
1712 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1713 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1715 V_VT(&v) = VT_DISPATCH;
1716 V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
1717 hres = IHTMLDocument2_put_onclick(doc, v);
1718 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1720 V_VT(&v) = VT_EMPTY;
1721 hres = IHTMLDocument2_get_onclick(doc, &v);
1722 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1723 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1724 ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1725 VariantClear(&v);
1727 body = doc_get_body(doc);
1729 V_VT(&v) = VT_DISPATCH;
1730 V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
1731 hres = IHTMLElement_put_onclick(body, v);
1732 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1734 if(winetest_interactive) {
1735 SET_EXPECT(div_onclick);
1736 SET_EXPECT(div_onclick_attached);
1737 SET_EXPECT(body_onclick);
1738 SET_EXPECT(document_onclick);
1739 SET_EXPECT(invoke_onclick);
1740 pump_msgs(&called_document_onclick);
1741 CHECK_CALLED(div_onclick);
1742 CHECK_CALLED(div_onclick_attached);
1743 CHECK_CALLED(body_onclick);
1744 CHECK_CALLED(document_onclick);
1745 CHECK_CALLED(invoke_onclick);
1748 SET_EXPECT(div_onclick);
1749 SET_EXPECT(div_onclick_attached);
1750 SET_EXPECT(body_onclick);
1751 SET_EXPECT(document_onclick);
1752 SET_EXPECT(invoke_onclick);
1754 hres = IHTMLElement_click(div);
1755 ok(hres == S_OK, "click failed: %08x\n", hres);
1757 CHECK_CALLED(div_onclick);
1758 CHECK_CALLED(div_onclick_attached);
1759 CHECK_CALLED(body_onclick);
1760 CHECK_CALLED(document_onclick);
1761 CHECK_CALLED(invoke_onclick);
1763 SET_EXPECT(div_onclick);
1764 SET_EXPECT(div_onclick_attached);
1765 SET_EXPECT(body_onclick);
1766 SET_EXPECT(document_onclick);
1767 SET_EXPECT(invoke_onclick);
1769 V_VT(&v) = VT_EMPTY;
1770 elem_fire_event((IUnknown*)div, "onclick", &v);
1772 CHECK_CALLED(div_onclick);
1773 CHECK_CALLED(div_onclick_attached);
1774 CHECK_CALLED(body_onclick);
1775 CHECK_CALLED(document_onclick);
1776 CHECK_CALLED(invoke_onclick);
1778 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_obj);
1779 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1780 doc_attach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1782 SET_EXPECT(div_onclick);
1783 SET_EXPECT(div_onclick_disp);
1784 SET_EXPECT(div_onclick_attached);
1785 SET_EXPECT(body_onclick);
1786 SET_EXPECT(document_onclick);
1787 SET_EXPECT(doc_onclick_attached);
1788 SET_EXPECT(doccp_onclick);
1789 SET_EXPECT(invoke_onclick);
1791 hres = IHTMLElement_click(div);
1792 ok(hres == S_OK, "click failed: %08x\n", hres);
1794 CHECK_CALLED(div_onclick);
1795 CHECK_CALLED(div_onclick_disp);
1796 CHECK_CALLED(div_onclick_attached);
1797 CHECK_CALLED(body_onclick);
1798 CHECK_CALLED(document_onclick);
1799 CHECK_CALLED(doc_onclick_attached);
1800 CHECK_CALLED(doccp_onclick);
1801 CHECK_CALLED(invoke_onclick);
1803 elem2_cp_cookie = register_cp((IUnknown*)div, &DIID_HTMLElementEvents2, (IUnknown*)&elem2_cp_obj);
1805 SET_EXPECT(div_onclick);
1806 SET_EXPECT(div_onclick_disp);
1807 SET_EXPECT(div_onclick_attached);
1808 SET_EXPECT(elem2_cp_onclick);
1809 SET_EXPECT(body_onclick);
1810 SET_EXPECT(document_onclick);
1811 SET_EXPECT(doc_onclick_attached);
1812 SET_EXPECT(doccp_onclick);
1813 SET_EXPECT(invoke_onclick);
1815 trace("click >>>\n");
1816 hres = IHTMLElement_click(div);
1817 ok(hres == S_OK, "click failed: %08x\n", hres);
1818 trace("click <<<\n");
1820 CHECK_CALLED(div_onclick);
1821 CHECK_CALLED(div_onclick_disp);
1822 CHECK_CALLED(div_onclick_attached);
1823 CHECK_CALLED(elem2_cp_onclick);
1824 CHECK_CALLED(body_onclick);
1825 CHECK_CALLED(document_onclick);
1826 CHECK_CALLED(doc_onclick_attached);
1827 CHECK_CALLED(doccp_onclick);
1828 CHECK_CALLED(invoke_onclick);
1830 unregister_cp((IUnknown*)div, &DIID_HTMLElementEvents2, elem2_cp_cookie);
1831 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
1833 V_VT(&v) = VT_NULL;
1834 hres = IHTMLElement_put_onclick(div, v);
1835 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1837 hres = IHTMLElement_get_onclick(div, &v);
1838 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1839 ok(V_VT(&v) == VT_NULL, "get_onclick returned vt %d\n", V_VT(&v));
1841 elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1842 elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1843 elem_detach_event((IUnknown*)div, "test", (IDispatch*)&div_onclick_disp);
1844 doc_detach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1846 SET_EXPECT(div_onclick_attached);
1847 SET_EXPECT(body_onclick);
1848 SET_EXPECT(document_onclick);
1849 SET_EXPECT(invoke_onclick);
1851 hres = IHTMLElement_click(div);
1852 ok(hres == S_OK, "click failed: %08x\n", hres);
1854 CHECK_CALLED(div_onclick_attached);
1855 CHECK_CALLED(body_onclick);
1856 CHECK_CALLED(document_onclick);
1857 CHECK_CALLED(invoke_onclick);
1859 IHTMLElement_Release(div);
1860 IHTMLElement_Release(body);
1863 static void test_onreadystatechange(IHTMLDocument2 *doc)
1865 IHTMLFrameBase *iframe;
1866 IHTMLElement2 *elem2;
1867 IHTMLElement *elem;
1868 VARIANT v;
1869 BSTR str;
1870 HRESULT hres;
1872 elem = get_elem_id(doc, "iframe");
1873 elem2 = get_elem2_iface((IUnknown*)elem);
1874 IHTMLElement_Release(elem);
1876 V_VT(&v) = VT_EMPTY;
1877 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1878 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1879 ok(V_VT(&v) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1881 V_VT(&v) = VT_DISPATCH;
1882 V_DISPATCH(&v) = (IDispatch*)&iframe_onreadystatechange_obj;
1883 hres = IHTMLElement2_put_onreadystatechange(elem2, v);
1884 ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
1886 V_VT(&v) = VT_EMPTY;
1887 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1888 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1889 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1890 ok(V_DISPATCH(&v) == (IDispatch*)&iframe_onreadystatechange_obj, "unexpected onreadystatechange value\n");
1892 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase, (void**)&iframe);
1893 IHTMLElement2_Release(elem2);
1894 ok(hres == S_OK, "Could not get IHTMLFrameBase iface: %08x\n", hres);
1896 hres = IHTMLFrameBase_put_src(iframe, (str = a2bstr("about:blank")));
1897 SysFreeString(str);
1898 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1900 SET_EXPECT(iframe_onreadystatechange_loading);
1901 SET_EXPECT(iframedoc_onreadystatechange);
1902 SET_EXPECT(iframe_onreadystatechange_interactive);
1903 SET_EXPECT(iframe_onreadystatechange_complete);
1904 pump_msgs(&called_iframe_onreadystatechange_complete);
1905 CHECK_CALLED(iframe_onreadystatechange_loading);
1906 CHECK_CALLED(iframedoc_onreadystatechange);
1907 CHECK_CALLED(iframe_onreadystatechange_interactive);
1908 CHECK_CALLED(iframe_onreadystatechange_complete);
1910 IHTMLFrameBase_Release(iframe);
1913 static void test_imgload(IHTMLDocument2 *doc)
1915 IHTMLImgElement *img;
1916 IHTMLElement *elem;
1917 VARIANT v;
1918 BSTR str;
1919 HRESULT hres;
1921 elem = get_elem_id(doc, "imgid");
1922 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLImgElement, (void**)&img);
1923 IHTMLElement_Release(elem);
1924 ok(hres == S_OK, "Could not get IHTMLImgElement iface: %08x\n", hres);
1926 V_VT(&v) = VT_EMPTY;
1927 hres = IHTMLImgElement_get_onload(img, &v);
1928 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1929 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
1931 V_VT(&v) = VT_DISPATCH;
1932 V_DISPATCH(&v) = (IDispatch*)&img_onload_obj;
1933 hres = IHTMLImgElement_put_onload(img, v);
1934 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
1936 V_VT(&v) = VT_EMPTY;
1937 hres = IHTMLImgElement_get_onload(img, &v);
1938 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1939 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
1940 ok(V_DISPATCH(&v) == (IDispatch*)&img_onload_obj, "V_DISPATCH(onload) != onloadkFunc\n");
1941 VariantClear(&v);
1943 V_VT(&v) = VT_DISPATCH;
1944 V_DISPATCH(&v) = (IDispatch*)&img_onerror_obj;
1945 hres = IHTMLImgElement_put_onerror(img, v);
1946 ok(hres == S_OK, "put_onerror failed: %08x\n", hres);
1948 V_VT(&v) = VT_EMPTY;
1949 hres = IHTMLImgElement_get_onerror(img, &v);
1950 ok(hres == S_OK, "get_onerror failed: %08x\n", hres);
1951 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onerror) = %d\n", V_VT(&v));
1952 ok(V_DISPATCH(&v) == (IDispatch*)&img_onerror_obj, "V_DISPATCH(onerror) != onerrorFunc\n");
1953 VariantClear(&v);
1955 str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_text.png");
1956 hres = IHTMLImgElement_put_src(img, str);
1957 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1958 SysFreeString(str);
1960 SET_EXPECT(img_onload);
1961 pump_msgs(&called_img_onload);
1962 CHECK_CALLED(img_onload);
1964 SET_EXPECT(img_onerror);
1966 str = a2bstr("about:blank");
1967 hres = IHTMLImgElement_put_src(img, str);
1968 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1969 SysFreeString(str);
1971 pump_msgs(&called_img_onerror); /* FIXME: should not be needed */
1973 CHECK_CALLED(img_onerror);
1975 IHTMLImgElement_Release(img);
1977 /* test onload on unattached image */
1978 hres = IHTMLDocument2_createElement(doc, (str = a2bstr("img")), &elem);
1979 SysFreeString(str);
1980 ok(hres == S_OK, "createElement(img) failed: %08x\n", hres);
1982 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLImgElement, (void**)&img);
1983 IHTMLElement_Release(elem);
1984 ok(hres == S_OK, "Could not get IHTMLImgElement iface: %08x\n", hres);
1986 V_VT(&v) = VT_EMPTY;
1987 hres = IHTMLImgElement_get_onload(img, &v);
1988 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1989 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
1991 V_VT(&v) = VT_DISPATCH;
1992 V_DISPATCH(&v) = (IDispatch*)&unattached_img_onload_obj;
1993 hres = IHTMLImgElement_put_onload(img, v);
1994 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
1996 V_VT(&v) = VT_EMPTY;
1997 hres = IHTMLImgElement_get_onload(img, &v);
1998 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1999 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
2000 ok(V_DISPATCH(&v) == (IDispatch*)&unattached_img_onload_obj, "incorrect V_DISPATCH(onload)\n");
2001 VariantClear(&v);
2003 str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_text.png?v=1");
2004 hres = IHTMLImgElement_put_src(img, str);
2005 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2006 SysFreeString(str);
2008 SET_EXPECT(img_onload);
2009 pump_msgs(&called_img_onload);
2010 CHECK_CALLED(img_onload);
2012 IHTMLImgElement_Release(img);
2015 static void test_link_load(IHTMLDocument2 *doc)
2017 IHTMLLinkElement *link;
2018 IHTMLElement *elem;
2019 VARIANT v;
2020 BSTR str;
2021 HRESULT hres;
2023 elem = get_elem_id(doc, "linkid");
2024 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLLinkElement, (void**)&link);
2025 IHTMLElement_Release(elem);
2026 ok(hres == S_OK, "Could not get IHTMLLinkElement iface: %08x\n", hres);
2028 V_VT(&v) = VT_EMPTY;
2029 hres = IHTMLLinkElement_get_onload(link, &v);
2030 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2031 ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
2033 V_VT(&v) = VT_DISPATCH;
2034 V_DISPATCH(&v) = (IDispatch*)&link_onload_obj;
2035 hres = IHTMLLinkElement_put_onload(link, v);
2036 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2038 V_VT(&v) = VT_EMPTY;
2039 hres = IHTMLLinkElement_get_onload(link, &v);
2040 ok(hres == S_OK, "get_onload failed: %08x\n", hres);
2041 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
2042 ok(V_DISPATCH(&v) == (IDispatch*)&link_onload_obj, "V_DISPATCH(onload) != onloadkFunc\n");
2043 VariantClear(&v);
2045 str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/styles.css");
2046 hres = IHTMLLinkElement_put_href(link, str);
2047 ok(hres == S_OK, "put_src failed: %08x\n", hres);
2048 SysFreeString(str);
2050 SET_EXPECT(link_onload);
2051 pump_msgs(&called_link_onload);
2052 CHECK_CALLED(link_onload);
2054 IHTMLLinkElement_Release(link);
2057 static void test_focus(IHTMLDocument2 *doc)
2059 IHTMLElement2 *elem2;
2060 IHTMLElement4 *div;
2061 IHTMLElement *elem;
2062 VARIANT v;
2063 HRESULT hres;
2065 elem = get_elem_id(doc, "inputid");
2066 elem2 = get_elem2_iface((IUnknown*)elem);
2067 IHTMLElement_Release(elem);
2069 elem = get_elem_id(doc, "divid");
2070 div = get_elem4_iface((IUnknown*)elem);
2071 IHTMLElement_Release(elem);
2073 V_VT(&v) = VT_EMPTY;
2074 hres = IHTMLElement2_get_onfocus(elem2, &v);
2075 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
2076 ok(V_VT(&v) == VT_NULL, "V_VT(onfocus) = %d\n", V_VT(&v));
2078 V_VT(&v) = VT_DISPATCH;
2079 V_DISPATCH(&v) = (IDispatch*)&input_onfocus_obj;
2080 hres = IHTMLElement2_put_onfocus(elem2, v);
2081 ok(hres == S_OK, "put_onfocus failed: %08x\n", hres);
2083 V_VT(&v) = VT_EMPTY;
2084 hres = IHTMLElement2_get_onfocus(elem2, &v);
2085 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
2086 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocus) = %d\n", V_VT(&v));
2087 ok(V_DISPATCH(&v) == (IDispatch*)&input_onfocus_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
2088 VariantClear(&v);
2090 V_VT(&v) = VT_DISPATCH;
2091 V_DISPATCH(&v) = (IDispatch*)&div_onfocusin_obj;
2092 hres = IHTMLElement4_put_onfocusin(div, v);
2093 ok(hres == S_OK, "put_onfocusin failed: %08x\n", hres);
2095 V_VT(&v) = VT_EMPTY;
2096 hres = IHTMLElement4_get_onfocusin(div, &v);
2097 ok(hres == S_OK, "get_onfocusin failed: %08x\n", hres);
2098 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocusin) = %d\n", V_VT(&v));
2099 ok(V_DISPATCH(&v) == (IDispatch*)&div_onfocusin_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
2100 VariantClear(&v);
2102 V_VT(&v) = VT_EMPTY;
2103 hres = IHTMLElement2_get_onfocus(elem2, &v);
2104 ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
2105 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocus) = %d\n", V_VT(&v));
2106 ok(V_DISPATCH(&v) == (IDispatch*)&input_onfocus_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
2107 VariantClear(&v);
2109 if(!winetest_interactive)
2110 ShowWindow(container_hwnd, SW_SHOW);
2112 SetFocus(NULL);
2113 ok(!IsChild(container_hwnd, GetFocus()), "focus belongs to document window\n");
2115 hres = IHTMLWindow2_focus(window);
2116 ok(hres == S_OK, "focus failed: %08x\n", hres);
2118 ok(IsChild(container_hwnd, GetFocus()), "focus does not belong to document window\n");
2119 pump_msgs(NULL);
2121 SET_EXPECT(div_onfocusin);
2122 SET_EXPECT(input_onfocus);
2123 hres = IHTMLElement2_focus(elem2);
2124 ok(hres == S_OK, "focus failed: %08x\n", hres);
2125 pump_msgs(NULL);
2126 CHECK_CALLED(div_onfocusin);
2127 CHECK_CALLED(input_onfocus);
2129 SET_EXPECT(div_onfocusin);
2130 V_VT(&v) = VT_EMPTY;
2131 elem_fire_event((IUnknown*)elem2, "onfocusin", &v);
2132 CHECK_CALLED(div_onfocusin);
2134 V_VT(&v) = VT_DISPATCH;
2135 V_DISPATCH(&v) = (IDispatch*)&input_onblur_obj;
2136 hres = IHTMLElement2_put_onblur(elem2, v);
2137 ok(hres == S_OK, "put_onblur failed: %08x\n", hres);
2139 V_VT(&v) = VT_DISPATCH;
2140 V_DISPATCH(&v) = (IDispatch*)&div_onfocusout_obj;
2141 hres = IHTMLElement4_put_onfocusout(div, v);
2142 ok(hres == S_OK, "put_onfocusout failed: %08x\n", hres);
2144 SET_EXPECT(div_onfocusout);
2145 SET_EXPECT(input_onblur);
2146 hres = IHTMLElement2_blur(elem2);
2147 pump_msgs(NULL);
2148 CHECK_CALLED(input_onblur);
2149 CHECK_CALLED(div_onfocusout);
2150 ok(hres == S_OK, "blur failed: %08x\n", hres);
2152 if(!winetest_interactive)
2153 ShowWindow(container_hwnd, SW_HIDE);
2155 IHTMLElement2_Release(elem2);
2156 IHTMLElement4_Release(div);
2159 static void test_submit(IHTMLDocument2 *doc)
2161 IHTMLElement *elem, *submit;
2162 IHTMLFormElement *form;
2163 VARIANT v;
2164 DWORD cp_cookie;
2165 HRESULT hres;
2167 elem = get_elem_id(doc, "formid");
2169 V_VT(&v) = VT_DISPATCH;
2170 V_DISPATCH(&v) = (IDispatch*)&form_onclick_obj;
2171 hres = IHTMLElement_put_onclick(elem, v);
2172 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2174 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFormElement, (void**)&form);
2175 IHTMLElement_Release(elem);
2176 ok(hres == S_OK, "Could not get IHTMLFormElement iface: %08x\n", hres);
2178 V_VT(&v) = VT_DISPATCH;
2179 V_DISPATCH(&v) = (IDispatch*)&form_onsubmit_obj;
2180 hres = IHTMLFormElement_put_onsubmit(form, v);
2181 ok(hres == S_OK, "put_onsubmit failed: %08x\n", hres);
2183 IHTMLFormElement_Release(form);
2185 submit = get_elem_id(doc, "submitid");
2187 SET_EXPECT(form_onclick);
2188 SET_EXPECT(form_onsubmit);
2189 hres = IHTMLElement_click(submit);
2190 ok(hres == S_OK, "click failed: %08x\n", hres);
2191 CHECK_CALLED(form_onclick);
2192 CHECK_CALLED(form_onsubmit);
2194 V_VT(&v) = VT_DISPATCH;
2195 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_obj;
2196 hres = IHTMLElement_put_onclick(submit, v);
2197 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2199 SET_EXPECT(form_onclick);
2200 SET_EXPECT(submit_onclick);
2201 hres = IHTMLElement_click(submit);
2202 ok(hres == S_OK, "click failed: %08x\n", hres);
2203 CHECK_CALLED(form_onclick);
2204 CHECK_CALLED(submit_onclick);
2206 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2208 SET_EXPECT(form_onclick);
2209 SET_EXPECT(submit_onclick);
2210 SET_EXPECT(submit_onclick_attached);
2211 hres = IHTMLElement_click(submit);
2212 ok(hres == S_OK, "click failed: %08x\n", hres);
2213 CHECK_CALLED(form_onclick);
2214 CHECK_CALLED(submit_onclick);
2215 CHECK_CALLED(submit_onclick_attached);
2217 V_VT(&v) = VT_NULL;
2218 hres = IHTMLElement_put_onclick(submit, v);
2219 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2221 SET_EXPECT(form_onclick);
2222 SET_EXPECT(submit_onclick_attached);
2223 hres = IHTMLElement_click(submit);
2224 ok(hres == S_OK, "click failed: %08x\n", hres);
2225 CHECK_CALLED(form_onclick);
2226 CHECK_CALLED(submit_onclick_attached);
2228 elem_detach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2230 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_onclick_cancel_obj);
2232 SET_EXPECT(form_onclick);
2233 SET_EXPECT(doccp_onclick_cancel);
2234 hres = IHTMLElement_click(submit);
2235 ok(hres == S_OK, "click failed: %08x\n", hres);
2236 CHECK_CALLED(form_onclick);
2237 CHECK_CALLED(doccp_onclick_cancel);
2239 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
2241 V_VT(&v) = VT_DISPATCH;
2242 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_setret_obj;
2243 hres = IHTMLElement_put_onclick(submit, v);
2244 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2246 V_VT(&onclick_retval) = VT_BOOL;
2247 V_BOOL(&onclick_retval) = VARIANT_TRUE;
2248 V_VT(&onclick_event_retval) = VT_BOOL;
2249 V_BOOL(&onclick_event_retval) = VARIANT_TRUE;
2251 SET_EXPECT(submit_onclick_setret);
2252 SET_EXPECT(form_onclick);
2253 SET_EXPECT(form_onsubmit);
2254 hres = IHTMLElement_click(submit);
2255 ok(hres == S_OK, "click failed: %08x\n", hres);
2256 CHECK_CALLED(submit_onclick_setret);
2257 CHECK_CALLED(form_onclick);
2258 CHECK_CALLED(form_onsubmit);
2260 V_VT(&onclick_event_retval) = VT_BOOL;
2261 V_BOOL(&onclick_event_retval) = VARIANT_FALSE;
2263 SET_EXPECT(submit_onclick_setret);
2264 SET_EXPECT(form_onclick);
2265 hres = IHTMLElement_click(submit);
2266 ok(hres == S_OK, "click failed: %08x\n", hres);
2267 CHECK_CALLED(submit_onclick_setret);
2268 CHECK_CALLED(form_onclick);
2270 V_VT(&onclick_retval) = VT_BOOL;
2271 V_BOOL(&onclick_retval) = VARIANT_FALSE;
2272 V_VT(&onclick_event_retval) = VT_BOOL;
2273 V_BOOL(&onclick_event_retval) = VARIANT_TRUE;
2275 SET_EXPECT(submit_onclick_setret);
2276 SET_EXPECT(form_onclick);
2277 hres = IHTMLElement_click(submit);
2278 ok(hres == S_OK, "click failed: %08x\n", hres);
2279 CHECK_CALLED(submit_onclick_setret);
2280 CHECK_CALLED(form_onclick);
2282 V_VT(&onclick_event_retval) = VT_BOOL;
2283 V_BOOL(&onclick_event_retval) = VARIANT_FALSE;
2285 SET_EXPECT(submit_onclick_setret);
2286 SET_EXPECT(form_onclick);
2287 hres = IHTMLElement_click(submit);
2288 ok(hres == S_OK, "click failed: %08x\n", hres);
2289 CHECK_CALLED(submit_onclick_setret);
2290 CHECK_CALLED(form_onclick);
2292 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2293 elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_check_cancel_obj);
2295 V_VT(&v) = VT_DISPATCH;
2296 V_DISPATCH(&v) = (IDispatch*)&submit_onclick_cancel_obj;
2297 hres = IHTMLElement_put_onclick(submit, v);
2298 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2300 SET_EXPECT(submit_onclick_cancel);
2301 SET_EXPECT(submit_onclick_attached_check_cancel);
2302 SET_EXPECT(submit_onclick_attached);
2303 hres = IHTMLElement_click(submit);
2304 ok(hres == S_OK, "click failed: %08x\n", hres);
2305 CHECK_CALLED(submit_onclick_cancel);
2306 CHECK_CALLED(submit_onclick_attached_check_cancel);
2307 CHECK_CALLED(submit_onclick_attached);
2309 if(1)pump_msgs(NULL);
2311 IHTMLElement_Release(submit);
2314 static void test_timeout(IHTMLDocument2 *doc)
2316 IHTMLWindow3 *win3;
2317 VARIANT expr, var;
2318 LONG id;
2319 HRESULT hres;
2321 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
2322 ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
2324 V_VT(&expr) = VT_DISPATCH;
2325 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc2;
2326 V_VT(&var) = VT_EMPTY;
2327 id = 0;
2328 hres = IHTMLWindow3_setInterval(win3, &expr, 1, &var, &id);
2329 ok(hres == S_OK, "setInterval failed: %08x\n", hres);
2330 ok(id, "id = 0\n");
2332 hres = IHTMLWindow2_clearTimeout(window, id);
2333 ok(hres == S_OK, "clearTimeout failer: %08x\n", hres);
2335 V_VT(&expr) = VT_DISPATCH;
2336 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2337 V_VT(&var) = VT_EMPTY;
2338 id = 0;
2339 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
2340 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
2341 ok(id, "id = 0\n");
2343 SET_EXPECT(timeout);
2344 pump_msgs(&called_timeout);
2345 CHECK_CALLED(timeout);
2347 V_VT(&expr) = VT_DISPATCH;
2348 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2349 V_VT(&var) = VT_EMPTY;
2350 id = 0;
2351 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
2352 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
2353 ok(id, "id = 0\n");
2355 hres = IHTMLWindow2_clearTimeout(window, id);
2356 ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
2358 V_VT(&expr) = VT_DISPATCH;
2359 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2360 V_VT(&var) = VT_EMPTY;
2361 id = 0;
2362 hres = IHTMLWindow3_setInterval(win3, &expr, 1, &var, &id);
2363 ok(hres == S_OK, "setInterval failed: %08x\n", hres);
2364 ok(id, "id = 0\n");
2366 SET_EXPECT(timeout);
2367 pump_msgs(&called_timeout);
2368 CHECK_CALLED(timeout);
2370 SET_EXPECT(timeout);
2371 pump_msgs(&called_timeout);
2372 CHECK_CALLED(timeout);
2374 hres = IHTMLWindow2_clearInterval(window, id);
2375 ok(hres == S_OK, "clearTimeout failer: %08x\n", hres);
2377 IHTMLWindow3_Release(win3);
2380 static IHTMLWindow2 *get_iframe_window(IHTMLIFrameElement *iframe)
2382 IHTMLWindow2 *window;
2383 IHTMLFrameBase2 *base;
2384 HRESULT hres;
2386 hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&base);
2387 ok(hres == S_OK, "QueryInterface(IID_IHTMLFrameBase2) failed: %08x\n", hres);
2389 hres = IHTMLFrameBase2_get_contentWindow(base, &window);
2390 ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
2391 ok(window != NULL, "window == NULL\n");
2393 if(base) IHTMLFrameBase2_Release(base);
2394 return window;
2397 static IHTMLDocument2 *get_iframe_doc(IHTMLIFrameElement *iframe)
2399 IHTMLDocument2 *result = NULL;
2400 IHTMLWindow2 *window;
2401 HRESULT hres;
2403 window = get_iframe_window(iframe);
2405 hres = IHTMLWindow2_get_document(window, &result);
2406 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2407 ok(result != NULL, "result == NULL\n");
2409 IHTMLWindow2_Release(window);
2410 return result;
2413 static void test_iframe_connections(IHTMLDocument2 *doc)
2415 IHTMLIFrameElement *iframe;
2416 IHTMLDocument2 *iframes_doc;
2417 DWORD cookie;
2418 IConnectionPoint *cp;
2419 IHTMLElement *element;
2420 BSTR str;
2421 HRESULT hres;
2423 trace("iframe tests...\n");
2425 element = get_elem_id(doc, "ifr");
2426 iframe = get_iframe_iface((IUnknown*)element);
2427 IHTMLElement_Release(element);
2429 iframes_doc = get_iframe_doc(iframe);
2430 IHTMLIFrameElement_Release(iframe);
2432 cookie = register_cp((IUnknown*)iframes_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
2434 cp = get_cp((IUnknown*)doc, &IID_IDispatch);
2435 hres = IConnectionPoint_Unadvise(cp, cookie);
2436 IConnectionPoint_Release(cp);
2437 ok(hres == CONNECT_E_NOCONNECTION, "Unadvise returned %08x, expected CONNECT_E_NOCONNECTION\n", hres);
2439 unregister_cp((IUnknown*)iframes_doc, &IID_IDispatch, cookie);
2441 if(is_ie9plus) {
2442 IHTMLFrameBase2 *frame_base2;
2443 VARIANT v;
2445 hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&frame_base2);
2446 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
2448 V_VT(&v) = VT_DISPATCH;
2449 V_DISPATCH(&v) = (IDispatch*)&iframe_onload_obj;
2450 hres = IHTMLFrameBase2_put_onload(frame_base2, v);
2451 ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2453 IHTMLFrameBase2_Release(frame_base2);
2455 str = a2bstr("about:blank");
2456 hres = IHTMLDocument2_put_URL(iframes_doc, str);
2457 ok(hres == S_OK, "put_URL failed: %08x\n", hres);
2458 SysFreeString(str);
2460 SET_EXPECT(iframe_onload);
2461 pump_msgs(&called_iframe_onload);
2462 CHECK_CALLED(iframe_onload);
2464 str = a2bstr("about:test");
2465 hres = IHTMLDocument2_put_URL(iframes_doc, str);
2466 ok(hres == S_OK, "put_URL failed: %08x\n", hres);
2467 SysFreeString(str);
2469 SET_EXPECT(iframe_onload);
2470 pump_msgs(&called_iframe_onload);
2471 CHECK_CALLED(iframe_onload);
2472 }else {
2473 win_skip("Skipping iframe onload tests on IE older than 9.\n");
2476 IHTMLDocument2_Release(iframes_doc);
2479 static HRESULT QueryInterface(REFIID,void**);
2481 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
2483 return E_NOINTERFACE;
2486 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
2488 return 2;
2491 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
2493 return 1;
2496 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
2498 return E_NOTIMPL;
2501 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
2503 return E_NOTIMPL;
2506 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
2508 return E_NOTIMPL;
2511 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
2512 LPCBORDERWIDTHS pborderwidths)
2514 return E_NOTIMPL;
2517 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
2518 LPCBORDERWIDTHS pborderwidths)
2520 return S_OK;
2523 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
2524 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
2526 return S_OK;
2529 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
2530 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
2532 return S_OK;
2535 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
2536 LPOLEMENUGROUPWIDTHS lpMenuWidths)
2538 return E_NOTIMPL;
2541 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
2542 HOLEMENU holemenu, HWND hwndActiveObject)
2544 ok(0, "unexpected call\n");
2545 return E_NOTIMPL;
2548 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
2550 ok(0, "unexpected call\n");
2551 return E_NOTIMPL;
2554 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
2556 return S_OK;
2559 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
2561 return E_NOTIMPL;
2564 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
2566 ok(0, "unexpected call\n");
2567 return E_NOTIMPL;
2570 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
2571 InPlaceFrame_QueryInterface,
2572 InPlaceFrame_AddRef,
2573 InPlaceFrame_Release,
2574 InPlaceFrame_GetWindow,
2575 InPlaceFrame_ContextSensitiveHelp,
2576 InPlaceFrame_GetBorder,
2577 InPlaceFrame_RequestBorderSpace,
2578 InPlaceFrame_SetBorderSpace,
2579 InPlaceFrame_SetActiveObject,
2580 InPlaceFrame_InsertMenus,
2581 InPlaceFrame_SetMenu,
2582 InPlaceFrame_RemoveMenus,
2583 InPlaceFrame_SetStatusText,
2584 InPlaceFrame_EnableModeless,
2585 InPlaceFrame_TranslateAccelerator
2588 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
2590 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
2591 InPlaceFrame_QueryInterface,
2592 InPlaceFrame_AddRef,
2593 InPlaceFrame_Release,
2594 InPlaceFrame_GetWindow,
2595 InPlaceFrame_ContextSensitiveHelp,
2596 InPlaceFrame_GetBorder,
2597 InPlaceFrame_RequestBorderSpace,
2598 InPlaceFrame_SetBorderSpace,
2599 InPlaceUIWindow_SetActiveObject,
2602 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
2604 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
2606 return QueryInterface(riid, ppv);
2609 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
2611 return 2;
2614 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
2616 return 1;
2619 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
2621 *phwnd = container_hwnd;
2622 return S_OK;
2625 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
2627 ok(0, "unexpected call\n");
2628 return E_NOTIMPL;
2631 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
2633 return S_OK;
2636 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
2638 return S_OK;
2641 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
2643 return S_OK;
2646 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
2647 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
2648 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
2650 static const RECT rect = {0,0,300,300};
2652 *ppFrame = &InPlaceFrame;
2653 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
2654 *lprcPosRect = rect;
2655 *lprcClipRect = rect;
2657 ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
2658 lpFrameInfo->fMDIApp = FALSE;
2659 lpFrameInfo->hwndFrame = container_hwnd;
2660 lpFrameInfo->haccel = NULL;
2661 lpFrameInfo->cAccelEntries = 0;
2663 return S_OK;
2666 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
2668 return E_NOTIMPL;
2671 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
2673 return S_OK;
2676 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
2678 return S_OK;
2681 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
2683 return E_NOTIMPL;
2686 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
2688 return E_NOTIMPL;
2691 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
2693 return E_NOTIMPL;
2696 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
2697 InPlaceSite_QueryInterface,
2698 InPlaceSite_AddRef,
2699 InPlaceSite_Release,
2700 InPlaceSite_GetWindow,
2701 InPlaceSite_ContextSensitiveHelp,
2702 InPlaceSite_CanInPlaceActivate,
2703 InPlaceSite_OnInPlaceActivate,
2704 InPlaceSite_OnUIActivate,
2705 InPlaceSite_GetWindowContext,
2706 InPlaceSite_Scroll,
2707 InPlaceSite_OnUIDeactivate,
2708 InPlaceSite_OnInPlaceDeactivate,
2709 InPlaceSite_DiscardUndoState,
2710 InPlaceSite_DeactivateAndUndo,
2711 InPlaceSite_OnPosRectChange,
2714 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
2716 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
2718 return QueryInterface(riid, ppv);
2721 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
2723 return 2;
2726 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
2728 return 1;
2731 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
2733 ok(0, "unexpected call\n");
2734 return E_NOTIMPL;
2737 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
2738 IMoniker **ppmon)
2740 ok(0, "unexpected call\n");
2741 return E_NOTIMPL;
2744 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
2746 return E_NOTIMPL;
2749 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
2751 ok(0, "unexpected call\n");
2752 return E_NOTIMPL;
2755 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
2757 ok(0, "unexpected call\n");
2758 return E_NOTIMPL;
2761 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
2763 ok(0, "unexpected call\n");
2764 return E_NOTIMPL;
2767 static const IOleClientSiteVtbl ClientSiteVtbl = {
2768 ClientSite_QueryInterface,
2769 ClientSite_AddRef,
2770 ClientSite_Release,
2771 ClientSite_SaveObject,
2772 ClientSite_GetMoniker,
2773 ClientSite_GetContainer,
2774 ClientSite_ShowObject,
2775 ClientSite_OnShowWindow,
2776 ClientSite_RequestNewObjectLayout
2779 static IOleClientSite ClientSite = { &ClientSiteVtbl };
2781 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
2783 return QueryInterface(riid, ppv);
2786 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
2788 return 2;
2791 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
2793 return 1;
2796 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
2798 RECT rect = {0,0,300,300};
2799 IOleDocument *document;
2800 HRESULT hres;
2802 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
2803 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
2805 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
2806 IOleDocument_Release(document);
2807 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
2809 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
2810 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
2812 hres = IOleDocumentView_UIActivate(view, TRUE);
2813 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
2815 hres = IOleDocumentView_SetRect(view, &rect);
2816 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
2818 hres = IOleDocumentView_Show(view, TRUE);
2819 ok(hres == S_OK, "Show failed: %08x\n", hres);
2821 return S_OK;
2824 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
2825 DocumentSite_QueryInterface,
2826 DocumentSite_AddRef,
2827 DocumentSite_Release,
2828 DocumentSite_ActivateMe
2831 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
2833 static HRESULT QueryInterface(REFIID riid, void **ppv)
2835 *ppv = NULL;
2837 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
2838 *ppv = &ClientSite;
2839 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
2840 *ppv = &DocumentSite;
2841 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
2842 *ppv = &InPlaceSite;
2844 return *ppv ? S_OK : E_NOINTERFACE;
2847 static IHTMLDocument2 *notif_doc;
2848 static BOOL doc_complete;
2850 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2851 REFIID riid, void**ppv)
2853 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2854 *ppv = iface;
2855 return S_OK;
2858 ok(0, "unexpected call\n");
2859 return E_NOINTERFACE;
2862 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2864 return 2;
2867 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2869 return 1;
2872 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2874 if(dispID == DISPID_READYSTATE){
2875 BSTR state;
2876 HRESULT hres;
2878 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2879 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2881 if(!strcmp_wa(state, "complete"))
2882 doc_complete = TRUE;
2884 SysFreeString(state);
2887 return S_OK;
2890 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2892 ok(0, "unexpected call\n");
2893 return E_NOTIMPL;
2896 static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2897 PropertyNotifySink_QueryInterface,
2898 PropertyNotifySink_AddRef,
2899 PropertyNotifySink_Release,
2900 PropertyNotifySink_OnChanged,
2901 PropertyNotifySink_OnRequestEdit
2904 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2906 static void doc_load_string(IHTMLDocument2 *doc, const char *str)
2908 IPersistStreamInit *init;
2909 IStream *stream;
2910 HGLOBAL mem;
2911 SIZE_T len;
2913 notif_doc = doc;
2915 doc_complete = FALSE;
2916 len = strlen(str);
2917 mem = GlobalAlloc(0, len);
2918 memcpy(mem, str, len);
2919 CreateStreamOnHGlobal(mem, TRUE, &stream);
2921 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2923 IPersistStreamInit_Load(init, stream);
2924 IPersistStreamInit_Release(init);
2925 IStream_Release(stream);
2928 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2930 IConnectionPointContainer *container;
2931 IConnectionPoint *cp;
2932 DWORD cookie;
2933 HRESULT hres;
2935 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2936 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2938 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2939 IConnectionPointContainer_Release(container);
2940 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2942 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2943 IConnectionPoint_Release(cp);
2944 ok(hres == S_OK, "Advise failed: %08x\n", hres);
2947 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
2949 IOleObject *oleobj;
2950 HRESULT hres;
2952 if(!set && view) {
2953 IOleDocumentView_Show(view, FALSE);
2954 IOleDocumentView_CloseView(view, 0);
2955 IOleDocumentView_SetInPlaceSite(view, NULL);
2956 IOleDocumentView_Release(view);
2957 view = NULL;
2960 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
2961 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
2963 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
2964 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
2966 if(set) {
2967 IHlinkTarget *hlink;
2969 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
2970 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
2972 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
2973 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
2975 IHlinkTarget_Release(hlink);
2978 IOleObject_Release(oleobj);
2980 static IHTMLDocument2 *create_document(void)
2982 IHTMLDocument2 *doc;
2983 HRESULT hres;
2985 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2986 &IID_IHTMLDocument2, (void**)&doc);
2987 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2988 return SUCCEEDED(hres) ? doc : NULL;
2992 typedef void (*testfunc_t)(IHTMLDocument2*);
2994 static void run_test(const char *str, testfunc_t test)
2996 IHTMLDocument2 *doc;
2997 IHTMLElement *body = NULL;
2998 MSG msg;
2999 HRESULT hres;
3001 doc = create_document();
3002 if (!doc)
3003 return;
3004 set_client_site(doc, TRUE);
3005 doc_load_string(doc, str);
3006 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3008 while(!doc_complete && GetMessageA(&msg, NULL, 0, 0)) {
3009 TranslateMessage(&msg);
3010 DispatchMessageA(&msg);
3013 hres = IHTMLDocument2_get_body(doc, &body);
3014 ok(hres == S_OK, "get_body failed: %08x\n", hres);
3016 if(body) {
3017 IHTMLElement_Release(body);
3019 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3020 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3021 ok(window != NULL, "window == NULL\n");
3023 test(doc);
3025 IHTMLWindow2_Release(window);
3026 window = NULL;
3027 }else {
3028 skip("Could not get document body. Assuming no Gecko installed.\n");
3031 set_client_site(doc, FALSE);
3032 IHTMLDocument2_Release(doc);
3035 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3037 return DefWindowProcA(hwnd, msg, wParam, lParam);
3040 static HWND create_container_window(void)
3042 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
3043 static WNDCLASSEXA wndclass = {
3044 sizeof(WNDCLASSEXA),
3046 wnd_proc,
3047 0, 0, NULL, NULL, NULL, NULL, NULL,
3048 szHTMLDocumentTest,
3049 NULL
3052 RegisterClassExA(&wndclass);
3053 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
3054 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
3055 300, 300, NULL, NULL, NULL, NULL);
3058 static void test_empty_document(void)
3060 HRESULT hres;
3061 IHTMLWindow2 *window;
3062 IHTMLDocument2 *windows_doc, *doc;
3063 IConnectionPoint *cp;
3064 DWORD cookie;
3066 doc = create_document();
3067 if(!doc)
3068 return;
3070 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3071 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3073 hres = IHTMLWindow2_get_document(window, &windows_doc);
3074 IHTMLWindow2_Release(window);
3075 ok(hres == S_OK, "get_document failed: %08x\n", hres);
3077 cookie = register_cp((IUnknown*)windows_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
3079 cp = get_cp((IUnknown*)doc, &IID_IDispatch);
3080 hres = IConnectionPoint_Unadvise(cp, cookie);
3081 IConnectionPoint_Release(cp);
3082 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
3084 IHTMLDocument2_Release(windows_doc);
3085 IHTMLDocument2_Release(doc);
3088 static BOOL check_ie(void)
3090 IHTMLDocument2 *doc;
3091 IHTMLDocument5 *doc5;
3092 IHTMLDocument7 *doc7;
3093 HRESULT hres;
3095 doc = create_document();
3096 if(!doc)
3097 return FALSE;
3099 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument7, (void**)&doc7);
3100 if(SUCCEEDED(hres)) {
3101 is_ie9plus = TRUE;
3102 IHTMLDocument7_Release(doc7);
3105 trace("is_ie9plus %x\n", is_ie9plus);
3107 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
3108 if(SUCCEEDED(hres))
3109 IHTMLDocument5_Release(doc5);
3111 IHTMLDocument2_Release(doc);
3112 return SUCCEEDED(hres);
3115 START_TEST(events)
3117 CoInitialize(NULL);
3119 if(check_ie()) {
3120 container_hwnd = create_container_window();
3122 if(winetest_interactive)
3123 ShowWindow(container_hwnd, SW_SHOW);
3125 run_test(empty_doc_str, test_timeout);
3126 run_test(click_doc_str, test_onclick);
3127 run_test(readystate_doc_str, test_onreadystatechange);
3128 run_test(img_doc_str, test_imgload);
3129 run_test(link_doc_str, test_link_load);
3130 run_test(input_doc_str, test_focus);
3131 run_test(form_doc_str, test_submit);
3132 run_test(iframe_doc_str, test_iframe_connections);
3134 test_empty_document();
3136 DestroyWindow(container_hwnd);
3137 }else {
3138 win_skip("Too old IE\n");
3141 CoUninitialize();