2 * Copyright 2008-2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
35 #define DEFINE_EXPECT(func) \
36 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
38 #define SET_EXPECT(func) \
39 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
41 #define CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
60 DEFINE_EXPECT(document_onclick
);
61 DEFINE_EXPECT(body_onclick
);
62 DEFINE_EXPECT(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(div_onclick_disp
);
68 DEFINE_EXPECT(iframe_onreadystatechange_loading
);
69 DEFINE_EXPECT(iframe_onreadystatechange_interactive
);
70 DEFINE_EXPECT(iframe_onreadystatechange_complete
);
71 DEFINE_EXPECT(iframedoc_onreadystatechange
);
72 DEFINE_EXPECT(img_onload
);
74 static HWND container_hwnd
= NULL
;
75 static IHTMLWindow2
*window
;
76 static IOleDocumentView
*view
;
86 static const xy_test_t no_xy
= {-10,-10,-10,-10};
87 static const xy_test_t zero_xy
= {0,0,0,0};
89 static const char empty_doc_str
[] =
92 static const char click_doc_str
[] =
94 "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
97 static const char readystate_doc_str
[] =
98 "<html><body><iframe id=\"iframe\"></iframe></body></html>";
100 static const char img_doc_str
[] =
101 "<html><body><img id=\"imgid\"></img></body></html>";
103 static const char *debugstr_guid(REFIID riid
)
107 sprintf(buf
, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
108 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
109 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
110 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
115 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
118 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), NULL
, NULL
);
119 return lstrcmpA(stra
, buf
);
122 static BSTR
a2bstr(const char *str
)
127 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
128 ret
= SysAllocStringLen(NULL
, len
-1);
129 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
134 static BOOL
iface_cmp(IUnknown
*iface1
, IUnknown
*iface2
)
136 IUnknown
*unk1
, *unk2
;
141 IUnknown_QueryInterface(iface1
, &IID_IUnknown
, (void**)&unk1
);
142 IUnknown_Release(unk1
);
143 IUnknown_QueryInterface(iface1
, &IID_IUnknown
, (void**)&unk2
);
144 IUnknown_Release(unk2
);
149 #define test_disp(u,id) _test_disp(__LINE__,u,id)
150 static void _test_disp(unsigned line
, IUnknown
*unk
, const IID
*diid
)
157 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&dispex
);
158 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IDispatch: %08x\n", hres
);
163 hres
= IDispatchEx_GetTypeInfoCount(dispex
, &ticnt
);
164 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfoCount failed: %08x\n", hres
);
165 ok_(__FILE__
,line
) (ticnt
== 1, "ticnt=%u\n", ticnt
);
167 hres
= IDispatchEx_GetTypeInfo(dispex
, 0, 0, &typeinfo
);
168 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeInfo failed: %08x\n", hres
);
170 if(SUCCEEDED(hres
)) {
173 hres
= ITypeInfo_GetTypeAttr(typeinfo
, &type_attr
);
174 ok_(__FILE__
,line
) (hres
== S_OK
, "GetTypeAttr failed: %08x\n", hres
);
175 ok_(__FILE__
,line
) (IsEqualGUID(&type_attr
->guid
, diid
), "unexpected guid %s\n",
176 debugstr_guid(&type_attr
->guid
));
178 ITypeInfo_ReleaseTypeAttr(typeinfo
, type_attr
);
179 ITypeInfo_Release(typeinfo
);
182 IDispatchEx_Release(dispex
);
185 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
186 static IHTMLDocument3
*_get_doc3_iface(unsigned line
, IUnknown
*unk
)
188 IHTMLDocument3
*doc3
;
191 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLDocument3
, (void**)&doc3
);
192 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLDocument3 iface: %08x\n", hres
);
197 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
198 static IHTMLElement
*_get_elem_iface(unsigned line
, IUnknown
*unk
)
203 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement
, (void**)&elem
);
204 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLElement iface: %08x\n", hres
);
209 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
210 static IHTMLElement2
*_get_elem2_iface(unsigned line
, IUnknown
*unk
)
212 IHTMLElement2
*elem2
;
215 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement2
, (void**)&elem2
);
216 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLElement2 iface: %08x\n", hres
);
221 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
222 static IHTMLElement3
*_get_elem3_iface(unsigned line
, IUnknown
*unk
)
224 IHTMLElement3
*elem3
;
227 hres
= IUnknown_QueryInterface(unk
, &IID_IHTMLElement3
, (void**)&elem3
);
228 ok_(__FILE__
,line
) (hres
== S_OK
, "Could not get IHTMLElement3 iface: %08x\n", hres
);
233 #define doc_get_body(d) _doc_get_body(__LINE__,d)
234 static IHTMLElement
*_doc_get_body(unsigned line
, IHTMLDocument2
*doc
)
236 IHTMLElement
*body
= NULL
;
239 hres
= IHTMLDocument2_get_body(doc
, &body
);
240 ok_(__FILE__
,line
) (hres
== S_OK
, "get_body failed: %08x\n", hres
);
241 ok_(__FILE__
,line
) (body
!= NULL
, "body == NULL\n");
246 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
247 static IHTMLElement
*_get_elem_id(unsigned line
, IHTMLDocument2
*doc
, const char *id
)
249 IHTMLDocument3
*doc3
= _get_doc3_iface(line
, (IUnknown
*)doc
);
255 hres
= IHTMLDocument3_getElementById(doc3
, str
, &elem
);
257 IHTMLDocument3_Release(doc3
);
258 ok_(__FILE__
,line
) (hres
== S_OK
, "getElementById failed: %08x\n", hres
);
263 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
264 static void _test_elem_tag(unsigned line
, IUnknown
*unk
, const char *extag
)
266 IHTMLElement
*elem
= _get_elem_iface(line
, unk
);
270 hres
= IHTMLElement_get_tagName(elem
, &tag
);
271 IHTMLElement_Release(elem
);
272 ok_(__FILE__
, line
) (hres
== S_OK
, "get_tagName failed: %08x\n", hres
);
273 ok_(__FILE__
, line
) (!strcmp_wa(tag
, extag
), "got tag: %s, expected %s\n", wine_dbgstr_w(tag
), extag
);
278 #define get_event_obj() _get_event_obj(__LINE__)
279 static IHTMLEventObj
*_get_event_obj(unsigned line
)
281 IHTMLEventObj
*event
= NULL
;
284 hres
= IHTMLWindow2_get_event(window
, &event
);
285 ok_(__FILE__
,line
) (hres
== S_OK
, "get_event failed: %08x\n", hres
);
286 ok_(__FILE__
,line
) (event
!= NULL
, "event = NULL\n");
287 _test_disp(line
, (IUnknown
*)event
, &DIID_DispCEventObj
);
292 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
293 static void _elem_fire_event(unsigned line
, IUnknown
*unk
, const char *event
, VARIANT
*evobj
)
295 IHTMLElement3
*elem3
= _get_elem3_iface(line
, unk
);
302 hres
= IHTMLElement3_fireEvent(elem3
, str
, evobj
, &b
);
304 ok_(__FILE__
,line
)(hres
== S_OK
, "fireEvent failed: %08x\n", hres
);
305 ok_(__FILE__
,line
)(b
== VARIANT_TRUE
, "fireEvent returned %x\n", b
);
308 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
309 static void _test_event_args(unsigned line
, const IID
*dispiid
, DISPID id
, WORD wFlags
, DISPPARAMS
*pdp
,
310 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
312 ok_(__FILE__
,line
) (id
== DISPID_VALUE
, "id = %d\n", id
);
313 ok_(__FILE__
,line
) (wFlags
== DISPATCH_METHOD
, "wFlags = %x\n", wFlags
);
314 ok_(__FILE__
,line
) (pdp
!= NULL
, "pdp == NULL\n");
315 ok_(__FILE__
,line
) (pdp
->cArgs
== 1, "pdp->cArgs = %d\n", pdp
->cArgs
);
316 ok_(__FILE__
,line
) (pdp
->cNamedArgs
== 1, "pdp->cNamedArgs = %d\n", pdp
->cNamedArgs
);
317 ok_(__FILE__
,line
) (pdp
->rgdispidNamedArgs
[0] == DISPID_THIS
, "pdp->rgdispidNamedArgs[0] = %d\n",
318 pdp
->rgdispidNamedArgs
[0]);
319 ok_(__FILE__
,line
) (V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(rgvarg) = %d\n", V_VT(pdp
->rgvarg
));
320 ok_(__FILE__
,line
) (pvarRes
!= NULL
, "pvarRes == NULL\n");
321 ok_(__FILE__
,line
) (pei
!= NULL
, "pei == NULL");
322 ok_(__FILE__
,line
) (!pspCaller
, "pspCaller != NULL\n");
325 _test_disp(line
, (IUnknown
*)V_DISPATCH(pdp
->rgvarg
), dispiid
);
328 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
329 static void _test_attached_event_args(unsigned line
, DISPID id
, WORD wFlags
, DISPPARAMS
*pdp
,
330 VARIANT
*pvarRes
, EXCEPINFO
*pei
)
332 IHTMLEventObj
*event
;
334 ok(id
== DISPID_VALUE
, "id = %d\n", id
);
335 ok(wFlags
== DISPATCH_METHOD
, "wFlags = %x\n", wFlags
);
336 ok(pdp
!= NULL
, "pDispParams == NULL\n");
337 ok(pdp
->cArgs
== 1, "pdp->cArgs = %d\n", pdp
->cArgs
);
338 ok(!pdp
->cNamedArgs
, "pdp->cNamedArgs = %d\n", pdp
->cNamedArgs
);
339 ok(!pdp
->rgdispidNamedArgs
, "pdp->rgdispidNamedArgs = %p\n", pdp
->rgdispidNamedArgs
);
340 ok(pdp
->rgvarg
!= NULL
, "rgvarg = NULL\n");
341 ok(pvarRes
!= NULL
, "pvarRes = NULL\n");
342 ok(pei
!= NULL
, "pei = NULL\n");
343 ok(V_VT(pvarRes
) == VT_EMPTY
, "V_VT(pVarRes) = %d\n", V_VT(pvarRes
));
344 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp
->rgvarg
));
345 ok(V_DISPATCH(pdp
->rgvarg
) != NULL
, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp
->rgvarg
));
347 event
= _get_event_obj(line
);
348 ok(iface_cmp((IUnknown
*)event
, (IUnknown
*)V_DISPATCH(pdp
->rgvarg
)), "event != arg0\n");
349 IHTMLEventObj_Release(event
);
352 #define get_event_src() _get_event_src(__LINE__)
353 static IHTMLElement
*_get_event_src(unsigned line
)
355 IHTMLEventObj
*event
= _get_event_obj(line
);
356 IHTMLElement
*src_elem
= NULL
;
359 hres
= IHTMLEventObj_get_srcElement(event
, &src_elem
);
360 IHTMLEventObj_Release(event
);
361 ok_(__FILE__
,line
) (hres
== S_OK
, "get_srcElement failed: %08x\n", hres
);
366 #define test_event_src(t) _test_event_src(__LINE__,t)
367 static void _test_event_src(unsigned line
, const char *src_tag
)
369 IHTMLElement
*src_elem
= _get_event_src(line
);
372 ok_(__FILE__
,line
) (src_elem
!= NULL
, "src_elem = NULL\n");
373 _test_elem_tag(line
, (IUnknown
*)src_elem
, src_tag
);
374 IHTMLElement_Release(src_elem
);
376 ok_(__FILE__
,line
) (!src_elem
, "src_elem != NULL\n");
380 static void _test_event_altkey(unsigned line
, IHTMLEventObj
*event
, VARIANT_BOOL exval
)
385 hres
= IHTMLEventObj_get_altKey(event
, &b
);
386 ok_(__FILE__
,line
)(hres
== S_OK
, "get_altKey failed: %08x\n", hres
);
387 ok_(__FILE__
,line
)(b
== exval
, "altKey = %x, expected %x\n", b
, exval
);
390 static void _test_event_ctrlkey(unsigned line
, IHTMLEventObj
*event
, VARIANT_BOOL exval
)
395 hres
= IHTMLEventObj_get_ctrlKey(event
, &b
);
396 ok_(__FILE__
,line
)(hres
== S_OK
, "get_ctrlKey failed: %08x\n", hres
);
397 ok_(__FILE__
,line
)(b
== exval
, "ctrlKey = %x, expected %x\n", b
, exval
);
400 static void _test_event_shiftkey(unsigned line
, IHTMLEventObj
*event
, VARIANT_BOOL exval
)
405 hres
= IHTMLEventObj_get_shiftKey(event
, &b
);
406 ok_(__FILE__
,line
)(hres
== S_OK
, "get_shiftKey failed: %08x\n", hres
);
407 ok_(__FILE__
,line
)(b
== exval
, "shiftKey = %x, expected %x\n", b
, exval
);
410 static void _test_event_cancelbubble(unsigned line
, IHTMLEventObj
*event
, VARIANT_BOOL exval
)
415 hres
= IHTMLEventObj_get_cancelBubble(event
, &b
);
416 ok_(__FILE__
,line
)(hres
== S_OK
, "get_cancelBubble failed: %08x\n", hres
);
417 ok_(__FILE__
,line
)(b
== exval
, "cancelBubble = %x, expected %x\n", b
, exval
);
420 static void _test_event_fromelem(unsigned line
, IHTMLEventObj
*event
, const char *from_tag
)
425 hres
= IHTMLEventObj_get_fromElement(event
, &elem
);
426 ok_(__FILE__
,line
)(hres
== S_OK
, "get_fromElement failed: %08x\n", hres
);
428 _test_elem_tag(line
, (IUnknown
*)elem
, from_tag
);
430 ok_(__FILE__
,line
)(elem
== NULL
, "fromElement != NULL\n");
432 IHTMLElement_Release(elem
);
435 static void _test_event_toelem(unsigned line
, IHTMLEventObj
*event
, const char *to_tag
)
440 hres
= IHTMLEventObj_get_toElement(event
, &elem
);
441 ok_(__FILE__
,line
)(hres
== S_OK
, "get_toElement failed: %08x\n", hres
);
443 _test_elem_tag(line
, (IUnknown
*)elem
, to_tag
);
445 ok_(__FILE__
,line
)(elem
== NULL
, "toElement != NULL\n");
447 IHTMLElement_Release(elem
);
450 static void _test_event_keycode(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
455 hres
= IHTMLEventObj_get_keyCode(event
, &l
);
456 ok_(__FILE__
,line
)(hres
== S_OK
, "get_keyCode failed: %08x\n", hres
);
457 ok_(__FILE__
,line
)(l
== exl
, "keyCode = %x, expected %x\n", l
, exl
);
460 static void _test_event_button(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
465 hres
= IHTMLEventObj_get_button(event
, &l
);
466 ok_(__FILE__
,line
)(hres
== S_OK
, "get_button failed: %08x\n", hres
);
467 ok_(__FILE__
,line
)(l
== exl
, "button = %x, expected %x\n", l
, exl
);
470 static void _test_event_reason(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
475 hres
= IHTMLEventObj_get_reason(event
, &l
);
476 ok_(__FILE__
,line
)(hres
== S_OK
, "get_reason failed: %08x\n", hres
);
477 ok_(__FILE__
,line
)(l
== exl
, "reason = %x, expected %x\n", l
, exl
);
480 static void _test_event_x(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
485 hres
= IHTMLEventObj_get_x(event
, &l
);
486 ok_(__FILE__
,line
)(hres
== S_OK
, "get_x failed: %08x\n", hres
);
487 if(exl
!= -10) /* don't test the exact value */
488 ok_(__FILE__
,line
)(l
== exl
, "x = %d, expected %d\n", l
, exl
);
491 static void _test_event_y(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
496 hres
= IHTMLEventObj_get_y(event
, &l
);
497 ok_(__FILE__
,line
)(hres
== S_OK
, "get_y failed: %08x\n", hres
);
498 if(exl
!= -10) /* don't test the exact value */
499 ok_(__FILE__
,line
)(l
== exl
, "y = %d, expected %d\n", l
, exl
);
502 static void _test_event_clientx(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
507 hres
= IHTMLEventObj_get_clientX(event
, &l
);
508 ok_(__FILE__
,line
)(hres
== S_OK
, "get_clientX failed: %08x\n", hres
);
509 if(exl
!= -10) /* don't test the exact value */
510 ok_(__FILE__
,line
)(l
== exl
, "clientX = %d, expected %d\n", l
, exl
);
513 static void _test_event_clienty(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
518 hres
= IHTMLEventObj_get_clientY(event
, &l
);
519 ok_(__FILE__
,line
)(hres
== S_OK
, "get_clientY failed: %08x\n", hres
);
520 if(exl
!= -10) /* don't test the exact value */
521 ok_(__FILE__
,line
)(l
== exl
, "clientY = %d, expected %d\n", l
, exl
);
524 static void _test_event_offsetx(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
529 hres
= IHTMLEventObj_get_offsetX(event
, &l
);
530 ok_(__FILE__
,line
)(hres
== S_OK
, "get_offsetX failed: %08x\n", hres
);
531 if(exl
!= -10) /* don't test the exact value */
532 ok_(__FILE__
,line
)(l
== exl
, "offsetX = %d, expected %d\n", l
, exl
);
535 static void _test_event_offsety(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
540 hres
= IHTMLEventObj_get_offsetY(event
, &l
);
541 ok_(__FILE__
,line
)(hres
== S_OK
, "get_offsetY failed: %08x\n", hres
);
542 if(exl
!= -10) /* don't test the exact value */
543 ok_(__FILE__
,line
)(l
== exl
, "offsetY = %d, expected %d\n", l
, exl
);
546 static void _test_event_screenx(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
551 hres
= IHTMLEventObj_get_screenX(event
, &l
);
552 ok_(__FILE__
,line
)(hres
== S_OK
, "get_screenX failed: %08x\n", hres
);
553 if(exl
!= -10) /* don't test the exact value */
554 ok_(__FILE__
,line
)(l
== exl
, "screenX = %d, expected %d\n", l
, exl
);
557 static void _test_event_screeny(unsigned line
, IHTMLEventObj
*event
, LONG exl
)
562 hres
= IHTMLEventObj_get_screenY(event
, &l
);
563 ok_(__FILE__
,line
)(hres
== S_OK
, "get_screenY failed: %08x\n", hres
);
564 if(exl
!= -10) /* don't test the exact value for -10 */
565 ok_(__FILE__
,line
)(l
== exl
, "screenY = %d, expected %d\n", l
, exl
);
568 static void _test_event_type(unsigned line
, IHTMLEventObj
*event
, const char *exstr
)
573 hres
= IHTMLEventObj_get_type(event
, &str
);
574 ok_(__FILE__
,line
)(hres
== S_OK
, "get_type failed: %08x\n", hres
);
575 ok_(__FILE__
,line
)(!strcmp_wa(str
, exstr
), "type = %s, expected %s\n", wine_dbgstr_w(str
), exstr
);
578 static void _test_event_qualifier(unsigned line
, IHTMLEventObj
*event
, const char *exstr
)
583 hres
= IHTMLEventObj_get_qualifier(event
, &str
);
584 ok_(__FILE__
,line
)(hres
== S_OK
, "get_qualifier failed: %08x\n", hres
);
586 ok_(__FILE__
,line
)(!strcmp_wa(str
, exstr
), "qualifier = %s, expected %s\n", wine_dbgstr_w(str
), exstr
);
588 ok_(__FILE__
,line
)(!str
, "qualifier != NULL\n");
591 static void _test_event_srcfilter(unsigned line
, IHTMLEventObj
*event
)
596 hres
= IHTMLEventObj_get_srcFilter(event
, &disp
);
597 ok_(__FILE__
,line
)(hres
== S_OK
, "get_srcFilter failed: %08x\n", hres
);
598 ok_(__FILE__
,line
)(!disp
, "srcFilter != NULL\n");
601 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
602 static void _test_event_obj(unsigned line
, const char *type
, const xy_test_t
*xy
)
604 IHTMLEventObj
*event
= _get_event_obj(line
);
608 _test_event_altkey(line
, event
, VARIANT_FALSE
);
609 _test_event_ctrlkey(line
, event
, VARIANT_FALSE
);
610 _test_event_shiftkey(line
, event
, VARIANT_FALSE
);
611 _test_event_cancelbubble(line
, event
, VARIANT_FALSE
);
612 _test_event_fromelem(line
, event
, NULL
);
613 _test_event_toelem(line
, event
, NULL
);
614 _test_event_keycode(line
, event
, 0);
615 _test_event_button(line
, event
, 0);
616 _test_event_type(line
, event
, type
);
617 _test_event_qualifier(line
, event
, NULL
);
618 _test_event_reason(line
, event
, 0);
619 _test_event_srcfilter(line
, event
);
620 _test_event_x(line
, event
, xy
->x
);
621 _test_event_y(line
, event
, xy
->y
);
622 _test_event_clientx(line
, event
, -10);
623 _test_event_clienty(line
, event
, -10);
624 _test_event_offsetx(line
, event
, xy
->offset_x
);
625 _test_event_offsety(line
, event
, xy
->offset_y
);
626 _test_event_screenx(line
, event
, -10);
627 _test_event_screeny(line
, event
, -10);
629 hres
= IHTMLEventObj_get_returnValue(event
, &v
);
630 ok_(__FILE__
,line
)(hres
== S_OK
, "get_returnValue failed: %08x\n", hres
);
631 ok_(__FILE__
,line
)(V_VT(&v
) == VT_EMPTY
, "V_VT(returnValue) = %d\n", V_VT(&v
));
633 IHTMLEventObj_Release(event
);
636 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
637 static void _elem_attach_event(unsigned line
, IUnknown
*unk
, const char *namea
, IDispatch
*disp
)
639 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
644 name
= a2bstr(namea
);
645 hres
= IHTMLElement2_attachEvent(elem
, name
, disp
, &res
);
646 IHTMLElement2_Release(elem
);
648 ok_(__FILE__
,line
)(hres
== S_OK
, "attachEvent failed: %08x\n", hres
);
649 ok_(__FILE__
,line
)(res
== VARIANT_TRUE
, "attachEvent returned %x\n", res
);
652 #define elem_detach_event(a,b,c) _elem_detach_event(__LINE__,a,b,c)
653 static void _elem_detach_event(unsigned line
, IUnknown
*unk
, const char *namea
, IDispatch
*disp
)
655 IHTMLElement2
*elem
= _get_elem2_iface(line
, unk
);
659 name
= a2bstr(namea
);
660 hres
= IHTMLElement2_detachEvent(elem
, name
, disp
);
661 IHTMLElement2_Release(elem
);
663 ok_(__FILE__
,line
)(hres
== S_OK
, "detachEvent failed: %08x\n", hres
);
666 #define doc_attach_event(a,b,c) _doc_attach_event(__LINE__,a,b,c)
667 static void _doc_attach_event(unsigned line
, IHTMLDocument2
*doc
, const char *namea
, IDispatch
*disp
)
669 IHTMLDocument3
*doc3
= _get_doc3_iface(line
, (IUnknown
*)doc
);
674 name
= a2bstr(namea
);
675 hres
= IHTMLDocument3_attachEvent(doc3
, name
, disp
, &res
);
676 IHTMLDocument3_Release(doc3
);
678 ok_(__FILE__
,line
)(hres
== S_OK
, "attachEvent failed: %08x\n", hres
);
679 ok_(__FILE__
,line
)(res
== VARIANT_TRUE
, "attachEvent returned %x\n", res
);
682 #define doc_detach_event(a,b,c) _doc_detach_event(__LINE__,a,b,c)
683 static void _doc_detach_event(unsigned line
, IHTMLDocument2
*doc
, const char *namea
, IDispatch
*disp
)
685 IHTMLDocument3
*doc3
= _get_doc3_iface(line
, (IUnknown
*)doc
);
689 name
= a2bstr(namea
);
690 hres
= IHTMLDocument3_detachEvent(doc3
, name
, disp
);
691 IHTMLDocument3_Release(doc3
);
693 ok_(__FILE__
,line
)(hres
== S_OK
, "detachEvent failed: %08x\n", hres
);
696 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
700 if(IsEqualGUID(riid
, &IID_IUnknown
)
701 || IsEqualGUID(riid
, &IID_IDispatch
)
702 || IsEqualGUID(riid
, &IID_IDispatchEx
))
705 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
706 return E_NOINTERFACE
;
712 static HRESULT WINAPI
Dispatch_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
716 if(IsEqualGUID(riid
, &IID_IUnknown
)
717 || IsEqualGUID(riid
, &IID_IDispatch
)) {
719 }else if(IsEqualGUID(riid
, &IID_IDispatchEx
)) {
720 return E_NOINTERFACE
;
722 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
723 return E_NOINTERFACE
;
729 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
734 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
739 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
741 ok(0, "unexpected call\n");
745 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
746 LCID lcid
, ITypeInfo
**ppTInfo
)
748 ok(0, "unexpected call\n");
752 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
753 LPOLESTR
*rgszNames
, UINT cNames
,
754 LCID lcid
, DISPID
*rgDispId
)
756 ok(0, "unexpected call\n");
760 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
761 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
762 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
764 ok(0, "unexpected call\n");
768 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
770 ok(0, "unexpected call\n");
774 static HRESULT WINAPI
DispatchEx_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
775 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
777 ok(0, "unexpected call\n");
781 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
783 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName
), grfdex
);
787 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
789 ok(0, "unexpected call\n");
793 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
795 ok(0, "unexpected call\n");
799 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
801 ok(0, "unexpected call\n");
805 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
807 ok(0, "unexpected call\n");
811 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
813 ok(0, "unexpected call\n");
817 #define EVENT_HANDLER_FUNC_OBJ(event) \
818 static IDispatchExVtbl event ## FuncVtbl = { \
819 DispatchEx_QueryInterface, \
821 DispatchEx_Release, \
822 DispatchEx_GetTypeInfoCount, \
823 DispatchEx_GetTypeInfo, \
824 DispatchEx_GetIDsOfNames, \
826 DispatchEx_GetDispID, \
828 DispatchEx_DeleteMemberByName, \
829 DispatchEx_DeleteMemberByDispID, \
830 DispatchEx_GetMemberProperties, \
831 DispatchEx_GetMemberName, \
832 DispatchEx_GetNextDispID, \
833 DispatchEx_GetNameSpaceParent \
835 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
837 static HRESULT WINAPI
document_onclick(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
838 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
840 IHTMLDocument3
*doc3
;
841 CHECK_EXPECT(document_onclick
);
842 test_event_args(NULL
, id
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
843 doc3
= get_doc3_iface((IUnknown
*)V_DISPATCH(pdp
->rgvarg
));
844 IHTMLDocument3_Release(doc3
);
845 test_event_src("DIV");
846 test_event_obj("click", &no_xy
);
850 EVENT_HANDLER_FUNC_OBJ(document_onclick
);
852 static HRESULT WINAPI
div_onclick(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
853 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
855 CHECK_EXPECT(div_onclick
);
856 test_event_args(NULL
, id
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
857 test_event_src("DIV");
861 EVENT_HANDLER_FUNC_OBJ(div_onclick
);
863 static HRESULT WINAPI
div_onclick_attached(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
864 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
866 CHECK_EXPECT(div_onclick_attached
);
868 test_attached_event_args(id
, wFlags
, pdp
, pvarRes
, pei
);
869 test_event_src("DIV");
873 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached
);
875 static HRESULT WINAPI
doc_onclick_attached(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
876 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
878 CHECK_EXPECT(doc_onclick_attached
);
880 test_attached_event_args(id
, wFlags
, pdp
, pvarRes
, pei
);
881 test_event_src("DIV");
885 EVENT_HANDLER_FUNC_OBJ(doc_onclick_attached
);
887 static HRESULT WINAPI
body_onclick(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
888 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
890 CHECK_EXPECT(body_onclick
);
891 test_event_args(&DIID_DispHTMLBody
, id
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
892 test_event_src("DIV");
896 EVENT_HANDLER_FUNC_OBJ(body_onclick
);
898 static HRESULT WINAPI
img_onload(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
899 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
901 CHECK_EXPECT(img_onload
);
902 test_event_args(&DIID_DispHTMLImg
, id
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
903 test_event_src("IMG");
907 EVENT_HANDLER_FUNC_OBJ(img_onload
);
909 static HRESULT WINAPI
iframedoc_onreadystatechange(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
910 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
912 IHTMLEventObj
*event
= NULL
;
915 CHECK_EXPECT2(iframedoc_onreadystatechange
);
916 test_event_args(&DIID_DispHTMLDocument
, id
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
918 event
= (void*)0xdeadbeef;
919 hres
= IHTMLWindow2_get_event(window
, &event
);
920 ok(hres
== S_OK
, "get_event failed: %08x\n", hres
);
921 ok(!event
, "event = %p\n", event
);
926 EVENT_HANDLER_FUNC_OBJ(iframedoc_onreadystatechange
);
928 static HRESULT WINAPI
iframe_onreadystatechange(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
929 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
931 IHTMLWindow2
*iframe_window
;
932 IHTMLDocument2
*iframe_doc
;
933 IHTMLFrameBase2
*iframe
;
934 IHTMLElement2
*elem2
;
940 test_event_args(&DIID_DispHTMLIFrame
, id
, wFlags
, pdp
, pvarRes
, pei
, pspCaller
);
941 test_event_src("IFRAME");
943 elem
= get_event_src();
944 elem2
= get_elem2_iface((IUnknown
*)elem
);
945 IHTMLElement_Release(elem
);
948 hres
= IHTMLElement2_get_readyState(elem2
, &v
);
949 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
950 ok(V_VT(&v
) == VT_BSTR
, "V_VT(readyState) = %d\n", V_VT(&v
));
952 hres
= IHTMLElement2_QueryInterface(elem2
, &IID_IHTMLFrameBase2
, (void**)&iframe
);
953 IHTMLElement2_Release(elem2
);
954 ok(hres
== S_OK
, "Could not get IHTMLFrameBase2 iface: %08x\n", hres
);
957 hres
= IHTMLFrameBase2_get_readyState(iframe
, &str
);
958 IHTMLFrameBase2_Release(iframe
);
959 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
960 ok(str
!= NULL
, "readyState == NULL\n");
961 ok(!lstrcmpW(str
, V_BSTR(&v
)), "ready states differ\n");
964 hres
= IHTMLFrameBase2_get_contentWindow(iframe
, &iframe_window
);
965 ok(hres
== S_OK
, "get_contentDocument failed: %08x\n", hres
);
967 hres
= IHTMLWindow2_get_document(iframe_window
, &iframe_doc
);
968 IHTMLWindow2_Release(iframe_window
);
969 ok(hres
== S_OK
, "get_document failed: %08x\n", hres
);
971 hres
= IHTMLDocument2_get_readyState(iframe_doc
, &str2
);
972 ok(!lstrcmpW(str
, str2
), "unexpected document readyState %s\n", wine_dbgstr_w(str2
));
975 if(!strcmp_wa(str
, "loading")) {
976 CHECK_EXPECT(iframe_onreadystatechange_loading
);
978 V_VT(&v
) = VT_DISPATCH
;
979 V_DISPATCH(&v
) = (IDispatch
*)&iframedoc_onreadystatechange_obj
;
980 hres
= IHTMLDocument2_put_onreadystatechange(iframe_doc
, v
);
981 ok(hres
== S_OK
, "put_onreadystatechange: %08x\n", hres
);
982 }else if(!strcmp_wa(str
, "interactive"))
983 CHECK_EXPECT(iframe_onreadystatechange_interactive
);
984 else if(!strcmp_wa(str
, "complete"))
985 CHECK_EXPECT(iframe_onreadystatechange_complete
);
987 ok(0, "unexpected state %s\n", wine_dbgstr_w(str
));
989 IHTMLDocument2_Release(iframe_doc
);
990 IHTMLFrameBase2_Release(iframe
);
994 EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange
);
996 static HRESULT WINAPI
nocall(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
997 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
999 ok(0, "unexpected call\n");
1003 EVENT_HANDLER_FUNC_OBJ(nocall
);
1005 #define CONNECTION_POINT_OBJ(cpname, diid) \
1006 static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
1009 if(IsEqualGUID(riid, &IID_IUnknown) \
1010 || IsEqualGUID(riid, &IID_IDispatch) \
1011 || IsEqualGUID(riid, &diid)) \
1014 ok(0, "unexpected riid %s\n", debugstr_guid(riid)); \
1015 return E_NOINTERFACE; \
1019 static IDispatchExVtbl cpname ## Vtbl = { \
1020 cpname ## _QueryInterface, \
1021 DispatchEx_AddRef, \
1022 DispatchEx_Release, \
1023 DispatchEx_GetTypeInfoCount, \
1024 DispatchEx_GetTypeInfo, \
1025 DispatchEx_GetIDsOfNames, \
1027 DispatchEx_GetDispID, \
1028 DispatchEx_InvokeEx, \
1029 DispatchEx_DeleteMemberByName, \
1030 DispatchEx_DeleteMemberByDispID, \
1031 DispatchEx_GetMemberProperties, \
1032 DispatchEx_GetMemberName, \
1033 DispatchEx_GetNextDispID, \
1034 DispatchEx_GetNameSpaceParent \
1036 static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
1038 #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
1039 static void _test_cp_args(unsigned line
, REFIID riid
, WORD flags
, DISPPARAMS
*dp
, VARIANT
*vres
, EXCEPINFO
*ei
, UINT
*argerr
)
1041 ok_(__FILE__
,line
)(IsEqualGUID(&IID_NULL
, riid
), "riid = %s\n", debugstr_guid(riid
));
1042 ok_(__FILE__
,line
)(flags
== DISPATCH_METHOD
, "flags = %x\n", flags
);
1043 ok_(__FILE__
,line
)(dp
!= NULL
, "dp == NULL\n");
1044 ok_(__FILE__
,line
)(!dp
->cArgs
, "dp->cArgs = %d\n", dp
->cArgs
);
1045 ok_(__FILE__
,line
)(!dp
->rgvarg
, "dp->rgvarg = %p\n", dp
->rgvarg
);
1046 ok_(__FILE__
,line
)(!dp
->cNamedArgs
, "dp->cNamedArgs = %d\n", dp
->cNamedArgs
);
1047 ok_(__FILE__
,line
)(!dp
->rgdispidNamedArgs
, "dp->rgdispidNamedArgs = %p\n", dp
->rgdispidNamedArgs
);
1048 ok_(__FILE__
,line
)(vres
!= NULL
, "vres == NULL\n");
1049 ok_(__FILE__
,line
)(V_VT(vres
) == VT_EMPTY
, "V_VT(vres) = %d\n", V_VT(vres
));
1050 ok_(__FILE__
,line
)(ei
!= NULL
, "ei == NULL\n");
1051 ok_(__FILE__
,line
)(argerr
!= NULL
, "argerr == NULL\n");
1054 static HRESULT WINAPI
doccp(IDispatchEx
*iface
, DISPID dispIdMember
,
1055 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1056 VARIANT
*pVarResult
, EXCEPINFO
*pei
, UINT
*puArgErr
)
1058 switch(dispIdMember
) {
1059 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK
:
1060 CHECK_EXPECT(doccp_onclick
);
1061 test_cp_args(riid
, wFlags
, pdp
, pVarResult
, pei
, puArgErr
);
1064 ok(0, "unexpected call %d\n", dispIdMember
);
1071 CONNECTION_POINT_OBJ(doccp
, DIID_HTMLDocumentEvents
);
1073 static HRESULT WINAPI
timeoutFunc_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
1074 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1075 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1077 CHECK_EXPECT(timeout
);
1079 ok(dispIdMember
== DISPID_VALUE
, "dispIdMember = %d\n", dispIdMember
);
1080 ok(IsEqualGUID(&IID_NULL
, riid
), "riid = %s\n", debugstr_guid(riid
));
1081 ok(wFlags
== DISPATCH_METHOD
, "wFlags = %x\n", wFlags
);
1082 ok(!lcid
, "lcid = %x\n", lcid
);
1083 ok(pDispParams
!= NULL
, "pDispParams == NULL\n");
1084 ok(!pDispParams
->cArgs
, "pdp->cArgs = %d\n", pDispParams
->cArgs
);
1085 ok(!pDispParams
->cNamedArgs
, "pdp->cNamedArgs = %d\n", pDispParams
->cNamedArgs
);
1086 ok(!pDispParams
->rgdispidNamedArgs
, "pdp->rgdispidNamedArgs = %p\n", pDispParams
->rgdispidNamedArgs
);
1087 ok(!pDispParams
->rgvarg
, "rgvarg = %p\n", pDispParams
->rgvarg
);
1088 ok(pVarResult
!= NULL
, "pVarResult = NULL\n");
1089 ok(pExcepInfo
!= NULL
, "pExcepInfo = NULL\n");
1090 ok(!puArgErr
, "puArgErr = %p\n", puArgErr
);
1091 ok(V_VT(pVarResult
) == VT_EMPTY
, "V_VT(pVarResult) = %d\n", V_VT(pVarResult
));
1096 static IDispatchExVtbl timeoutFuncVtbl
= {
1097 DispatchEx_QueryInterface
,
1100 DispatchEx_GetTypeInfoCount
,
1101 DispatchEx_GetTypeInfo
,
1102 DispatchEx_GetIDsOfNames
,
1104 DispatchEx_GetDispID
,
1105 DispatchEx_InvokeEx
,
1106 DispatchEx_DeleteMemberByName
,
1107 DispatchEx_DeleteMemberByDispID
,
1108 DispatchEx_GetMemberProperties
,
1109 DispatchEx_GetMemberName
,
1110 DispatchEx_GetNextDispID
,
1111 DispatchEx_GetNameSpaceParent
1114 static IDispatchEx timeoutFunc
= { &timeoutFuncVtbl
};
1116 static HRESULT WINAPI
div_onclick_disp_Invoke(IDispatchEx
*iface
, DISPID id
,
1117 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
1118 VARIANT
*pvarRes
, EXCEPINFO
*pei
, UINT
*puArgErr
)
1120 CHECK_EXPECT(div_onclick_disp
);
1122 test_attached_event_args(id
, wFlags
, pdp
, pvarRes
, pei
);
1124 ok(IsEqualGUID(&IID_NULL
, riid
), "riid = %s\n", debugstr_guid(riid
));
1125 ok(!puArgErr
, "puArgErr = %p\n", puArgErr
);
1130 static IDispatchExVtbl div_onclick_dispVtbl
= {
1131 Dispatch_QueryInterface
,
1134 DispatchEx_GetTypeInfoCount
,
1135 DispatchEx_GetTypeInfo
,
1136 DispatchEx_GetIDsOfNames
,
1137 div_onclick_disp_Invoke
,
1140 static IDispatchEx div_onclick_disp
= { &div_onclick_dispVtbl
};
1142 static void pump_msgs(BOOL
*b
)
1145 while(!*b
&& GetMessage(&msg
, NULL
, 0, 0)) {
1146 TranslateMessage(&msg
);
1147 DispatchMessage(&msg
);
1151 static IConnectionPoint
*get_cp(IUnknown
*unk
, REFIID riid
)
1153 IConnectionPointContainer
*cp_container
;
1154 IConnectionPoint
*cp
;
1157 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&cp_container
);
1158 ok(hres
== S_OK
, "Could not get IConnectionPointContainer: %08x\n", hres
);
1160 hres
= IConnectionPointContainer_FindConnectionPoint(cp_container
, riid
, &cp
);
1161 IConnectionPointContainer_Release(cp_container
);
1162 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
1167 static DWORD
register_cp(IUnknown
*unk
, REFIID riid
, IUnknown
*sink
)
1169 IConnectionPoint
*cp
;
1173 cp
= get_cp(unk
, riid
);
1174 hres
= IConnectionPoint_Advise(cp
, sink
, &cookie
);
1175 IConnectionPoint_Release(cp
);
1176 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
1181 static void unregister_cp(IUnknown
*unk
, REFIID riid
, DWORD cookie
)
1183 IConnectionPoint
*cp
;
1186 cp
= get_cp(unk
, riid
);
1187 hres
= IConnectionPoint_Unadvise(cp
, cookie
);
1188 IConnectionPoint_Release(cp
);
1189 ok(hres
== S_OK
, "Unadvise failed: %08x\n", hres
);
1192 static void test_onclick(IHTMLDocument2
*doc
)
1194 IHTMLElement
*div
, *body
;
1199 div
= get_elem_id(doc
, "clickdiv");
1201 elem_attach_event((IUnknown
*)div
, "abcde", (IDispatch
*)&nocall_obj
);
1202 elem_attach_event((IUnknown
*)div
, "onclick", (IDispatch
*)&div_onclick_attached_obj
);
1204 V_VT(&v
) = VT_EMPTY
;
1205 hres
= IHTMLElement_get_onclick(div
, &v
);
1206 ok(hres
== S_OK
, "get_onclick failed: %08x\n", hres
);
1207 ok(V_VT(&v
) == VT_NULL
, "V_VT(onclick) = %d\n", V_VT(&v
));
1209 V_VT(&v
) = VT_EMPTY
;
1210 hres
= IHTMLElement_put_onclick(div
, v
);
1211 ok(hres
== E_NOTIMPL
, "put_onclick failed: %08x\n", hres
);
1213 V_VT(&v
) = VT_DISPATCH
;
1214 V_DISPATCH(&v
) = (IDispatch
*)&div_onclick_obj
;
1215 hres
= IHTMLElement_put_onclick(div
, v
);
1216 ok(hres
== S_OK
, "put_onclick failed: %08x\n", hres
);
1219 hres
= IHTMLElement_put_ondblclick(div
, v
);
1220 ok(hres
== S_OK
, "put_ondblclick failed: %08x\n", hres
);
1222 V_VT(&v
) = VT_EMPTY
;
1223 hres
= IHTMLElement_get_onclick(div
, &v
);
1224 ok(hres
== S_OK
, "get_onclick failed: %08x\n", hres
);
1225 ok(V_VT(&v
) == VT_DISPATCH
, "V_VT(onclick) = %d\n", V_VT(&v
));
1226 ok(V_DISPATCH(&v
) == (IDispatch
*)&div_onclick_obj
, "V_DISPATCH(onclick) != onclickFunc\n");
1229 V_VT(&v
) = VT_EMPTY
;
1230 hres
= IHTMLDocument2_get_onclick(doc
, &v
);
1231 ok(hres
== S_OK
, "get_onclick failed: %08x\n", hres
);
1232 ok(V_VT(&v
) == VT_NULL
, "V_VT(onclick) = %d\n", V_VT(&v
));
1234 V_VT(&v
) = VT_DISPATCH
;
1235 V_DISPATCH(&v
) = (IDispatch
*)&document_onclick_obj
;
1236 hres
= IHTMLDocument2_put_onclick(doc
, v
);
1237 ok(hres
== S_OK
, "put_onclick failed: %08x\n", hres
);
1239 V_VT(&v
) = VT_EMPTY
;
1240 hres
= IHTMLDocument2_get_onclick(doc
, &v
);
1241 ok(hres
== S_OK
, "get_onclick failed: %08x\n", hres
);
1242 ok(V_VT(&v
) == VT_DISPATCH
, "V_VT(onclick) = %d\n", V_VT(&v
));
1243 ok(V_DISPATCH(&v
) == (IDispatch
*)&document_onclick_obj
, "V_DISPATCH(onclick) != onclickFunc\n");
1246 body
= doc_get_body(doc
);
1248 V_VT(&v
) = VT_DISPATCH
;
1249 V_DISPATCH(&v
) = (IDispatch
*)&body_onclick_obj
;
1250 hres
= IHTMLElement_put_onclick(body
, v
);
1251 ok(hres
== S_OK
, "put_onclick failed: %08x\n", hres
);
1253 if(winetest_interactive
) {
1254 SET_EXPECT(div_onclick
);
1255 SET_EXPECT(div_onclick_attached
);
1256 SET_EXPECT(body_onclick
);
1257 SET_EXPECT(document_onclick
);
1258 pump_msgs(&called_document_onclick
);
1259 CHECK_CALLED(div_onclick
);
1260 CHECK_CALLED(div_onclick_attached
);
1261 CHECK_CALLED(body_onclick
);
1262 CHECK_CALLED(document_onclick
);
1267 SET_EXPECT(div_onclick
);
1268 SET_EXPECT(div_onclick_attached
);
1269 SET_EXPECT(body_onclick
);
1270 SET_EXPECT(document_onclick
);
1272 hres
= IHTMLElement_click(div
);
1273 ok(hres
== S_OK
, "click failed: %08x\n", hres
);
1275 CHECK_CALLED(div_onclick
);
1276 CHECK_CALLED(div_onclick_attached
);
1277 CHECK_CALLED(body_onclick
);
1278 CHECK_CALLED(document_onclick
);
1280 SET_EXPECT(div_onclick
);
1281 SET_EXPECT(div_onclick_attached
);
1282 SET_EXPECT(body_onclick
);
1283 SET_EXPECT(document_onclick
);
1285 V_VT(&v
) = VT_EMPTY
;
1286 elem_fire_event((IUnknown
*)div
, "onclick", &v
);
1288 CHECK_CALLED(div_onclick
);
1289 CHECK_CALLED(div_onclick_attached
);
1290 CHECK_CALLED(body_onclick
);
1291 CHECK_CALLED(document_onclick
);
1293 cp_cookie
= register_cp((IUnknown
*)doc
, &DIID_HTMLDocumentEvents
, (IUnknown
*)&doccp_obj
);
1294 elem_attach_event((IUnknown
*)div
, "onclick", (IDispatch
*)&div_onclick_disp
);
1295 doc_attach_event(doc
, "onclick", (IDispatch
*)&doc_onclick_attached_obj
);
1297 SET_EXPECT(div_onclick
);
1298 SET_EXPECT(div_onclick_disp
);
1299 SET_EXPECT(div_onclick_attached
);
1300 SET_EXPECT(body_onclick
);
1301 SET_EXPECT(document_onclick
);
1302 SET_EXPECT(doc_onclick_attached
);
1303 SET_EXPECT(doccp_onclick
);
1305 hres
= IHTMLElement_click(div
);
1306 ok(hres
== S_OK
, "click failed: %08x\n", hres
);
1308 CHECK_CALLED(div_onclick
);
1309 CHECK_CALLED(div_onclick_disp
);
1310 CHECK_CALLED(div_onclick_attached
);
1311 CHECK_CALLED(body_onclick
);
1312 CHECK_CALLED(document_onclick
);
1313 CHECK_CALLED(doc_onclick_attached
);
1314 CHECK_CALLED(doccp_onclick
);
1316 unregister_cp((IUnknown
*)doc
, &DIID_HTMLDocumentEvents
, cp_cookie
);
1319 hres
= IHTMLElement_put_onclick(div
, v
);
1320 ok(hres
== S_OK
, "put_onclick failed: %08x\n", hres
);
1322 hres
= IHTMLElement_get_onclick(div
, &v
);
1323 ok(hres
== S_OK
, "get_onclick failed: %08x\n", hres
);
1324 ok(V_VT(&v
) == VT_NULL
, "get_onclick returned vt %d\n", V_VT(&v
));
1326 elem_detach_event((IUnknown
*)div
, "onclick", (IDispatch
*)&div_onclick_disp
);
1327 elem_detach_event((IUnknown
*)div
, "onclick", (IDispatch
*)&div_onclick_disp
);
1328 elem_detach_event((IUnknown
*)div
, "test", (IDispatch
*)&div_onclick_disp
);
1329 doc_detach_event(doc
, "onclick", (IDispatch
*)&doc_onclick_attached_obj
);
1331 SET_EXPECT(div_onclick_attached
);
1332 SET_EXPECT(body_onclick
);
1333 SET_EXPECT(document_onclick
);
1335 hres
= IHTMLElement_click(div
);
1336 ok(hres
== S_OK
, "click failed: %08x\n", hres
);
1338 CHECK_CALLED(div_onclick_attached
);
1339 CHECK_CALLED(body_onclick
);
1340 CHECK_CALLED(document_onclick
);
1342 IHTMLElement_Release(div
);
1343 IHTMLElement_Release(body
);
1346 static void test_onreadystatechange(IHTMLDocument2
*doc
)
1348 IHTMLFrameBase
*iframe
;
1349 IHTMLElement2
*elem2
;
1355 elem
= get_elem_id(doc
, "iframe");
1356 elem2
= get_elem2_iface((IUnknown
*)elem
);
1357 IHTMLElement_Release(elem
);
1359 V_VT(&v
) = VT_EMPTY
;
1360 hres
= IHTMLElement2_get_onreadystatechange(elem2
, &v
);
1361 ok(hres
== S_OK
, "get_onreadystatechange failed: %08x\n", hres
);
1362 ok(V_VT(&v
) == VT_NULL
, "V_VT(onreadystatechange) = %d\n", V_VT(&v
));
1364 V_VT(&v
) = VT_DISPATCH
;
1365 V_DISPATCH(&v
) = (IDispatch
*)&iframe_onreadystatechange_obj
;
1366 hres
= IHTMLElement2_put_onreadystatechange(elem2
, v
);
1367 ok(hres
== S_OK
, "put_onreadystatechange failed: %08x\n", hres
);
1369 V_VT(&v
) = VT_EMPTY
;
1370 hres
= IHTMLElement2_get_onreadystatechange(elem2
, &v
);
1371 ok(hres
== S_OK
, "get_onreadystatechange failed: %08x\n", hres
);
1372 ok(V_VT(&v
) == VT_DISPATCH
, "V_VT(onreadystatechange) = %d\n", V_VT(&v
));
1373 ok(V_DISPATCH(&v
) == (IDispatch
*)&iframe_onreadystatechange_obj
, "unexpected onreadystatechange value\n");
1375 hres
= IHTMLElement2_QueryInterface(elem2
, &IID_IHTMLFrameBase
, (void**)&iframe
);
1376 IHTMLElement2_Release(elem2
);
1377 ok(hres
== S_OK
, "Could not get IHTMLFrameBase iface: %08x\n", hres
);
1379 hres
= IHTMLFrameBase_put_src(iframe
, (str
= a2bstr("about:blank")));
1381 ok(hres
== S_OK
, "put_src failed: %08x\n", hres
);
1383 SET_EXPECT(iframe_onreadystatechange_loading
);
1384 SET_EXPECT(iframedoc_onreadystatechange
);
1385 SET_EXPECT(iframe_onreadystatechange_interactive
);
1386 SET_EXPECT(iframe_onreadystatechange_complete
);
1387 pump_msgs(&called_iframe_onreadystatechange_complete
);
1388 CHECK_CALLED(iframe_onreadystatechange_loading
);
1389 CHECK_CALLED(iframedoc_onreadystatechange
);
1390 CHECK_CALLED(iframe_onreadystatechange_interactive
);
1391 CHECK_CALLED(iframe_onreadystatechange_complete
);
1393 IHTMLFrameBase_Release(iframe
);
1396 static void test_imgload(IHTMLDocument2
*doc
)
1398 IHTMLImgElement
*img
;
1404 elem
= get_elem_id(doc
, "imgid");
1405 hres
= IHTMLElement_QueryInterface(elem
, &IID_IHTMLImgElement
, (void**)&img
);
1406 IHTMLElement_Release(elem
);
1407 ok(hres
== S_OK
, "Could not get IHTMLImgElement iface: %08x\n", hres
);
1409 V_VT(&v
) = VT_EMPTY
;
1410 hres
= IHTMLImgElement_get_onload(img
, &v
);
1411 ok(hres
== S_OK
, "get_onload failed: %08x\n", hres
);
1412 ok(V_VT(&v
) == VT_NULL
, "V_VT(onload) = %d\n", V_VT(&v
));
1414 V_VT(&v
) = VT_DISPATCH
;
1415 V_DISPATCH(&v
) = (IDispatch
*)&img_onload_obj
;
1416 hres
= IHTMLImgElement_put_onload(img
, v
);
1417 ok(hres
== S_OK
, "put_onload failed: %08x\n", hres
);
1419 V_VT(&v
) = VT_EMPTY
;
1420 hres
= IHTMLImgElement_get_onload(img
, &v
);
1421 ok(hres
== S_OK
, "get_onload failed: %08x\n", hres
);
1422 ok(V_VT(&v
) == VT_DISPATCH
, "V_VT(onload) = %d\n", V_VT(&v
));
1423 ok(V_DISPATCH(&v
) == (IDispatch
*)&img_onload_obj
, "V_DISPATCH(onload) != onloadkFunc\n");
1426 str
= a2bstr("http://www.winehq.org/images/winehq_logo_text.png");
1427 hres
= IHTMLImgElement_put_src(img
, str
);
1428 ok(hres
== S_OK
, "put_src failed: %08x\n", hres
);
1431 SET_EXPECT(img_onload
);
1432 pump_msgs(&called_img_onload
);
1433 CHECK_CALLED(img_onload
);
1435 IHTMLImgElement_Release(img
);
1438 static void test_timeout(IHTMLDocument2
*doc
)
1445 hres
= IHTMLWindow2_QueryInterface(window
, &IID_IHTMLWindow3
, (void**)&win3
);
1446 ok(hres
== S_OK
, "Could not get IHTMLWindow3 iface: %08x\n", hres
);
1448 V_VT(&expr
) = VT_DISPATCH
;
1449 V_DISPATCH(&expr
) = (IDispatch
*)&timeoutFunc
;
1450 V_VT(&var
) = VT_EMPTY
;
1452 hres
= IHTMLWindow3_setTimeout(win3
, &expr
, 0, &var
, &id
);
1453 ok(hres
== S_OK
, "setTimeout failed: %08x\n", hres
);
1456 SET_EXPECT(timeout
);
1457 pump_msgs(&called_timeout
);
1458 CHECK_CALLED(timeout
);
1460 V_VT(&expr
) = VT_DISPATCH
;
1461 V_DISPATCH(&expr
) = (IDispatch
*)&timeoutFunc
;
1462 V_VT(&var
) = VT_EMPTY
;
1464 hres
= IHTMLWindow3_setTimeout(win3
, &expr
, 0, &var
, &id
);
1465 ok(hres
== S_OK
, "setTimeout failed: %08x\n", hres
);
1468 hres
= IHTMLWindow2_clearTimeout(window
, id
);
1469 ok(hres
== S_OK
, "clearTimeout failed: %08x\n", hres
);
1471 IHTMLWindow3_Release(win3
);
1474 static HRESULT
QueryInterface(REFIID
,void**);
1476 static HRESULT WINAPI
InPlaceFrame_QueryInterface(IOleInPlaceFrame
*iface
, REFIID riid
, void **ppv
)
1478 return E_NOINTERFACE
;
1481 static ULONG WINAPI
InPlaceFrame_AddRef(IOleInPlaceFrame
*iface
)
1486 static ULONG WINAPI
InPlaceFrame_Release(IOleInPlaceFrame
*iface
)
1491 static HRESULT WINAPI
InPlaceFrame_GetWindow(IOleInPlaceFrame
*iface
, HWND
*phwnd
)
1496 static HRESULT WINAPI
InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame
*iface
, BOOL fEnterMode
)
1501 static HRESULT WINAPI
InPlaceFrame_GetBorder(IOleInPlaceFrame
*iface
, LPRECT lprectBorder
)
1506 static HRESULT WINAPI
InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame
*iface
,
1507 LPCBORDERWIDTHS pborderwidths
)
1512 static HRESULT WINAPI
InPlaceFrame_SetBorderSpace(IOleInPlaceFrame
*iface
,
1513 LPCBORDERWIDTHS pborderwidths
)
1518 static HRESULT WINAPI
InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame
*iface
,
1519 IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1524 static HRESULT WINAPI
InPlaceFrame_SetActiveObject(IOleInPlaceFrame
*iface
,
1525 IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1530 static HRESULT WINAPI
InPlaceFrame_InsertMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
,
1531 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1536 static HRESULT WINAPI
InPlaceFrame_SetMenu(IOleInPlaceFrame
*iface
, HMENU hmenuShared
,
1537 HOLEMENU holemenu
, HWND hwndActiveObject
)
1539 ok(0, "unexpected call\n");
1543 static HRESULT WINAPI
InPlaceFrame_RemoveMenus(IOleInPlaceFrame
*iface
, HMENU hmenuShared
)
1545 ok(0, "unexpected call\n");
1549 static HRESULT WINAPI
InPlaceFrame_SetStatusText(IOleInPlaceFrame
*iface
, LPCOLESTR pszStatusText
)
1554 static HRESULT WINAPI
InPlaceFrame_EnableModeless(IOleInPlaceFrame
*iface
, BOOL fEnable
)
1559 static HRESULT WINAPI
InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame
*iface
, LPMSG lpmsg
, WORD wID
)
1561 ok(0, "unexpected call\n");
1565 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl
= {
1566 InPlaceFrame_QueryInterface
,
1567 InPlaceFrame_AddRef
,
1568 InPlaceFrame_Release
,
1569 InPlaceFrame_GetWindow
,
1570 InPlaceFrame_ContextSensitiveHelp
,
1571 InPlaceFrame_GetBorder
,
1572 InPlaceFrame_RequestBorderSpace
,
1573 InPlaceFrame_SetBorderSpace
,
1574 InPlaceFrame_SetActiveObject
,
1575 InPlaceFrame_InsertMenus
,
1576 InPlaceFrame_SetMenu
,
1577 InPlaceFrame_RemoveMenus
,
1578 InPlaceFrame_SetStatusText
,
1579 InPlaceFrame_EnableModeless
,
1580 InPlaceFrame_TranslateAccelerator
1583 static IOleInPlaceFrame InPlaceFrame
= { &InPlaceFrameVtbl
};
1585 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl
= {
1586 InPlaceFrame_QueryInterface
,
1587 InPlaceFrame_AddRef
,
1588 InPlaceFrame_Release
,
1589 InPlaceFrame_GetWindow
,
1590 InPlaceFrame_ContextSensitiveHelp
,
1591 InPlaceFrame_GetBorder
,
1592 InPlaceFrame_RequestBorderSpace
,
1593 InPlaceFrame_SetBorderSpace
,
1594 InPlaceUIWindow_SetActiveObject
,
1597 static IOleInPlaceFrame InPlaceUIWindow
= { &InPlaceUIWindowVtbl
};
1599 static HRESULT WINAPI
InPlaceSite_QueryInterface(IOleInPlaceSite
*iface
, REFIID riid
, void **ppv
)
1601 return QueryInterface(riid
, ppv
);
1604 static ULONG WINAPI
InPlaceSite_AddRef(IOleInPlaceSite
*iface
)
1609 static ULONG WINAPI
InPlaceSite_Release(IOleInPlaceSite
*iface
)
1614 static HRESULT WINAPI
InPlaceSite_GetWindow(IOleInPlaceSite
*iface
, HWND
*phwnd
)
1616 *phwnd
= container_hwnd
;
1620 static HRESULT WINAPI
InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite
*iface
, BOOL fEnterMode
)
1622 ok(0, "unexpected call\n");
1626 static HRESULT WINAPI
InPlaceSite_CanInPlaceActivate(IOleInPlaceSite
*iface
)
1631 static HRESULT WINAPI
InPlaceSite_OnInPlaceActivate(IOleInPlaceSite
*iface
)
1636 static HRESULT WINAPI
InPlaceSite_OnUIActivate(IOleInPlaceSite
*iface
)
1641 static HRESULT WINAPI
InPlaceSite_GetWindowContext(IOleInPlaceSite
*iface
,
1642 IOleInPlaceFrame
**ppFrame
, IOleInPlaceUIWindow
**ppDoc
, LPRECT lprcPosRect
,
1643 LPRECT lprcClipRect
, LPOLEINPLACEFRAMEINFO lpFrameInfo
)
1645 static const RECT rect
= {0,0,300,300};
1647 *ppFrame
= &InPlaceFrame
;
1648 *ppDoc
= (IOleInPlaceUIWindow
*)&InPlaceUIWindow
;
1649 *lprcPosRect
= rect
;
1650 *lprcClipRect
= rect
;
1652 lpFrameInfo
->cb
= sizeof(*lpFrameInfo
);
1653 lpFrameInfo
->fMDIApp
= FALSE
;
1654 lpFrameInfo
->hwndFrame
= container_hwnd
;
1655 lpFrameInfo
->haccel
= NULL
;
1656 lpFrameInfo
->cAccelEntries
= 0;
1661 static HRESULT WINAPI
InPlaceSite_Scroll(IOleInPlaceSite
*iface
, SIZE scrollExtant
)
1666 static HRESULT WINAPI
InPlaceSite_OnUIDeactivate(IOleInPlaceSite
*iface
, BOOL fUndoable
)
1671 static HRESULT WINAPI
InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite
*iface
)
1676 static HRESULT WINAPI
InPlaceSite_DiscardUndoState(IOleInPlaceSite
*iface
)
1681 static HRESULT WINAPI
InPlaceSite_DeactivateAndUndo(IOleInPlaceSite
*iface
)
1686 static HRESULT WINAPI
InPlaceSite_OnPosRectChange(IOleInPlaceSite
*iface
, LPCRECT lprcPosRect
)
1691 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl
= {
1692 InPlaceSite_QueryInterface
,
1694 InPlaceSite_Release
,
1695 InPlaceSite_GetWindow
,
1696 InPlaceSite_ContextSensitiveHelp
,
1697 InPlaceSite_CanInPlaceActivate
,
1698 InPlaceSite_OnInPlaceActivate
,
1699 InPlaceSite_OnUIActivate
,
1700 InPlaceSite_GetWindowContext
,
1702 InPlaceSite_OnUIDeactivate
,
1703 InPlaceSite_OnInPlaceDeactivate
,
1704 InPlaceSite_DiscardUndoState
,
1705 InPlaceSite_DeactivateAndUndo
,
1706 InPlaceSite_OnPosRectChange
,
1709 static IOleInPlaceSite InPlaceSite
= { &InPlaceSiteVtbl
};
1711 static HRESULT WINAPI
ClientSite_QueryInterface(IOleClientSite
*iface
, REFIID riid
, void **ppv
)
1713 return QueryInterface(riid
, ppv
);
1716 static ULONG WINAPI
ClientSite_AddRef(IOleClientSite
*iface
)
1721 static ULONG WINAPI
ClientSite_Release(IOleClientSite
*iface
)
1726 static HRESULT WINAPI
ClientSite_SaveObject(IOleClientSite
*iface
)
1728 ok(0, "unexpected call\n");
1732 static HRESULT WINAPI
ClientSite_GetMoniker(IOleClientSite
*iface
, DWORD dwAssign
, DWORD dwWhichMoniker
,
1735 ok(0, "unexpected call\n");
1739 static HRESULT WINAPI
ClientSite_GetContainer(IOleClientSite
*iface
, IOleContainer
**ppContainer
)
1744 static HRESULT WINAPI
ClientSite_ShowObject(IOleClientSite
*iface
)
1746 ok(0, "unexpected call\n");
1750 static HRESULT WINAPI
ClientSite_OnShowWindow(IOleClientSite
*iface
, BOOL fShow
)
1752 ok(0, "unexpected call\n");
1756 static HRESULT WINAPI
ClientSite_RequestNewObjectLayout(IOleClientSite
*iface
)
1758 ok(0, "unexpected call\n");
1762 static const IOleClientSiteVtbl ClientSiteVtbl
= {
1763 ClientSite_QueryInterface
,
1766 ClientSite_SaveObject
,
1767 ClientSite_GetMoniker
,
1768 ClientSite_GetContainer
,
1769 ClientSite_ShowObject
,
1770 ClientSite_OnShowWindow
,
1771 ClientSite_RequestNewObjectLayout
1774 static IOleClientSite ClientSite
= { &ClientSiteVtbl
};
1776 static HRESULT WINAPI
DocumentSite_QueryInterface(IOleDocumentSite
*iface
, REFIID riid
, void **ppv
)
1778 return QueryInterface(riid
, ppv
);
1781 static ULONG WINAPI
DocumentSite_AddRef(IOleDocumentSite
*iface
)
1786 static ULONG WINAPI
DocumentSite_Release(IOleDocumentSite
*iface
)
1791 static HRESULT WINAPI
DocumentSite_ActivateMe(IOleDocumentSite
*iface
, IOleDocumentView
*pViewToActivate
)
1793 RECT rect
= {0,0,300,300};
1794 IOleDocument
*document
;
1797 hres
= IOleDocumentView_QueryInterface(pViewToActivate
, &IID_IOleDocument
, (void**)&document
);
1798 ok(hres
== S_OK
, "could not get IOleDocument: %08x\n", hres
);
1800 hres
= IOleDocument_CreateView(document
, &InPlaceSite
, NULL
, 0, &view
);
1801 IOleDocument_Release(document
);
1802 ok(hres
== S_OK
, "CreateView failed: %08x\n", hres
);
1804 hres
= IOleDocumentView_SetInPlaceSite(view
, &InPlaceSite
);
1805 ok(hres
== S_OK
, "SetInPlaceSite failed: %08x\n", hres
);
1807 hres
= IOleDocumentView_UIActivate(view
, TRUE
);
1808 ok(hres
== S_OK
, "UIActivate failed: %08x\n", hres
);
1810 hres
= IOleDocumentView_SetRect(view
, &rect
);
1811 ok(hres
== S_OK
, "SetRect failed: %08x\n", hres
);
1813 hres
= IOleDocumentView_Show(view
, TRUE
);
1814 ok(hres
== S_OK
, "Show failed: %08x\n", hres
);
1819 static const IOleDocumentSiteVtbl DocumentSiteVtbl
= {
1820 DocumentSite_QueryInterface
,
1821 DocumentSite_AddRef
,
1822 DocumentSite_Release
,
1823 DocumentSite_ActivateMe
1826 static IOleDocumentSite DocumentSite
= { &DocumentSiteVtbl
};
1828 static HRESULT
QueryInterface(REFIID riid
, void **ppv
)
1832 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IOleClientSite
, riid
))
1834 else if(IsEqualGUID(&IID_IOleDocumentSite
, riid
))
1835 *ppv
= &DocumentSite
;
1836 else if(IsEqualGUID(&IID_IOleWindow
, riid
) || IsEqualGUID(&IID_IOleInPlaceSite
, riid
))
1837 *ppv
= &InPlaceSite
;
1839 return *ppv
? S_OK
: E_NOINTERFACE
;
1842 static IHTMLDocument2
*notif_doc
;
1843 static BOOL doc_complete
;
1845 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
1846 REFIID riid
, void**ppv
)
1848 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
1853 ok(0, "unexpected call\n");
1854 return E_NOINTERFACE
;
1857 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
1862 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
1867 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
1869 if(dispID
== DISPID_READYSTATE
){
1873 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
1874 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
1876 if(!strcmp_wa(state
, "complete"))
1877 doc_complete
= TRUE
;
1879 SysFreeString(state
);
1885 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
1887 ok(0, "unexpected call\n");
1891 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
1892 PropertyNotifySink_QueryInterface
,
1893 PropertyNotifySink_AddRef
,
1894 PropertyNotifySink_Release
,
1895 PropertyNotifySink_OnChanged
,
1896 PropertyNotifySink_OnRequestEdit
1899 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
1901 static void doc_load_string(IHTMLDocument2
*doc
, const char *str
)
1903 IPersistStreamInit
*init
;
1910 doc_complete
= FALSE
;
1912 mem
= GlobalAlloc(0, len
);
1913 memcpy(mem
, str
, len
);
1914 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
1916 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
1918 IPersistStreamInit_Load(init
, stream
);
1919 IPersistStreamInit_Release(init
);
1920 IStream_Release(stream
);
1923 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
1925 IConnectionPointContainer
*container
;
1926 IConnectionPoint
*cp
;
1930 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
1931 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
1933 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
1934 IConnectionPointContainer_Release(container
);
1935 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
1937 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
1938 IConnectionPoint_Release(cp
);
1939 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
1942 static void set_client_site(IHTMLDocument2
*doc
, BOOL set
)
1948 IOleDocumentView_Show(view
, FALSE
);
1949 IOleDocumentView_CloseView(view
, 0);
1950 IOleDocumentView_SetInPlaceSite(view
, NULL
);
1951 IOleDocumentView_Release(view
);
1955 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IOleObject
, (void**)&oleobj
);
1956 ok(hres
== S_OK
, "Could not et IOleObject: %08x\n", hres
);
1958 hres
= IOleObject_SetClientSite(oleobj
, set
? &ClientSite
: NULL
);
1959 ok(hres
== S_OK
, "SetClientSite failed: %08x\n", hres
);
1962 IHlinkTarget
*hlink
;
1964 hres
= IOleObject_QueryInterface(oleobj
, &IID_IHlinkTarget
, (void**)&hlink
);
1965 ok(hres
== S_OK
, "Could not get IHlinkTarget iface: %08x\n", hres
);
1967 hres
= IHlinkTarget_Navigate(hlink
, 0, NULL
);
1968 ok(hres
== S_OK
, "Navgate failed: %08x\n", hres
);
1970 IHlinkTarget_Release(hlink
);
1973 IOleObject_Release(oleobj
);
1975 static IHTMLDocument2
*create_document(void)
1977 IHTMLDocument2
*doc
;
1978 IHTMLDocument5
*doc5
;
1981 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1982 &IID_IHTMLDocument2
, (void**)&doc
);
1983 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
1987 hres
= IHTMLDocument2_QueryInterface(doc
, &IID_IHTMLDocument5
, (void**)&doc5
);
1989 win_skip("Could not get IHTMLDocument5 interface, probably too old IE\n");
1990 IHTMLDocument2_Release(doc
);
1994 IHTMLDocument5_Release(doc5
);
1999 typedef void (*testfunc_t
)(IHTMLDocument2
*);
2001 static void run_test(const char *str
, testfunc_t test
)
2003 IHTMLDocument2
*doc
;
2004 IHTMLElement
*body
= NULL
;
2009 doc
= create_document();
2012 set_client_site(doc
, TRUE
);
2013 doc_load_string(doc
, str
);
2014 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
2016 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
2017 TranslateMessage(&msg
);
2018 DispatchMessage(&msg
);
2021 hres
= IHTMLDocument2_get_body(doc
, &body
);
2022 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
2025 IHTMLElement_Release(body
);
2027 hres
= IHTMLDocument2_get_parentWindow(doc
, &window
);
2028 ok(hres
== S_OK
, "get_parentWindow failed: %08x\n", hres
);
2029 ok(window
!= NULL
, "window == NULL\n");
2033 IHTMLWindow2_Release(window
);
2036 skip("Could not get document body. Assuming no Gecko installed.\n");
2039 set_client_site(doc
, FALSE
);
2040 IHTMLDocument2_Release(doc
);
2043 static LRESULT WINAPI
wnd_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2045 return DefWindowProc(hwnd
, msg
, wParam
, lParam
);
2048 static HWND
create_container_window(void)
2050 static const CHAR szHTMLDocumentTest
[] = "HTMLDocumentTest";
2051 static WNDCLASSEXA wndclass
= {
2052 sizeof(WNDCLASSEXA
),
2055 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
,
2060 RegisterClassExA(&wndclass
);
2061 return CreateWindowA(szHTMLDocumentTest
, szHTMLDocumentTest
,
2062 WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
,
2063 300, 300, NULL
, NULL
, NULL
, NULL
);
2069 container_hwnd
= create_container_window();
2071 if(winetest_interactive
)
2072 ShowWindow(container_hwnd
, SW_SHOW
);
2074 run_test(empty_doc_str
, test_timeout
);
2075 run_test(click_doc_str
, test_onclick
);
2076 run_test(readystate_doc_str
, test_onreadystatechange
);
2077 run_test(img_doc_str
, test_imgload
);
2079 DestroyWindow(container_hwnd
);