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