84bfae25347b40a31adc9295284bf2bd8191870c
[reactos.git] / rostests / winetests / mshtml / events.c
1 /*
2 * Copyright 2008-2009 Jacek Caban for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "mshtmdid.h"
31 #include "docobj.h"
32 #include "hlink.h"
33 #include "dispex.h"
34
35 #define DEFINE_EXPECT(func) \
36 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37
38 #define SET_EXPECT(func) \
39 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
40
41 #define CHECK_EXPECT2(func) \
42 do { \
43 trace(#func "\n"); \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
46 }while(0)
47
48 #define CHECK_EXPECT(func) \
49 do { \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
52 }while(0)
53
54 #define CHECK_CALLED(func) \
55 do { \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
58 }while(0)
59
60 DEFINE_EXPECT(document_onclick);
61 DEFINE_EXPECT(body_onclick);
62 DEFINE_EXPECT(div_onclick);
63 DEFINE_EXPECT(div_onclick_attached);
64 DEFINE_EXPECT(timeout);
65 DEFINE_EXPECT(doccp_onclick);
66 DEFINE_EXPECT(iframe_onreadystatechange_loading);
67 DEFINE_EXPECT(iframe_onreadystatechange_interactive);
68 DEFINE_EXPECT(iframe_onreadystatechange_complete);
69
70 static HWND container_hwnd = NULL;
71 static IHTMLWindow2 *window;
72 static IOleDocumentView *view;
73 static BOOL xy_todo;
74
75 typedef struct {
76 LONG x;
77 LONG y;
78 LONG offset_x;
79 LONG offset_y;
80 } xy_test_t;
81
82 static const xy_test_t no_xy = {-10,-10,-10,-10};
83 static const xy_test_t zero_xy = {0,0,0,0};
84
85 static const char empty_doc_str[] =
86 "<html></html>";
87
88 static const char click_doc_str[] =
89 "<html><body>"
90 "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
91 "</body></html>";
92
93 static const char readystate_doc_str[] =
94 "<<html><body><iframe id=\"iframe\"></iframe></body></html>";
95
96 static const char *debugstr_guid(REFIID riid)
97 {
98 static char buf[50];
99
100 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
101 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
102 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
103 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
104
105 return buf;
106 }
107
108 static int strcmp_wa(LPCWSTR strw, const char *stra)
109 {
110 CHAR buf[512];
111 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
112 return lstrcmpA(stra, buf);
113 }
114
115 static BSTR a2bstr(const char *str)
116 {
117 BSTR ret;
118 int len;
119
120 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
121 ret = SysAllocStringLen(NULL, len-1);
122 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
123
124 return ret;
125 }
126
127 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
128 {
129 IUnknown *unk1, *unk2;
130
131 if(iface1 == iface2)
132 return TRUE;
133
134 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
135 IUnknown_Release(unk1);
136 IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
137 IUnknown_Release(unk2);
138
139 return unk1 == unk2;
140 }
141
142 #define test_disp(u,id) _test_disp(__LINE__,u,id)
143 static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
144 {
145 IDispatchEx *dispex;
146 ITypeInfo *typeinfo;
147 UINT ticnt;
148 HRESULT hres;
149
150 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
151 ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
152 if(FAILED(hres))
153 return;
154
155 ticnt = 0xdeadbeef;
156 hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
157 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
158 ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
159
160 hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
161 ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
162
163 if(SUCCEEDED(hres)) {
164 TYPEATTR *type_attr;
165
166 hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
167 ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
168 ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
169 debugstr_guid(&type_attr->guid));
170
171 ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
172 ITypeInfo_Release(typeinfo);
173 }
174
175 IDispatchEx_Release(dispex);
176 }
177
178 #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
179 static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
180 {
181 IHTMLDocument3 *doc3;
182 HRESULT hres;
183
184 hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
185 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
186
187 return doc3;
188 }
189
190 #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
191 static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
192 {
193 IHTMLElement *elem;
194 HRESULT hres;
195
196 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
197 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
198
199 return elem;
200 }
201
202 #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
203 static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
204 {
205 IHTMLElement2 *elem2;
206 HRESULT hres;
207
208 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
209 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
210
211 return elem2;
212 }
213
214 #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
215 static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
216 {
217 IHTMLElement3 *elem3;
218 HRESULT hres;
219
220 hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
221 ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
222
223 return elem3;
224 }
225
226 #define doc_get_body(d) _doc_get_body(__LINE__,d)
227 static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
228 {
229 IHTMLElement *body = NULL;
230 HRESULT hres;
231
232 hres = IHTMLDocument2_get_body(doc, &body);
233 ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
234 ok_(__FILE__,line) (body != NULL, "body == NULL\n");
235
236 return body;
237 }
238
239 #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
240 static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
241 {
242 IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
243 IHTMLElement *elem;
244 BSTR str;
245 HRESULT hres;
246
247 str = a2bstr(id);
248 hres = IHTMLDocument3_getElementById(doc3, str, &elem);
249 SysFreeString(str);
250 IHTMLDocument3_Release(doc3);
251 ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
252
253 return elem;
254 }
255
256 #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
257 static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
258 {
259 IHTMLElement *elem = _get_elem_iface(line, unk);
260 BSTR tag;
261 HRESULT hres;
262
263 hres = IHTMLElement_get_tagName(elem, &tag);
264 IHTMLElement_Release(elem);
265 ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
266 ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
267
268 SysFreeString(tag);
269 }
270
271 #define get_event_obj() _get_event_obj(__LINE__)
272 static IHTMLEventObj *_get_event_obj(unsigned line)
273 {
274 IHTMLEventObj *event = NULL;
275 HRESULT hres;
276
277 hres = IHTMLWindow2_get_event(window, &event);
278 ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
279 ok_(__FILE__,line) (event != NULL, "event = NULL\n");
280 _test_disp(line, (IUnknown*)event, &DIID_DispCEventObj);
281
282 return event;
283 }
284
285 #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
286 static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
287 {
288 IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
289 VARIANT_BOOL b;
290 BSTR str;
291 HRESULT hres;
292
293 b = 100;
294 str = a2bstr(event);
295 hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
296 SysFreeString(str);
297 ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
298 ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
299 }
300
301 #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
302 static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
303 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
304 {
305 ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
306 ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
307 ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
308 ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
309 ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
310 ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
311 pdp->rgdispidNamedArgs[0]);
312 ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
313 ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
314 ok_(__FILE__,line) (pei != NULL, "pei == NULL");
315 ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
316
317 if(dispiid)
318 _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
319 }
320
321 #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
322 static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
323 VARIANT *pvarRes, EXCEPINFO *pei)
324 {
325 IHTMLEventObj *event;
326
327 ok(id == DISPID_VALUE, "id = %d\n", id);
328 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
329 ok(pdp != NULL, "pDispParams == NULL\n");
330 ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
331 ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
332 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
333 ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
334 ok(pvarRes != NULL, "pvarRes = NULL\n");
335 ok(pei != NULL, "pei = NULL\n");
336 ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
337 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
338 ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
339
340 event = _get_event_obj(line);
341 ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
342 IHTMLEventObj_Release(event);
343 }
344
345 #define get_event_src() _get_event_src(__LINE__)
346 static IHTMLElement *_get_event_src(unsigned line)
347 {
348 IHTMLEventObj *event = _get_event_obj(line);
349 IHTMLElement *src_elem = NULL;
350 HRESULT hres;
351
352 hres = IHTMLEventObj_get_srcElement(event, &src_elem);
353 IHTMLEventObj_Release(event);
354 ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
355
356 return src_elem;
357 }
358
359 #define test_event_src(t) _test_event_src(__LINE__,t)
360 static void _test_event_src(unsigned line, const char *src_tag)
361 {
362 IHTMLElement *src_elem = _get_event_src(line);
363
364 if(src_tag) {
365 ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
366 _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
367 IHTMLElement_Release(src_elem);
368 }else {
369 ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
370 }
371 }
372
373 static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
374 {
375 VARIANT_BOOL b;
376 HRESULT hres;
377
378 hres = IHTMLEventObj_get_altKey(event, &b);
379 ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
380 ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
381 }
382
383 static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
384 {
385 VARIANT_BOOL b;
386 HRESULT hres;
387
388 hres = IHTMLEventObj_get_ctrlKey(event, &b);
389 ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
390 ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
391 }
392
393 static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
394 {
395 VARIANT_BOOL b;
396 HRESULT hres;
397
398 hres = IHTMLEventObj_get_shiftKey(event, &b);
399 ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
400 ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
401 }
402
403 static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
404 {
405 VARIANT_BOOL b;
406 HRESULT hres;
407
408 hres = IHTMLEventObj_get_cancelBubble(event, &b);
409 ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
410 ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
411 }
412
413 static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
414 {
415 IHTMLElement *elem;
416 HRESULT hres;
417
418 hres = IHTMLEventObj_get_fromElement(event, &elem);
419 ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
420 if(from_tag)
421 _test_elem_tag(line, (IUnknown*)elem, from_tag);
422 else
423 ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
424 if(elem)
425 IHTMLElement_Release(elem);
426 }
427
428 static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
429 {
430 IHTMLElement *elem;
431 HRESULT hres;
432
433 hres = IHTMLEventObj_get_toElement(event, &elem);
434 ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
435 if(to_tag)
436 _test_elem_tag(line, (IUnknown*)elem, to_tag);
437 else
438 ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
439 if(elem)
440 IHTMLElement_Release(elem);
441 }
442
443 static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
444 {
445 LONG l;
446 HRESULT hres;
447
448 hres = IHTMLEventObj_get_keyCode(event, &l);
449 ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
450 ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
451 }
452
453 static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
454 {
455 LONG l;
456 HRESULT hres;
457
458 hres = IHTMLEventObj_get_button(event, &l);
459 ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
460 ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
461 }
462
463 static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
464 {
465 LONG l;
466 HRESULT hres;
467
468 hres = IHTMLEventObj_get_reason(event, &l);
469 ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
470 ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
471 }
472
473 static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
474 {
475 LONG l;
476 HRESULT hres;
477
478 hres = IHTMLEventObj_get_x(event, &l);
479 ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
480 if(exl == -10) /* don't test the exact value */
481 todo_wine ok_(__FILE__,line)(l > 0, "x = %d\n", l);
482 else
483 ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
484 }
485
486 static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
487 {
488 LONG l;
489 HRESULT hres;
490
491 hres = IHTMLEventObj_get_y(event, &l);
492 ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
493 if(exl == -10) /* don't test the exact value */
494 todo_wine ok_(__FILE__,line)(l > 0, "y = %d\n", l);
495 else
496 ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
497 }
498
499 static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
500 {
501 LONG l;
502 HRESULT hres;
503
504 hres = IHTMLEventObj_get_clientX(event, &l);
505 ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
506 if(exl == -10) {/* don't test the exact value */
507 if(xy_todo)
508 todo_wine ok_(__FILE__,line)(l > 0, "clientX = %d\n", l);
509 else
510 ok_(__FILE__,line)(l > 0, "clientX = %d\n", l);
511 }else {
512 ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
513 }
514 }
515
516 static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
517 {
518 LONG l;
519 HRESULT hres;
520
521 hres = IHTMLEventObj_get_clientY(event, &l);
522 ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
523 if(exl == -10) {/* don't test the exact value */
524 if(xy_todo)
525 todo_wine ok_(__FILE__,line)(l > 0, "clientY = %d\n", l);
526 else
527 ok_(__FILE__,line)(l > 0, "clientY = %d\n", l);
528 }else {
529 ok_(__FILE__,line)(l == exl, "clientY = %d, expected %d\n", l, exl);
530 }
531 }
532
533 static void _test_event_offsetx(unsigned line, IHTMLEventObj *event, LONG exl)
534 {
535 LONG l;
536 HRESULT hres;
537
538 hres = IHTMLEventObj_get_offsetX(event, &l);
539 ok_(__FILE__,line)(hres == S_OK, "get_offsetX failed: %08x\n", hres);
540 if(exl == -10) /* don't test the exact value */
541 todo_wine ok_(__FILE__,line)(l > 0, "offsetX = %d\n", l);
542 else
543 ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
544 }
545
546 static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
547 {
548 LONG l;
549 HRESULT hres;
550
551 hres = IHTMLEventObj_get_offsetY(event, &l);
552 ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
553 if(exl == -10) /* don't test the exact value */
554 todo_wine ok_(__FILE__,line)(l > 0, "offsetY = %d\n", l);
555 else
556 ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
557 }
558
559 static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
560 {
561 LONG l;
562 HRESULT hres;
563
564 hres = IHTMLEventObj_get_screenX(event, &l);
565 ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
566 if(exl == -10) { /* don't test the exact value */
567 if(xy_todo)
568 todo_wine ok_(__FILE__,line)(l > 0, "screenX = %d\n", l);
569 else
570 ok_(__FILE__,line)(l > 0, "screenX = %d\n", l);
571 }else {
572 ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
573 }
574 }
575
576 static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
577 {
578 LONG l;
579 HRESULT hres;
580
581 hres = IHTMLEventObj_get_screenY(event, &l);
582 ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
583 if(exl == -10) { /* don't test the exact value */
584 if(xy_todo)
585 todo_wine ok_(__FILE__,line)(l > 0, "screenY = %d\n", l);
586 else
587 ok_(__FILE__,line)(l > 0, "screenY = %d\n", l);
588 }else {
589 ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
590 }
591 }
592
593 static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
594 {
595 BSTR str;
596 HRESULT hres;
597
598 hres = IHTMLEventObj_get_type(event, &str);
599 ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
600 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
601 }
602
603 static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
604 {
605 BSTR str;
606 HRESULT hres;
607
608 hres = IHTMLEventObj_get_qualifier(event, &str);
609 ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
610 if(exstr)
611 ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
612 else
613 ok_(__FILE__,line)(!str, "qualifier != NULL\n");
614 }
615
616 static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
617 {
618 IDispatch *disp;
619 HRESULT hres;
620
621 hres = IHTMLEventObj_get_srcFilter(event, &disp);
622 ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
623 ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
624 }
625
626 #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
627 static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
628 {
629 IHTMLEventObj *event = _get_event_obj(line);
630 VARIANT v;
631 HRESULT hres;
632
633 _test_event_altkey(line, event, VARIANT_FALSE);
634 _test_event_ctrlkey(line, event, VARIANT_FALSE);
635 _test_event_shiftkey(line, event, VARIANT_FALSE);
636 _test_event_cancelbubble(line, event, VARIANT_FALSE);
637 _test_event_fromelem(line, event, NULL);
638 _test_event_toelem(line, event, NULL);
639 _test_event_keycode(line, event, 0);
640 _test_event_button(line, event, 0);
641 _test_event_type(line, event, type);
642 _test_event_qualifier(line, event, NULL);
643 _test_event_reason(line, event, 0);
644 _test_event_srcfilter(line, event);
645 _test_event_x(line, event, xy->x);
646 _test_event_y(line, event, xy->y);
647 _test_event_clientx(line, event, -10);
648 _test_event_clienty(line, event, -10);
649 _test_event_offsetx(line, event, xy->offset_x);
650 _test_event_offsety(line, event, xy->offset_y);
651 _test_event_screenx(line, event, -10);
652 _test_event_screeny(line, event, -10);
653
654 hres = IHTMLEventObj_get_returnValue(event, &v);
655 ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
656 ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
657
658 IHTMLEventObj_Release(event);
659 }
660
661 #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
662 static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
663 {
664 IHTMLElement2 *elem = _get_elem2_iface(line, unk);
665 VARIANT_BOOL res;
666 BSTR name;
667 HRESULT hres;
668
669 name = a2bstr(namea);
670 hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
671 IHTMLElement2_Release(elem);
672 SysFreeString(name);
673 ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
674 ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
675 }
676
677 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
678 {
679 *ppv = NULL;
680
681 if(IsEqualGUID(riid, &IID_IUnknown)
682 || IsEqualGUID(riid, &IID_IDispatch)
683 || IsEqualGUID(riid, &IID_IDispatchEx))
684 *ppv = iface;
685 else {
686 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
687 return E_NOINTERFACE;
688 }
689
690 return S_OK;
691 }
692
693 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
694 {
695 return 2;
696 }
697
698 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
699 {
700 return 1;
701 }
702
703 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
704 {
705 ok(0, "unexpected call\n");
706 return E_NOTIMPL;
707 }
708
709 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
710 LCID lcid, ITypeInfo **ppTInfo)
711 {
712 ok(0, "unexpected call\n");
713 return E_NOTIMPL;
714 }
715
716 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
717 LPOLESTR *rgszNames, UINT cNames,
718 LCID lcid, DISPID *rgDispId)
719 {
720 ok(0, "unexpected call\n");
721 return E_NOTIMPL;
722 }
723
724 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
725 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
726 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
727 {
728 ok(0, "unexpected call\n");
729 return E_NOTIMPL;
730 }
731
732 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
733 {
734 ok(0, "unexpected call\n");
735 return E_NOTIMPL;
736 }
737
738 static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
739 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
740 {
741 ok(0, "unexpected call\n");
742 return E_NOTIMPL;
743 }
744
745 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
746 {
747 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
748 return E_NOTIMPL;
749 }
750
751 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
752 {
753 ok(0, "unexpected call\n");
754 return E_NOTIMPL;
755 }
756
757 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
758 {
759 ok(0, "unexpected call\n");
760 return E_NOTIMPL;
761 }
762
763 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
764 {
765 ok(0, "unexpected call\n");
766 return E_NOTIMPL;
767 }
768
769 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
770 {
771 ok(0, "unexpected call\n");
772 return E_NOTIMPL;
773 }
774
775 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
776 {
777 ok(0, "unexpected call\n");
778 return E_NOTIMPL;
779 }
780
781 #define EVENT_HANDLER_FUNC_OBJ(event) \
782 static IDispatchExVtbl event ## FuncVtbl = { \
783 DispatchEx_QueryInterface, \
784 DispatchEx_AddRef, \
785 DispatchEx_Release, \
786 DispatchEx_GetTypeInfoCount, \
787 DispatchEx_GetTypeInfo, \
788 DispatchEx_GetIDsOfNames, \
789 DispatchEx_Invoke, \
790 DispatchEx_GetDispID, \
791 event, \
792 DispatchEx_DeleteMemberByName, \
793 DispatchEx_DeleteMemberByDispID, \
794 DispatchEx_GetMemberProperties, \
795 DispatchEx_GetMemberName, \
796 DispatchEx_GetNextDispID, \
797 DispatchEx_GetNameSpaceParent \
798 }; \
799 static IDispatchEx event ## _obj = { &event ## FuncVtbl };
800
801 static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
802 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
803 {
804 IHTMLDocument3 *doc3;
805 CHECK_EXPECT(document_onclick);
806 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
807 doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
808 IHTMLDocument3_Release(doc3);
809 test_event_src("DIV");
810 test_event_obj("click", &no_xy);
811 return S_OK;
812 }
813
814 EVENT_HANDLER_FUNC_OBJ(document_onclick);
815
816 static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
817 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
818 {
819 CHECK_EXPECT(div_onclick);
820 test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
821 test_event_src("DIV");
822 return S_OK;
823 }
824
825 EVENT_HANDLER_FUNC_OBJ(div_onclick);
826
827 static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
828 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
829 {
830 CHECK_EXPECT(div_onclick_attached);
831
832 test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
833 test_event_src("DIV");
834 return S_OK;
835 }
836
837 EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
838
839 static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
840 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
841 {
842 CHECK_EXPECT(body_onclick);
843 test_event_args(&DIID_DispHTMLBody, id, wFlags, pdp, pvarRes, pei, pspCaller);
844 test_event_src("DIV");
845 return S_OK;
846 }
847
848 EVENT_HANDLER_FUNC_OBJ(body_onclick);
849
850 static HRESULT WINAPI iframe_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
851 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
852 {
853 IHTMLFrameBase2 *iframe;
854 IHTMLElement2 *elem2;
855 IHTMLElement *elem;
856 VARIANT v;
857 BSTR str;
858 HRESULT hres;
859
860 test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
861 test_event_src("IFRAME");
862
863 elem = get_event_src();
864 elem2 = get_elem2_iface((IUnknown*)elem);
865 IHTMLElement_Release(elem);
866
867 V_VT(&v) = VT_EMPTY;
868 hres = IHTMLElement2_get_readyState(elem2, &v);
869 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
870 ok(V_VT(&v) == VT_BSTR, "V_VT(readyState) = %d\n", V_VT(&v));
871
872 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase2, (void**)&iframe);
873 IHTMLElement2_Release(elem2);
874 ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
875
876 str = NULL;
877 hres = IHTMLFrameBase2_get_readyState(iframe, &str);
878 IHTMLFrameBase2_Release(iframe);
879 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
880 ok(str != NULL, "readyState == NULL\n");
881 ok(!lstrcmpW(str, V_BSTR(&v)), "ready states differ\n");
882 VariantClear(&v);
883
884 if(!strcmp_wa(str, "loading"))
885 CHECK_EXPECT(iframe_onreadystatechange_loading);
886 else if(!strcmp_wa(str, "interactive"))
887 CHECK_EXPECT(iframe_onreadystatechange_interactive);
888 else if(!strcmp_wa(str, "complete"))
889 CHECK_EXPECT(iframe_onreadystatechange_complete);
890 else
891 ok(0, "unexpected state %s\n", wine_dbgstr_w(str));
892
893 return S_OK;
894 }
895
896 EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange);
897
898 static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
899 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
900 {
901 ok(0, "unexpected call\n");
902 return S_OK;
903 }
904
905 EVENT_HANDLER_FUNC_OBJ(nocall);
906
907 #define CONNECTION_POINT_OBJ(cpname, diid) \
908 static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
909 { \
910 *ppv = NULL; \
911 if(IsEqualGUID(riid, &IID_IUnknown) \
912 || IsEqualGUID(riid, &IID_IDispatch) \
913 || IsEqualGUID(riid, &diid)) \
914 *ppv = iface; \
915 else { \
916 ok(0, "unexpected riid %s\n", debugstr_guid(riid)); \
917 return E_NOINTERFACE; \
918 } \
919 return S_OK; \
920 } \
921 static IDispatchExVtbl cpname ## Vtbl = { \
922 cpname ## _QueryInterface, \
923 DispatchEx_AddRef, \
924 DispatchEx_Release, \
925 DispatchEx_GetTypeInfoCount, \
926 DispatchEx_GetTypeInfo, \
927 DispatchEx_GetIDsOfNames, \
928 cpname, \
929 DispatchEx_GetDispID, \
930 DispatchEx_InvokeEx, \
931 DispatchEx_DeleteMemberByName, \
932 DispatchEx_DeleteMemberByDispID, \
933 DispatchEx_GetMemberProperties, \
934 DispatchEx_GetMemberName, \
935 DispatchEx_GetNextDispID, \
936 DispatchEx_GetNameSpaceParent \
937 }; \
938 static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
939
940 #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
941 static void _test_cp_args(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
942 {
943 ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
944 ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
945 ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
946 ok_(__FILE__,line)(!dp->cArgs, "dp->cArgs = %d\n", dp->cArgs);
947 ok_(__FILE__,line)(!dp->rgvarg, "dp->rgvarg = %p\n", dp->rgvarg);
948 ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
949 ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
950 ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
951 ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
952 ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
953 ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
954 }
955
956 static HRESULT WINAPI doccp(IDispatchEx *iface, DISPID dispIdMember,
957 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
958 VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
959 {
960 switch(dispIdMember) {
961 case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
962 CHECK_EXPECT(doccp_onclick);
963 test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
964 break;
965 default:
966 ok(0, "unexpected call %d\n", dispIdMember);
967 return E_NOTIMPL;
968 }
969
970 return S_OK;
971 }
972
973 CONNECTION_POINT_OBJ(doccp, DIID_HTMLDocumentEvents);
974
975 static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
976 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
977 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
978 {
979 CHECK_EXPECT(timeout);
980
981 ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
982 ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", debugstr_guid(riid));
983 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
984 ok(!lcid, "lcid = %x\n", lcid);
985 ok(pDispParams != NULL, "pDispParams == NULL\n");
986 ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
987 ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
988 ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
989 ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
990 ok(pVarResult != NULL, "pVarResult = NULL\n");
991 ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
992 ok(!puArgErr, "puArgErr = %p\n", puArgErr);
993 ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
994
995 return S_OK;
996 }
997
998 static IDispatchExVtbl timeoutFuncVtbl = {
999 DispatchEx_QueryInterface,
1000 DispatchEx_AddRef,
1001 DispatchEx_Release,
1002 DispatchEx_GetTypeInfoCount,
1003 DispatchEx_GetTypeInfo,
1004 DispatchEx_GetIDsOfNames,
1005 timeoutFunc_Invoke,
1006 DispatchEx_GetDispID,
1007 DispatchEx_InvokeEx,
1008 DispatchEx_DeleteMemberByName,
1009 DispatchEx_DeleteMemberByDispID,
1010 DispatchEx_GetMemberProperties,
1011 DispatchEx_GetMemberName,
1012 DispatchEx_GetNextDispID,
1013 DispatchEx_GetNameSpaceParent
1014 };
1015
1016 static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
1017
1018 static void pump_msgs(BOOL *b)
1019 {
1020 MSG msg;
1021 while(!*b && GetMessage(&msg, NULL, 0, 0)) {
1022 TranslateMessage(&msg);
1023 DispatchMessage(&msg);
1024 }
1025 }
1026
1027 static IConnectionPoint *get_cp(IUnknown *unk, REFIID riid)
1028 {
1029 IConnectionPointContainer *cp_container;
1030 IConnectionPoint *cp;
1031 HRESULT hres;
1032
1033 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1034 ok(hres == S_OK, "Could not get IConnectionPointContainer: %08x\n", hres);
1035
1036 hres = IConnectionPointContainer_FindConnectionPoint(cp_container, riid, &cp);
1037 IConnectionPointContainer_Release(cp_container);
1038 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1039
1040 return cp;
1041 }
1042
1043 static DWORD register_cp(IUnknown *unk, REFIID riid, IUnknown *sink)
1044 {
1045 IConnectionPoint *cp;
1046 DWORD cookie;
1047 HRESULT hres;
1048
1049 cp = get_cp(unk, riid);
1050 hres = IConnectionPoint_Advise(cp, sink, &cookie);
1051 IConnectionPoint_Release(cp);
1052 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1053
1054 return cookie;
1055 }
1056
1057 static void unregister_cp(IUnknown *unk, REFIID riid, DWORD cookie)
1058 {
1059 IConnectionPoint *cp;
1060 HRESULT hres;
1061
1062 cp = get_cp(unk, riid);
1063 hres = IConnectionPoint_Unadvise(cp, cookie);
1064 IConnectionPoint_Release(cp);
1065 ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
1066 }
1067
1068 static void test_onclick(IHTMLDocument2 *doc)
1069 {
1070 IHTMLElement *div, *body;
1071 DWORD cp_cookie;
1072 VARIANT v;
1073 HRESULT hres;
1074
1075 div = get_elem_id(doc, "clickdiv");
1076
1077 elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
1078 elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
1079
1080 V_VT(&v) = VT_EMPTY;
1081 hres = IHTMLElement_get_onclick(div, &v);
1082 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1083 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1084
1085 V_VT(&v) = VT_EMPTY;
1086 hres = IHTMLElement_put_onclick(div, v);
1087 ok(hres == E_NOTIMPL, "put_onclick failed: %08x\n", hres);
1088
1089 V_VT(&v) = VT_DISPATCH;
1090 V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
1091 hres = IHTMLElement_put_onclick(div, v);
1092 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1093
1094 V_VT(&v) = VT_EMPTY;
1095 hres = IHTMLElement_get_onclick(div, &v);
1096 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1097 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1098 ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1099 VariantClear(&v);
1100
1101 V_VT(&v) = VT_EMPTY;
1102 hres = IHTMLDocument2_get_onclick(doc, &v);
1103 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1104 ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1105
1106 V_VT(&v) = VT_DISPATCH;
1107 V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
1108 hres = IHTMLDocument2_put_onclick(doc, v);
1109 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1110
1111 V_VT(&v) = VT_EMPTY;
1112 hres = IHTMLDocument2_get_onclick(doc, &v);
1113 ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1114 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1115 ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1116 VariantClear(&v);
1117
1118 body = doc_get_body(doc);
1119
1120 V_VT(&v) = VT_DISPATCH;
1121 V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
1122 hres = IHTMLElement_put_onclick(body, v);
1123 ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1124
1125 if(winetest_interactive) {
1126 SET_EXPECT(div_onclick);
1127 SET_EXPECT(div_onclick_attached);
1128 SET_EXPECT(body_onclick);
1129 SET_EXPECT(document_onclick);
1130 pump_msgs(&called_document_onclick);
1131 CHECK_CALLED(div_onclick);
1132 CHECK_CALLED(div_onclick_attached);
1133 CHECK_CALLED(body_onclick);
1134 CHECK_CALLED(document_onclick);
1135 }
1136
1137 xy_todo = TRUE;
1138
1139 SET_EXPECT(div_onclick);
1140 SET_EXPECT(div_onclick_attached);
1141 SET_EXPECT(body_onclick);
1142 SET_EXPECT(document_onclick);
1143
1144 hres = IHTMLElement_click(div);
1145 ok(hres == S_OK, "click failed: %08x\n", hres);
1146
1147 CHECK_CALLED(div_onclick);
1148 CHECK_CALLED(div_onclick_attached);
1149 CHECK_CALLED(body_onclick);
1150 CHECK_CALLED(document_onclick);
1151
1152 SET_EXPECT(div_onclick);
1153 SET_EXPECT(div_onclick_attached);
1154 SET_EXPECT(body_onclick);
1155 SET_EXPECT(document_onclick);
1156
1157 V_VT(&v) = VT_EMPTY;
1158 elem_fire_event((IUnknown*)div, "onclick", &v);
1159
1160 CHECK_CALLED(div_onclick);
1161 CHECK_CALLED(div_onclick_attached);
1162 CHECK_CALLED(body_onclick);
1163 CHECK_CALLED(document_onclick);
1164
1165 cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_obj);
1166
1167 SET_EXPECT(div_onclick);
1168 SET_EXPECT(div_onclick_attached);
1169 SET_EXPECT(body_onclick);
1170 SET_EXPECT(document_onclick);
1171 SET_EXPECT(doccp_onclick);
1172
1173 hres = IHTMLElement_click(div);
1174 ok(hres == S_OK, "click failed: %08x\n", hres);
1175
1176 CHECK_CALLED(div_onclick);
1177 CHECK_CALLED(div_onclick_attached);
1178 CHECK_CALLED(body_onclick);
1179 CHECK_CALLED(document_onclick);
1180 CHECK_CALLED(doccp_onclick);
1181
1182 unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
1183
1184 IHTMLElement_Release(div);
1185 IHTMLElement_Release(body);
1186 }
1187
1188 static void test_onreadystatechange(IHTMLDocument2 *doc)
1189 {
1190 IHTMLFrameBase *iframe;
1191 IHTMLElement2 *elem2;
1192 IHTMLElement *elem;
1193 VARIANT v;
1194 BSTR str;
1195 HRESULT hres;
1196
1197 elem = get_elem_id(doc, "iframe");
1198 elem2 = get_elem2_iface((IUnknown*)elem);
1199 IHTMLElement_Release(elem);
1200
1201 V_VT(&v) = VT_EMPTY;
1202 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1203 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1204 ok(V_VT(&v) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1205
1206 V_VT(&v) = VT_DISPATCH;
1207 V_DISPATCH(&v) = (IDispatch*)&iframe_onreadystatechange_obj;
1208 hres = IHTMLElement2_put_onreadystatechange(elem2, v);
1209 ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
1210
1211 V_VT(&v) = VT_EMPTY;
1212 hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1213 ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1214 ok(V_VT(&v) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1215 ok(V_DISPATCH(&v) == (IDispatch*)&iframe_onreadystatechange_obj, "unexpected onreadystatechange value\n");
1216
1217 hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase, (void**)&iframe);
1218 IHTMLElement2_Release(elem2);
1219 ok(hres == S_OK, "Could not get IHTMLFrameBase iface: %08x\n", hres);
1220
1221 hres = IHTMLFrameBase_put_src(iframe, (str = a2bstr("about:blank")));
1222 SysFreeString(str);
1223 ok(hres == S_OK, "put_src failed: %08x\n", hres);
1224
1225 SET_EXPECT(iframe_onreadystatechange_loading);
1226 SET_EXPECT(iframe_onreadystatechange_interactive);
1227 SET_EXPECT(iframe_onreadystatechange_complete);
1228 pump_msgs(&called_iframe_onreadystatechange_complete);
1229 todo_wine
1230 CHECK_CALLED(iframe_onreadystatechange_loading);
1231 CHECK_CALLED(iframe_onreadystatechange_interactive);
1232 CHECK_CALLED(iframe_onreadystatechange_complete);
1233
1234 IHTMLFrameBase_Release(iframe);
1235 }
1236
1237 static void test_timeout(IHTMLDocument2 *doc)
1238 {
1239 IHTMLWindow3 *win3;
1240 VARIANT expr, var;
1241 LONG id;
1242 HRESULT hres;
1243
1244 hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
1245 ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
1246
1247 V_VT(&expr) = VT_DISPATCH;
1248 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1249 V_VT(&var) = VT_EMPTY;
1250 id = 0;
1251 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1252 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1253 ok(id, "id = 0\n");
1254
1255 SET_EXPECT(timeout);
1256 pump_msgs(&called_timeout);
1257 CHECK_CALLED(timeout);
1258
1259 V_VT(&expr) = VT_DISPATCH;
1260 V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
1261 V_VT(&var) = VT_EMPTY;
1262 id = 0;
1263 hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
1264 ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
1265 ok(id, "id = 0\n");
1266
1267 hres = IHTMLWindow2_clearTimeout(window, id);
1268 ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
1269
1270 IHTMLWindow3_Release(win3);
1271 }
1272
1273 static HRESULT QueryInterface(REFIID,void**);
1274
1275 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
1276 {
1277 return E_NOINTERFACE;
1278 }
1279
1280 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
1281 {
1282 return 2;
1283 }
1284
1285 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
1286 {
1287 return 1;
1288 }
1289
1290 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1291 {
1292 return E_NOTIMPL;
1293 }
1294
1295 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
1296 {
1297 return E_NOTIMPL;
1298 }
1299
1300 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
1301 {
1302 return E_NOTIMPL;
1303 }
1304
1305 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
1306 LPCBORDERWIDTHS pborderwidths)
1307 {
1308 return E_NOTIMPL;
1309 }
1310
1311 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
1312 LPCBORDERWIDTHS pborderwidths)
1313 {
1314 return S_OK;
1315 }
1316
1317 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
1318 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1319 {
1320 return S_OK;
1321 }
1322
1323 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
1324 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1325 {
1326 return S_OK;
1327 }
1328
1329 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
1330 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1331 {
1332 return E_NOTIMPL;
1333 }
1334
1335 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
1336 HOLEMENU holemenu, HWND hwndActiveObject)
1337 {
1338 ok(0, "unexpected call\n");
1339 return E_NOTIMPL;
1340 }
1341
1342 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
1343 {
1344 ok(0, "unexpected call\n");
1345 return E_NOTIMPL;
1346 }
1347
1348 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
1349 {
1350 return S_OK;
1351 }
1352
1353 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
1354 {
1355 return E_NOTIMPL;
1356 }
1357
1358 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
1359 {
1360 ok(0, "unexpected call\n");
1361 return E_NOTIMPL;
1362 }
1363
1364 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
1365 InPlaceFrame_QueryInterface,
1366 InPlaceFrame_AddRef,
1367 InPlaceFrame_Release,
1368 InPlaceFrame_GetWindow,
1369 InPlaceFrame_ContextSensitiveHelp,
1370 InPlaceFrame_GetBorder,
1371 InPlaceFrame_RequestBorderSpace,
1372 InPlaceFrame_SetBorderSpace,
1373 InPlaceFrame_SetActiveObject,
1374 InPlaceFrame_InsertMenus,
1375 InPlaceFrame_SetMenu,
1376 InPlaceFrame_RemoveMenus,
1377 InPlaceFrame_SetStatusText,
1378 InPlaceFrame_EnableModeless,
1379 InPlaceFrame_TranslateAccelerator
1380 };
1381
1382 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
1383
1384 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
1385 InPlaceFrame_QueryInterface,
1386 InPlaceFrame_AddRef,
1387 InPlaceFrame_Release,
1388 InPlaceFrame_GetWindow,
1389 InPlaceFrame_ContextSensitiveHelp,
1390 InPlaceFrame_GetBorder,
1391 InPlaceFrame_RequestBorderSpace,
1392 InPlaceFrame_SetBorderSpace,
1393 InPlaceUIWindow_SetActiveObject,
1394 };
1395
1396 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
1397
1398 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
1399 {
1400 return QueryInterface(riid, ppv);
1401 }
1402
1403 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
1404 {
1405 return 2;
1406 }
1407
1408 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
1409 {
1410 return 1;
1411 }
1412
1413 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
1414 {
1415 *phwnd = container_hwnd;
1416 return S_OK;
1417 }
1418
1419 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1420 {
1421 ok(0, "unexpected call\n");
1422 return E_NOTIMPL;
1423 }
1424
1425 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
1426 {
1427 return S_OK;
1428 }
1429
1430 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
1431 {
1432 return S_OK;
1433 }
1434
1435 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
1436 {
1437 return S_OK;
1438 }
1439
1440 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
1441 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1442 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1443 {
1444 static const RECT rect = {0,0,300,300};
1445
1446 *ppFrame = &InPlaceFrame;
1447 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
1448 *lprcPosRect = rect;
1449 *lprcClipRect = rect;
1450
1451 lpFrameInfo->cb = sizeof(*lpFrameInfo);
1452 lpFrameInfo->fMDIApp = FALSE;
1453 lpFrameInfo->hwndFrame = container_hwnd;
1454 lpFrameInfo->haccel = NULL;
1455 lpFrameInfo->cAccelEntries = 0;
1456
1457 return S_OK;
1458 }
1459
1460 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
1461 {
1462 return E_NOTIMPL;
1463 }
1464
1465 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1466 {
1467 return S_OK;
1468 }
1469
1470 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
1471 {
1472 return S_OK;
1473 }
1474
1475 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
1476 {
1477 return E_NOTIMPL;
1478 }
1479
1480 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
1481 {
1482 return E_NOTIMPL;
1483 }
1484
1485 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1486 {
1487 return E_NOTIMPL;
1488 }
1489
1490 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
1491 InPlaceSite_QueryInterface,
1492 InPlaceSite_AddRef,
1493 InPlaceSite_Release,
1494 InPlaceSite_GetWindow,
1495 InPlaceSite_ContextSensitiveHelp,
1496 InPlaceSite_CanInPlaceActivate,
1497 InPlaceSite_OnInPlaceActivate,
1498 InPlaceSite_OnUIActivate,
1499 InPlaceSite_GetWindowContext,
1500 InPlaceSite_Scroll,
1501 InPlaceSite_OnUIDeactivate,
1502 InPlaceSite_OnInPlaceDeactivate,
1503 InPlaceSite_DiscardUndoState,
1504 InPlaceSite_DeactivateAndUndo,
1505 InPlaceSite_OnPosRectChange,
1506 };
1507
1508 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
1509
1510 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
1511 {
1512 return QueryInterface(riid, ppv);
1513 }
1514
1515 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
1516 {
1517 return 2;
1518 }
1519
1520 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1521 {
1522 return 1;
1523 }
1524
1525 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1526 {
1527 ok(0, "unexpected call\n");
1528 return E_NOTIMPL;
1529 }
1530
1531 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1532 IMoniker **ppmon)
1533 {
1534 ok(0, "unexpected call\n");
1535 return E_NOTIMPL;
1536 }
1537
1538 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1539 {
1540 return E_NOTIMPL;
1541 }
1542
1543 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1544 {
1545 ok(0, "unexpected call\n");
1546 return E_NOTIMPL;
1547 }
1548
1549 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1550 {
1551 ok(0, "unexpected call\n");
1552 return E_NOTIMPL;
1553 }
1554
1555 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1556 {
1557 ok(0, "unexpected call\n");
1558 return E_NOTIMPL;
1559 }
1560
1561 static const IOleClientSiteVtbl ClientSiteVtbl = {
1562 ClientSite_QueryInterface,
1563 ClientSite_AddRef,
1564 ClientSite_Release,
1565 ClientSite_SaveObject,
1566 ClientSite_GetMoniker,
1567 ClientSite_GetContainer,
1568 ClientSite_ShowObject,
1569 ClientSite_OnShowWindow,
1570 ClientSite_RequestNewObjectLayout
1571 };
1572
1573 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1574
1575 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1576 {
1577 return QueryInterface(riid, ppv);
1578 }
1579
1580 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1581 {
1582 return 2;
1583 }
1584
1585 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1586 {
1587 return 1;
1588 }
1589
1590 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1591 {
1592 RECT rect = {0,0,300,300};
1593 IOleDocument *document;
1594 HRESULT hres;
1595
1596 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1597 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1598
1599 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1600 IOleDocument_Release(document);
1601 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1602
1603 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1604 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1605
1606 hres = IOleDocumentView_UIActivate(view, TRUE);
1607 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1608
1609 hres = IOleDocumentView_SetRect(view, &rect);
1610 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1611
1612 hres = IOleDocumentView_Show(view, TRUE);
1613 ok(hres == S_OK, "Show failed: %08x\n", hres);
1614
1615 return S_OK;
1616 }
1617
1618 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1619 DocumentSite_QueryInterface,
1620 DocumentSite_AddRef,
1621 DocumentSite_Release,
1622 DocumentSite_ActivateMe
1623 };
1624
1625 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1626
1627 static HRESULT QueryInterface(REFIID riid, void **ppv)
1628 {
1629 *ppv = NULL;
1630
1631 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1632 *ppv = &ClientSite;
1633 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1634 *ppv = &DocumentSite;
1635 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1636 *ppv = &InPlaceSite;
1637
1638 return *ppv ? S_OK : E_NOINTERFACE;
1639 }
1640
1641 static IHTMLDocument2 *notif_doc;
1642 static BOOL doc_complete;
1643
1644 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
1645 REFIID riid, void**ppv)
1646 {
1647 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
1648 *ppv = iface;
1649 return S_OK;
1650 }
1651
1652 ok(0, "unexpected call\n");
1653 return E_NOINTERFACE;
1654 }
1655
1656 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
1657 {
1658 return 2;
1659 }
1660
1661 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
1662 {
1663 return 1;
1664 }
1665
1666 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
1667 {
1668 if(dispID == DISPID_READYSTATE){
1669 BSTR state;
1670 HRESULT hres;
1671
1672 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
1673 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1674
1675 if(!strcmp_wa(state, "complete"))
1676 doc_complete = TRUE;
1677
1678 SysFreeString(state);
1679 }
1680
1681 return S_OK;
1682 }
1683
1684 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
1685 {
1686 ok(0, "unexpected call\n");
1687 return E_NOTIMPL;
1688 }
1689
1690 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1691 PropertyNotifySink_QueryInterface,
1692 PropertyNotifySink_AddRef,
1693 PropertyNotifySink_Release,
1694 PropertyNotifySink_OnChanged,
1695 PropertyNotifySink_OnRequestEdit
1696 };
1697
1698 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1699
1700 static void doc_load_string(IHTMLDocument2 *doc, const char *str)
1701 {
1702 IPersistStreamInit *init;
1703 IStream *stream;
1704 HGLOBAL mem;
1705 SIZE_T len;
1706
1707 notif_doc = doc;
1708
1709 doc_complete = FALSE;
1710 len = strlen(str);
1711 mem = GlobalAlloc(0, len);
1712 memcpy(mem, str, len);
1713 CreateStreamOnHGlobal(mem, TRUE, &stream);
1714
1715 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1716
1717 IPersistStreamInit_Load(init, stream);
1718 IPersistStreamInit_Release(init);
1719 IStream_Release(stream);
1720 }
1721
1722 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
1723 {
1724 IConnectionPointContainer *container;
1725 IConnectionPoint *cp;
1726 DWORD cookie;
1727 HRESULT hres;
1728
1729 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
1730 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1731
1732 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1733 IConnectionPointContainer_Release(container);
1734 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1735
1736 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1737 IConnectionPoint_Release(cp);
1738 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1739 }
1740
1741 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1742 {
1743 IOleObject *oleobj;
1744 HRESULT hres;
1745
1746 if(!set && view) {
1747 IOleDocumentView_Show(view, FALSE);
1748 IOleDocumentView_CloseView(view, 0);
1749 IOleDocumentView_SetInPlaceSite(view, NULL);
1750 IOleDocumentView_Release(view);
1751 view = NULL;
1752 }
1753
1754 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1755 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1756
1757 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1758 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1759
1760 if(set) {
1761 IHlinkTarget *hlink;
1762
1763 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1764 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1765
1766 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1767 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1768
1769 IHlinkTarget_Release(hlink);
1770 }
1771
1772 IOleObject_Release(oleobj);
1773 }
1774 static IHTMLDocument2 *create_document(void)
1775 {
1776 IHTMLDocument2 *doc;
1777 IHTMLDocument5 *doc5;
1778 HRESULT hres;
1779
1780 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1781 &IID_IHTMLDocument2, (void**)&doc);
1782 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1783 if (FAILED(hres))
1784 return NULL;
1785
1786 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1787 if(FAILED(hres)) {
1788 win_skip("Could not get IHTMLDocument5 interface, probably too old IE\n");
1789 IHTMLDocument2_Release(doc);
1790 return NULL;
1791 }
1792
1793 IHTMLDocument5_Release(doc5);
1794 return doc;
1795 }
1796
1797
1798 typedef void (*testfunc_t)(IHTMLDocument2*);
1799
1800 static void run_test(const char *str, testfunc_t test)
1801 {
1802 IHTMLDocument2 *doc;
1803 IHTMLElement *body = NULL;
1804 MSG msg;
1805 HRESULT hres;
1806
1807 xy_todo = FALSE;
1808 doc = create_document();
1809 if (!doc)
1810 return;
1811 set_client_site(doc, TRUE);
1812 doc_load_string(doc, str);
1813 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1814
1815 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1816 TranslateMessage(&msg);
1817 DispatchMessage(&msg);
1818 }
1819
1820 hres = IHTMLDocument2_get_body(doc, &body);
1821 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1822
1823 if(body) {
1824 IHTMLElement_Release(body);
1825
1826 hres = IHTMLDocument2_get_parentWindow(doc, &window);
1827 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
1828 ok(window != NULL, "window == NULL\n");
1829
1830 test(doc);
1831
1832 IHTMLWindow2_Release(window);
1833 window = NULL;
1834 }else {
1835 skip("Could not get document body. Assuming no Gecko installed.\n");
1836 }
1837
1838 set_client_site(doc, FALSE);
1839 IHTMLDocument2_Release(doc);
1840 }
1841
1842 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1843 {
1844 return DefWindowProc(hwnd, msg, wParam, lParam);
1845 }
1846
1847 static HWND create_container_window(void)
1848 {
1849 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
1850 static WNDCLASSEXA wndclass = {
1851 sizeof(WNDCLASSEXA),
1852 0,
1853 wnd_proc,
1854 0, 0, NULL, NULL, NULL, NULL, NULL,
1855 szHTMLDocumentTest,
1856 NULL
1857 };
1858
1859 RegisterClassExA(&wndclass);
1860 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
1861 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
1862 300, 300, NULL, NULL, NULL, NULL);
1863 }
1864
1865 START_TEST(events)
1866 {
1867 CoInitialize(NULL);
1868 container_hwnd = create_container_window();
1869
1870 if(winetest_interactive)
1871 ShowWindow(container_hwnd, SW_SHOW);
1872
1873 run_test(empty_doc_str, test_timeout);
1874 run_test(click_doc_str, test_onclick);
1875 run_test(readystate_doc_str, test_onreadystatechange);
1876
1877 DestroyWindow(container_hwnd);
1878 CoUninitialize();
1879 }