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>
34 #define DEFINE_EXPECT(func) \
35 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37 #define SET_EXPECT(func) \
38 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
40 #define CHECK_EXPECT2(func) \
43 ok(expect_ ##func, "unexpected call " #func "\n"); \
44 called_ ## func = TRUE; \
47 #define CHECK_EXPECT(func) \
49 CHECK_EXPECT2(func); \
50 expect_ ## func = FALSE; \
53 #define CHECK_CALLED(func) \
55 ok(called_ ## func, "expected " #func "\n"); \
56 expect_ ## func = called_ ## func = FALSE; \
59 DEFINE_EXPECT(document_onclick);
60 DEFINE_EXPECT(body_onclick);
61 DEFINE_EXPECT(div_onclick);
62 DEFINE_EXPECT(div_onclick_attached);
63 DEFINE_EXPECT(timeout);
65 static HWND container_hwnd = NULL;
66 static IHTMLWindow2 *window;
67 static IOleDocumentView *view;
77 static const xy_test_t no_xy = {-10,-10,-10,-10};
78 static const xy_test_t zero_xy = {0,0,0,0};
80 static const char empty_doc_str[] =
83 static const char click_doc_str[] =
85 "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
88 static const char *debugstr_w(LPCWSTR str)
90 static char buf[1024];
91 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
95 static const char *debugstr_guid(REFIID riid)
99 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
100 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
101 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
102 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
107 static int strcmp_wa(LPCWSTR strw, const char *stra)
110 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
111 return lstrcmpA(stra, buf);
114 static BSTR a2bstr(const char *str)
119 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
120 ret = SysAllocStringLen(NULL, len-1);
121 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
126 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
128 IUnknown *unk1, *unk2;
133 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
134 IUnknown_Release(unk1);
135 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
136 IUnknown_Release(unk2);
141 #define test_disp(u,id) _test_disp(__LINE__,u,id)
142 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
149 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
150 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
155 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
156 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
157 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
159 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
160 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
162 if(SUCCEEDED(hres)) {
165 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
166 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
167 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
168 debugstr_guid(&type_attr->guid));
170 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
171 ITypeInfo_Release(typeinfo);
174 IDispatchEx_Release(dispex);
177 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
178 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
180 IHTMLDocument3 *doc3;
183 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
184 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
189 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
190 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
195 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
196 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
201 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
202 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
204 IHTMLElement2 *elem2;
207 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
208 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
213 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
214 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
216 IHTMLElement3 *elem3;
219 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
220 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
225 #define doc_get_body(d) _doc_get_body(__LINE__,d)
226 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
228 IHTMLElement *body = NULL;
231 hres = IHTMLDocument2_get_body(doc, &body);
232 ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
233 ok_(__FILE__,line) (body != NULL, "body == NULL\n");
238 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
239 static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
241 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
247 hres = IHTMLDocument3_getElementById(doc3, str, &elem);
249 IHTMLDocument3_Release(doc3);
250 ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
255 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
256 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
258 IHTMLElement *elem = _get_elem_iface(line, unk);
262 hres = IHTMLElement_get_tagName(elem, &tag);
263 IHTMLElement_Release(elem);
264 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
265 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", debugstr_w(tag), extag);
270 #define get_event_obj() _get_event_obj(__LINE__)
271 static IHTMLEventObj *_get_event_obj(unsigned line)
273 IHTMLEventObj *event = NULL;
276 hres = IHTMLWindow2_get_event(window, &event);
277 ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
278 ok_(__FILE__,line) (event != NULL, "event = NULL\n");
279 _test_disp(line, (IUnknown*)event, &DIID_DispCEventObj);
284 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
285 static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
287 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
294 hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
296 ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
297 ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
300 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
301 static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
302 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
304 ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
305 ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
306 ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
307 ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
308 ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
309 ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
310 pdp->rgdispidNamedArgs[0]);
311 ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
312 ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
313 ok_(__FILE__,line) (pei != NULL, "pei == NULL");
314 ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
317 _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
320 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
321 static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
322 VARIANT *pvarRes, EXCEPINFO *pei)
324 IHTMLEventObj *event;
326 ok(id == DISPID_VALUE, "id = %d\n", id);
327 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
328 ok(pdp != NULL, "pDispParams == NULL\n");
329 ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
330 ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
331 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
332 ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
333 ok(pvarRes != NULL, "pvarRes = NULL\n");
334 ok(pei != NULL, "pei = NULL\n");
335 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
336 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
337 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
339 event = _get_event_obj(line);
340 ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
341 IHTMLEventObj_Release(event);
344 #define test_event_src(t) _test_event_src(__LINE__,t)
345 static void _test_event_src(unsigned line, const char *src_tag)
347 IHTMLEventObj *event = _get_event_obj(line);
348 IHTMLElement *src_elem = NULL;
351 hres = IHTMLEventObj_get_srcElement(event, &src_elem);
352 IHTMLEventObj_Release(event);
353 ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
356 ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
357 _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
358 IHTMLElement_Release(src_elem);
360 ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
364 static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
369 hres = IHTMLEventObj_get_altKey(event, &b);
370 ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
371 ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
374 static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
379 hres = IHTMLEventObj_get_ctrlKey(event, &b);
380 ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
381 ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
384 static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
389 hres = IHTMLEventObj_get_shiftKey(event, &b);
390 ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
391 ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
394 static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
399 hres = IHTMLEventObj_get_cancelBubble(event, &b);
400 ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
401 ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
404 static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
409 hres = IHTMLEventObj_get_fromElement(event, &elem);
410 ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
412 _test_elem_tag(line, (IUnknown*)elem, from_tag);
414 ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
416 IHTMLElement_Release(elem);
419 static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
424 hres = IHTMLEventObj_get_toElement(event, &elem);
425 ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
427 _test_elem_tag(line, (IUnknown*)elem, to_tag);
429 ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
431 IHTMLElement_Release(elem);
434 static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
439 hres = IHTMLEventObj_get_keyCode(event, &l);
440 ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
441 ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
444 static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
449 hres = IHTMLEventObj_get_button(event, &l);
450 ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
451 ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
454 static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
459 hres = IHTMLEventObj_get_reason(event, &l);
460 ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
461 ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
464 static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
469 hres = IHTMLEventObj_get_x(event, &l);
470 ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
471 if(exl == -10) /* don't test the exact value */
472 todo_wine ok_(__FILE__,line)(l > 0, "x = %d\n", l);
474 ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
477 static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
482 hres = IHTMLEventObj_get_y(event, &l);
483 ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
484 if(exl == -10) /* don't test the exact value */
485 todo_wine ok_(__FILE__,line)(l > 0, "y = %d\n", l);
487 ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
490 static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
495 hres = IHTMLEventObj_get_clientX(event, &l);
496 ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
497 if(exl == -10) {/* don't test the exact value */
499 todo_wine ok_(__FILE__,line)(l > 0, "clientX = %d\n", l);
501 ok_(__FILE__,line)(l > 0, "clientX = %d\n", l);
503 ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
507 static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
512 hres = IHTMLEventObj_get_clientY(event, &l);
513 ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
514 if(exl == -10) {/* don't test the exact value */
516 todo_wine ok_(__FILE__,line)(l > 0, "clientY = %d\n", l);
518 ok_(__FILE__,line)(l > 0, "clientY = %d\n", l);
520 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 todo_wine ok_(__FILE__,line)(l > 0, "offsetX = %d\n", l);
534 ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
537 static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
542 hres = IHTMLEventObj_get_offsetY(event, &l);
543 ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
544 if(exl == -10) /* don't test the exact value */
545 todo_wine ok_(__FILE__,line)(l > 0, "offsetY = %d\n", l);
547 ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
550 static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
555 hres = IHTMLEventObj_get_screenX(event, &l);
556 ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
557 if(exl == -10) { /* don't test the exact value */
559 todo_wine ok_(__FILE__,line)(l > 0, "screenX = %d\n", l);
561 ok_(__FILE__,line)(l > 0, "screenX = %d\n", l);
563 ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
567 static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
572 hres = IHTMLEventObj_get_screenY(event, &l);
573 ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
574 if(exl == -10) { /* don't test the exact value */
576 todo_wine ok_(__FILE__,line)(l > 0, "screenY = %d\n", l);
578 ok_(__FILE__,line)(l > 0, "screenY = %d\n", l);
580 ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
584 static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
589 hres = IHTMLEventObj_get_type(event, &str);
590 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
591 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
594 static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
599 hres = IHTMLEventObj_get_qualifier(event, &str);
600 ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
602 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
604 ok_(__FILE__,line)(!str, "qualifier != NULL\n");
607 static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
612 hres = IHTMLEventObj_get_srcFilter(event, &disp);
613 ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
614 ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
617 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
618 static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
620 IHTMLEventObj *event = _get_event_obj(line);
624 _test_event_altkey(line, event, VARIANT_FALSE);
625 _test_event_ctrlkey(line, event, VARIANT_FALSE);
626 _test_event_shiftkey(line, event, VARIANT_FALSE);
627 _test_event_cancelbubble(line, event, VARIANT_FALSE);
628 _test_event_fromelem(line, event, NULL);
629 _test_event_toelem(line, event, NULL);
630 _test_event_keycode(line, event, 0);
631 _test_event_button(line, event, 0);
632 _test_event_type(line, event, type);
633 _test_event_qualifier(line, event, NULL);
634 _test_event_reason(line, event, 0);
635 _test_event_srcfilter(line, event);
636 _test_event_x(line, event, xy->x);
637 _test_event_y(line, event, xy->y);
638 _test_event_clientx(line, event, -10);
639 _test_event_clienty(line, event, -10);
640 _test_event_offsetx(line, event, xy->offset_x);
641 _test_event_offsety(line, event, xy->offset_y);
642 _test_event_screenx(line, event, -10);
643 _test_event_screeny(line, event, -10);
645 hres = IHTMLEventObj_get_returnValue(event, &v);
646 ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
647 ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
649 IHTMLEventObj_Release(event);
652 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
653 static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
655 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
660 name = a2bstr(namea);
661 hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
662 IHTMLElement2_Release(elem);
664 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
665 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
668 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
672 if(IsEqualGUID(riid, &IID_IUnknown)
673 || IsEqualGUID(riid, &IID_IDispatch)
674 || IsEqualGUID(riid, &IID_IDispatchEx))
677 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
678 return E_NOINTERFACE;
684 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
689 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
694 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
696 ok(0, "unexpected call\n");
700 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
701 LCID lcid, ITypeInfo **ppTInfo)
703 ok(0, "unexpected call\n");
707 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
708 LPOLESTR *rgszNames, UINT cNames,
709 LCID lcid, DISPID *rgDispId)
711 ok(0, "unexpected call\n");
715 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
716 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
717 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
719 ok(0, "unexpected call\n");
723 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
725 ok(0, "unexpected call\n");
729 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
730 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
732 ok(0, "unexpected call\n");
736 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
738 ok(0, "unexpected call %s %x\n", debugstr_w(bstrName), grfdex);
742 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
744 ok(0, "unexpected call\n");
748 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
750 ok(0, "unexpected call\n");
754 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
756 ok(0, "unexpected call\n");
760 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
762 ok(0, "unexpected call\n");
766 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
768 ok(0, "unexpected call\n");
772 #define EVENT_HANDLER_FUNC_OBJ(event) \
773 static IDispatchExVtbl event ## FuncVtbl = { \
774 DispatchEx_QueryInterface, \
776 DispatchEx_Release, \
777 DispatchEx_GetTypeInfoCount, \
778 DispatchEx_GetTypeInfo, \
779 DispatchEx_GetIDsOfNames, \
781 DispatchEx_GetDispID, \
783 DispatchEx_DeleteMemberByName, \
784 DispatchEx_DeleteMemberByDispID, \
785 DispatchEx_GetMemberProperties, \
786 DispatchEx_GetMemberName, \
787 DispatchEx_GetNextDispID, \
788 DispatchEx_GetNameSpaceParent \
790 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
792 static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
793 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
795 IHTMLDocument3 *doc3;
796 CHECK_EXPECT(document_onclick);
797 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
798 doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
799 IHTMLDocument3_Release(doc3);
800 test_event_src("DIV");
801 test_event_obj("click", &no_xy);
805 EVENT_HANDLER_FUNC_OBJ(document_onclick);
807 static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
808 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
810 CHECK_EXPECT(div_onclick);
811 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
812 test_event_src("DIV");
816 EVENT_HANDLER_FUNC_OBJ(div_onclick);
818 static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
819 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
821 CHECK_EXPECT(div_onclick_attached);
823 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
824 test_event_src("DIV");
828 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
830 static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
831 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
833 CHECK_EXPECT(body_onclick);
834 test_event_args(&DIID_DispHTMLBody, id, wFlags, pdp, pvarRes, pei, pspCaller);
835 test_event_src("DIV");
839 EVENT_HANDLER_FUNC_OBJ(body_onclick);
841 static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
842 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
844 ok(0, "unexpected call\n");
848 EVENT_HANDLER_FUNC_OBJ(nocall);
850 static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
851 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
852 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
854 CHECK_EXPECT(timeout);
856 ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
857 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
858 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
859 ok(!lcid, "lcid = %x\n", lcid);
860 ok(pDispParams != NULL, "pDispParams == NULL\n");
861 ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
862 ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
863 ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
864 ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
865 ok(pVarResult != NULL, "pVarResult = NULL\n");
866 ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
867 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
868 ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
873 static IDispatchExVtbl timeoutFuncVtbl = {
874 DispatchEx_QueryInterface,
877 DispatchEx_GetTypeInfoCount,
878 DispatchEx_GetTypeInfo,
879 DispatchEx_GetIDsOfNames,
881 DispatchEx_GetDispID,
883 DispatchEx_DeleteMemberByName,
884 DispatchEx_DeleteMemberByDispID,
885 DispatchEx_GetMemberProperties,
886 DispatchEx_GetMemberName,
887 DispatchEx_GetNextDispID,
888 DispatchEx_GetNameSpaceParent
891 static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
893 static void pump_msgs(BOOL *b)
896 while(!*b && GetMessage(&msg, NULL, 0, 0)) {
897 TranslateMessage(&msg);
898 DispatchMessage(&msg);
902 static void test_onclick(IHTMLDocument2 *doc)
904 IHTMLElement *div, *body;
908 div = get_elem_id(doc, "clickdiv");
910 elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
911 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
914 hres = IHTMLElement_get_onclick(div, &v);
915 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
916 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
918 V_VT(&v) = VT_DISPATCH;
919 V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
920 hres = IHTMLElement_put_onclick(div, v);
921 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
924 hres = IHTMLElement_get_onclick(div, &v);
925 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
926 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
927 ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
931 hres = IHTMLDocument2_get_onclick(doc, &v);
932 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
933 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
935 V_VT(&v) = VT_DISPATCH;
936 V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
937 hres = IHTMLDocument2_put_onclick(doc, v);
938 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
941 hres = IHTMLDocument2_get_onclick(doc, &v);
942 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
943 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
944 ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
947 body = doc_get_body(doc);
949 V_VT(&v) = VT_DISPATCH;
950 V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
951 hres = IHTMLElement_put_onclick(body, v);
952 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
954 if(winetest_interactive) {
955 SET_EXPECT(div_onclick);
956 SET_EXPECT(div_onclick_attached);
957 SET_EXPECT(body_onclick);
958 SET_EXPECT(document_onclick);
959 pump_msgs(&called_document_onclick);
960 CHECK_CALLED(div_onclick);
961 CHECK_CALLED(div_onclick_attached);
962 CHECK_CALLED(body_onclick);
963 CHECK_CALLED(document_onclick);
968 SET_EXPECT(div_onclick);
969 SET_EXPECT(div_onclick_attached);
970 SET_EXPECT(body_onclick);
971 SET_EXPECT(document_onclick);
973 hres = IHTMLElement_click(div);
974 ok(hres == S_OK, "click failed: %08x\n", hres);
976 CHECK_CALLED(div_onclick);
977 CHECK_CALLED(div_onclick_attached);
978 CHECK_CALLED(body_onclick);
979 CHECK_CALLED(document_onclick);
981 SET_EXPECT(div_onclick);
982 SET_EXPECT(div_onclick_attached);
983 SET_EXPECT(body_onclick);
984 SET_EXPECT(document_onclick);
987 elem_fire_event((IUnknown*)div, "onclick", &v);
989 CHECK_CALLED(div_onclick);
990 CHECK_CALLED(div_onclick_attached);
991 CHECK_CALLED(body_onclick);
992 CHECK_CALLED(document_onclick);
994 IHTMLElement_Release(div);
995 IHTMLElement_Release(body);
998 static void test_timeout(IHTMLDocument2 *doc)
1005 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
1006 ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
1008 V_VT(&expr) = VT_DISPATCH;
1009 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1010 V_VT(&var) = VT_EMPTY;
1012 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1013 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1016 SET_EXPECT(timeout);
1017 pump_msgs(&called_timeout);
1018 CHECK_CALLED(timeout);
1020 V_VT(&expr) = VT_DISPATCH;
1021 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1022 V_VT(&var) = VT_EMPTY;
1024 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1025 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1028 hres = IHTMLWindow2_clearTimeout(window, id);
1029 ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
1031 IHTMLWindow3_Release(win3);
1034 static HRESULT QueryInterface(REFIID,void**);
1036 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
1038 return E_NOINTERFACE;
1041 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
1046 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
1051 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1056 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
1061 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
1066 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
1067 LPCBORDERWIDTHS pborderwidths)
1072 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
1073 LPCBORDERWIDTHS pborderwidths)
1078 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
1079 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1084 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
1085 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1090 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
1091 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1096 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
1097 HOLEMENU holemenu, HWND hwndActiveObject)
1099 ok(0, "unexpected call\n");
1103 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
1105 ok(0, "unexpected call\n");
1109 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
1114 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
1119 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
1121 ok(0, "unexpected call\n");
1125 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
1126 InPlaceFrame_QueryInterface,
1127 InPlaceFrame_AddRef,
1128 InPlaceFrame_Release,
1129 InPlaceFrame_GetWindow,
1130 InPlaceFrame_ContextSensitiveHelp,
1131 InPlaceFrame_GetBorder,
1132 InPlaceFrame_RequestBorderSpace,
1133 InPlaceFrame_SetBorderSpace,
1134 InPlaceFrame_SetActiveObject,
1135 InPlaceFrame_InsertMenus,
1136 InPlaceFrame_SetMenu,
1137 InPlaceFrame_RemoveMenus,
1138 InPlaceFrame_SetStatusText,
1139 InPlaceFrame_EnableModeless,
1140 InPlaceFrame_TranslateAccelerator
1143 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
1145 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
1146 InPlaceFrame_QueryInterface,
1147 InPlaceFrame_AddRef,
1148 InPlaceFrame_Release,
1149 InPlaceFrame_GetWindow,
1150 InPlaceFrame_ContextSensitiveHelp,
1151 InPlaceFrame_GetBorder,
1152 InPlaceFrame_RequestBorderSpace,
1153 InPlaceFrame_SetBorderSpace,
1154 InPlaceUIWindow_SetActiveObject,
1157 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
1159 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
1161 return QueryInterface(riid, ppv);
1164 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
1169 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
1174 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1176 *phwnd = container_hwnd;
1180 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1182 ok(0, "unexpected call\n");
1186 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
1191 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
1196 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
1201 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
1202 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1203 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1205 static const RECT rect = {0,0,300,300};
1207 *ppFrame = &InPlaceFrame;
1208 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
1209 *lprcPosRect = rect;
1210 *lprcClipRect = rect;
1212 lpFrameInfo->cb = sizeof(*lpFrameInfo);
1213 lpFrameInfo->fMDIApp = FALSE;
1214 lpFrameInfo->hwndFrame = container_hwnd;
1215 lpFrameInfo->haccel = NULL;
1216 lpFrameInfo->cAccelEntries = 0;
1221 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
1226 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1231 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
1236 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
1241 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
1246 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1251 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
1252 InPlaceSite_QueryInterface,
1254 InPlaceSite_Release,
1255 InPlaceSite_GetWindow,
1256 InPlaceSite_ContextSensitiveHelp,
1257 InPlaceSite_CanInPlaceActivate,
1258 InPlaceSite_OnInPlaceActivate,
1259 InPlaceSite_OnUIActivate,
1260 InPlaceSite_GetWindowContext,
1262 InPlaceSite_OnUIDeactivate,
1263 InPlaceSite_OnInPlaceDeactivate,
1264 InPlaceSite_DiscardUndoState,
1265 InPlaceSite_DeactivateAndUndo,
1266 InPlaceSite_OnPosRectChange,
1269 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
1271 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
1273 return QueryInterface(riid, ppv);
1276 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
1281 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1286 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1288 ok(0, "unexpected call\n");
1292 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1295 ok(0, "unexpected call\n");
1299 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1304 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1306 ok(0, "unexpected call\n");
1310 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1312 ok(0, "unexpected call\n");
1316 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1318 ok(0, "unexpected call\n");
1322 static const IOleClientSiteVtbl ClientSiteVtbl = {
1323 ClientSite_QueryInterface,
1326 ClientSite_SaveObject,
1327 ClientSite_GetMoniker,
1328 ClientSite_GetContainer,
1329 ClientSite_ShowObject,
1330 ClientSite_OnShowWindow,
1331 ClientSite_RequestNewObjectLayout
1334 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1336 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1338 return QueryInterface(riid, ppv);
1341 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1346 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1351 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1353 RECT rect = {0,0,300,300};
1354 IOleDocument *document;
1357 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1358 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1360 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1361 IOleDocument_Release(document);
1362 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1364 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1365 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1367 hres = IOleDocumentView_UIActivate(view, TRUE);
1368 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1370 hres = IOleDocumentView_SetRect(view, &rect);
1371 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1373 hres = IOleDocumentView_Show(view, TRUE);
1374 ok(hres == S_OK, "Show failed: %08x\n", hres);
1379 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1380 DocumentSite_QueryInterface,
1381 DocumentSite_AddRef,
1382 DocumentSite_Release,
1383 DocumentSite_ActivateMe
1386 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1388 static HRESULT QueryInterface(REFIID riid, void **ppv)
1392 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1394 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1395 *ppv = &DocumentSite;
1396 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1397 *ppv = &InPlaceSite;
1399 return *ppv ? S_OK : E_NOINTERFACE;
1402 static IHTMLDocument2 *notif_doc;
1403 static BOOL doc_complete;
1405 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1406 REFIID riid, void**ppv)
1408 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1413 ok(0, "unexpected call\n");
1414 return E_NOINTERFACE;
1417 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1422 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1427 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1429 if(dispID == DISPID_READYSTATE){
1433 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1434 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1436 if(!strcmp_wa(state, "complete"))
1437 doc_complete = TRUE;
1439 SysFreeString(state);
1445 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1447 ok(0, "unexpected call\n");
1451 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1452 PropertyNotifySink_QueryInterface,
1453 PropertyNotifySink_AddRef,
1454 PropertyNotifySink_Release,
1455 PropertyNotifySink_OnChanged,
1456 PropertyNotifySink_OnRequestEdit
1459 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1461 static void doc_load_string(IHTMLDocument2 *doc, const char *str)
1463 IPersistStreamInit *init;
1470 doc_complete = FALSE;
1472 mem = GlobalAlloc(0, len);
1473 memcpy(mem, str, len);
1474 CreateStreamOnHGlobal(mem, TRUE, &stream);
1476 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1478 IPersistStreamInit_Load(init, stream);
1479 IPersistStreamInit_Release(init);
1480 IStream_Release(stream);
1483 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1485 IConnectionPointContainer *container;
1486 IConnectionPoint *cp;
1490 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1491 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1493 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1494 IConnectionPointContainer_Release(container);
1495 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1497 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1498 IConnectionPoint_Release(cp);
1499 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1502 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1508 IOleDocumentView_Show(view, FALSE);
1509 IOleDocumentView_CloseView(view, 0);
1510 IOleDocumentView_SetInPlaceSite(view, NULL);
1511 IOleDocumentView_Release(view);
1515 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1516 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1518 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1519 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1522 IHlinkTarget *hlink;
1524 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1525 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1527 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1528 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1530 IHlinkTarget_Release(hlink);
1533 IOleObject_Release(oleobj);
1535 static IHTMLDocument2 *create_document(void)
1537 IHTMLDocument2 *doc;
1540 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1541 &IID_IHTMLDocument2, (void**)&doc);
1542 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1548 typedef void (*testfunc_t)(IHTMLDocument2*);
1550 static void run_test(const char *str, testfunc_t test)
1552 IHTMLDocument2 *doc;
1553 IHTMLElement *body = NULL;
1559 doc = create_document();
1560 set_client_site(doc, TRUE);
1561 doc_load_string(doc, str);
1562 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1564 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1565 TranslateMessage(&msg);
1566 DispatchMessage(&msg);
1569 hres = IHTMLDocument2_get_body(doc, &body);
1570 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1573 IHTMLElement_Release(body);
1575 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1576 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1577 ok(window != NULL, "window == NULL\n");
1581 IHTMLWindow2_Release(window);
1584 skip("Could not get document body. Assuming no Gecko installed.\n");
1587 set_client_site(doc, FALSE);
1588 ref = IHTMLDocument2_Release(doc);
1589 ok(!ref, "ref = %d\n", ref);
1592 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1594 return DefWindowProc(hwnd, msg, wParam, lParam);
1597 static HWND create_container_window(void)
1599 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
1600 static WNDCLASSEXA wndclass = {
1601 sizeof(WNDCLASSEXA),
1604 0, 0, NULL, NULL, NULL, NULL, NULL,
1609 RegisterClassExA(&wndclass);
1610 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
1611 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
1612 300, 300, NULL, NULL, NULL, NULL);
1618 container_hwnd = create_container_window();
1620 if(winetest_interactive)
1621 ShowWindow(container_hwnd, SW_SHOW);
1623 run_test(empty_doc_str, test_timeout);
1624 run_test(click_doc_str, test_onclick);
1626 DestroyWindow(container_hwnd);