1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Copyright 2008-2011 Jacek Caban for CodeWeavers
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck  * License as published by the Free Software Foundation; either
7c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck  *
9c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12c2c66affSColin Finck  * Lesser General Public License for more details.
13c2c66affSColin Finck  *
14c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck  */
18c2c66affSColin Finck 
19*ba54c564SAmine Khaldi #include "precomp.h"
20c2c66affSColin Finck 
21c2c66affSColin Finck #include <docobj.h>
22c2c66affSColin Finck 
23c2c66affSColin Finck #define DEFINE_EXPECT(func) \
24c2c66affSColin Finck     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
25c2c66affSColin Finck 
26c2c66affSColin Finck #define SET_EXPECT(func) \
27c2c66affSColin Finck     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
28c2c66affSColin Finck 
29c2c66affSColin Finck #define CHECK_EXPECT2(func) \
30c2c66affSColin Finck     do { \
31c2c66affSColin Finck     trace(#func "\n"); \
32c2c66affSColin Finck         ok(expect_ ##func, "unexpected call " #func "\n"); \
33c2c66affSColin Finck         called_ ## func = TRUE; \
34c2c66affSColin Finck     }while(0)
35c2c66affSColin Finck 
36c2c66affSColin Finck #define CHECK_EXPECT(func) \
37c2c66affSColin Finck     do { \
38c2c66affSColin Finck         CHECK_EXPECT2(func); \
39c2c66affSColin Finck         expect_ ## func = FALSE; \
40c2c66affSColin Finck     }while(0)
41c2c66affSColin Finck 
42c2c66affSColin Finck #define CHECK_CALLED(func) \
43c2c66affSColin Finck     do { \
44c2c66affSColin Finck         ok(called_ ## func, "expected " #func "\n"); \
45c2c66affSColin Finck         expect_ ## func = called_ ## func = FALSE; \
46c2c66affSColin Finck     }while(0)
47c2c66affSColin Finck 
48c2c66affSColin Finck DEFINE_EXPECT(document_onclick);
49c2c66affSColin Finck DEFINE_EXPECT(body_onclick);
50c2c66affSColin Finck DEFINE_EXPECT(doc_onclick_attached);
51c2c66affSColin Finck DEFINE_EXPECT(div_onclick);
52c2c66affSColin Finck DEFINE_EXPECT(div_onclick_attached);
53c2c66affSColin Finck DEFINE_EXPECT(timeout);
54c2c66affSColin Finck DEFINE_EXPECT(doccp_onclick);
55c2c66affSColin Finck DEFINE_EXPECT(doccp_onclick_cancel);
56c2c66affSColin Finck DEFINE_EXPECT(div_onclick_disp);
57c2c66affSColin Finck DEFINE_EXPECT(invoke_onclick);
58c2c66affSColin Finck DEFINE_EXPECT(iframe_onreadystatechange_loading);
59c2c66affSColin Finck DEFINE_EXPECT(iframe_onreadystatechange_interactive);
60c2c66affSColin Finck DEFINE_EXPECT(iframe_onreadystatechange_complete);
61c2c66affSColin Finck DEFINE_EXPECT(iframedoc_onreadystatechange);
62c2c66affSColin Finck DEFINE_EXPECT(img_onload);
63c2c66affSColin Finck DEFINE_EXPECT(img_onerror);
64c2c66affSColin Finck DEFINE_EXPECT(input_onfocus);
65c2c66affSColin Finck DEFINE_EXPECT(input_onblur);
66c2c66affSColin Finck DEFINE_EXPECT(form_onsubmit);
67c2c66affSColin Finck DEFINE_EXPECT(form_onclick);
68c2c66affSColin Finck DEFINE_EXPECT(submit_onclick);
69c2c66affSColin Finck DEFINE_EXPECT(submit_onclick_cancel);
70c2c66affSColin Finck DEFINE_EXPECT(submit_onclick_attached);
71c2c66affSColin Finck DEFINE_EXPECT(submit_onclick_attached_check_cancel);
72c2c66affSColin Finck DEFINE_EXPECT(submit_onclick_setret);
73c2c66affSColin Finck DEFINE_EXPECT(elem2_cp_onclick);
74c2c66affSColin Finck DEFINE_EXPECT(iframe_onload);
75c2c66affSColin Finck 
76c2c66affSColin Finck static HWND container_hwnd = NULL;
77c2c66affSColin Finck static IHTMLWindow2 *window;
78c2c66affSColin Finck static IOleDocumentView *view;
79c2c66affSColin Finck static BOOL is_ie9plus;
80c2c66affSColin Finck 
81c2c66affSColin Finck typedef struct {
82c2c66affSColin Finck     LONG x;
83c2c66affSColin Finck     LONG y;
84c2c66affSColin Finck     LONG offset_x;
85c2c66affSColin Finck     LONG offset_y;
86c2c66affSColin Finck } xy_test_t;
87c2c66affSColin Finck 
88c2c66affSColin Finck static const xy_test_t no_xy = {-10,-10,-10,-10};
89c2c66affSColin Finck 
90c2c66affSColin Finck static const char empty_doc_str[] =
91c2c66affSColin Finck     "<html></html>";
92c2c66affSColin Finck 
93c2c66affSColin Finck static const char click_doc_str[] =
94c2c66affSColin Finck     "<html><body>"
95c2c66affSColin Finck     "<div id=\"clickdiv\" style=\"text-align: center; background: red; font-size: 32\">click here</div>"
96c2c66affSColin Finck     "</body></html>";
97c2c66affSColin Finck 
98c2c66affSColin Finck static const char readystate_doc_str[] =
99c2c66affSColin Finck     "<html><body><iframe id=\"iframe\"></iframe></body></html>";
100c2c66affSColin Finck 
101c2c66affSColin Finck static const char img_doc_str[] =
102c2c66affSColin Finck     "<html><body><img id=\"imgid\"></img></body></html>";
103c2c66affSColin Finck 
104c2c66affSColin Finck static const char input_doc_str[] =
105c2c66affSColin Finck     "<html><body><input id=\"inputid\"></input></body></html>";
106c2c66affSColin Finck 
107c2c66affSColin Finck static const char iframe_doc_str[] =
108c2c66affSColin Finck     "<html><body><iframe id=\"ifr\">Testing</iframe></body></html>";
109c2c66affSColin Finck 
110c2c66affSColin Finck static const char form_doc_str[] =
111c2c66affSColin Finck     "<html><body><form id=\"formid\" method=\"post\" action=\"about:blank\">"
112c2c66affSColin Finck     "<input type=\"text\" value=\"test\" name=\"i\"/>"
113c2c66affSColin Finck     "<input type=\"submit\" id=\"submitid\" />"
114c2c66affSColin Finck     "</form></body></html>";
115c2c66affSColin Finck 
strcmp_wa(LPCWSTR strw,const char * stra)116c2c66affSColin Finck static int strcmp_wa(LPCWSTR strw, const char *stra)
117c2c66affSColin Finck {
118c2c66affSColin Finck     CHAR buf[512];
119c2c66affSColin Finck     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
120c2c66affSColin Finck     return lstrcmpA(stra, buf);
121c2c66affSColin Finck }
122c2c66affSColin Finck 
a2bstr(const char * str)123c2c66affSColin Finck static BSTR a2bstr(const char *str)
124c2c66affSColin Finck {
125c2c66affSColin Finck     BSTR ret;
126c2c66affSColin Finck     int len;
127c2c66affSColin Finck 
128c2c66affSColin Finck     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
129c2c66affSColin Finck     ret = SysAllocStringLen(NULL, len-1);
130c2c66affSColin Finck     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
131c2c66affSColin Finck 
132c2c66affSColin Finck     return ret;
133c2c66affSColin Finck }
134c2c66affSColin Finck 
iface_cmp(IUnknown * iface1,IUnknown * iface2)135c2c66affSColin Finck static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
136c2c66affSColin Finck {
137c2c66affSColin Finck     IUnknown *unk1, *unk2;
138c2c66affSColin Finck 
139c2c66affSColin Finck     if(iface1 == iface2)
140c2c66affSColin Finck         return TRUE;
141c2c66affSColin Finck 
142c2c66affSColin Finck     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
143c2c66affSColin Finck     IUnknown_Release(unk1);
144c2c66affSColin Finck     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk2);
145c2c66affSColin Finck     IUnknown_Release(unk2);
146c2c66affSColin Finck 
147c2c66affSColin Finck     return unk1 == unk2;
148c2c66affSColin Finck }
149c2c66affSColin Finck 
150c2c66affSColin Finck #define test_disp(u,id) _test_disp(__LINE__,u,id)
_test_disp(unsigned line,IUnknown * unk,const IID * diid)151c2c66affSColin Finck static void _test_disp(unsigned line, IUnknown *unk, const IID *diid)
152c2c66affSColin Finck {
153c2c66affSColin Finck     IDispatchEx *dispex;
154c2c66affSColin Finck     ITypeInfo *typeinfo;
155c2c66affSColin Finck     UINT ticnt;
156c2c66affSColin Finck     HRESULT hres;
157c2c66affSColin Finck 
158c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&dispex);
159c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "Could not get IDispatch: %08x\n", hres);
160c2c66affSColin Finck     if(FAILED(hres))
161c2c66affSColin Finck         return;
162c2c66affSColin Finck 
163c2c66affSColin Finck     ticnt = 0xdeadbeef;
164c2c66affSColin Finck     hres = IDispatchEx_GetTypeInfoCount(dispex, &ticnt);
165c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfoCount failed: %08x\n", hres);
166c2c66affSColin Finck     ok_(__FILE__,line) (ticnt == 1, "ticnt=%u\n", ticnt);
167c2c66affSColin Finck 
168c2c66affSColin Finck     hres = IDispatchEx_GetTypeInfo(dispex, 0, 0, &typeinfo);
169c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "GetTypeInfo failed: %08x\n", hres);
170c2c66affSColin Finck 
171c2c66affSColin Finck     if(SUCCEEDED(hres)) {
172c2c66affSColin Finck         TYPEATTR *type_attr;
173c2c66affSColin Finck 
174c2c66affSColin Finck         hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
175c2c66affSColin Finck         ok_(__FILE__,line) (hres == S_OK, "GetTypeAttr failed: %08x\n", hres);
176c2c66affSColin Finck         ok_(__FILE__,line) (IsEqualGUID(&type_attr->guid, diid), "unexpected guid %s\n",
177c2c66affSColin Finck                             wine_dbgstr_guid(&type_attr->guid));
178c2c66affSColin Finck 
179c2c66affSColin Finck         ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
180c2c66affSColin Finck         ITypeInfo_Release(typeinfo);
181c2c66affSColin Finck     }
182c2c66affSColin Finck 
183c2c66affSColin Finck     IDispatchEx_Release(dispex);
184c2c66affSColin Finck }
185c2c66affSColin Finck 
186c2c66affSColin Finck #define get_doc3_iface(u) _get_doc3_iface(__LINE__,u)
_get_doc3_iface(unsigned line,IUnknown * unk)187c2c66affSColin Finck static IHTMLDocument3 *_get_doc3_iface(unsigned line, IUnknown *unk)
188c2c66affSColin Finck {
189c2c66affSColin Finck     IHTMLDocument3 *doc3;
190c2c66affSColin Finck     HRESULT hres;
191c2c66affSColin Finck 
192c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc3);
193c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
194c2c66affSColin Finck 
195c2c66affSColin Finck     return doc3;
196c2c66affSColin Finck }
197c2c66affSColin Finck 
198c2c66affSColin Finck #define get_elem_iface(u) _get_elem_iface(__LINE__,u)
_get_elem_iface(unsigned line,IUnknown * unk)199c2c66affSColin Finck static IHTMLElement *_get_elem_iface(unsigned line, IUnknown *unk)
200c2c66affSColin Finck {
201c2c66affSColin Finck     IHTMLElement *elem;
202c2c66affSColin Finck     HRESULT hres;
203c2c66affSColin Finck 
204c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement, (void**)&elem);
205c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement iface: %08x\n", hres);
206c2c66affSColin Finck 
207c2c66affSColin Finck     return elem;
208c2c66affSColin Finck }
209c2c66affSColin Finck 
210c2c66affSColin Finck #define get_elem2_iface(u) _get_elem2_iface(__LINE__,u)
_get_elem2_iface(unsigned line,IUnknown * unk)211c2c66affSColin Finck static IHTMLElement2 *_get_elem2_iface(unsigned line, IUnknown *unk)
212c2c66affSColin Finck {
213c2c66affSColin Finck     IHTMLElement2 *elem2;
214c2c66affSColin Finck     HRESULT hres;
215c2c66affSColin Finck 
216c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement2, (void**)&elem2);
217c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
218c2c66affSColin Finck 
219c2c66affSColin Finck     return elem2;
220c2c66affSColin Finck }
221c2c66affSColin Finck 
222c2c66affSColin Finck #define get_elem3_iface(u) _get_elem3_iface(__LINE__,u)
_get_elem3_iface(unsigned line,IUnknown * unk)223c2c66affSColin Finck static IHTMLElement3 *_get_elem3_iface(unsigned line, IUnknown *unk)
224c2c66affSColin Finck {
225c2c66affSColin Finck     IHTMLElement3 *elem3;
226c2c66affSColin Finck     HRESULT hres;
227c2c66affSColin Finck 
228c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IHTMLElement3, (void**)&elem3);
229c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
230c2c66affSColin Finck 
231c2c66affSColin Finck     return elem3;
232c2c66affSColin Finck }
233c2c66affSColin Finck 
234c2c66affSColin Finck #define get_iframe_iface(u) _get_iframe_iface(__LINE__,u)
_get_iframe_iface(unsigned line,IUnknown * unk)235c2c66affSColin Finck static IHTMLIFrameElement *_get_iframe_iface(unsigned line, IUnknown *unk)
236c2c66affSColin Finck {
237c2c66affSColin Finck     IHTMLIFrameElement *iframe;
238c2c66affSColin Finck     HRESULT hres;
239c2c66affSColin Finck 
240c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IHTMLIFrameElement, (void**)&iframe);
241c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "QueryInterface(IID_IHTMLIFrameElement) failed: %08x\n", hres);
242c2c66affSColin Finck 
243c2c66affSColin Finck     return iframe;
244c2c66affSColin Finck }
245c2c66affSColin Finck 
246c2c66affSColin Finck #define doc_get_body(d) _doc_get_body(__LINE__,d)
_doc_get_body(unsigned line,IHTMLDocument2 * doc)247c2c66affSColin Finck static IHTMLElement *_doc_get_body(unsigned line, IHTMLDocument2 *doc)
248c2c66affSColin Finck {
249c2c66affSColin Finck     IHTMLElement *body = NULL;
250c2c66affSColin Finck     HRESULT hres;
251c2c66affSColin Finck 
252c2c66affSColin Finck     hres = IHTMLDocument2_get_body(doc, &body);
253c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "get_body failed: %08x\n", hres);
254c2c66affSColin Finck     ok_(__FILE__,line) (body != NULL, "body == NULL\n");
255c2c66affSColin Finck 
256c2c66affSColin Finck     return body;
257c2c66affSColin Finck }
258c2c66affSColin Finck 
259c2c66affSColin Finck #define get_elem_id(d,i) _get_elem_id(__LINE__,d,i)
_get_elem_id(unsigned line,IHTMLDocument2 * doc,const char * id)260c2c66affSColin Finck static IHTMLElement *_get_elem_id(unsigned line, IHTMLDocument2 *doc, const char *id)
261c2c66affSColin Finck {
262c2c66affSColin Finck     IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
263c2c66affSColin Finck     IHTMLElement *elem;
264c2c66affSColin Finck     BSTR str;
265c2c66affSColin Finck     HRESULT hres;
266c2c66affSColin Finck 
267c2c66affSColin Finck     str = a2bstr(id);
268c2c66affSColin Finck     hres = IHTMLDocument3_getElementById(doc3, str, &elem);
269c2c66affSColin Finck     SysFreeString(str);
270c2c66affSColin Finck     IHTMLDocument3_Release(doc3);
271c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "getElementById failed: %08x\n", hres);
272c2c66affSColin Finck 
273c2c66affSColin Finck     return elem;
274c2c66affSColin Finck }
275c2c66affSColin Finck 
276c2c66affSColin Finck #define test_elem_tag(u,n) _test_elem_tag(__LINE__,u,n)
_test_elem_tag(unsigned line,IUnknown * unk,const char * extag)277c2c66affSColin Finck static void _test_elem_tag(unsigned line, IUnknown *unk, const char *extag)
278c2c66affSColin Finck {
279c2c66affSColin Finck     IHTMLElement *elem = _get_elem_iface(line, unk);
280c2c66affSColin Finck     BSTR tag;
281c2c66affSColin Finck     HRESULT hres;
282c2c66affSColin Finck 
283c2c66affSColin Finck     hres = IHTMLElement_get_tagName(elem, &tag);
284c2c66affSColin Finck     IHTMLElement_Release(elem);
285c2c66affSColin Finck     ok_(__FILE__, line) (hres == S_OK, "get_tagName failed: %08x\n", hres);
286c2c66affSColin Finck     ok_(__FILE__, line) (!strcmp_wa(tag, extag), "got tag: %s, expected %s\n", wine_dbgstr_w(tag), extag);
287c2c66affSColin Finck 
288c2c66affSColin Finck     SysFreeString(tag);
289c2c66affSColin Finck }
290c2c66affSColin Finck 
291c2c66affSColin Finck #define get_event_obj() _get_event_obj(__LINE__)
_get_event_obj(unsigned line)292c2c66affSColin Finck static IHTMLEventObj *_get_event_obj(unsigned line)
293c2c66affSColin Finck {
294c2c66affSColin Finck     IHTMLEventObj *event = NULL;
295c2c66affSColin Finck     HRESULT hres;
296c2c66affSColin Finck 
297c2c66affSColin Finck     hres = IHTMLWindow2_get_event(window, &event);
298c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "get_event failed: %08x\n", hres);
299c2c66affSColin Finck     ok_(__FILE__,line) (event != NULL, "event = NULL\n");
300c2c66affSColin Finck     _test_disp(line, (IUnknown*)event, &DIID_DispCEventObj);
301c2c66affSColin Finck 
302c2c66affSColin Finck     return event;
303c2c66affSColin Finck }
304c2c66affSColin Finck 
305c2c66affSColin Finck #define elem_fire_event(a,b,c) _elem_fire_event(__LINE__,a,b,c)
_elem_fire_event(unsigned line,IUnknown * unk,const char * event,VARIANT * evobj)306c2c66affSColin Finck static void _elem_fire_event(unsigned line, IUnknown *unk, const char *event, VARIANT *evobj)
307c2c66affSColin Finck {
308c2c66affSColin Finck     IHTMLElement3 *elem3 = _get_elem3_iface(line, unk);
309c2c66affSColin Finck     VARIANT_BOOL b;
310c2c66affSColin Finck     BSTR str;
311c2c66affSColin Finck     HRESULT hres;
312c2c66affSColin Finck 
313c2c66affSColin Finck     b = 100;
314c2c66affSColin Finck     str = a2bstr(event);
315c2c66affSColin Finck     hres = IHTMLElement3_fireEvent(elem3, str, evobj, &b);
316c2c66affSColin Finck     SysFreeString(str);
317c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "fireEvent failed: %08x\n", hres);
318c2c66affSColin Finck     ok_(__FILE__,line)(b == VARIANT_TRUE, "fireEvent returned %x\n", b);
319c2c66affSColin Finck }
320c2c66affSColin Finck 
321c2c66affSColin Finck #define test_event_args(a,b,c,d,e,f,g) _test_event_args(__LINE__,a,b,c,d,e,f,g)
_test_event_args(unsigned line,const IID * dispiid,DISPID id,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)322c2c66affSColin Finck static void _test_event_args(unsigned line, const IID *dispiid, DISPID id, WORD wFlags, DISPPARAMS *pdp,
323c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
324c2c66affSColin Finck {
325c2c66affSColin Finck     ok_(__FILE__,line) (id == DISPID_VALUE, "id = %d\n", id);
326c2c66affSColin Finck     ok_(__FILE__,line) (wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
327c2c66affSColin Finck     ok_(__FILE__,line) (pdp != NULL, "pdp == NULL\n");
328c2c66affSColin Finck     ok_(__FILE__,line) (pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
329c2c66affSColin Finck     ok_(__FILE__,line) (pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
330c2c66affSColin Finck     ok_(__FILE__,line) (pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n",
331c2c66affSColin Finck                         pdp->rgdispidNamedArgs[0]);
332c2c66affSColin Finck     ok_(__FILE__,line) (V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
333c2c66affSColin Finck     ok_(__FILE__,line) (pvarRes != NULL, "pvarRes == NULL\n");
334c2c66affSColin Finck     ok_(__FILE__,line) (pei != NULL, "pei == NULL");
335c2c66affSColin Finck     ok_(__FILE__,line) (!pspCaller, "pspCaller != NULL\n");
336c2c66affSColin Finck 
337c2c66affSColin Finck     if(dispiid)
338c2c66affSColin Finck         _test_disp(line, (IUnknown*)V_DISPATCH(pdp->rgvarg), dispiid);
339c2c66affSColin Finck }
340c2c66affSColin Finck 
341c2c66affSColin Finck #define test_attached_event_args(a,b,c,d,e) _test_attached_event_args(__LINE__,a,b,c,d,e)
_test_attached_event_args(unsigned line,DISPID id,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei)342c2c66affSColin Finck static void _test_attached_event_args(unsigned line, DISPID id, WORD wFlags, DISPPARAMS *pdp,
343c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei)
344c2c66affSColin Finck {
345c2c66affSColin Finck     IHTMLEventObj *event;
346c2c66affSColin Finck 
347c2c66affSColin Finck     ok(id == DISPID_VALUE, "id = %d\n", id);
348c2c66affSColin Finck     ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
349c2c66affSColin Finck     ok(pdp != NULL, "pDispParams == NULL\n");
350c2c66affSColin Finck     ok(pdp->cArgs == 1, "pdp->cArgs = %d\n", pdp->cArgs);
351c2c66affSColin Finck     ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
352c2c66affSColin Finck     ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
353c2c66affSColin Finck     ok(pdp->rgvarg != NULL, "rgvarg = NULL\n");
354c2c66affSColin Finck     ok(pvarRes != NULL, "pvarRes = NULL\n");
355c2c66affSColin Finck     ok(pei != NULL, "pei = NULL\n");
356c2c66affSColin Finck     ok(V_VT(pvarRes) == VT_EMPTY, "V_VT(pVarRes) = %d\n", V_VT(pvarRes));
357c2c66affSColin Finck     ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(pdp->rgvarg) = %d\n", V_VT(pdp->rgvarg));
358c2c66affSColin Finck     ok(V_DISPATCH(pdp->rgvarg) != NULL, "V_DISPATCH(pdp->rgvarg) = %p\n", V_DISPATCH(pdp->rgvarg));
359c2c66affSColin Finck 
360c2c66affSColin Finck     event = _get_event_obj(line);
361c2c66affSColin Finck     ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(pdp->rgvarg)), "event != arg0\n");
362c2c66affSColin Finck     IHTMLEventObj_Release(event);
363c2c66affSColin Finck }
364c2c66affSColin Finck 
365c2c66affSColin Finck #define get_event_src() _get_event_src(__LINE__)
_get_event_src(unsigned line)366c2c66affSColin Finck static IHTMLElement *_get_event_src(unsigned line)
367c2c66affSColin Finck {
368c2c66affSColin Finck     IHTMLEventObj *event = _get_event_obj(line);
369c2c66affSColin Finck     IHTMLElement *src_elem = NULL;
370c2c66affSColin Finck     HRESULT hres;
371c2c66affSColin Finck 
372c2c66affSColin Finck     hres = IHTMLEventObj_get_srcElement(event, &src_elem);
373c2c66affSColin Finck     IHTMLEventObj_Release(event);
374c2c66affSColin Finck     ok_(__FILE__,line) (hres == S_OK, "get_srcElement failed: %08x\n", hres);
375c2c66affSColin Finck 
376c2c66affSColin Finck     return src_elem;
377c2c66affSColin Finck }
378c2c66affSColin Finck 
379c2c66affSColin Finck #define test_event_src(t) _test_event_src(__LINE__,t)
_test_event_src(unsigned line,const char * src_tag)380c2c66affSColin Finck static void _test_event_src(unsigned line, const char *src_tag)
381c2c66affSColin Finck {
382c2c66affSColin Finck     IHTMLElement *src_elem = _get_event_src(line);
383c2c66affSColin Finck 
384c2c66affSColin Finck     if(src_tag) {
385c2c66affSColin Finck         ok_(__FILE__,line) (src_elem != NULL, "src_elem = NULL\n");
386c2c66affSColin Finck         _test_elem_tag(line, (IUnknown*)src_elem, src_tag);
387c2c66affSColin Finck         IHTMLElement_Release(src_elem);
388c2c66affSColin Finck     }else {
389c2c66affSColin Finck         ok_(__FILE__,line) (!src_elem, "src_elem != NULL\n");
390c2c66affSColin Finck     }
391c2c66affSColin Finck }
392c2c66affSColin Finck 
_test_event_altkey(unsigned line,IHTMLEventObj * event,VARIANT_BOOL exval)393c2c66affSColin Finck static void _test_event_altkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
394c2c66affSColin Finck {
395c2c66affSColin Finck     VARIANT_BOOL b;
396c2c66affSColin Finck     HRESULT hres;
397c2c66affSColin Finck 
398c2c66affSColin Finck     hres = IHTMLEventObj_get_altKey(event, &b);
399c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_altKey failed: %08x\n", hres);
400c2c66affSColin Finck     ok_(__FILE__,line)(b == exval, "altKey = %x, expected %x\n", b, exval);
401c2c66affSColin Finck }
402c2c66affSColin Finck 
_test_event_ctrlkey(unsigned line,IHTMLEventObj * event,VARIANT_BOOL exval)403c2c66affSColin Finck static void _test_event_ctrlkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
404c2c66affSColin Finck {
405c2c66affSColin Finck     VARIANT_BOOL b;
406c2c66affSColin Finck     HRESULT hres;
407c2c66affSColin Finck 
408c2c66affSColin Finck     hres = IHTMLEventObj_get_ctrlKey(event, &b);
409c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_ctrlKey failed: %08x\n", hres);
410c2c66affSColin Finck     ok_(__FILE__,line)(b == exval, "ctrlKey = %x, expected %x\n", b, exval);
411c2c66affSColin Finck }
412c2c66affSColin Finck 
_test_event_shiftkey(unsigned line,IHTMLEventObj * event,VARIANT_BOOL exval)413c2c66affSColin Finck static void _test_event_shiftkey(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
414c2c66affSColin Finck {
415c2c66affSColin Finck     VARIANT_BOOL b;
416c2c66affSColin Finck     HRESULT hres;
417c2c66affSColin Finck 
418c2c66affSColin Finck     hres = IHTMLEventObj_get_shiftKey(event, &b);
419c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_shiftKey failed: %08x\n", hres);
420c2c66affSColin Finck     ok_(__FILE__,line)(b == exval, "shiftKey = %x, expected %x\n", b, exval);
421c2c66affSColin Finck }
422c2c66affSColin Finck 
423c2c66affSColin Finck #define test_event_cancelbubble(a,b) _test_event_cancelbubble(__LINE__,a,b)
_test_event_cancelbubble(unsigned line,IHTMLEventObj * event,VARIANT_BOOL exval)424c2c66affSColin Finck static void _test_event_cancelbubble(unsigned line, IHTMLEventObj *event, VARIANT_BOOL exval)
425c2c66affSColin Finck {
426c2c66affSColin Finck     VARIANT_BOOL b;
427c2c66affSColin Finck     HRESULT hres;
428c2c66affSColin Finck 
429c2c66affSColin Finck     hres = IHTMLEventObj_get_cancelBubble(event, &b);
430c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_cancelBubble failed: %08x\n", hres);
431c2c66affSColin Finck     ok_(__FILE__,line)(b == exval, "cancelBubble = %x, expected %x\n", b, exval);
432c2c66affSColin Finck }
433c2c66affSColin Finck 
_test_event_fromelem(unsigned line,IHTMLEventObj * event,const char * from_tag)434c2c66affSColin Finck static void _test_event_fromelem(unsigned line, IHTMLEventObj *event, const char *from_tag)
435c2c66affSColin Finck {
436c2c66affSColin Finck     IHTMLElement *elem;
437c2c66affSColin Finck     HRESULT hres;
438c2c66affSColin Finck 
439c2c66affSColin Finck     hres = IHTMLEventObj_get_fromElement(event, &elem);
440c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_fromElement failed: %08x\n", hres);
441c2c66affSColin Finck     if(from_tag)
442c2c66affSColin Finck         _test_elem_tag(line, (IUnknown*)elem, from_tag);
443c2c66affSColin Finck     else
444c2c66affSColin Finck         ok_(__FILE__,line)(elem == NULL, "fromElement != NULL\n");
445c2c66affSColin Finck     if(elem)
446c2c66affSColin Finck         IHTMLElement_Release(elem);
447c2c66affSColin Finck }
448c2c66affSColin Finck 
_test_event_toelem(unsigned line,IHTMLEventObj * event,const char * to_tag)449c2c66affSColin Finck static void _test_event_toelem(unsigned line, IHTMLEventObj *event, const char *to_tag)
450c2c66affSColin Finck {
451c2c66affSColin Finck     IHTMLElement *elem;
452c2c66affSColin Finck     HRESULT hres;
453c2c66affSColin Finck 
454c2c66affSColin Finck     hres = IHTMLEventObj_get_toElement(event, &elem);
455c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_toElement failed: %08x\n", hres);
456c2c66affSColin Finck     if(to_tag)
457c2c66affSColin Finck         _test_elem_tag(line, (IUnknown*)elem, to_tag);
458c2c66affSColin Finck     else
459c2c66affSColin Finck         ok_(__FILE__,line)(elem == NULL, "toElement != NULL\n");
460c2c66affSColin Finck     if(elem)
461c2c66affSColin Finck         IHTMLElement_Release(elem);
462c2c66affSColin Finck }
463c2c66affSColin Finck 
_test_event_keycode(unsigned line,IHTMLEventObj * event,LONG exl)464c2c66affSColin Finck static void _test_event_keycode(unsigned line, IHTMLEventObj *event, LONG exl)
465c2c66affSColin Finck {
466c2c66affSColin Finck     LONG l;
467c2c66affSColin Finck     HRESULT hres;
468c2c66affSColin Finck 
469c2c66affSColin Finck     hres = IHTMLEventObj_get_keyCode(event, &l);
470c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_keyCode failed: %08x\n", hres);
471c2c66affSColin Finck     ok_(__FILE__,line)(l == exl, "keyCode = %x, expected %x\n", l, exl);
472c2c66affSColin Finck }
473c2c66affSColin Finck 
_test_event_button(unsigned line,IHTMLEventObj * event,LONG exl)474c2c66affSColin Finck static void _test_event_button(unsigned line, IHTMLEventObj *event, LONG exl)
475c2c66affSColin Finck {
476c2c66affSColin Finck     LONG l;
477c2c66affSColin Finck     HRESULT hres;
478c2c66affSColin Finck 
479c2c66affSColin Finck     hres = IHTMLEventObj_get_button(event, &l);
480c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_button failed: %08x\n", hres);
481c2c66affSColin Finck     ok_(__FILE__,line)(l == exl, "button = %x, expected %x\n", l, exl);
482c2c66affSColin Finck }
483c2c66affSColin Finck 
_test_event_reason(unsigned line,IHTMLEventObj * event,LONG exl)484c2c66affSColin Finck static void _test_event_reason(unsigned line, IHTMLEventObj *event, LONG exl)
485c2c66affSColin Finck {
486c2c66affSColin Finck     LONG l;
487c2c66affSColin Finck     HRESULT hres;
488c2c66affSColin Finck 
489c2c66affSColin Finck     hres = IHTMLEventObj_get_reason(event, &l);
490c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_reason failed: %08x\n", hres);
491c2c66affSColin Finck     ok_(__FILE__,line)(l == exl, "reason = %x, expected %x\n", l, exl);
492c2c66affSColin Finck }
493c2c66affSColin Finck 
_test_event_x(unsigned line,IHTMLEventObj * event,LONG exl)494c2c66affSColin Finck static void _test_event_x(unsigned line, IHTMLEventObj *event, LONG exl)
495c2c66affSColin Finck {
496c2c66affSColin Finck     LONG l;
497c2c66affSColin Finck     HRESULT hres;
498c2c66affSColin Finck 
499c2c66affSColin Finck     hres = IHTMLEventObj_get_x(event, &l);
500c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_x failed: %08x\n", hres);
501c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
502c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "x = %d, expected %d\n", l, exl);
503c2c66affSColin Finck }
504c2c66affSColin Finck 
_test_event_y(unsigned line,IHTMLEventObj * event,LONG exl)505c2c66affSColin Finck static void _test_event_y(unsigned line, IHTMLEventObj *event, LONG exl)
506c2c66affSColin Finck {
507c2c66affSColin Finck     LONG l;
508c2c66affSColin Finck     HRESULT hres;
509c2c66affSColin Finck 
510c2c66affSColin Finck     hres = IHTMLEventObj_get_y(event, &l);
511c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_y failed: %08x\n", hres);
512c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
513c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "y = %d, expected %d\n", l, exl);
514c2c66affSColin Finck }
515c2c66affSColin Finck 
_test_event_clientx(unsigned line,IHTMLEventObj * event,LONG exl)516c2c66affSColin Finck static void _test_event_clientx(unsigned line, IHTMLEventObj *event, LONG exl)
517c2c66affSColin Finck {
518c2c66affSColin Finck     LONG l;
519c2c66affSColin Finck     HRESULT hres;
520c2c66affSColin Finck 
521c2c66affSColin Finck     hres = IHTMLEventObj_get_clientX(event, &l);
522c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_clientX failed: %08x\n", hres);
523c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
524c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "clientX = %d, expected %d\n", l, exl);
525c2c66affSColin Finck }
526c2c66affSColin Finck 
_test_event_clienty(unsigned line,IHTMLEventObj * event,LONG exl)527c2c66affSColin Finck static void _test_event_clienty(unsigned line, IHTMLEventObj *event, LONG exl)
528c2c66affSColin Finck {
529c2c66affSColin Finck     LONG l;
530c2c66affSColin Finck     HRESULT hres;
531c2c66affSColin Finck 
532c2c66affSColin Finck     hres = IHTMLEventObj_get_clientY(event, &l);
533c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_clientY failed: %08x\n", hres);
534c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
535c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "clientY = %d, expected %d\n", l, exl);
536c2c66affSColin Finck }
537c2c66affSColin Finck 
_test_event_offsetx(unsigned line,IHTMLEventObj * event,LONG exl)538c2c66affSColin Finck static void _test_event_offsetx(unsigned line, IHTMLEventObj *event, LONG exl)
539c2c66affSColin Finck {
540c2c66affSColin Finck     LONG l;
541c2c66affSColin Finck     HRESULT hres;
542c2c66affSColin Finck 
543c2c66affSColin Finck     hres = IHTMLEventObj_get_offsetX(event, &l);
544c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_offsetX failed: %08x\n", hres);
545c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
546c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "offsetX = %d, expected %d\n", l, exl);
547c2c66affSColin Finck }
548c2c66affSColin Finck 
_test_event_offsety(unsigned line,IHTMLEventObj * event,LONG exl)549c2c66affSColin Finck static void _test_event_offsety(unsigned line, IHTMLEventObj *event, LONG exl)
550c2c66affSColin Finck {
551c2c66affSColin Finck     LONG l;
552c2c66affSColin Finck     HRESULT hres;
553c2c66affSColin Finck 
554c2c66affSColin Finck     hres = IHTMLEventObj_get_offsetY(event, &l);
555c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_offsetY failed: %08x\n", hres);
556c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
557c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "offsetY = %d, expected %d\n", l, exl);
558c2c66affSColin Finck }
559c2c66affSColin Finck 
_test_event_screenx(unsigned line,IHTMLEventObj * event,LONG exl)560c2c66affSColin Finck static void _test_event_screenx(unsigned line, IHTMLEventObj *event, LONG exl)
561c2c66affSColin Finck {
562c2c66affSColin Finck     LONG l;
563c2c66affSColin Finck     HRESULT hres;
564c2c66affSColin Finck 
565c2c66affSColin Finck     hres = IHTMLEventObj_get_screenX(event, &l);
566c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_screenX failed: %08x\n", hres);
567c2c66affSColin Finck     if(exl != -10) /* don't test the exact value */
568c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "screenX = %d, expected %d\n", l, exl);
569c2c66affSColin Finck }
570c2c66affSColin Finck 
_test_event_screeny(unsigned line,IHTMLEventObj * event,LONG exl)571c2c66affSColin Finck static void _test_event_screeny(unsigned line, IHTMLEventObj *event, LONG exl)
572c2c66affSColin Finck {
573c2c66affSColin Finck     LONG l;
574c2c66affSColin Finck     HRESULT hres;
575c2c66affSColin Finck 
576c2c66affSColin Finck     hres = IHTMLEventObj_get_screenY(event, &l);
577c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_screenY failed: %08x\n", hres);
578c2c66affSColin Finck     if(exl != -10) /* don't test the exact value for -10 */
579c2c66affSColin Finck         ok_(__FILE__,line)(l == exl, "screenY = %d, expected %d\n", l, exl);
580c2c66affSColin Finck }
581c2c66affSColin Finck 
_test_event_type(unsigned line,IHTMLEventObj * event,const char * exstr)582c2c66affSColin Finck static void _test_event_type(unsigned line, IHTMLEventObj *event, const char *exstr)
583c2c66affSColin Finck {
584c2c66affSColin Finck     BSTR str;
585c2c66affSColin Finck     HRESULT hres;
586c2c66affSColin Finck 
587c2c66affSColin Finck     hres = IHTMLEventObj_get_type(event, &str);
588c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_type failed: %08x\n", hres);
589c2c66affSColin Finck     ok_(__FILE__,line)(!strcmp_wa(str, exstr), "type = %s, expected %s\n", wine_dbgstr_w(str), exstr);
590c2c66affSColin Finck }
591c2c66affSColin Finck 
_test_event_qualifier(unsigned line,IHTMLEventObj * event,const char * exstr)592c2c66affSColin Finck static void _test_event_qualifier(unsigned line, IHTMLEventObj *event, const char *exstr)
593c2c66affSColin Finck {
594c2c66affSColin Finck     BSTR str;
595c2c66affSColin Finck     HRESULT hres;
596c2c66affSColin Finck 
597c2c66affSColin Finck     hres = IHTMLEventObj_get_qualifier(event, &str);
598c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_qualifier failed: %08x\n", hres);
599c2c66affSColin Finck     if(exstr)
600c2c66affSColin Finck         ok_(__FILE__,line)(!strcmp_wa(str, exstr), "qualifier = %s, expected %s\n", wine_dbgstr_w(str), exstr);
601c2c66affSColin Finck     else
602c2c66affSColin Finck         ok_(__FILE__,line)(!str, "qualifier != NULL\n");
603c2c66affSColin Finck }
604c2c66affSColin Finck 
_test_event_srcfilter(unsigned line,IHTMLEventObj * event)605c2c66affSColin Finck static void _test_event_srcfilter(unsigned line, IHTMLEventObj *event)
606c2c66affSColin Finck {
607c2c66affSColin Finck     IDispatch *disp;
608c2c66affSColin Finck     HRESULT hres;
609c2c66affSColin Finck 
610c2c66affSColin Finck     hres = IHTMLEventObj_get_srcFilter(event, &disp);
611c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_srcFilter failed: %08x\n", hres);
612c2c66affSColin Finck     ok_(__FILE__,line)(!disp, "srcFilter != NULL\n");
613c2c66affSColin Finck }
614c2c66affSColin Finck 
615c2c66affSColin Finck #define test_event_obj(t,x) _test_event_obj(__LINE__,t,x)
_test_event_obj(unsigned line,const char * type,const xy_test_t * xy)616c2c66affSColin Finck static void _test_event_obj(unsigned line, const char *type, const xy_test_t *xy)
617c2c66affSColin Finck {
618c2c66affSColin Finck     IHTMLEventObj *event = _get_event_obj(line);
619c2c66affSColin Finck     VARIANT v;
620c2c66affSColin Finck     HRESULT hres;
621c2c66affSColin Finck 
622c2c66affSColin Finck     _test_event_altkey(line, event, VARIANT_FALSE);
623c2c66affSColin Finck     _test_event_ctrlkey(line, event, VARIANT_FALSE);
624c2c66affSColin Finck     _test_event_shiftkey(line, event, VARIANT_FALSE);
625c2c66affSColin Finck     _test_event_cancelbubble(line, event, VARIANT_FALSE);
626c2c66affSColin Finck     _test_event_fromelem(line, event, NULL);
627c2c66affSColin Finck     _test_event_toelem(line, event, NULL);
628c2c66affSColin Finck     _test_event_keycode(line, event, 0);
629c2c66affSColin Finck     _test_event_button(line, event, 0);
630c2c66affSColin Finck     _test_event_type(line, event, type);
631c2c66affSColin Finck     _test_event_qualifier(line, event, NULL);
632c2c66affSColin Finck     _test_event_reason(line, event, 0);
633c2c66affSColin Finck     _test_event_srcfilter(line, event);
634c2c66affSColin Finck     _test_event_x(line, event, xy->x);
635c2c66affSColin Finck     _test_event_y(line, event, xy->y);
636c2c66affSColin Finck     _test_event_clientx(line, event, -10);
637c2c66affSColin Finck     _test_event_clienty(line, event, -10);
638c2c66affSColin Finck     _test_event_offsetx(line, event, xy->offset_x);
639c2c66affSColin Finck     _test_event_offsety(line, event, xy->offset_y);
640c2c66affSColin Finck     _test_event_screenx(line, event, -10);
641c2c66affSColin Finck     _test_event_screeny(line, event, -10);
642c2c66affSColin Finck 
643c2c66affSColin Finck     V_VT(&v) = VT_NULL;
644c2c66affSColin Finck     hres = IHTMLEventObj_get_returnValue(event, &v);
645c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "get_returnValue failed: %08x\n", hres);
646c2c66affSColin Finck     ok_(__FILE__,line)(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
647c2c66affSColin Finck 
648c2c66affSColin Finck     IHTMLEventObj_Release(event);
649c2c66affSColin Finck }
650c2c66affSColin Finck 
651c2c66affSColin Finck #define elem_attach_event(a,b,c) _elem_attach_event(__LINE__,a,b,c)
_elem_attach_event(unsigned line,IUnknown * unk,const char * namea,IDispatch * disp)652c2c66affSColin Finck static void _elem_attach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
653c2c66affSColin Finck {
654c2c66affSColin Finck     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
655c2c66affSColin Finck     VARIANT_BOOL res;
656c2c66affSColin Finck     BSTR name;
657c2c66affSColin Finck     HRESULT hres;
658c2c66affSColin Finck 
659c2c66affSColin Finck     name = a2bstr(namea);
660c2c66affSColin Finck     hres = IHTMLElement2_attachEvent(elem, name, disp, &res);
661c2c66affSColin Finck     IHTMLElement2_Release(elem);
662c2c66affSColin Finck     SysFreeString(name);
663c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
664c2c66affSColin Finck     ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
665c2c66affSColin Finck }
666c2c66affSColin Finck 
667c2c66affSColin Finck #define elem_detach_event(a,b,c) _elem_detach_event(__LINE__,a,b,c)
_elem_detach_event(unsigned line,IUnknown * unk,const char * namea,IDispatch * disp)668c2c66affSColin Finck static void _elem_detach_event(unsigned line, IUnknown *unk, const char *namea, IDispatch *disp)
669c2c66affSColin Finck {
670c2c66affSColin Finck     IHTMLElement2 *elem = _get_elem2_iface(line, unk);
671c2c66affSColin Finck     BSTR name;
672c2c66affSColin Finck     HRESULT hres;
673c2c66affSColin Finck 
674c2c66affSColin Finck     name = a2bstr(namea);
675c2c66affSColin Finck     hres = IHTMLElement2_detachEvent(elem, name, disp);
676c2c66affSColin Finck     IHTMLElement2_Release(elem);
677c2c66affSColin Finck     SysFreeString(name);
678c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
679c2c66affSColin Finck }
680c2c66affSColin Finck 
681c2c66affSColin Finck #define doc_attach_event(a,b,c) _doc_attach_event(__LINE__,a,b,c)
_doc_attach_event(unsigned line,IHTMLDocument2 * doc,const char * namea,IDispatch * disp)682c2c66affSColin Finck static void _doc_attach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
683c2c66affSColin Finck {
684c2c66affSColin Finck     IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
685c2c66affSColin Finck     VARIANT_BOOL res;
686c2c66affSColin Finck     BSTR name;
687c2c66affSColin Finck     HRESULT hres;
688c2c66affSColin Finck 
689c2c66affSColin Finck     name = a2bstr(namea);
690c2c66affSColin Finck     hres = IHTMLDocument3_attachEvent(doc3, name, disp, &res);
691c2c66affSColin Finck     IHTMLDocument3_Release(doc3);
692c2c66affSColin Finck     SysFreeString(name);
693c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "attachEvent failed: %08x\n", hres);
694c2c66affSColin Finck     ok_(__FILE__,line)(res == VARIANT_TRUE, "attachEvent returned %x\n", res);
695c2c66affSColin Finck }
696c2c66affSColin Finck 
697c2c66affSColin Finck #define doc_detach_event(a,b,c) _doc_detach_event(__LINE__,a,b,c)
_doc_detach_event(unsigned line,IHTMLDocument2 * doc,const char * namea,IDispatch * disp)698c2c66affSColin Finck static void _doc_detach_event(unsigned line, IHTMLDocument2 *doc, const char *namea, IDispatch *disp)
699c2c66affSColin Finck {
700c2c66affSColin Finck     IHTMLDocument3 *doc3 = _get_doc3_iface(line, (IUnknown*)doc);
701c2c66affSColin Finck     BSTR name;
702c2c66affSColin Finck     HRESULT hres;
703c2c66affSColin Finck 
704c2c66affSColin Finck     name = a2bstr(namea);
705c2c66affSColin Finck     hres = IHTMLDocument3_detachEvent(doc3, name, disp);
706c2c66affSColin Finck     IHTMLDocument3_Release(doc3);
707c2c66affSColin Finck     SysFreeString(name);
708c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "detachEvent failed: %08x\n", hres);
709c2c66affSColin Finck }
710c2c66affSColin Finck 
DispatchEx_QueryInterface(IDispatchEx * iface,REFIID riid,void ** ppv)711c2c66affSColin Finck static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
712c2c66affSColin Finck {
713c2c66affSColin Finck     *ppv = NULL;
714c2c66affSColin Finck 
715c2c66affSColin Finck     if(IsEqualGUID(riid, &IID_IUnknown)
716c2c66affSColin Finck        || IsEqualGUID(riid, &IID_IDispatch)
717c2c66affSColin Finck        || IsEqualGUID(riid, &IID_IDispatchEx))
718c2c66affSColin Finck         *ppv = iface;
719c2c66affSColin Finck     else {
720c2c66affSColin Finck         ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
721c2c66affSColin Finck         return E_NOINTERFACE;
722c2c66affSColin Finck     }
723c2c66affSColin Finck 
724c2c66affSColin Finck     return S_OK;
725c2c66affSColin Finck }
726c2c66affSColin Finck 
Dispatch_QueryInterface(IDispatchEx * iface,REFIID riid,void ** ppv)727c2c66affSColin Finck static HRESULT WINAPI Dispatch_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
728c2c66affSColin Finck {
729c2c66affSColin Finck     *ppv = NULL;
730c2c66affSColin Finck 
731c2c66affSColin Finck     if(IsEqualGUID(riid, &IID_IUnknown)
732c2c66affSColin Finck        || IsEqualGUID(riid, &IID_IDispatch)) {
733c2c66affSColin Finck         *ppv = iface;
734c2c66affSColin Finck     }else if(IsEqualGUID(riid, &IID_IDispatchEx)) {
735c2c66affSColin Finck         return E_NOINTERFACE;
736c2c66affSColin Finck     }else {
737c2c66affSColin Finck         ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
738c2c66affSColin Finck         return E_NOINTERFACE;
739c2c66affSColin Finck     }
740c2c66affSColin Finck 
741c2c66affSColin Finck     return S_OK;
742c2c66affSColin Finck }
743c2c66affSColin Finck 
DispatchEx_AddRef(IDispatchEx * iface)744c2c66affSColin Finck static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
745c2c66affSColin Finck {
746c2c66affSColin Finck     return 2;
747c2c66affSColin Finck }
748c2c66affSColin Finck 
DispatchEx_Release(IDispatchEx * iface)749c2c66affSColin Finck static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
750c2c66affSColin Finck {
751c2c66affSColin Finck     return 1;
752c2c66affSColin Finck }
753c2c66affSColin Finck 
DispatchEx_GetTypeInfoCount(IDispatchEx * iface,UINT * pctinfo)754c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
755c2c66affSColin Finck {
756c2c66affSColin Finck     ok(0, "unexpected call\n");
757c2c66affSColin Finck     return E_NOTIMPL;
758c2c66affSColin Finck }
759c2c66affSColin Finck 
DispatchEx_GetTypeInfo(IDispatchEx * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)760c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
761c2c66affSColin Finck                                               LCID lcid, ITypeInfo **ppTInfo)
762c2c66affSColin Finck {
763c2c66affSColin Finck     ok(0, "unexpected call\n");
764c2c66affSColin Finck     return E_NOTIMPL;
765c2c66affSColin Finck }
766c2c66affSColin Finck 
DispatchEx_GetIDsOfNames(IDispatchEx * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)767c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
768c2c66affSColin Finck                                                 LPOLESTR *rgszNames, UINT cNames,
769c2c66affSColin Finck                                                 LCID lcid, DISPID *rgDispId)
770c2c66affSColin Finck {
771c2c66affSColin Finck     ok(0, "unexpected call\n");
772c2c66affSColin Finck     return E_NOTIMPL;
773c2c66affSColin Finck }
774c2c66affSColin Finck 
DispatchEx_Invoke(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)775c2c66affSColin Finck static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
776c2c66affSColin Finck                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
777c2c66affSColin Finck                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
778c2c66affSColin Finck {
779c2c66affSColin Finck     ok(0, "unexpected call\n");
780c2c66affSColin Finck     return E_NOTIMPL;
781c2c66affSColin Finck }
782c2c66affSColin Finck 
DispatchEx_GetDispID(IDispatchEx * iface,BSTR bstrName,DWORD grfdex,DISPID * pid)783c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
784c2c66affSColin Finck {
785c2c66affSColin Finck     ok(0, "unexpected call\n");
786c2c66affSColin Finck     return E_NOTIMPL;
787c2c66affSColin Finck }
788c2c66affSColin Finck 
DispatchEx_InvokeEx(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)789c2c66affSColin Finck static HRESULT WINAPI DispatchEx_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
790c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
791c2c66affSColin Finck {
792c2c66affSColin Finck     ok(0, "unexpected call\n");
793c2c66affSColin Finck     return E_NOTIMPL;
794c2c66affSColin Finck }
795c2c66affSColin Finck 
DispatchEx_DeleteMemberByName(IDispatchEx * iface,BSTR bstrName,DWORD grfdex)796c2c66affSColin Finck static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
797c2c66affSColin Finck {
798c2c66affSColin Finck     ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
799c2c66affSColin Finck     return E_NOTIMPL;
800c2c66affSColin Finck }
801c2c66affSColin Finck 
DispatchEx_DeleteMemberByDispID(IDispatchEx * iface,DISPID id)802c2c66affSColin Finck static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
803c2c66affSColin Finck {
804c2c66affSColin Finck     ok(0, "unexpected call\n");
805c2c66affSColin Finck     return E_NOTIMPL;
806c2c66affSColin Finck }
807c2c66affSColin Finck 
DispatchEx_GetMemberProperties(IDispatchEx * iface,DISPID id,DWORD grfdexFetch,DWORD * pgrfdex)808c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
809c2c66affSColin Finck {
810c2c66affSColin Finck     ok(0, "unexpected call\n");
811c2c66affSColin Finck     return E_NOTIMPL;
812c2c66affSColin Finck }
813c2c66affSColin Finck 
DispatchEx_GetMemberName(IDispatchEx * iface,DISPID id,BSTR * pbstrName)814c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
815c2c66affSColin Finck {
816c2c66affSColin Finck     ok(0, "unexpected call\n");
817c2c66affSColin Finck     return E_NOTIMPL;
818c2c66affSColin Finck }
819c2c66affSColin Finck 
DispatchEx_GetNextDispID(IDispatchEx * iface,DWORD grfdex,DISPID id,DISPID * pid)820c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
821c2c66affSColin Finck {
822c2c66affSColin Finck     ok(0, "unexpected call\n");
823c2c66affSColin Finck     return E_NOTIMPL;
824c2c66affSColin Finck }
825c2c66affSColin Finck 
DispatchEx_GetNameSpaceParent(IDispatchEx * iface,IUnknown ** ppunk)826c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
827c2c66affSColin Finck {
828c2c66affSColin Finck     ok(0, "unexpected call\n");
829c2c66affSColin Finck     return E_NOTIMPL;
830c2c66affSColin Finck }
831c2c66affSColin Finck 
832c2c66affSColin Finck #define EVENT_HANDLER_FUNC_OBJ(event) \
833c2c66affSColin Finck     static IDispatchExVtbl event ## FuncVtbl = { \
834c2c66affSColin Finck         DispatchEx_QueryInterface, \
835c2c66affSColin Finck         DispatchEx_AddRef, \
836c2c66affSColin Finck         DispatchEx_Release, \
837c2c66affSColin Finck         DispatchEx_GetTypeInfoCount, \
838c2c66affSColin Finck         DispatchEx_GetTypeInfo, \
839c2c66affSColin Finck         DispatchEx_GetIDsOfNames, \
840c2c66affSColin Finck         DispatchEx_Invoke, \
841c2c66affSColin Finck         DispatchEx_GetDispID, \
842c2c66affSColin Finck         event, \
843c2c66affSColin Finck         DispatchEx_DeleteMemberByName, \
844c2c66affSColin Finck         DispatchEx_DeleteMemberByDispID, \
845c2c66affSColin Finck         DispatchEx_GetMemberProperties, \
846c2c66affSColin Finck         DispatchEx_GetMemberName, \
847c2c66affSColin Finck         DispatchEx_GetNextDispID, \
848c2c66affSColin Finck         DispatchEx_GetNameSpaceParent \
849c2c66affSColin Finck     }; \
850c2c66affSColin Finck     static IDispatchEx event ## _obj = { &event ## FuncVtbl };
851c2c66affSColin Finck 
document_onclick(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)852c2c66affSColin Finck static HRESULT WINAPI document_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
853c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
854c2c66affSColin Finck {
855c2c66affSColin Finck     IHTMLDocument3 *doc3;
856c2c66affSColin Finck     CHECK_EXPECT(document_onclick);
857c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
858c2c66affSColin Finck     doc3 = get_doc3_iface((IUnknown*)V_DISPATCH(pdp->rgvarg));
859c2c66affSColin Finck     IHTMLDocument3_Release(doc3);
860c2c66affSColin Finck     test_event_src("DIV");
861c2c66affSColin Finck     test_event_obj("click", &no_xy);
862c2c66affSColin Finck     return S_OK;
863c2c66affSColin Finck }
864c2c66affSColin Finck 
865c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(document_onclick);
866c2c66affSColin Finck 
div_onclick(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)867c2c66affSColin Finck static HRESULT WINAPI div_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
868c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
869c2c66affSColin Finck {
870c2c66affSColin Finck     CHECK_EXPECT(div_onclick);
871c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
872c2c66affSColin Finck     test_event_src("DIV");
873c2c66affSColin Finck     return S_OK;
874c2c66affSColin Finck }
875c2c66affSColin Finck 
876c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(div_onclick);
877c2c66affSColin Finck 
div_onclick_attached(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)878c2c66affSColin Finck static HRESULT WINAPI div_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
879c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
880c2c66affSColin Finck {
881c2c66affSColin Finck     CHECK_EXPECT(div_onclick_attached);
882c2c66affSColin Finck 
883c2c66affSColin Finck     test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
884c2c66affSColin Finck     test_event_src("DIV");
885c2c66affSColin Finck     return S_OK;
886c2c66affSColin Finck }
887c2c66affSColin Finck 
888c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(div_onclick_attached);
889c2c66affSColin Finck 
doc_onclick_attached(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)890c2c66affSColin Finck static HRESULT WINAPI doc_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
891c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
892c2c66affSColin Finck {
893c2c66affSColin Finck     CHECK_EXPECT(doc_onclick_attached);
894c2c66affSColin Finck 
895c2c66affSColin Finck     test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
896c2c66affSColin Finck     test_event_src("DIV");
897c2c66affSColin Finck     return S_OK;
898c2c66affSColin Finck }
899c2c66affSColin Finck 
900c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(doc_onclick_attached);
901c2c66affSColin Finck 
body_onclick(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)902c2c66affSColin Finck static HRESULT WINAPI body_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
903c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
904c2c66affSColin Finck {
905c2c66affSColin Finck     CHECK_EXPECT(body_onclick);
906c2c66affSColin Finck     test_event_args(&DIID_DispHTMLBody, id, wFlags, pdp, pvarRes, pei, pspCaller);
907c2c66affSColin Finck     test_event_src("DIV");
908c2c66affSColin Finck     return S_OK;
909c2c66affSColin Finck }
910c2c66affSColin Finck 
911c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(body_onclick);
912c2c66affSColin Finck 
img_onload(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)913c2c66affSColin Finck static HRESULT WINAPI img_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
914c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
915c2c66affSColin Finck {
916c2c66affSColin Finck     CHECK_EXPECT(img_onload);
917c2c66affSColin Finck     test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
918c2c66affSColin Finck     test_event_src("IMG");
919c2c66affSColin Finck     return S_OK;
920c2c66affSColin Finck }
921c2c66affSColin Finck 
922c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(img_onload);
923c2c66affSColin Finck 
img_onerror(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)924c2c66affSColin Finck static HRESULT WINAPI img_onerror(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
925c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
926c2c66affSColin Finck {
927c2c66affSColin Finck     CHECK_EXPECT(img_onerror);
928c2c66affSColin Finck     test_event_args(&DIID_DispHTMLImg, id, wFlags, pdp, pvarRes, pei, pspCaller);
929c2c66affSColin Finck     test_event_src("IMG");
930c2c66affSColin Finck     return S_OK;
931c2c66affSColin Finck }
932c2c66affSColin Finck 
933c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(img_onerror);
934c2c66affSColin Finck 
input_onfocus(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)935c2c66affSColin Finck static HRESULT WINAPI input_onfocus(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
936c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
937c2c66affSColin Finck {
938c2c66affSColin Finck     CHECK_EXPECT(input_onfocus);
939c2c66affSColin Finck     test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
940c2c66affSColin Finck     test_event_src("INPUT");
941c2c66affSColin Finck     return S_OK;
942c2c66affSColin Finck }
943c2c66affSColin Finck 
944c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(input_onfocus);
945c2c66affSColin Finck 
input_onblur(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)946c2c66affSColin Finck static HRESULT WINAPI input_onblur(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
947c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
948c2c66affSColin Finck {
949c2c66affSColin Finck     CHECK_EXPECT(input_onblur);
950c2c66affSColin Finck     test_event_args(&DIID_DispHTMLInputElement, id, wFlags, pdp, pvarRes, pei, pspCaller);
951c2c66affSColin Finck     test_event_src("INPUT");
952c2c66affSColin Finck     return S_OK;
953c2c66affSColin Finck }
954c2c66affSColin Finck 
955c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(input_onblur);
956c2c66affSColin Finck 
form_onsubmit(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)957c2c66affSColin Finck static HRESULT WINAPI form_onsubmit(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
958c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
959c2c66affSColin Finck {
960c2c66affSColin Finck     CHECK_EXPECT(form_onsubmit);
961c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
962c2c66affSColin Finck     test_event_src("FORM");
963c2c66affSColin Finck 
964c2c66affSColin Finck     V_VT(pvarRes) = VT_BOOL;
965c2c66affSColin Finck     V_BOOL(pvarRes) = VARIANT_FALSE;
966c2c66affSColin Finck     return S_OK;
967c2c66affSColin Finck }
968c2c66affSColin Finck 
969c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(form_onsubmit);
970c2c66affSColin Finck 
form_onclick(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)971c2c66affSColin Finck static HRESULT WINAPI form_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
972c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
973c2c66affSColin Finck {
974c2c66affSColin Finck     CHECK_EXPECT(form_onclick);
975c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
976c2c66affSColin Finck 
977c2c66affSColin Finck     return S_OK;
978c2c66affSColin Finck }
979c2c66affSColin Finck 
980c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(form_onclick);
981c2c66affSColin Finck 
submit_onclick(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)982c2c66affSColin Finck static HRESULT WINAPI submit_onclick(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
983c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
984c2c66affSColin Finck {
985c2c66affSColin Finck     CHECK_EXPECT(submit_onclick);
986c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
987c2c66affSColin Finck     test_event_src("INPUT");
988c2c66affSColin Finck 
989c2c66affSColin Finck     V_VT(pvarRes) = VT_BOOL;
990c2c66affSColin Finck     V_BOOL(pvarRes) = VARIANT_FALSE;
991c2c66affSColin Finck     return S_OK;
992c2c66affSColin Finck }
993c2c66affSColin Finck 
994c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(submit_onclick);
995c2c66affSColin Finck 
iframe_onload(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)996c2c66affSColin Finck static HRESULT WINAPI iframe_onload(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
997c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
998c2c66affSColin Finck {
999c2c66affSColin Finck     CHECK_EXPECT(iframe_onload);
1000c2c66affSColin Finck     test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
1001c2c66affSColin Finck     test_event_src("IFRAME");
1002c2c66affSColin Finck     return S_OK;
1003c2c66affSColin Finck }
1004c2c66affSColin Finck 
1005c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(iframe_onload);
1006c2c66affSColin Finck 
submit_onclick_attached(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1007c2c66affSColin Finck static HRESULT WINAPI submit_onclick_attached(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1008c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1009c2c66affSColin Finck {
1010c2c66affSColin Finck     CHECK_EXPECT(submit_onclick_attached);
1011c2c66affSColin Finck     test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1012c2c66affSColin Finck     test_event_src("INPUT");
1013c2c66affSColin Finck 
1014c2c66affSColin Finck     V_VT(pvarRes) = VT_BOOL;
1015c2c66affSColin Finck     V_BOOL(pvarRes) = VARIANT_FALSE;
1016c2c66affSColin Finck     return S_OK;
1017c2c66affSColin Finck }
1018c2c66affSColin Finck 
1019c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached);
1020c2c66affSColin Finck 
submit_onclick_attached_check_cancel(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1021c2c66affSColin Finck static HRESULT WINAPI submit_onclick_attached_check_cancel(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1022c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1023c2c66affSColin Finck {
1024c2c66affSColin Finck     IHTMLEventObj *event;
1025c2c66affSColin Finck     HRESULT hres;
1026c2c66affSColin Finck 
1027c2c66affSColin Finck     CHECK_EXPECT(submit_onclick_attached_check_cancel);
1028c2c66affSColin Finck     test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1029c2c66affSColin Finck     test_event_src("INPUT");
1030c2c66affSColin Finck 
1031c2c66affSColin Finck     event = NULL;
1032c2c66affSColin Finck     hres = IHTMLWindow2_get_event(window, &event);
1033c2c66affSColin Finck     ok(hres == S_OK, "get_event failed: %08x\n", hres);
1034c2c66affSColin Finck     ok(event != NULL, "event == NULL\n");
1035c2c66affSColin Finck 
1036c2c66affSColin Finck     test_event_cancelbubble(event, VARIANT_TRUE);
1037c2c66affSColin Finck     return S_OK;
1038c2c66affSColin Finck }
1039c2c66affSColin Finck 
1040c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(submit_onclick_attached_check_cancel);
1041c2c66affSColin Finck 
1042c2c66affSColin Finck static VARIANT onclick_retval, onclick_event_retval;
1043c2c66affSColin Finck 
submit_onclick_setret(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1044c2c66affSColin Finck static HRESULT WINAPI submit_onclick_setret(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1045c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1046c2c66affSColin Finck {
1047c2c66affSColin Finck     IHTMLEventObj *event;
1048c2c66affSColin Finck     VARIANT v;
1049c2c66affSColin Finck     HRESULT hres;
1050c2c66affSColin Finck 
1051c2c66affSColin Finck     CHECK_EXPECT(submit_onclick_setret);
1052c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1053c2c66affSColin Finck     test_event_src("INPUT");
1054c2c66affSColin Finck 
1055c2c66affSColin Finck     event = NULL;
1056c2c66affSColin Finck     hres = IHTMLWindow2_get_event(window, &event);
1057c2c66affSColin Finck     ok(hres == S_OK, "get_event failed: %08x\n", hres);
1058c2c66affSColin Finck     ok(event != NULL, "event == NULL\n");
1059c2c66affSColin Finck 
1060c2c66affSColin Finck     V_VT(&v) = VT_ERROR;
1061c2c66affSColin Finck     hres = IHTMLEventObj_get_returnValue(event, &v);
1062c2c66affSColin Finck     ok(hres == S_OK, "get_returnValue failed: %08x\n", hres);
1063c2c66affSColin Finck     ok(V_VT(&v) == VT_EMPTY, "V_VT(returnValue) = %d\n", V_VT(&v));
1064c2c66affSColin Finck 
1065c2c66affSColin Finck     hres = IHTMLEventObj_put_returnValue(event, onclick_event_retval);
1066c2c66affSColin Finck     ok(hres == S_OK, "put_returnValue failed: %08x\n", hres);
1067c2c66affSColin Finck 
1068c2c66affSColin Finck     V_VT(&v) = VT_ERROR;
1069c2c66affSColin Finck     hres = IHTMLEventObj_get_returnValue(event, &v);
1070c2c66affSColin Finck     ok(hres == S_OK, "get_returnValue failed: %08x\n", hres);
1071c2c66affSColin Finck     ok(VarCmp(&v, &onclick_event_retval, 0, 0) == VARCMP_EQ, "unexpected returnValue\n");
1072c2c66affSColin Finck 
1073c2c66affSColin Finck     IHTMLEventObj_Release(event);
1074c2c66affSColin Finck     *pvarRes = onclick_retval;
1075c2c66affSColin Finck     return S_OK;
1076c2c66affSColin Finck }
1077c2c66affSColin Finck 
1078c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(submit_onclick_setret);
1079c2c66affSColin Finck 
submit_onclick_cancel(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1080c2c66affSColin Finck static HRESULT WINAPI submit_onclick_cancel(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1081c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1082c2c66affSColin Finck {
1083c2c66affSColin Finck     IHTMLEventObj *event;
1084c2c66affSColin Finck     HRESULT hres;
1085c2c66affSColin Finck 
1086c2c66affSColin Finck     CHECK_EXPECT(submit_onclick_cancel);
1087c2c66affSColin Finck     test_event_args(NULL, id, wFlags, pdp, pvarRes, pei, pspCaller);
1088c2c66affSColin Finck     test_event_src("INPUT");
1089c2c66affSColin Finck 
1090c2c66affSColin Finck     event = NULL;
1091c2c66affSColin Finck     hres = IHTMLWindow2_get_event(window, &event);
1092c2c66affSColin Finck     ok(hres == S_OK, "get_event failed: %08x\n", hres);
1093c2c66affSColin Finck     ok(event != NULL, "event == NULL\n");
1094c2c66affSColin Finck 
1095c2c66affSColin Finck     test_event_cancelbubble(event, VARIANT_FALSE);
1096c2c66affSColin Finck 
1097c2c66affSColin Finck     hres = IHTMLEventObj_put_cancelBubble(event, VARIANT_TRUE);
1098c2c66affSColin Finck     ok(hres == S_OK, "put_returnValue failed: %08x\n", hres);
1099c2c66affSColin Finck 
1100c2c66affSColin Finck     test_event_cancelbubble(event, VARIANT_TRUE);
1101c2c66affSColin Finck     IHTMLEventObj_Release(event);
1102c2c66affSColin Finck     return S_OK;
1103c2c66affSColin Finck }
1104c2c66affSColin Finck 
1105c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(submit_onclick_cancel);
1106c2c66affSColin Finck 
iframedoc_onreadystatechange(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1107c2c66affSColin Finck static HRESULT WINAPI iframedoc_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1108c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1109c2c66affSColin Finck {
1110c2c66affSColin Finck     IHTMLEventObj *event = NULL;
1111c2c66affSColin Finck     HRESULT hres;
1112c2c66affSColin Finck 
1113c2c66affSColin Finck     CHECK_EXPECT2(iframedoc_onreadystatechange);
1114c2c66affSColin Finck     test_event_args(&DIID_DispHTMLDocument, id, wFlags, pdp, pvarRes, pei, pspCaller);
1115c2c66affSColin Finck 
1116c2c66affSColin Finck     event = (void*)0xdeadbeef;
1117c2c66affSColin Finck     hres = IHTMLWindow2_get_event(window, &event);
1118c2c66affSColin Finck     ok(hres == S_OK, "get_event failed: %08x\n", hres);
1119c2c66affSColin Finck     ok(!event, "event = %p\n", event);
1120c2c66affSColin Finck 
1121c2c66affSColin Finck     return S_OK;
1122c2c66affSColin Finck }
1123c2c66affSColin Finck 
1124c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(iframedoc_onreadystatechange);
1125c2c66affSColin Finck 
iframe_onreadystatechange(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1126c2c66affSColin Finck static HRESULT WINAPI iframe_onreadystatechange(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1127c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1128c2c66affSColin Finck {
1129c2c66affSColin Finck     IHTMLWindow2 *iframe_window;
1130c2c66affSColin Finck     IHTMLDocument2 *iframe_doc;
1131c2c66affSColin Finck     IHTMLFrameBase2 *iframe;
1132c2c66affSColin Finck     IHTMLElement2 *elem2;
1133c2c66affSColin Finck     IHTMLElement *elem;
1134c2c66affSColin Finck     VARIANT v;
1135c2c66affSColin Finck     BSTR str, str2;
1136c2c66affSColin Finck     HRESULT hres;
1137c2c66affSColin Finck 
1138c2c66affSColin Finck     test_event_args(&DIID_DispHTMLIFrame, id, wFlags, pdp, pvarRes, pei, pspCaller);
1139c2c66affSColin Finck     test_event_src("IFRAME");
1140c2c66affSColin Finck 
1141c2c66affSColin Finck     elem = get_event_src();
1142c2c66affSColin Finck     elem2 = get_elem2_iface((IUnknown*)elem);
1143c2c66affSColin Finck     IHTMLElement_Release(elem);
1144c2c66affSColin Finck 
1145c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1146c2c66affSColin Finck     hres = IHTMLElement2_get_readyState(elem2, &v);
1147c2c66affSColin Finck     ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1148c2c66affSColin Finck     ok(V_VT(&v) == VT_BSTR, "V_VT(readyState) = %d\n", V_VT(&v));
1149c2c66affSColin Finck 
1150c2c66affSColin Finck     hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase2, (void**)&iframe);
1151c2c66affSColin Finck     IHTMLElement2_Release(elem2);
1152c2c66affSColin Finck     ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
1153c2c66affSColin Finck 
1154c2c66affSColin Finck     str = NULL;
1155c2c66affSColin Finck     hres = IHTMLFrameBase2_get_readyState(iframe, &str);
1156c2c66affSColin Finck     ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
1157c2c66affSColin Finck     ok(str != NULL, "readyState == NULL\n");
1158c2c66affSColin Finck     ok(!lstrcmpW(str, V_BSTR(&v)), "ready states differ\n");
1159c2c66affSColin Finck     VariantClear(&v);
1160c2c66affSColin Finck 
1161c2c66affSColin Finck     hres = IHTMLFrameBase2_get_contentWindow(iframe, &iframe_window);
1162c2c66affSColin Finck     ok(hres == S_OK, "get_contentDocument failed: %08x\n", hres);
1163c2c66affSColin Finck 
1164c2c66affSColin Finck     hres = IHTMLWindow2_get_document(iframe_window, &iframe_doc);
1165c2c66affSColin Finck     IHTMLWindow2_Release(iframe_window);
1166c2c66affSColin Finck     ok(hres == S_OK, "get_document failed: %08x\n", hres);
1167c2c66affSColin Finck 
1168c2c66affSColin Finck     hres = IHTMLDocument2_get_readyState(iframe_doc, &str2);
1169c2c66affSColin Finck     ok(hres == S_OK, "get_document failed: %08x\n", hres);
1170c2c66affSColin Finck     ok(!lstrcmpW(str, str2), "unexpected document readyState %s\n", wine_dbgstr_w(str2));
1171c2c66affSColin Finck     SysFreeString(str2);
1172c2c66affSColin Finck 
1173c2c66affSColin Finck     if(!strcmp_wa(str, "loading")) {
1174c2c66affSColin Finck         CHECK_EXPECT(iframe_onreadystatechange_loading);
1175c2c66affSColin Finck 
1176c2c66affSColin Finck         V_VT(&v) = VT_DISPATCH;
1177c2c66affSColin Finck         V_DISPATCH(&v) = (IDispatch*)&iframedoc_onreadystatechange_obj;
1178c2c66affSColin Finck         hres = IHTMLDocument2_put_onreadystatechange(iframe_doc, v);
1179c2c66affSColin Finck         ok(hres == S_OK, "put_onreadystatechange: %08x\n", hres);
1180c2c66affSColin Finck     }else if(!strcmp_wa(str, "interactive"))
1181c2c66affSColin Finck         CHECK_EXPECT(iframe_onreadystatechange_interactive);
1182c2c66affSColin Finck     else if(!strcmp_wa(str, "complete"))
1183c2c66affSColin Finck         CHECK_EXPECT(iframe_onreadystatechange_complete);
1184c2c66affSColin Finck     else
1185c2c66affSColin Finck         ok(0, "unexpected state %s\n", wine_dbgstr_w(str));
1186c2c66affSColin Finck 
1187c2c66affSColin Finck     SysFreeString(str);
1188c2c66affSColin Finck     IHTMLDocument2_Release(iframe_doc);
1189c2c66affSColin Finck     IHTMLFrameBase2_Release(iframe);
1190c2c66affSColin Finck     return S_OK;
1191c2c66affSColin Finck }
1192c2c66affSColin Finck 
1193c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(iframe_onreadystatechange);
1194c2c66affSColin Finck 
nocall(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)1195c2c66affSColin Finck static HRESULT WINAPI nocall(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1196c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
1197c2c66affSColin Finck {
1198c2c66affSColin Finck     ok(0, "unexpected call\n");
1199c2c66affSColin Finck     return S_OK;
1200c2c66affSColin Finck }
1201c2c66affSColin Finck 
1202c2c66affSColin Finck EVENT_HANDLER_FUNC_OBJ(nocall);
1203c2c66affSColin Finck 
1204c2c66affSColin Finck #define CONNECTION_POINT_OBJ(cpname, diid) \
1205c2c66affSColin Finck     static HRESULT WINAPI cpname ## _QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv) \
1206c2c66affSColin Finck     { \
1207c2c66affSColin Finck         *ppv = NULL; \
1208c2c66affSColin Finck         if(IsEqualGUID(riid, &IID_IUnknown) \
1209c2c66affSColin Finck            || IsEqualGUID(riid, &IID_IDispatch) \
1210c2c66affSColin Finck            || IsEqualGUID(riid, &diid)) \
1211c2c66affSColin Finck             *ppv = iface; \
1212c2c66affSColin Finck         else { \
1213c2c66affSColin Finck             ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid)); \
1214c2c66affSColin Finck             return E_NOINTERFACE; \
1215c2c66affSColin Finck         } \
1216c2c66affSColin Finck         return S_OK; \
1217c2c66affSColin Finck     } \
1218c2c66affSColin Finck     static IDispatchExVtbl cpname ## Vtbl = { \
1219c2c66affSColin Finck         cpname ## _QueryInterface, \
1220c2c66affSColin Finck         DispatchEx_AddRef,  \
1221c2c66affSColin Finck         DispatchEx_Release, \
1222c2c66affSColin Finck         DispatchEx_GetTypeInfoCount, \
1223c2c66affSColin Finck         DispatchEx_GetTypeInfo, \
1224c2c66affSColin Finck         DispatchEx_GetIDsOfNames, \
1225c2c66affSColin Finck         cpname, \
1226c2c66affSColin Finck         DispatchEx_GetDispID, \
1227c2c66affSColin Finck         DispatchEx_InvokeEx, \
1228c2c66affSColin Finck         DispatchEx_DeleteMemberByName, \
1229c2c66affSColin Finck         DispatchEx_DeleteMemberByDispID, \
1230c2c66affSColin Finck         DispatchEx_GetMemberProperties, \
1231c2c66affSColin Finck         DispatchEx_GetMemberName, \
1232c2c66affSColin Finck         DispatchEx_GetNextDispID, \
1233c2c66affSColin Finck         DispatchEx_GetNameSpaceParent \
1234c2c66affSColin Finck     }; \
1235c2c66affSColin Finck     static IDispatchEx cpname ## _obj = { &cpname ## Vtbl }
1236c2c66affSColin Finck 
1237c2c66affSColin Finck #define test_cp_args(a,b,c,d,e,f) _test_cp_args(__LINE__,a,b,c,d,e,f)
_test_cp_args(unsigned line,REFIID riid,WORD flags,DISPPARAMS * dp,VARIANT * vres,EXCEPINFO * ei,UINT * argerr)1238c2c66affSColin Finck static void _test_cp_args(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1239c2c66affSColin Finck {
1240c2c66affSColin Finck     ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1241c2c66affSColin Finck     ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1242c2c66affSColin Finck     ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1243c2c66affSColin Finck     ok_(__FILE__,line)(!dp->cArgs, "dp->cArgs = %d\n", dp->cArgs);
1244c2c66affSColin Finck     ok_(__FILE__,line)(!dp->rgvarg, "dp->rgvarg = %p\n", dp->rgvarg);
1245c2c66affSColin Finck     ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1246c2c66affSColin Finck     ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1247c2c66affSColin Finck     ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1248c2c66affSColin Finck     ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1249c2c66affSColin Finck     ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1250c2c66affSColin Finck     ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1251c2c66affSColin Finck }
1252c2c66affSColin Finck 
1253c2c66affSColin Finck #define test_cp_eventarg(a,b,c,d,e,f) _test_cp_eventarg(__LINE__,a,b,c,d,e,f)
_test_cp_eventarg(unsigned line,REFIID riid,WORD flags,DISPPARAMS * dp,VARIANT * vres,EXCEPINFO * ei,UINT * argerr)1254c2c66affSColin Finck static void _test_cp_eventarg(unsigned line, REFIID riid, WORD flags, DISPPARAMS *dp, VARIANT *vres, EXCEPINFO *ei, UINT *argerr)
1255c2c66affSColin Finck {
1256c2c66affSColin Finck     IHTMLEventObj *event;
1257c2c66affSColin Finck 
1258c2c66affSColin Finck     ok_(__FILE__,line)(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1259c2c66affSColin Finck     ok_(__FILE__,line)(flags == DISPATCH_METHOD, "flags = %x\n", flags);
1260c2c66affSColin Finck     ok_(__FILE__,line)(dp != NULL, "dp == NULL\n");
1261c2c66affSColin Finck     ok_(__FILE__,line)(dp->cArgs == 1, "dp->cArgs = %d\n", dp->cArgs);
1262c2c66affSColin Finck     ok_(__FILE__,line)(dp->rgvarg != NULL, "dp->rgvarg = %p\n", dp->rgvarg);
1263c2c66affSColin Finck     ok_(__FILE__,line)(!dp->cNamedArgs, "dp->cNamedArgs = %d\n", dp->cNamedArgs);
1264c2c66affSColin Finck     ok_(__FILE__,line)(!dp->rgdispidNamedArgs, "dp->rgdispidNamedArgs = %p\n", dp->rgdispidNamedArgs);
1265c2c66affSColin Finck     ok_(__FILE__,line)(vres != NULL, "vres == NULL\n");
1266c2c66affSColin Finck     ok_(__FILE__,line)(V_VT(vres) == VT_EMPTY, "V_VT(vres) = %d\n", V_VT(vres));
1267c2c66affSColin Finck     ok_(__FILE__,line)(ei != NULL, "ei == NULL\n");
1268c2c66affSColin Finck     ok_(__FILE__,line)(argerr != NULL, "argerr == NULL\n");
1269c2c66affSColin Finck 
1270c2c66affSColin Finck     ok(V_VT(dp->rgvarg) == VT_DISPATCH, "V_VT(dp->rgvarg) = %d\n", V_VT(dp->rgvarg));
1271c2c66affSColin Finck     ok(V_DISPATCH(dp->rgvarg) != NULL, "V_DISPATCH(dp->rgvarg) = %p\n", V_DISPATCH(dp->rgvarg));
1272c2c66affSColin Finck 
1273c2c66affSColin Finck     event = _get_event_obj(line);
1274c2c66affSColin Finck     ok(iface_cmp((IUnknown*)event, (IUnknown*)V_DISPATCH(dp->rgvarg)), "event != arg0\n");
1275c2c66affSColin Finck     IHTMLEventObj_Release(event);
1276c2c66affSColin Finck }
1277c2c66affSColin Finck 
doccp(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pVarResult,EXCEPINFO * pei,UINT * puArgErr)1278c2c66affSColin Finck static HRESULT WINAPI doccp(IDispatchEx *iface, DISPID dispIdMember,
1279c2c66affSColin Finck                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1280c2c66affSColin Finck                             VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1281c2c66affSColin Finck {
1282c2c66affSColin Finck     switch(dispIdMember) {
1283c2c66affSColin Finck     case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1284c2c66affSColin Finck         CHECK_EXPECT(doccp_onclick);
1285c2c66affSColin Finck         test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1286c2c66affSColin Finck         break;
1287c2c66affSColin Finck     default:
1288c2c66affSColin Finck         ok(0, "unexpected call %d\n", dispIdMember);
1289c2c66affSColin Finck         return E_NOTIMPL;
1290c2c66affSColin Finck     }
1291c2c66affSColin Finck 
1292c2c66affSColin Finck     return S_OK;
1293c2c66affSColin Finck }
1294c2c66affSColin Finck 
1295c2c66affSColin Finck CONNECTION_POINT_OBJ(doccp, DIID_HTMLDocumentEvents);
1296c2c66affSColin Finck 
doccp_onclick_cancel(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pVarResult,EXCEPINFO * pei,UINT * puArgErr)1297c2c66affSColin Finck static HRESULT WINAPI doccp_onclick_cancel(IDispatchEx *iface, DISPID dispIdMember,
1298c2c66affSColin Finck         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1299c2c66affSColin Finck {
1300c2c66affSColin Finck     switch(dispIdMember) {
1301c2c66affSColin Finck     case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1302c2c66affSColin Finck         CHECK_EXPECT(doccp_onclick_cancel);
1303c2c66affSColin Finck         test_cp_args(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1304c2c66affSColin Finck         V_VT(pVarResult) = VT_BOOL;
1305c2c66affSColin Finck         V_BOOL(pVarResult) = VARIANT_FALSE;
1306c2c66affSColin Finck         break;
1307c2c66affSColin Finck     default:
1308c2c66affSColin Finck         ok(0, "unexpected call %d\n", dispIdMember);
1309c2c66affSColin Finck         return E_NOTIMPL;
1310c2c66affSColin Finck     }
1311c2c66affSColin Finck 
1312c2c66affSColin Finck     return S_OK;
1313c2c66affSColin Finck }
1314c2c66affSColin Finck 
1315c2c66affSColin Finck CONNECTION_POINT_OBJ(doccp_onclick_cancel, DIID_HTMLDocumentEvents);
1316c2c66affSColin Finck 
elem2_cp(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pVarResult,EXCEPINFO * pei,UINT * puArgErr)1317c2c66affSColin Finck static HRESULT WINAPI elem2_cp(IDispatchEx *iface, DISPID dispIdMember, REFIID riid, LCID lcid,
1318c2c66affSColin Finck         WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult, EXCEPINFO *pei, UINT *puArgErr)
1319c2c66affSColin Finck {
1320c2c66affSColin Finck     switch(dispIdMember) {
1321c2c66affSColin Finck     case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1322c2c66affSColin Finck         CHECK_EXPECT(elem2_cp_onclick);
1323c2c66affSColin Finck         test_cp_eventarg(riid, wFlags, pdp, pVarResult, pei, puArgErr);
1324c2c66affSColin Finck         break;
1325c2c66affSColin Finck     default:
1326c2c66affSColin Finck         ok(0, "unexpected call %d\n", dispIdMember);
1327c2c66affSColin Finck         return E_NOTIMPL;
1328c2c66affSColin Finck     }
1329c2c66affSColin Finck 
1330c2c66affSColin Finck     return S_OK;
1331c2c66affSColin Finck }
1332c2c66affSColin Finck 
1333c2c66affSColin Finck CONNECTION_POINT_OBJ(elem2_cp, DIID_HTMLElementEvents2);
1334c2c66affSColin Finck 
timeoutFunc_Invoke(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)1335c2c66affSColin Finck static HRESULT WINAPI timeoutFunc_Invoke(IDispatchEx *iface, DISPID dispIdMember,
1336c2c66affSColin Finck                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1337c2c66affSColin Finck                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1338c2c66affSColin Finck {
1339c2c66affSColin Finck     CHECK_EXPECT(timeout);
1340c2c66affSColin Finck 
1341c2c66affSColin Finck     ok(dispIdMember == DISPID_VALUE, "dispIdMember = %d\n", dispIdMember);
1342c2c66affSColin Finck     ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1343c2c66affSColin Finck     ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
1344c2c66affSColin Finck     ok(!lcid, "lcid = %x\n", lcid);
1345c2c66affSColin Finck     ok(pDispParams != NULL, "pDispParams == NULL\n");
1346c2c66affSColin Finck     ok(!pDispParams->cArgs, "pdp->cArgs = %d\n", pDispParams->cArgs);
1347c2c66affSColin Finck     ok(!pDispParams->cNamedArgs, "pdp->cNamedArgs = %d\n", pDispParams->cNamedArgs);
1348c2c66affSColin Finck     ok(!pDispParams->rgdispidNamedArgs, "pdp->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
1349c2c66affSColin Finck     ok(!pDispParams->rgvarg, "rgvarg = %p\n", pDispParams->rgvarg);
1350c2c66affSColin Finck     ok(pVarResult != NULL, "pVarResult = NULL\n");
1351c2c66affSColin Finck     ok(pExcepInfo != NULL, "pExcepInfo = NULL\n");
1352c2c66affSColin Finck     ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1353c2c66affSColin Finck     ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1354c2c66affSColin Finck 
1355c2c66affSColin Finck     return S_OK;
1356c2c66affSColin Finck }
1357c2c66affSColin Finck 
1358c2c66affSColin Finck static const IDispatchExVtbl timeoutFuncVtbl = {
1359c2c66affSColin Finck     DispatchEx_QueryInterface,
1360c2c66affSColin Finck     DispatchEx_AddRef,
1361c2c66affSColin Finck     DispatchEx_Release,
1362c2c66affSColin Finck     DispatchEx_GetTypeInfoCount,
1363c2c66affSColin Finck     DispatchEx_GetTypeInfo,
1364c2c66affSColin Finck     DispatchEx_GetIDsOfNames,
1365c2c66affSColin Finck     timeoutFunc_Invoke,
1366c2c66affSColin Finck     DispatchEx_GetDispID,
1367c2c66affSColin Finck     DispatchEx_InvokeEx,
1368c2c66affSColin Finck     DispatchEx_DeleteMemberByName,
1369c2c66affSColin Finck     DispatchEx_DeleteMemberByDispID,
1370c2c66affSColin Finck     DispatchEx_GetMemberProperties,
1371c2c66affSColin Finck     DispatchEx_GetMemberName,
1372c2c66affSColin Finck     DispatchEx_GetNextDispID,
1373c2c66affSColin Finck     DispatchEx_GetNameSpaceParent
1374c2c66affSColin Finck };
1375c2c66affSColin Finck 
1376c2c66affSColin Finck static IDispatchEx timeoutFunc = { &timeoutFuncVtbl };
1377c2c66affSColin Finck 
div_onclick_disp_Invoke(IDispatchEx * iface,DISPID id,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,UINT * puArgErr)1378c2c66affSColin Finck static HRESULT WINAPI div_onclick_disp_Invoke(IDispatchEx *iface, DISPID id,
1379c2c66affSColin Finck         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
1380c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, UINT *puArgErr)
1381c2c66affSColin Finck {
1382c2c66affSColin Finck     CHECK_EXPECT(div_onclick_disp);
1383c2c66affSColin Finck 
1384c2c66affSColin Finck     test_attached_event_args(id, wFlags, pdp, pvarRes, pei);
1385c2c66affSColin Finck 
1386c2c66affSColin Finck     ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1387c2c66affSColin Finck     ok(!puArgErr, "puArgErr = %p\n", puArgErr);
1388c2c66affSColin Finck 
1389c2c66affSColin Finck     return S_OK;
1390c2c66affSColin Finck }
1391c2c66affSColin Finck 
1392c2c66affSColin Finck static const IDispatchExVtbl div_onclick_dispVtbl = {
1393c2c66affSColin Finck     Dispatch_QueryInterface,
1394c2c66affSColin Finck     DispatchEx_AddRef,
1395c2c66affSColin Finck     DispatchEx_Release,
1396c2c66affSColin Finck     DispatchEx_GetTypeInfoCount,
1397c2c66affSColin Finck     DispatchEx_GetTypeInfo,
1398c2c66affSColin Finck     DispatchEx_GetIDsOfNames,
1399c2c66affSColin Finck     div_onclick_disp_Invoke,
1400c2c66affSColin Finck };
1401c2c66affSColin Finck 
1402c2c66affSColin Finck static IDispatchEx div_onclick_disp = { &div_onclick_dispVtbl };
1403c2c66affSColin Finck 
pump_msgs(BOOL * b)1404c2c66affSColin Finck static void pump_msgs(BOOL *b)
1405c2c66affSColin Finck {
1406c2c66affSColin Finck     MSG msg;
1407c2c66affSColin Finck 
1408c2c66affSColin Finck     if(b) {
1409c2c66affSColin Finck         while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
1410c2c66affSColin Finck             TranslateMessage(&msg);
1411c2c66affSColin Finck             DispatchMessageW(&msg);
1412c2c66affSColin Finck         }
1413c2c66affSColin Finck     }else {
1414c2c66affSColin Finck         while(PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
1415c2c66affSColin Finck             TranslateMessage(&msg);
1416c2c66affSColin Finck             DispatchMessageW(&msg);
1417c2c66affSColin Finck         }
1418c2c66affSColin Finck     }
1419c2c66affSColin Finck }
1420c2c66affSColin Finck 
get_cp(IUnknown * unk,REFIID riid)1421c2c66affSColin Finck static IConnectionPoint *get_cp(IUnknown *unk, REFIID riid)
1422c2c66affSColin Finck {
1423c2c66affSColin Finck     IConnectionPointContainer *cp_container;
1424c2c66affSColin Finck     IConnectionPoint *cp;
1425c2c66affSColin Finck     HRESULT hres;
1426c2c66affSColin Finck 
1427c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&cp_container);
1428c2c66affSColin Finck     ok(hres == S_OK, "Could not get IConnectionPointContainer: %08x\n", hres);
1429c2c66affSColin Finck 
1430c2c66affSColin Finck     hres = IConnectionPointContainer_FindConnectionPoint(cp_container, riid, &cp);
1431c2c66affSColin Finck     IConnectionPointContainer_Release(cp_container);
1432c2c66affSColin Finck     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1433c2c66affSColin Finck 
1434c2c66affSColin Finck     return cp;
1435c2c66affSColin Finck }
1436c2c66affSColin Finck 
register_cp(IUnknown * unk,REFIID riid,IUnknown * sink)1437c2c66affSColin Finck static DWORD register_cp(IUnknown *unk, REFIID riid, IUnknown *sink)
1438c2c66affSColin Finck {
1439c2c66affSColin Finck     IConnectionPoint *cp;
1440c2c66affSColin Finck     DWORD cookie;
1441c2c66affSColin Finck     HRESULT hres;
1442c2c66affSColin Finck 
1443c2c66affSColin Finck     cp = get_cp(unk, riid);
1444c2c66affSColin Finck     hres = IConnectionPoint_Advise(cp, sink, &cookie);
1445c2c66affSColin Finck     IConnectionPoint_Release(cp);
1446c2c66affSColin Finck     ok(hres == S_OK, "Advise failed: %08x\n", hres);
1447c2c66affSColin Finck 
1448c2c66affSColin Finck     return cookie;
1449c2c66affSColin Finck }
1450c2c66affSColin Finck 
unregister_cp(IUnknown * unk,REFIID riid,DWORD cookie)1451c2c66affSColin Finck static void unregister_cp(IUnknown *unk, REFIID riid, DWORD cookie)
1452c2c66affSColin Finck {
1453c2c66affSColin Finck     IConnectionPoint *cp;
1454c2c66affSColin Finck     HRESULT hres;
1455c2c66affSColin Finck 
1456c2c66affSColin Finck     cp = get_cp(unk, riid);
1457c2c66affSColin Finck     hres = IConnectionPoint_Unadvise(cp, cookie);
1458c2c66affSColin Finck     IConnectionPoint_Release(cp);
1459c2c66affSColin Finck     ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
1460c2c66affSColin Finck }
1461c2c66affSColin Finck 
EventDispatch_QueryInterface(IDispatch * iface,REFIID riid,void ** ppv)1462c2c66affSColin Finck static HRESULT WINAPI EventDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
1463c2c66affSColin Finck {
1464c2c66affSColin Finck     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
1465c2c66affSColin Finck         *ppv = iface;
1466c2c66affSColin Finck         return S_OK;
1467c2c66affSColin Finck     }
1468c2c66affSColin Finck 
1469c2c66affSColin Finck     ok(0, "Unexpected call\n");
1470c2c66affSColin Finck     return E_NOINTERFACE;
1471c2c66affSColin Finck }
1472c2c66affSColin Finck 
EventDispatch_AddRef(IDispatch * iface)1473c2c66affSColin Finck static DWORD WINAPI EventDispatch_AddRef(IDispatch *iface)
1474c2c66affSColin Finck {
1475c2c66affSColin Finck     return 2;
1476c2c66affSColin Finck }
1477c2c66affSColin Finck 
EventDispatch_Release(IDispatch * iface)1478c2c66affSColin Finck static DWORD WINAPI EventDispatch_Release(IDispatch *iface)
1479c2c66affSColin Finck {
1480c2c66affSColin Finck     return 1;
1481c2c66affSColin Finck }
1482c2c66affSColin Finck 
EventDispatch_GetTypeInfoCount(IDispatch * iface,UINT * pctinfo)1483c2c66affSColin Finck static HRESULT WINAPI EventDispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
1484c2c66affSColin Finck {
1485c2c66affSColin Finck     ok(0, "Unexpected call\n");
1486c2c66affSColin Finck     return E_NOTIMPL;
1487c2c66affSColin Finck }
1488c2c66affSColin Finck 
EventDispatch_GetTypeInfo(IDispatch * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)1489c2c66affSColin Finck static HRESULT WINAPI EventDispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1490c2c66affSColin Finck {
1491c2c66affSColin Finck     ok(0, "Unexpected call\n");
1492c2c66affSColin Finck     return E_NOTIMPL;
1493c2c66affSColin Finck }
1494c2c66affSColin Finck 
EventDispatch_GetIDsOfNames(IDispatch * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)1495c2c66affSColin Finck static HRESULT WINAPI EventDispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
1496c2c66affSColin Finck         UINT cNames, LCID lcid, DISPID *rgDispId)
1497c2c66affSColin Finck {
1498c2c66affSColin Finck     ok(0, "Unexpected call\n");
1499c2c66affSColin Finck     return E_NOTIMPL;
1500c2c66affSColin Finck }
1501c2c66affSColin Finck 
EventDispatch_Invoke(IDispatch * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)1502c2c66affSColin Finck static HRESULT WINAPI EventDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
1503c2c66affSColin Finck         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1504c2c66affSColin Finck         EXCEPINFO *pExcepInfo, UINT *puArgErr)
1505c2c66affSColin Finck {
1506c2c66affSColin Finck     ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
1507c2c66affSColin Finck     ok(pDispParams != NULL, "pDispParams == NULL\n");
1508c2c66affSColin Finck     ok(pExcepInfo != NULL, "pExcepInfo == NULL\n");
1509c2c66affSColin Finck     ok(puArgErr != NULL, "puArgErr == NULL\n");
1510c2c66affSColin Finck     ok(V_VT(pVarResult) == 0, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
1511c2c66affSColin Finck     ok(wFlags == DISPATCH_METHOD, "wFlags = %d\n", wFlags);
1512c2c66affSColin Finck 
1513c2c66affSColin Finck     switch(dispIdMember) {
1514c2c66affSColin Finck     case DISPID_HTMLDOCUMENTEVENTS_ONCLICK:
1515c2c66affSColin Finck         CHECK_EXPECT2(invoke_onclick);
1516c2c66affSColin Finck         break;
1517c2c66affSColin Finck     case DISPID_HTMLDOCUMENTEVENTS2_ONPROPERTYCHANGE:
1518c2c66affSColin Finck     case DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE:
1519c2c66affSColin Finck     case 1027:
1520c2c66affSColin Finck     case 1034:
1521c2c66affSColin Finck     case 1037:
1522c2c66affSColin Finck     case 1044:
1523c2c66affSColin Finck     case 1045:
1524c2c66affSColin Finck     case 1047:
1525c2c66affSColin Finck     case 1048:
1526c2c66affSColin Finck     case 1049:
1527c2c66affSColin Finck         break; /* TODO */
1528c2c66affSColin Finck     default:
1529c2c66affSColin Finck         ok(0, "Unexpected call: %d\n", dispIdMember);
1530c2c66affSColin Finck     }
1531c2c66affSColin Finck 
1532c2c66affSColin Finck     return S_OK;
1533c2c66affSColin Finck }
1534c2c66affSColin Finck 
1535c2c66affSColin Finck static const IDispatchVtbl EventDispatchVtbl = {
1536c2c66affSColin Finck     EventDispatch_QueryInterface,
1537c2c66affSColin Finck     EventDispatch_AddRef,
1538c2c66affSColin Finck     EventDispatch_Release,
1539c2c66affSColin Finck     EventDispatch_GetTypeInfoCount,
1540c2c66affSColin Finck     EventDispatch_GetTypeInfo,
1541c2c66affSColin Finck     EventDispatch_GetIDsOfNames,
1542c2c66affSColin Finck     EventDispatch_Invoke
1543c2c66affSColin Finck };
1544c2c66affSColin Finck 
1545c2c66affSColin Finck static IDispatch EventDispatch = { &EventDispatchVtbl };
1546c2c66affSColin Finck 
test_onclick(IHTMLDocument2 * doc)1547c2c66affSColin Finck static void test_onclick(IHTMLDocument2 *doc)
1548c2c66affSColin Finck {
1549c2c66affSColin Finck     DWORD cp_cookie, elem2_cp_cookie;
1550c2c66affSColin Finck     IHTMLElement *div, *body;
1551c2c66affSColin Finck     VARIANT v;
1552c2c66affSColin Finck     HRESULT hres;
1553c2c66affSColin Finck 
1554c2c66affSColin Finck     register_cp((IUnknown*)doc, &IID_IDispatch, (IUnknown*)&EventDispatch);
1555c2c66affSColin Finck 
1556c2c66affSColin Finck     div = get_elem_id(doc, "clickdiv");
1557c2c66affSColin Finck 
1558c2c66affSColin Finck     elem_attach_event((IUnknown*)div, "abcde", (IDispatch*)&nocall_obj);
1559c2c66affSColin Finck     elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_attached_obj);
1560c2c66affSColin Finck 
1561c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1562c2c66affSColin Finck     hres = IHTMLElement_get_onclick(div, &v);
1563c2c66affSColin Finck     ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1564c2c66affSColin Finck     ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1565c2c66affSColin Finck 
1566c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1567c2c66affSColin Finck     hres = IHTMLElement_put_onclick(div, v);
1568c2c66affSColin Finck     ok(hres == E_NOTIMPL, "put_onclick failed: %08x\n", hres);
1569c2c66affSColin Finck 
1570c2c66affSColin Finck     V_VT(&v) = VT_BSTR;
1571c2c66affSColin Finck     V_BSTR(&v) = a2bstr("function();");
1572c2c66affSColin Finck     hres = IHTMLElement_put_onclick(div, v);
1573c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1574c2c66affSColin Finck 
1575c2c66affSColin Finck     if(hres == S_OK) {
1576c2c66affSColin Finck         V_VT(&v) = VT_EMPTY;
1577c2c66affSColin Finck         hres = IHTMLElement_get_onclick(div, &v);
1578c2c66affSColin Finck         ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1579c2c66affSColin Finck         ok(V_VT(&v) == VT_BSTR, "V_VT(onclick) = %d\n", V_VT(&v));
1580c2c66affSColin Finck         ok(!strcmp_wa(V_BSTR(&v), "function();"), "V_BSTR(onclick) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
1581c2c66affSColin Finck     }
1582c2c66affSColin Finck     VariantClear(&v);
1583c2c66affSColin Finck 
1584c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1585c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&div_onclick_obj;
1586c2c66affSColin Finck     hres = IHTMLElement_put_onclick(div, v);
1587c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1588c2c66affSColin Finck 
1589c2c66affSColin Finck     V_VT(&v) = VT_NULL;
1590c2c66affSColin Finck     hres = IHTMLElement_put_ondblclick(div, v);
1591c2c66affSColin Finck     ok(hres == S_OK, "put_ondblclick failed: %08x\n", hres);
1592c2c66affSColin Finck 
1593c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1594c2c66affSColin Finck     hres = IHTMLElement_get_onclick(div, &v);
1595c2c66affSColin Finck     ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1596c2c66affSColin Finck     ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1597c2c66affSColin Finck     ok(V_DISPATCH(&v) == (IDispatch*)&div_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1598c2c66affSColin Finck     VariantClear(&v);
1599c2c66affSColin Finck 
1600c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1601c2c66affSColin Finck     hres = IHTMLDocument2_get_onclick(doc, &v);
1602c2c66affSColin Finck     ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1603c2c66affSColin Finck     ok(V_VT(&v) == VT_NULL, "V_VT(onclick) = %d\n", V_VT(&v));
1604c2c66affSColin Finck 
1605c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1606c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&document_onclick_obj;
1607c2c66affSColin Finck     hres = IHTMLDocument2_put_onclick(doc, v);
1608c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1609c2c66affSColin Finck 
1610c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1611c2c66affSColin Finck     hres = IHTMLDocument2_get_onclick(doc, &v);
1612c2c66affSColin Finck     ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1613c2c66affSColin Finck     ok(V_VT(&v) == VT_DISPATCH, "V_VT(onclick) = %d\n", V_VT(&v));
1614c2c66affSColin Finck     ok(V_DISPATCH(&v) == (IDispatch*)&document_onclick_obj, "V_DISPATCH(onclick) != onclickFunc\n");
1615c2c66affSColin Finck     VariantClear(&v);
1616c2c66affSColin Finck 
1617c2c66affSColin Finck     body = doc_get_body(doc);
1618c2c66affSColin Finck 
1619c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1620c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&body_onclick_obj;
1621c2c66affSColin Finck     hres = IHTMLElement_put_onclick(body, v);
1622c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1623c2c66affSColin Finck 
1624c2c66affSColin Finck     if(winetest_interactive) {
1625c2c66affSColin Finck         SET_EXPECT(div_onclick);
1626c2c66affSColin Finck         SET_EXPECT(div_onclick_attached);
1627c2c66affSColin Finck         SET_EXPECT(body_onclick);
1628c2c66affSColin Finck         SET_EXPECT(document_onclick);
1629c2c66affSColin Finck         SET_EXPECT(invoke_onclick);
1630c2c66affSColin Finck         pump_msgs(&called_document_onclick);
1631c2c66affSColin Finck         CHECK_CALLED(div_onclick);
1632c2c66affSColin Finck         CHECK_CALLED(div_onclick_attached);
1633c2c66affSColin Finck         CHECK_CALLED(body_onclick);
1634c2c66affSColin Finck         CHECK_CALLED(document_onclick);
1635c2c66affSColin Finck         CHECK_CALLED(invoke_onclick);
1636c2c66affSColin Finck     }
1637c2c66affSColin Finck 
1638c2c66affSColin Finck     SET_EXPECT(div_onclick);
1639c2c66affSColin Finck     SET_EXPECT(div_onclick_attached);
1640c2c66affSColin Finck     SET_EXPECT(body_onclick);
1641c2c66affSColin Finck     SET_EXPECT(document_onclick);
1642c2c66affSColin Finck     SET_EXPECT(invoke_onclick);
1643c2c66affSColin Finck 
1644c2c66affSColin Finck     hres = IHTMLElement_click(div);
1645c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1646c2c66affSColin Finck 
1647c2c66affSColin Finck     CHECK_CALLED(div_onclick);
1648c2c66affSColin Finck     CHECK_CALLED(div_onclick_attached);
1649c2c66affSColin Finck     CHECK_CALLED(body_onclick);
1650c2c66affSColin Finck     CHECK_CALLED(document_onclick);
1651c2c66affSColin Finck     CHECK_CALLED(invoke_onclick);
1652c2c66affSColin Finck 
1653c2c66affSColin Finck     SET_EXPECT(div_onclick);
1654c2c66affSColin Finck     SET_EXPECT(div_onclick_attached);
1655c2c66affSColin Finck     SET_EXPECT(body_onclick);
1656c2c66affSColin Finck     SET_EXPECT(document_onclick);
1657c2c66affSColin Finck     SET_EXPECT(invoke_onclick);
1658c2c66affSColin Finck 
1659c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1660c2c66affSColin Finck     elem_fire_event((IUnknown*)div, "onclick", &v);
1661c2c66affSColin Finck 
1662c2c66affSColin Finck     CHECK_CALLED(div_onclick);
1663c2c66affSColin Finck     CHECK_CALLED(div_onclick_attached);
1664c2c66affSColin Finck     CHECK_CALLED(body_onclick);
1665c2c66affSColin Finck     CHECK_CALLED(document_onclick);
1666c2c66affSColin Finck     CHECK_CALLED(invoke_onclick);
1667c2c66affSColin Finck 
1668c2c66affSColin Finck     cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_obj);
1669c2c66affSColin Finck     elem_attach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1670c2c66affSColin Finck     doc_attach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1671c2c66affSColin Finck 
1672c2c66affSColin Finck     SET_EXPECT(div_onclick);
1673c2c66affSColin Finck     SET_EXPECT(div_onclick_disp);
1674c2c66affSColin Finck     SET_EXPECT(div_onclick_attached);
1675c2c66affSColin Finck     SET_EXPECT(body_onclick);
1676c2c66affSColin Finck     SET_EXPECT(document_onclick);
1677c2c66affSColin Finck     SET_EXPECT(doc_onclick_attached);
1678c2c66affSColin Finck     SET_EXPECT(doccp_onclick);
1679c2c66affSColin Finck     SET_EXPECT(invoke_onclick);
1680c2c66affSColin Finck 
1681c2c66affSColin Finck     hres = IHTMLElement_click(div);
1682c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1683c2c66affSColin Finck 
1684c2c66affSColin Finck     CHECK_CALLED(div_onclick);
1685c2c66affSColin Finck     CHECK_CALLED(div_onclick_disp);
1686c2c66affSColin Finck     CHECK_CALLED(div_onclick_attached);
1687c2c66affSColin Finck     CHECK_CALLED(body_onclick);
1688c2c66affSColin Finck     CHECK_CALLED(document_onclick);
1689c2c66affSColin Finck     CHECK_CALLED(doc_onclick_attached);
1690c2c66affSColin Finck     CHECK_CALLED(doccp_onclick);
1691c2c66affSColin Finck     CHECK_CALLED(invoke_onclick);
1692c2c66affSColin Finck 
1693c2c66affSColin Finck     elem2_cp_cookie = register_cp((IUnknown*)div, &DIID_HTMLElementEvents2, (IUnknown*)&elem2_cp_obj);
1694c2c66affSColin Finck 
1695c2c66affSColin Finck     SET_EXPECT(div_onclick);
1696c2c66affSColin Finck     SET_EXPECT(div_onclick_disp);
1697c2c66affSColin Finck     SET_EXPECT(div_onclick_attached);
1698c2c66affSColin Finck     SET_EXPECT(elem2_cp_onclick);
1699c2c66affSColin Finck     SET_EXPECT(body_onclick);
1700c2c66affSColin Finck     SET_EXPECT(document_onclick);
1701c2c66affSColin Finck     SET_EXPECT(doc_onclick_attached);
1702c2c66affSColin Finck     SET_EXPECT(doccp_onclick);
1703c2c66affSColin Finck     SET_EXPECT(invoke_onclick);
1704c2c66affSColin Finck 
1705c2c66affSColin Finck     trace("click >>>\n");
1706c2c66affSColin Finck     hres = IHTMLElement_click(div);
1707c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1708c2c66affSColin Finck     trace("click <<<\n");
1709c2c66affSColin Finck 
1710c2c66affSColin Finck     CHECK_CALLED(div_onclick);
1711c2c66affSColin Finck     CHECK_CALLED(div_onclick_disp);
1712c2c66affSColin Finck     CHECK_CALLED(div_onclick_attached);
1713c2c66affSColin Finck     CHECK_CALLED(elem2_cp_onclick);
1714c2c66affSColin Finck     CHECK_CALLED(body_onclick);
1715c2c66affSColin Finck     CHECK_CALLED(document_onclick);
1716c2c66affSColin Finck     CHECK_CALLED(doc_onclick_attached);
1717c2c66affSColin Finck     CHECK_CALLED(doccp_onclick);
1718c2c66affSColin Finck     CHECK_CALLED(invoke_onclick);
1719c2c66affSColin Finck 
1720c2c66affSColin Finck     unregister_cp((IUnknown*)div, &DIID_HTMLElementEvents2, elem2_cp_cookie);
1721c2c66affSColin Finck     unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
1722c2c66affSColin Finck 
1723c2c66affSColin Finck     V_VT(&v) = VT_NULL;
1724c2c66affSColin Finck     hres = IHTMLElement_put_onclick(div, v);
1725c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1726c2c66affSColin Finck 
1727c2c66affSColin Finck     hres = IHTMLElement_get_onclick(div, &v);
1728c2c66affSColin Finck     ok(hres == S_OK, "get_onclick failed: %08x\n", hres);
1729c2c66affSColin Finck     ok(V_VT(&v) == VT_NULL, "get_onclick returned vt %d\n", V_VT(&v));
1730c2c66affSColin Finck 
1731c2c66affSColin Finck     elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1732c2c66affSColin Finck     elem_detach_event((IUnknown*)div, "onclick", (IDispatch*)&div_onclick_disp);
1733c2c66affSColin Finck     elem_detach_event((IUnknown*)div, "test", (IDispatch*)&div_onclick_disp);
1734c2c66affSColin Finck     doc_detach_event(doc, "onclick", (IDispatch*)&doc_onclick_attached_obj);
1735c2c66affSColin Finck 
1736c2c66affSColin Finck     SET_EXPECT(div_onclick_attached);
1737c2c66affSColin Finck     SET_EXPECT(body_onclick);
1738c2c66affSColin Finck     SET_EXPECT(document_onclick);
1739c2c66affSColin Finck     SET_EXPECT(invoke_onclick);
1740c2c66affSColin Finck 
1741c2c66affSColin Finck     hres = IHTMLElement_click(div);
1742c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1743c2c66affSColin Finck 
1744c2c66affSColin Finck     CHECK_CALLED(div_onclick_attached);
1745c2c66affSColin Finck     CHECK_CALLED(body_onclick);
1746c2c66affSColin Finck     CHECK_CALLED(document_onclick);
1747c2c66affSColin Finck     CHECK_CALLED(invoke_onclick);
1748c2c66affSColin Finck 
1749c2c66affSColin Finck     IHTMLElement_Release(div);
1750c2c66affSColin Finck     IHTMLElement_Release(body);
1751c2c66affSColin Finck }
1752c2c66affSColin Finck 
test_onreadystatechange(IHTMLDocument2 * doc)1753c2c66affSColin Finck static void test_onreadystatechange(IHTMLDocument2 *doc)
1754c2c66affSColin Finck {
1755c2c66affSColin Finck     IHTMLFrameBase *iframe;
1756c2c66affSColin Finck     IHTMLElement2 *elem2;
1757c2c66affSColin Finck     IHTMLElement *elem;
1758c2c66affSColin Finck     VARIANT v;
1759c2c66affSColin Finck     BSTR str;
1760c2c66affSColin Finck     HRESULT hres;
1761c2c66affSColin Finck 
1762c2c66affSColin Finck     elem = get_elem_id(doc, "iframe");
1763c2c66affSColin Finck     elem2 = get_elem2_iface((IUnknown*)elem);
1764c2c66affSColin Finck     IHTMLElement_Release(elem);
1765c2c66affSColin Finck 
1766c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1767c2c66affSColin Finck     hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1768c2c66affSColin Finck     ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1769c2c66affSColin Finck     ok(V_VT(&v) == VT_NULL, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1770c2c66affSColin Finck 
1771c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1772c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&iframe_onreadystatechange_obj;
1773c2c66affSColin Finck     hres = IHTMLElement2_put_onreadystatechange(elem2, v);
1774c2c66affSColin Finck     ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
1775c2c66affSColin Finck 
1776c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1777c2c66affSColin Finck     hres = IHTMLElement2_get_onreadystatechange(elem2, &v);
1778c2c66affSColin Finck     ok(hres == S_OK, "get_onreadystatechange failed: %08x\n", hres);
1779c2c66affSColin Finck     ok(V_VT(&v) == VT_DISPATCH, "V_VT(onreadystatechange) = %d\n", V_VT(&v));
1780c2c66affSColin Finck     ok(V_DISPATCH(&v) == (IDispatch*)&iframe_onreadystatechange_obj, "unexpected onreadystatechange value\n");
1781c2c66affSColin Finck 
1782c2c66affSColin Finck     hres = IHTMLElement2_QueryInterface(elem2, &IID_IHTMLFrameBase, (void**)&iframe);
1783c2c66affSColin Finck     IHTMLElement2_Release(elem2);
1784c2c66affSColin Finck     ok(hres == S_OK, "Could not get IHTMLFrameBase iface: %08x\n", hres);
1785c2c66affSColin Finck 
1786c2c66affSColin Finck     hres = IHTMLFrameBase_put_src(iframe, (str = a2bstr("about:blank")));
1787c2c66affSColin Finck     SysFreeString(str);
1788c2c66affSColin Finck     ok(hres == S_OK, "put_src failed: %08x\n", hres);
1789c2c66affSColin Finck 
1790c2c66affSColin Finck     SET_EXPECT(iframe_onreadystatechange_loading);
1791c2c66affSColin Finck     SET_EXPECT(iframedoc_onreadystatechange);
1792c2c66affSColin Finck     SET_EXPECT(iframe_onreadystatechange_interactive);
1793c2c66affSColin Finck     SET_EXPECT(iframe_onreadystatechange_complete);
1794c2c66affSColin Finck     pump_msgs(&called_iframe_onreadystatechange_complete);
1795c2c66affSColin Finck     CHECK_CALLED(iframe_onreadystatechange_loading);
1796c2c66affSColin Finck     CHECK_CALLED(iframedoc_onreadystatechange);
1797c2c66affSColin Finck     CHECK_CALLED(iframe_onreadystatechange_interactive);
1798c2c66affSColin Finck     CHECK_CALLED(iframe_onreadystatechange_complete);
1799c2c66affSColin Finck 
1800c2c66affSColin Finck     IHTMLFrameBase_Release(iframe);
1801c2c66affSColin Finck }
1802c2c66affSColin Finck 
test_imgload(IHTMLDocument2 * doc)1803c2c66affSColin Finck static void test_imgload(IHTMLDocument2 *doc)
1804c2c66affSColin Finck {
1805c2c66affSColin Finck     IHTMLImgElement *img;
1806c2c66affSColin Finck     IHTMLElement *elem;
1807c2c66affSColin Finck     VARIANT v;
1808c2c66affSColin Finck     BSTR str;
1809c2c66affSColin Finck     HRESULT hres;
1810c2c66affSColin Finck 
1811c2c66affSColin Finck     elem = get_elem_id(doc, "imgid");
1812c2c66affSColin Finck     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLImgElement, (void**)&img);
1813c2c66affSColin Finck     IHTMLElement_Release(elem);
1814c2c66affSColin Finck     ok(hres == S_OK, "Could not get IHTMLImgElement iface: %08x\n", hres);
1815c2c66affSColin Finck 
1816c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1817c2c66affSColin Finck     hres = IHTMLImgElement_get_onload(img, &v);
1818c2c66affSColin Finck     ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1819c2c66affSColin Finck     ok(V_VT(&v) == VT_NULL, "V_VT(onload) = %d\n", V_VT(&v));
1820c2c66affSColin Finck 
1821c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1822c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&img_onload_obj;
1823c2c66affSColin Finck     hres = IHTMLImgElement_put_onload(img, v);
1824c2c66affSColin Finck     ok(hres == S_OK, "put_onload failed: %08x\n", hres);
1825c2c66affSColin Finck 
1826c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1827c2c66affSColin Finck     hres = IHTMLImgElement_get_onload(img, &v);
1828c2c66affSColin Finck     ok(hres == S_OK, "get_onload failed: %08x\n", hres);
1829c2c66affSColin Finck     ok(V_VT(&v) == VT_DISPATCH, "V_VT(onload) = %d\n", V_VT(&v));
1830c2c66affSColin Finck     ok(V_DISPATCH(&v) == (IDispatch*)&img_onload_obj, "V_DISPATCH(onload) != onloadkFunc\n");
1831c2c66affSColin Finck     VariantClear(&v);
1832c2c66affSColin Finck 
1833c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1834c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&img_onerror_obj;
1835c2c66affSColin Finck     hres = IHTMLImgElement_put_onerror(img, v);
1836c2c66affSColin Finck     ok(hres == S_OK, "put_onerror failed: %08x\n", hres);
1837c2c66affSColin Finck 
1838c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1839c2c66affSColin Finck     hres = IHTMLImgElement_get_onerror(img, &v);
1840c2c66affSColin Finck     ok(hres == S_OK, "get_onerror failed: %08x\n", hres);
1841c2c66affSColin Finck     ok(V_VT(&v) == VT_DISPATCH, "V_VT(onerror) = %d\n", V_VT(&v));
1842c2c66affSColin Finck     ok(V_DISPATCH(&v) == (IDispatch*)&img_onerror_obj, "V_DISPATCH(onerror) != onerrorFunc\n");
1843c2c66affSColin Finck     VariantClear(&v);
1844c2c66affSColin Finck 
1845c2c66affSColin Finck     str = a2bstr("http://test.winehq.org/tests/winehq_snapshot/index_files/winehq_logo_text.png");
1846c2c66affSColin Finck     hres = IHTMLImgElement_put_src(img, str);
1847c2c66affSColin Finck     ok(hres == S_OK, "put_src failed: %08x\n", hres);
1848c2c66affSColin Finck     SysFreeString(str);
1849c2c66affSColin Finck 
1850c2c66affSColin Finck     SET_EXPECT(img_onload);
1851c2c66affSColin Finck     pump_msgs(&called_img_onload);
1852c2c66affSColin Finck     CHECK_CALLED(img_onload);
1853c2c66affSColin Finck 
1854c2c66affSColin Finck     SET_EXPECT(img_onerror);
1855c2c66affSColin Finck 
1856c2c66affSColin Finck     str = a2bstr("about:blank");
1857c2c66affSColin Finck     hres = IHTMLImgElement_put_src(img, str);
1858c2c66affSColin Finck     ok(hres == S_OK, "put_src failed: %08x\n", hres);
1859c2c66affSColin Finck     SysFreeString(str);
1860c2c66affSColin Finck 
1861c2c66affSColin Finck     pump_msgs(&called_img_onerror); /* FIXME: should not be needed */
1862c2c66affSColin Finck 
1863c2c66affSColin Finck     CHECK_CALLED(img_onerror);
1864c2c66affSColin Finck 
1865c2c66affSColin Finck     IHTMLImgElement_Release(img);
1866c2c66affSColin Finck }
1867c2c66affSColin Finck 
test_focus(IHTMLDocument2 * doc)1868c2c66affSColin Finck static void test_focus(IHTMLDocument2 *doc)
1869c2c66affSColin Finck {
1870c2c66affSColin Finck     IHTMLElement2 *elem2;
1871c2c66affSColin Finck     IHTMLElement *elem;
1872c2c66affSColin Finck     VARIANT v;
1873c2c66affSColin Finck     HRESULT hres;
1874c2c66affSColin Finck 
1875c2c66affSColin Finck     elem = get_elem_id(doc, "inputid");
1876c2c66affSColin Finck     elem2 = get_elem2_iface((IUnknown*)elem);
1877c2c66affSColin Finck     IHTMLElement_Release(elem);
1878c2c66affSColin Finck 
1879c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1880c2c66affSColin Finck     hres = IHTMLElement2_get_onfocus(elem2, &v);
1881c2c66affSColin Finck     ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
1882c2c66affSColin Finck     ok(V_VT(&v) == VT_NULL, "V_VT(onfocus) = %d\n", V_VT(&v));
1883c2c66affSColin Finck 
1884c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1885c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&input_onfocus_obj;
1886c2c66affSColin Finck     hres = IHTMLElement2_put_onfocus(elem2, v);
1887c2c66affSColin Finck     ok(hres == S_OK, "put_onfocus failed: %08x\n", hres);
1888c2c66affSColin Finck 
1889c2c66affSColin Finck     V_VT(&v) = VT_EMPTY;
1890c2c66affSColin Finck     hres = IHTMLElement2_get_onfocus(elem2, &v);
1891c2c66affSColin Finck     ok(hres == S_OK, "get_onfocus failed: %08x\n", hres);
1892c2c66affSColin Finck     ok(V_VT(&v) == VT_DISPATCH, "V_VT(onfocus) = %d\n", V_VT(&v));
1893c2c66affSColin Finck     ok(V_DISPATCH(&v) == (IDispatch*)&input_onfocus_obj, "V_DISPATCH(onfocus) != onfocusFunc\n");
1894c2c66affSColin Finck     VariantClear(&v);
1895c2c66affSColin Finck 
1896c2c66affSColin Finck     if(!winetest_interactive)
1897c2c66affSColin Finck         ShowWindow(container_hwnd, SW_SHOW);
1898c2c66affSColin Finck 
1899c2c66affSColin Finck     SetFocus(NULL);
1900c2c66affSColin Finck     ok(!IsChild(container_hwnd, GetFocus()), "focus belongs to document window\n");
1901c2c66affSColin Finck 
1902c2c66affSColin Finck     hres = IHTMLWindow2_focus(window);
1903c2c66affSColin Finck     ok(hres == S_OK, "focus failed: %08x\n", hres);
1904c2c66affSColin Finck 
1905c2c66affSColin Finck     ok(IsChild(container_hwnd, GetFocus()), "focus does not belong to document window\n");
1906c2c66affSColin Finck     pump_msgs(NULL);
1907c2c66affSColin Finck 
1908c2c66affSColin Finck     SET_EXPECT(input_onfocus);
1909c2c66affSColin Finck     hres = IHTMLElement2_focus(elem2);
1910c2c66affSColin Finck     pump_msgs(NULL);
1911c2c66affSColin Finck     CHECK_CALLED(input_onfocus);
1912c2c66affSColin Finck     ok(hres == S_OK, "focus failed: %08x\n", hres);
1913c2c66affSColin Finck 
1914c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1915c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&input_onblur_obj;
1916c2c66affSColin Finck     hres = IHTMLElement2_put_onblur(elem2, v);
1917c2c66affSColin Finck     ok(hres == S_OK, "put_onblur failed: %08x\n", hres);
1918c2c66affSColin Finck 
1919c2c66affSColin Finck     SET_EXPECT(input_onblur);
1920c2c66affSColin Finck     hres = IHTMLElement2_blur(elem2);
1921c2c66affSColin Finck     pump_msgs(NULL);
1922c2c66affSColin Finck     CHECK_CALLED(input_onblur);
1923c2c66affSColin Finck     ok(hres == S_OK, "blur failed: %08x\n", hres);
1924c2c66affSColin Finck 
1925c2c66affSColin Finck     if(!winetest_interactive)
1926c2c66affSColin Finck         ShowWindow(container_hwnd, SW_HIDE);
1927c2c66affSColin Finck 
1928c2c66affSColin Finck     IHTMLElement2_Release(elem2);
1929c2c66affSColin Finck }
1930c2c66affSColin Finck 
test_submit(IHTMLDocument2 * doc)1931c2c66affSColin Finck static void test_submit(IHTMLDocument2 *doc)
1932c2c66affSColin Finck {
1933c2c66affSColin Finck     IHTMLElement *elem, *submit;
1934c2c66affSColin Finck     IHTMLFormElement *form;
1935c2c66affSColin Finck     VARIANT v;
1936c2c66affSColin Finck     DWORD cp_cookie;
1937c2c66affSColin Finck     HRESULT hres;
1938c2c66affSColin Finck 
1939c2c66affSColin Finck     elem = get_elem_id(doc, "formid");
1940c2c66affSColin Finck 
1941c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1942c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&form_onclick_obj;
1943c2c66affSColin Finck     hres = IHTMLElement_put_onclick(elem, v);
1944c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1945c2c66affSColin Finck 
1946c2c66affSColin Finck     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLFormElement, (void**)&form);
1947c2c66affSColin Finck     IHTMLElement_Release(elem);
1948c2c66affSColin Finck     ok(hres == S_OK, "Could not get IHTMLFormElement iface: %08x\n", hres);
1949c2c66affSColin Finck 
1950c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1951c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&form_onsubmit_obj;
1952c2c66affSColin Finck     hres = IHTMLFormElement_put_onsubmit(form, v);
1953c2c66affSColin Finck     ok(hres == S_OK, "put_onsubmit failed: %08x\n", hres);
1954c2c66affSColin Finck 
1955c2c66affSColin Finck     IHTMLFormElement_Release(form);
1956c2c66affSColin Finck 
1957c2c66affSColin Finck     submit = get_elem_id(doc, "submitid");
1958c2c66affSColin Finck 
1959c2c66affSColin Finck     SET_EXPECT(form_onclick);
1960c2c66affSColin Finck     SET_EXPECT(form_onsubmit);
1961c2c66affSColin Finck     hres = IHTMLElement_click(submit);
1962c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1963c2c66affSColin Finck     CHECK_CALLED(form_onclick);
1964c2c66affSColin Finck     CHECK_CALLED(form_onsubmit);
1965c2c66affSColin Finck 
1966c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
1967c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&submit_onclick_obj;
1968c2c66affSColin Finck     hres = IHTMLElement_put_onclick(submit, v);
1969c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1970c2c66affSColin Finck 
1971c2c66affSColin Finck     SET_EXPECT(form_onclick);
1972c2c66affSColin Finck     SET_EXPECT(submit_onclick);
1973c2c66affSColin Finck     hres = IHTMLElement_click(submit);
1974c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1975c2c66affSColin Finck     CHECK_CALLED(form_onclick);
1976c2c66affSColin Finck     CHECK_CALLED(submit_onclick);
1977c2c66affSColin Finck 
1978c2c66affSColin Finck     elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
1979c2c66affSColin Finck 
1980c2c66affSColin Finck     SET_EXPECT(form_onclick);
1981c2c66affSColin Finck     SET_EXPECT(submit_onclick);
1982c2c66affSColin Finck     SET_EXPECT(submit_onclick_attached);
1983c2c66affSColin Finck     hres = IHTMLElement_click(submit);
1984c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1985c2c66affSColin Finck     CHECK_CALLED(form_onclick);
1986c2c66affSColin Finck     CHECK_CALLED(submit_onclick);
1987c2c66affSColin Finck     CHECK_CALLED(submit_onclick_attached);
1988c2c66affSColin Finck 
1989c2c66affSColin Finck     V_VT(&v) = VT_NULL;
1990c2c66affSColin Finck     hres = IHTMLElement_put_onclick(submit, v);
1991c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
1992c2c66affSColin Finck 
1993c2c66affSColin Finck     SET_EXPECT(form_onclick);
1994c2c66affSColin Finck     SET_EXPECT(submit_onclick_attached);
1995c2c66affSColin Finck     hres = IHTMLElement_click(submit);
1996c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
1997c2c66affSColin Finck     CHECK_CALLED(form_onclick);
1998c2c66affSColin Finck     CHECK_CALLED(submit_onclick_attached);
1999c2c66affSColin Finck 
2000c2c66affSColin Finck     elem_detach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2001c2c66affSColin Finck 
2002c2c66affSColin Finck     cp_cookie = register_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, (IUnknown*)&doccp_onclick_cancel_obj);
2003c2c66affSColin Finck 
2004c2c66affSColin Finck     SET_EXPECT(form_onclick);
2005c2c66affSColin Finck     SET_EXPECT(doccp_onclick_cancel);
2006c2c66affSColin Finck     hres = IHTMLElement_click(submit);
2007c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
2008c2c66affSColin Finck     CHECK_CALLED(form_onclick);
2009c2c66affSColin Finck     CHECK_CALLED(doccp_onclick_cancel);
2010c2c66affSColin Finck 
2011c2c66affSColin Finck     unregister_cp((IUnknown*)doc, &DIID_HTMLDocumentEvents, cp_cookie);
2012c2c66affSColin Finck 
2013c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
2014c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&submit_onclick_setret_obj;
2015c2c66affSColin Finck     hres = IHTMLElement_put_onclick(submit, v);
2016c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2017c2c66affSColin Finck 
2018c2c66affSColin Finck     V_VT(&onclick_retval) = VT_BOOL;
2019c2c66affSColin Finck     V_BOOL(&onclick_retval) = VARIANT_TRUE;
2020c2c66affSColin Finck     V_VT(&onclick_event_retval) = VT_BOOL;
2021c2c66affSColin Finck     V_BOOL(&onclick_event_retval) = VARIANT_TRUE;
2022c2c66affSColin Finck 
2023c2c66affSColin Finck     SET_EXPECT(submit_onclick_setret);
2024c2c66affSColin Finck     SET_EXPECT(form_onclick);
2025c2c66affSColin Finck     SET_EXPECT(form_onsubmit);
2026c2c66affSColin Finck     hres = IHTMLElement_click(submit);
2027c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
2028c2c66affSColin Finck     CHECK_CALLED(submit_onclick_setret);
2029c2c66affSColin Finck     CHECK_CALLED(form_onclick);
2030c2c66affSColin Finck     CHECK_CALLED(form_onsubmit);
2031c2c66affSColin Finck 
2032c2c66affSColin Finck     V_VT(&onclick_event_retval) = VT_BOOL;
2033c2c66affSColin Finck     V_BOOL(&onclick_event_retval) = VARIANT_FALSE;
2034c2c66affSColin Finck 
2035c2c66affSColin Finck     SET_EXPECT(submit_onclick_setret);
2036c2c66affSColin Finck     SET_EXPECT(form_onclick);
2037c2c66affSColin Finck     hres = IHTMLElement_click(submit);
2038c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
2039c2c66affSColin Finck     CHECK_CALLED(submit_onclick_setret);
2040c2c66affSColin Finck     CHECK_CALLED(form_onclick);
2041c2c66affSColin Finck 
2042c2c66affSColin Finck     V_VT(&onclick_retval) = VT_BOOL;
2043c2c66affSColin Finck     V_BOOL(&onclick_retval) = VARIANT_FALSE;
2044c2c66affSColin Finck     V_VT(&onclick_event_retval) = VT_BOOL;
2045c2c66affSColin Finck     V_BOOL(&onclick_event_retval) = VARIANT_TRUE;
2046c2c66affSColin Finck 
2047c2c66affSColin Finck     SET_EXPECT(submit_onclick_setret);
2048c2c66affSColin Finck     SET_EXPECT(form_onclick);
2049c2c66affSColin Finck     hres = IHTMLElement_click(submit);
2050c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
2051c2c66affSColin Finck     CHECK_CALLED(submit_onclick_setret);
2052c2c66affSColin Finck     CHECK_CALLED(form_onclick);
2053c2c66affSColin Finck 
2054c2c66affSColin Finck     V_VT(&onclick_event_retval) = VT_BOOL;
2055c2c66affSColin Finck     V_BOOL(&onclick_event_retval) = VARIANT_FALSE;
2056c2c66affSColin Finck 
2057c2c66affSColin Finck     SET_EXPECT(submit_onclick_setret);
2058c2c66affSColin Finck     SET_EXPECT(form_onclick);
2059c2c66affSColin Finck     hres = IHTMLElement_click(submit);
2060c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
2061c2c66affSColin Finck     CHECK_CALLED(submit_onclick_setret);
2062c2c66affSColin Finck     CHECK_CALLED(form_onclick);
2063c2c66affSColin Finck 
2064c2c66affSColin Finck     elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_obj);
2065c2c66affSColin Finck     elem_attach_event((IUnknown*)submit, "onclick", (IDispatch*)&submit_onclick_attached_check_cancel_obj);
2066c2c66affSColin Finck 
2067c2c66affSColin Finck     V_VT(&v) = VT_DISPATCH;
2068c2c66affSColin Finck     V_DISPATCH(&v) = (IDispatch*)&submit_onclick_cancel_obj;
2069c2c66affSColin Finck     hres = IHTMLElement_put_onclick(submit, v);
2070c2c66affSColin Finck     ok(hres == S_OK, "put_onclick failed: %08x\n", hres);
2071c2c66affSColin Finck 
2072c2c66affSColin Finck     SET_EXPECT(submit_onclick_cancel);
2073c2c66affSColin Finck     SET_EXPECT(submit_onclick_attached_check_cancel);
2074c2c66affSColin Finck     SET_EXPECT(submit_onclick_attached);
2075c2c66affSColin Finck     hres = IHTMLElement_click(submit);
2076c2c66affSColin Finck     ok(hres == S_OK, "click failed: %08x\n", hres);
2077c2c66affSColin Finck     CHECK_CALLED(submit_onclick_cancel);
2078c2c66affSColin Finck     CHECK_CALLED(submit_onclick_attached_check_cancel);
2079c2c66affSColin Finck     CHECK_CALLED(submit_onclick_attached);
2080c2c66affSColin Finck 
2081c2c66affSColin Finck     if(1)pump_msgs(NULL);
2082c2c66affSColin Finck 
2083c2c66affSColin Finck     IHTMLElement_Release(submit);
2084c2c66affSColin Finck }
2085c2c66affSColin Finck 
test_timeout(IHTMLDocument2 * doc)2086c2c66affSColin Finck static void test_timeout(IHTMLDocument2 *doc)
2087c2c66affSColin Finck {
2088c2c66affSColin Finck     IHTMLWindow3 *win3;
2089c2c66affSColin Finck     VARIANT expr, var;
2090c2c66affSColin Finck     LONG id;
2091c2c66affSColin Finck     HRESULT hres;
2092c2c66affSColin Finck 
2093c2c66affSColin Finck     hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLWindow3, (void**)&win3);
2094c2c66affSColin Finck     ok(hres == S_OK, "Could not get IHTMLWindow3 iface: %08x\n", hres);
2095c2c66affSColin Finck 
2096c2c66affSColin Finck     V_VT(&expr) = VT_DISPATCH;
2097c2c66affSColin Finck     V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2098c2c66affSColin Finck     V_VT(&var) = VT_EMPTY;
2099c2c66affSColin Finck     id = 0;
2100c2c66affSColin Finck     hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
2101c2c66affSColin Finck     ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
2102c2c66affSColin Finck     ok(id, "id = 0\n");
2103c2c66affSColin Finck 
2104c2c66affSColin Finck     SET_EXPECT(timeout);
2105c2c66affSColin Finck     pump_msgs(&called_timeout);
2106c2c66affSColin Finck     CHECK_CALLED(timeout);
2107c2c66affSColin Finck 
2108c2c66affSColin Finck     V_VT(&expr) = VT_DISPATCH;
2109c2c66affSColin Finck     V_DISPATCH(&expr) = (IDispatch*)&timeoutFunc;
2110c2c66affSColin Finck     V_VT(&var) = VT_EMPTY;
2111c2c66affSColin Finck     id = 0;
2112c2c66affSColin Finck     hres = IHTMLWindow3_setTimeout(win3, &expr, 0, &var, &id);
2113c2c66affSColin Finck     ok(hres == S_OK, "setTimeout failed: %08x\n", hres);
2114c2c66affSColin Finck     ok(id, "id = 0\n");
2115c2c66affSColin Finck 
2116c2c66affSColin Finck     hres = IHTMLWindow2_clearTimeout(window, id);
2117c2c66affSColin Finck     ok(hres == S_OK, "clearTimeout failed: %08x\n", hres);
2118c2c66affSColin Finck 
2119c2c66affSColin Finck     IHTMLWindow3_Release(win3);
2120c2c66affSColin Finck }
2121c2c66affSColin Finck 
find_element_by_id(IHTMLDocument2 * doc,const char * id)2122c2c66affSColin Finck static IHTMLElement* find_element_by_id(IHTMLDocument2 *doc, const char *id)
2123c2c66affSColin Finck {
2124c2c66affSColin Finck     HRESULT hres;
2125c2c66affSColin Finck     IHTMLDocument3 *doc3;
2126c2c66affSColin Finck     IHTMLElement *result;
2127c2c66affSColin Finck     BSTR idW = a2bstr(id);
2128c2c66affSColin Finck 
2129c2c66affSColin Finck     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
2130c2c66affSColin Finck     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
2131c2c66affSColin Finck 
2132c2c66affSColin Finck     hres = IHTMLDocument3_getElementById(doc3, idW, &result);
2133c2c66affSColin Finck     ok(hres == S_OK, "getElementById failed: %08x\n", hres);
2134c2c66affSColin Finck     ok(result != NULL, "result == NULL\n");
2135c2c66affSColin Finck     SysFreeString(idW);
2136c2c66affSColin Finck 
2137c2c66affSColin Finck     IHTMLDocument3_Release(doc3);
2138c2c66affSColin Finck     return result;
2139c2c66affSColin Finck }
2140c2c66affSColin Finck 
get_iframe_doc(IHTMLIFrameElement * iframe)2141c2c66affSColin Finck static IHTMLDocument2* get_iframe_doc(IHTMLIFrameElement *iframe)
2142c2c66affSColin Finck {
2143c2c66affSColin Finck     HRESULT hres;
2144c2c66affSColin Finck     IHTMLFrameBase2 *base;
2145c2c66affSColin Finck     IHTMLDocument2 *result = NULL;
2146c2c66affSColin Finck 
2147c2c66affSColin Finck     hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&base);
2148c2c66affSColin Finck     ok(hres == S_OK, "QueryInterface(IID_IHTMLFrameBase2) failed: %08x\n", hres);
2149c2c66affSColin Finck     if(hres == S_OK) {
2150c2c66affSColin Finck         IHTMLWindow2 *window;
2151c2c66affSColin Finck 
2152c2c66affSColin Finck         hres = IHTMLFrameBase2_get_contentWindow(base, &window);
2153c2c66affSColin Finck         ok(hres == S_OK, "get_contentWindow failed: %08x\n", hres);
2154c2c66affSColin Finck         ok(window != NULL, "window == NULL\n");
2155c2c66affSColin Finck         if(window) {
2156c2c66affSColin Finck             hres = IHTMLWindow2_get_document(window, &result);
2157c2c66affSColin Finck             ok(hres == S_OK, "get_document failed: %08x\n", hres);
2158c2c66affSColin Finck             ok(result != NULL, "result == NULL\n");
2159c2c66affSColin Finck             IHTMLWindow2_Release(window);
2160c2c66affSColin Finck         }
2161c2c66affSColin Finck     }
2162c2c66affSColin Finck     if(base) IHTMLFrameBase2_Release(base);
2163c2c66affSColin Finck 
2164c2c66affSColin Finck     return result;
2165c2c66affSColin Finck }
2166c2c66affSColin Finck 
test_iframe_connections(IHTMLDocument2 * doc)2167c2c66affSColin Finck static void test_iframe_connections(IHTMLDocument2 *doc)
2168c2c66affSColin Finck {
2169c2c66affSColin Finck     IHTMLIFrameElement *iframe;
2170c2c66affSColin Finck     IHTMLDocument2 *iframes_doc;
2171c2c66affSColin Finck     DWORD cookie;
2172c2c66affSColin Finck     IConnectionPoint *cp;
2173c2c66affSColin Finck     IHTMLElement *element;
2174c2c66affSColin Finck     BSTR str;
2175c2c66affSColin Finck     HRESULT hres;
2176c2c66affSColin Finck 
2177c2c66affSColin Finck     trace("iframe tests...\n");
2178c2c66affSColin Finck 
2179c2c66affSColin Finck     element = find_element_by_id(doc, "ifr");
2180c2c66affSColin Finck     iframe = get_iframe_iface((IUnknown*)element);
2181c2c66affSColin Finck     IHTMLElement_Release(element);
2182c2c66affSColin Finck 
2183c2c66affSColin Finck     iframes_doc = get_iframe_doc(iframe);
2184c2c66affSColin Finck     IHTMLIFrameElement_Release(iframe);
2185c2c66affSColin Finck 
2186c2c66affSColin Finck     cookie = register_cp((IUnknown*)iframes_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
2187c2c66affSColin Finck 
2188c2c66affSColin Finck     cp = get_cp((IUnknown*)doc, &IID_IDispatch);
2189c2c66affSColin Finck     hres = IConnectionPoint_Unadvise(cp, cookie);
2190c2c66affSColin Finck     IConnectionPoint_Release(cp);
2191c2c66affSColin Finck     ok(hres == CONNECT_E_NOCONNECTION, "Unadvise returned %08x, expected CONNECT_E_NOCONNECTION\n", hres);
2192c2c66affSColin Finck 
2193c2c66affSColin Finck     unregister_cp((IUnknown*)iframes_doc, &IID_IDispatch, cookie);
2194c2c66affSColin Finck 
2195c2c66affSColin Finck     if(is_ie9plus) {
2196c2c66affSColin Finck         IHTMLFrameBase2 *frame_base2;
2197c2c66affSColin Finck         VARIANT v;
2198c2c66affSColin Finck 
2199c2c66affSColin Finck         hres = IHTMLIFrameElement_QueryInterface(iframe, &IID_IHTMLFrameBase2, (void**)&frame_base2);
2200c2c66affSColin Finck         ok(hres == S_OK, "Could not get IHTMLFrameBase2 iface: %08x\n", hres);
2201c2c66affSColin Finck 
2202c2c66affSColin Finck         V_VT(&v) = VT_DISPATCH;
2203c2c66affSColin Finck         V_DISPATCH(&v) = (IDispatch*)&iframe_onload_obj;
2204c2c66affSColin Finck         hres = IHTMLFrameBase2_put_onload(frame_base2, v);
2205c2c66affSColin Finck         ok(hres == S_OK, "put_onload failed: %08x\n", hres);
2206c2c66affSColin Finck 
2207c2c66affSColin Finck         IHTMLFrameBase2_Release(frame_base2);
2208c2c66affSColin Finck 
2209c2c66affSColin Finck         str = a2bstr("about:blank");
2210c2c66affSColin Finck         hres = IHTMLDocument2_put_URL(iframes_doc, str);
2211c2c66affSColin Finck         ok(hres == S_OK, "put_URL failed: %08x\n", hres);
2212c2c66affSColin Finck         SysFreeString(str);
2213c2c66affSColin Finck 
2214c2c66affSColin Finck         SET_EXPECT(iframe_onload);
2215c2c66affSColin Finck         pump_msgs(&called_iframe_onload);
2216c2c66affSColin Finck         CHECK_CALLED(iframe_onload);
2217c2c66affSColin Finck 
2218c2c66affSColin Finck         str = a2bstr("about:test");
2219c2c66affSColin Finck         hres = IHTMLDocument2_put_URL(iframes_doc, str);
2220c2c66affSColin Finck         ok(hres == S_OK, "put_URL failed: %08x\n", hres);
2221c2c66affSColin Finck         SysFreeString(str);
2222c2c66affSColin Finck 
2223c2c66affSColin Finck         SET_EXPECT(iframe_onload);
2224c2c66affSColin Finck         pump_msgs(&called_iframe_onload);
2225c2c66affSColin Finck         CHECK_CALLED(iframe_onload);
2226c2c66affSColin Finck     }else {
2227c2c66affSColin Finck         win_skip("Skipping iframe onload tests on IE older than 9.\n");
2228c2c66affSColin Finck     }
2229c2c66affSColin Finck 
2230c2c66affSColin Finck     IHTMLDocument2_Release(iframes_doc);
2231c2c66affSColin Finck }
2232c2c66affSColin Finck 
2233c2c66affSColin Finck static HRESULT QueryInterface(REFIID,void**);
2234c2c66affSColin Finck 
InPlaceFrame_QueryInterface(IOleInPlaceFrame * iface,REFIID riid,void ** ppv)2235c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
2236c2c66affSColin Finck {
2237c2c66affSColin Finck     return E_NOINTERFACE;
2238c2c66affSColin Finck }
2239c2c66affSColin Finck 
InPlaceFrame_AddRef(IOleInPlaceFrame * iface)2240c2c66affSColin Finck static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
2241c2c66affSColin Finck {
2242c2c66affSColin Finck     return 2;
2243c2c66affSColin Finck }
2244c2c66affSColin Finck 
InPlaceFrame_Release(IOleInPlaceFrame * iface)2245c2c66affSColin Finck static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
2246c2c66affSColin Finck {
2247c2c66affSColin Finck     return 1;
2248c2c66affSColin Finck }
2249c2c66affSColin Finck 
InPlaceFrame_GetWindow(IOleInPlaceFrame * iface,HWND * phwnd)2250c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
2251c2c66affSColin Finck {
2252c2c66affSColin Finck     return E_NOTIMPL;
2253c2c66affSColin Finck }
2254c2c66affSColin Finck 
InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame * iface,BOOL fEnterMode)2255c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
2256c2c66affSColin Finck {
2257c2c66affSColin Finck     return E_NOTIMPL;
2258c2c66affSColin Finck }
2259c2c66affSColin Finck 
InPlaceFrame_GetBorder(IOleInPlaceFrame * iface,LPRECT lprectBorder)2260c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
2261c2c66affSColin Finck {
2262c2c66affSColin Finck     return E_NOTIMPL;
2263c2c66affSColin Finck }
2264c2c66affSColin Finck 
InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame * iface,LPCBORDERWIDTHS pborderwidths)2265c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
2266c2c66affSColin Finck         LPCBORDERWIDTHS pborderwidths)
2267c2c66affSColin Finck {
2268c2c66affSColin Finck     return E_NOTIMPL;
2269c2c66affSColin Finck }
2270c2c66affSColin Finck 
InPlaceFrame_SetBorderSpace(IOleInPlaceFrame * iface,LPCBORDERWIDTHS pborderwidths)2271c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
2272c2c66affSColin Finck         LPCBORDERWIDTHS pborderwidths)
2273c2c66affSColin Finck {
2274c2c66affSColin Finck     return S_OK;
2275c2c66affSColin Finck }
2276c2c66affSColin Finck 
InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame * iface,IOleInPlaceActiveObject * pActiveObject,LPCOLESTR pszObjName)2277c2c66affSColin Finck static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
2278c2c66affSColin Finck         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
2279c2c66affSColin Finck {
2280c2c66affSColin Finck     return S_OK;
2281c2c66affSColin Finck }
2282c2c66affSColin Finck 
InPlaceFrame_SetActiveObject(IOleInPlaceFrame * iface,IOleInPlaceActiveObject * pActiveObject,LPCOLESTR pszObjName)2283c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
2284c2c66affSColin Finck         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
2285c2c66affSColin Finck {
2286c2c66affSColin Finck     return S_OK;
2287c2c66affSColin Finck }
2288c2c66affSColin Finck 
InPlaceFrame_InsertMenus(IOleInPlaceFrame * iface,HMENU hmenuShared,LPOLEMENUGROUPWIDTHS lpMenuWidths)2289c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
2290c2c66affSColin Finck         LPOLEMENUGROUPWIDTHS lpMenuWidths)
2291c2c66affSColin Finck {
2292c2c66affSColin Finck     return E_NOTIMPL;
2293c2c66affSColin Finck }
2294c2c66affSColin Finck 
InPlaceFrame_SetMenu(IOleInPlaceFrame * iface,HMENU hmenuShared,HOLEMENU holemenu,HWND hwndActiveObject)2295c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
2296c2c66affSColin Finck         HOLEMENU holemenu, HWND hwndActiveObject)
2297c2c66affSColin Finck {
2298c2c66affSColin Finck     ok(0, "unexpected call\n");
2299c2c66affSColin Finck     return E_NOTIMPL;
2300c2c66affSColin Finck }
2301c2c66affSColin Finck 
InPlaceFrame_RemoveMenus(IOleInPlaceFrame * iface,HMENU hmenuShared)2302c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
2303c2c66affSColin Finck {
2304c2c66affSColin Finck     ok(0, "unexpected call\n");
2305c2c66affSColin Finck     return E_NOTIMPL;
2306c2c66affSColin Finck }
2307c2c66affSColin Finck 
InPlaceFrame_SetStatusText(IOleInPlaceFrame * iface,LPCOLESTR pszStatusText)2308c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
2309c2c66affSColin Finck {
2310c2c66affSColin Finck     return S_OK;
2311c2c66affSColin Finck }
2312c2c66affSColin Finck 
InPlaceFrame_EnableModeless(IOleInPlaceFrame * iface,BOOL fEnable)2313c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
2314c2c66affSColin Finck {
2315c2c66affSColin Finck     return E_NOTIMPL;
2316c2c66affSColin Finck }
2317c2c66affSColin Finck 
InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame * iface,LPMSG lpmsg,WORD wID)2318c2c66affSColin Finck static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
2319c2c66affSColin Finck {
2320c2c66affSColin Finck     ok(0, "unexpected call\n");
2321c2c66affSColin Finck     return E_NOTIMPL;
2322c2c66affSColin Finck }
2323c2c66affSColin Finck 
2324c2c66affSColin Finck static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
2325c2c66affSColin Finck     InPlaceFrame_QueryInterface,
2326c2c66affSColin Finck     InPlaceFrame_AddRef,
2327c2c66affSColin Finck     InPlaceFrame_Release,
2328c2c66affSColin Finck     InPlaceFrame_GetWindow,
2329c2c66affSColin Finck     InPlaceFrame_ContextSensitiveHelp,
2330c2c66affSColin Finck     InPlaceFrame_GetBorder,
2331c2c66affSColin Finck     InPlaceFrame_RequestBorderSpace,
2332c2c66affSColin Finck     InPlaceFrame_SetBorderSpace,
2333c2c66affSColin Finck     InPlaceFrame_SetActiveObject,
2334c2c66affSColin Finck     InPlaceFrame_InsertMenus,
2335c2c66affSColin Finck     InPlaceFrame_SetMenu,
2336c2c66affSColin Finck     InPlaceFrame_RemoveMenus,
2337c2c66affSColin Finck     InPlaceFrame_SetStatusText,
2338c2c66affSColin Finck     InPlaceFrame_EnableModeless,
2339c2c66affSColin Finck     InPlaceFrame_TranslateAccelerator
2340c2c66affSColin Finck };
2341c2c66affSColin Finck 
2342c2c66affSColin Finck static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
2343c2c66affSColin Finck 
2344c2c66affSColin Finck static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
2345c2c66affSColin Finck     InPlaceFrame_QueryInterface,
2346c2c66affSColin Finck     InPlaceFrame_AddRef,
2347c2c66affSColin Finck     InPlaceFrame_Release,
2348c2c66affSColin Finck     InPlaceFrame_GetWindow,
2349c2c66affSColin Finck     InPlaceFrame_ContextSensitiveHelp,
2350c2c66affSColin Finck     InPlaceFrame_GetBorder,
2351c2c66affSColin Finck     InPlaceFrame_RequestBorderSpace,
2352c2c66affSColin Finck     InPlaceFrame_SetBorderSpace,
2353c2c66affSColin Finck     InPlaceUIWindow_SetActiveObject,
2354c2c66affSColin Finck };
2355c2c66affSColin Finck 
2356c2c66affSColin Finck static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
2357c2c66affSColin Finck 
InPlaceSite_QueryInterface(IOleInPlaceSite * iface,REFIID riid,void ** ppv)2358c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
2359c2c66affSColin Finck {
2360c2c66affSColin Finck     return QueryInterface(riid, ppv);
2361c2c66affSColin Finck }
2362c2c66affSColin Finck 
InPlaceSite_AddRef(IOleInPlaceSite * iface)2363c2c66affSColin Finck static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
2364c2c66affSColin Finck {
2365c2c66affSColin Finck     return 2;
2366c2c66affSColin Finck }
2367c2c66affSColin Finck 
InPlaceSite_Release(IOleInPlaceSite * iface)2368c2c66affSColin Finck static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
2369c2c66affSColin Finck {
2370c2c66affSColin Finck     return 1;
2371c2c66affSColin Finck }
2372c2c66affSColin Finck 
InPlaceSite_GetWindow(IOleInPlaceSite * iface,HWND * phwnd)2373c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
2374c2c66affSColin Finck {
2375c2c66affSColin Finck     *phwnd = container_hwnd;
2376c2c66affSColin Finck     return S_OK;
2377c2c66affSColin Finck }
2378c2c66affSColin Finck 
InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite * iface,BOOL fEnterMode)2379c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
2380c2c66affSColin Finck {
2381c2c66affSColin Finck     ok(0, "unexpected call\n");
2382c2c66affSColin Finck     return E_NOTIMPL;
2383c2c66affSColin Finck }
2384c2c66affSColin Finck 
InPlaceSite_CanInPlaceActivate(IOleInPlaceSite * iface)2385c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
2386c2c66affSColin Finck {
2387c2c66affSColin Finck     return S_OK;
2388c2c66affSColin Finck }
2389c2c66affSColin Finck 
InPlaceSite_OnInPlaceActivate(IOleInPlaceSite * iface)2390c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
2391c2c66affSColin Finck {
2392c2c66affSColin Finck     return S_OK;
2393c2c66affSColin Finck }
2394c2c66affSColin Finck 
InPlaceSite_OnUIActivate(IOleInPlaceSite * iface)2395c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
2396c2c66affSColin Finck {
2397c2c66affSColin Finck     return S_OK;
2398c2c66affSColin Finck }
2399c2c66affSColin Finck 
InPlaceSite_GetWindowContext(IOleInPlaceSite * iface,IOleInPlaceFrame ** ppFrame,IOleInPlaceUIWindow ** ppDoc,LPRECT lprcPosRect,LPRECT lprcClipRect,LPOLEINPLACEFRAMEINFO lpFrameInfo)2400c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
2401c2c66affSColin Finck         IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
2402c2c66affSColin Finck         LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
2403c2c66affSColin Finck {
2404c2c66affSColin Finck     static const RECT rect = {0,0,300,300};
2405c2c66affSColin Finck 
2406c2c66affSColin Finck     *ppFrame = &InPlaceFrame;
2407c2c66affSColin Finck     *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
2408c2c66affSColin Finck     *lprcPosRect = rect;
2409c2c66affSColin Finck     *lprcClipRect = rect;
2410c2c66affSColin Finck 
2411c2c66affSColin Finck     ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
2412c2c66affSColin Finck     lpFrameInfo->fMDIApp = FALSE;
2413c2c66affSColin Finck     lpFrameInfo->hwndFrame = container_hwnd;
2414c2c66affSColin Finck     lpFrameInfo->haccel = NULL;
2415c2c66affSColin Finck     lpFrameInfo->cAccelEntries = 0;
2416c2c66affSColin Finck 
2417c2c66affSColin Finck     return S_OK;
2418c2c66affSColin Finck }
2419c2c66affSColin Finck 
InPlaceSite_Scroll(IOleInPlaceSite * iface,SIZE scrollExtant)2420c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
2421c2c66affSColin Finck {
2422c2c66affSColin Finck     return E_NOTIMPL;
2423c2c66affSColin Finck }
2424c2c66affSColin Finck 
InPlaceSite_OnUIDeactivate(IOleInPlaceSite * iface,BOOL fUndoable)2425c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
2426c2c66affSColin Finck {
2427c2c66affSColin Finck     return S_OK;
2428c2c66affSColin Finck }
2429c2c66affSColin Finck 
InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite * iface)2430c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
2431c2c66affSColin Finck {
2432c2c66affSColin Finck     return S_OK;
2433c2c66affSColin Finck }
2434c2c66affSColin Finck 
InPlaceSite_DiscardUndoState(IOleInPlaceSite * iface)2435c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
2436c2c66affSColin Finck {
2437c2c66affSColin Finck     return E_NOTIMPL;
2438c2c66affSColin Finck }
2439c2c66affSColin Finck 
InPlaceSite_DeactivateAndUndo(IOleInPlaceSite * iface)2440c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
2441c2c66affSColin Finck {
2442c2c66affSColin Finck     return E_NOTIMPL;
2443c2c66affSColin Finck }
2444c2c66affSColin Finck 
InPlaceSite_OnPosRectChange(IOleInPlaceSite * iface,LPCRECT lprcPosRect)2445c2c66affSColin Finck static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
2446c2c66affSColin Finck {
2447c2c66affSColin Finck     return E_NOTIMPL;
2448c2c66affSColin Finck }
2449c2c66affSColin Finck 
2450c2c66affSColin Finck static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
2451c2c66affSColin Finck     InPlaceSite_QueryInterface,
2452c2c66affSColin Finck     InPlaceSite_AddRef,
2453c2c66affSColin Finck     InPlaceSite_Release,
2454c2c66affSColin Finck     InPlaceSite_GetWindow,
2455c2c66affSColin Finck     InPlaceSite_ContextSensitiveHelp,
2456c2c66affSColin Finck     InPlaceSite_CanInPlaceActivate,
2457c2c66affSColin Finck     InPlaceSite_OnInPlaceActivate,
2458c2c66affSColin Finck     InPlaceSite_OnUIActivate,
2459c2c66affSColin Finck     InPlaceSite_GetWindowContext,
2460c2c66affSColin Finck     InPlaceSite_Scroll,
2461c2c66affSColin Finck     InPlaceSite_OnUIDeactivate,
2462c2c66affSColin Finck     InPlaceSite_OnInPlaceDeactivate,
2463c2c66affSColin Finck     InPlaceSite_DiscardUndoState,
2464c2c66affSColin Finck     InPlaceSite_DeactivateAndUndo,
2465c2c66affSColin Finck     InPlaceSite_OnPosRectChange,
2466c2c66affSColin Finck };
2467c2c66affSColin Finck 
2468c2c66affSColin Finck static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
2469c2c66affSColin Finck 
ClientSite_QueryInterface(IOleClientSite * iface,REFIID riid,void ** ppv)2470c2c66affSColin Finck static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
2471c2c66affSColin Finck {
2472c2c66affSColin Finck     return QueryInterface(riid, ppv);
2473c2c66affSColin Finck }
2474c2c66affSColin Finck 
ClientSite_AddRef(IOleClientSite * iface)2475c2c66affSColin Finck static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
2476c2c66affSColin Finck {
2477c2c66affSColin Finck     return 2;
2478c2c66affSColin Finck }
2479c2c66affSColin Finck 
ClientSite_Release(IOleClientSite * iface)2480c2c66affSColin Finck static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
2481c2c66affSColin Finck {
2482c2c66affSColin Finck     return 1;
2483c2c66affSColin Finck }
2484c2c66affSColin Finck 
ClientSite_SaveObject(IOleClientSite * iface)2485c2c66affSColin Finck static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
2486c2c66affSColin Finck {
2487c2c66affSColin Finck     ok(0, "unexpected call\n");
2488c2c66affSColin Finck     return E_NOTIMPL;
2489c2c66affSColin Finck }
2490c2c66affSColin Finck 
ClientSite_GetMoniker(IOleClientSite * iface,DWORD dwAssign,DWORD dwWhichMoniker,IMoniker ** ppmon)2491c2c66affSColin Finck static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
2492c2c66affSColin Finck         IMoniker **ppmon)
2493c2c66affSColin Finck {
2494c2c66affSColin Finck     ok(0, "unexpected call\n");
2495c2c66affSColin Finck     return E_NOTIMPL;
2496c2c66affSColin Finck }
2497c2c66affSColin Finck 
ClientSite_GetContainer(IOleClientSite * iface,IOleContainer ** ppContainer)2498c2c66affSColin Finck static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
2499c2c66affSColin Finck {
2500c2c66affSColin Finck     return E_NOTIMPL;
2501c2c66affSColin Finck }
2502c2c66affSColin Finck 
ClientSite_ShowObject(IOleClientSite * iface)2503c2c66affSColin Finck static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
2504c2c66affSColin Finck {
2505c2c66affSColin Finck     ok(0, "unexpected call\n");
2506c2c66affSColin Finck     return E_NOTIMPL;
2507c2c66affSColin Finck }
2508c2c66affSColin Finck 
ClientSite_OnShowWindow(IOleClientSite * iface,BOOL fShow)2509c2c66affSColin Finck static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
2510c2c66affSColin Finck {
2511c2c66affSColin Finck     ok(0, "unexpected call\n");
2512c2c66affSColin Finck     return E_NOTIMPL;
2513c2c66affSColin Finck }
2514c2c66affSColin Finck 
ClientSite_RequestNewObjectLayout(IOleClientSite * iface)2515c2c66affSColin Finck static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
2516c2c66affSColin Finck {
2517c2c66affSColin Finck     ok(0, "unexpected call\n");
2518c2c66affSColin Finck     return E_NOTIMPL;
2519c2c66affSColin Finck }
2520c2c66affSColin Finck 
2521c2c66affSColin Finck static const IOleClientSiteVtbl ClientSiteVtbl = {
2522c2c66affSColin Finck     ClientSite_QueryInterface,
2523c2c66affSColin Finck     ClientSite_AddRef,
2524c2c66affSColin Finck     ClientSite_Release,
2525c2c66affSColin Finck     ClientSite_SaveObject,
2526c2c66affSColin Finck     ClientSite_GetMoniker,
2527c2c66affSColin Finck     ClientSite_GetContainer,
2528c2c66affSColin Finck     ClientSite_ShowObject,
2529c2c66affSColin Finck     ClientSite_OnShowWindow,
2530c2c66affSColin Finck     ClientSite_RequestNewObjectLayout
2531c2c66affSColin Finck };
2532c2c66affSColin Finck 
2533c2c66affSColin Finck static IOleClientSite ClientSite = { &ClientSiteVtbl };
2534c2c66affSColin Finck 
DocumentSite_QueryInterface(IOleDocumentSite * iface,REFIID riid,void ** ppv)2535c2c66affSColin Finck static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
2536c2c66affSColin Finck {
2537c2c66affSColin Finck     return QueryInterface(riid, ppv);
2538c2c66affSColin Finck }
2539c2c66affSColin Finck 
DocumentSite_AddRef(IOleDocumentSite * iface)2540c2c66affSColin Finck static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
2541c2c66affSColin Finck {
2542c2c66affSColin Finck     return 2;
2543c2c66affSColin Finck }
2544c2c66affSColin Finck 
DocumentSite_Release(IOleDocumentSite * iface)2545c2c66affSColin Finck static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
2546c2c66affSColin Finck {
2547c2c66affSColin Finck     return 1;
2548c2c66affSColin Finck }
2549c2c66affSColin Finck 
DocumentSite_ActivateMe(IOleDocumentSite * iface,IOleDocumentView * pViewToActivate)2550c2c66affSColin Finck static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
2551c2c66affSColin Finck {
2552c2c66affSColin Finck     RECT rect = {0,0,300,300};
2553c2c66affSColin Finck     IOleDocument *document;
2554c2c66affSColin Finck     HRESULT hres;
2555c2c66affSColin Finck 
2556c2c66affSColin Finck     hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
2557c2c66affSColin Finck     ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
2558c2c66affSColin Finck 
2559c2c66affSColin Finck     hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
2560c2c66affSColin Finck     IOleDocument_Release(document);
2561c2c66affSColin Finck     ok(hres == S_OK, "CreateView failed: %08x\n", hres);
2562c2c66affSColin Finck 
2563c2c66affSColin Finck     hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
2564c2c66affSColin Finck     ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
2565c2c66affSColin Finck 
2566c2c66affSColin Finck     hres = IOleDocumentView_UIActivate(view, TRUE);
2567c2c66affSColin Finck     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
2568c2c66affSColin Finck 
2569c2c66affSColin Finck     hres = IOleDocumentView_SetRect(view, &rect);
2570c2c66affSColin Finck     ok(hres == S_OK, "SetRect failed: %08x\n", hres);
2571c2c66affSColin Finck 
2572c2c66affSColin Finck     hres = IOleDocumentView_Show(view, TRUE);
2573c2c66affSColin Finck     ok(hres == S_OK, "Show failed: %08x\n", hres);
2574c2c66affSColin Finck 
2575c2c66affSColin Finck     return S_OK;
2576c2c66affSColin Finck }
2577c2c66affSColin Finck 
2578c2c66affSColin Finck static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
2579c2c66affSColin Finck     DocumentSite_QueryInterface,
2580c2c66affSColin Finck     DocumentSite_AddRef,
2581c2c66affSColin Finck     DocumentSite_Release,
2582c2c66affSColin Finck     DocumentSite_ActivateMe
2583c2c66affSColin Finck };
2584c2c66affSColin Finck 
2585c2c66affSColin Finck static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
2586c2c66affSColin Finck 
QueryInterface(REFIID riid,void ** ppv)2587c2c66affSColin Finck static HRESULT QueryInterface(REFIID riid, void **ppv)
2588c2c66affSColin Finck {
2589c2c66affSColin Finck     *ppv = NULL;
2590c2c66affSColin Finck 
2591c2c66affSColin Finck     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
2592c2c66affSColin Finck         *ppv = &ClientSite;
2593c2c66affSColin Finck     else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
2594c2c66affSColin Finck         *ppv = &DocumentSite;
2595c2c66affSColin Finck     else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
2596c2c66affSColin Finck         *ppv = &InPlaceSite;
2597c2c66affSColin Finck 
2598c2c66affSColin Finck     return *ppv ? S_OK : E_NOINTERFACE;
2599c2c66affSColin Finck }
2600c2c66affSColin Finck 
2601c2c66affSColin Finck static IHTMLDocument2 *notif_doc;
2602c2c66affSColin Finck static BOOL doc_complete;
2603c2c66affSColin Finck 
PropertyNotifySink_QueryInterface(IPropertyNotifySink * iface,REFIID riid,void ** ppv)2604c2c66affSColin Finck static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
2605c2c66affSColin Finck         REFIID riid, void**ppv)
2606c2c66affSColin Finck {
2607c2c66affSColin Finck     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2608c2c66affSColin Finck         *ppv = iface;
2609c2c66affSColin Finck         return S_OK;
2610c2c66affSColin Finck     }
2611c2c66affSColin Finck 
2612c2c66affSColin Finck     ok(0, "unexpected call\n");
2613c2c66affSColin Finck     return E_NOINTERFACE;
2614c2c66affSColin Finck }
2615c2c66affSColin Finck 
PropertyNotifySink_AddRef(IPropertyNotifySink * iface)2616c2c66affSColin Finck static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
2617c2c66affSColin Finck {
2618c2c66affSColin Finck     return 2;
2619c2c66affSColin Finck }
2620c2c66affSColin Finck 
PropertyNotifySink_Release(IPropertyNotifySink * iface)2621c2c66affSColin Finck static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
2622c2c66affSColin Finck {
2623c2c66affSColin Finck     return 1;
2624c2c66affSColin Finck }
2625c2c66affSColin Finck 
PropertyNotifySink_OnChanged(IPropertyNotifySink * iface,DISPID dispID)2626c2c66affSColin Finck static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
2627c2c66affSColin Finck {
2628c2c66affSColin Finck     if(dispID == DISPID_READYSTATE){
2629c2c66affSColin Finck         BSTR state;
2630c2c66affSColin Finck         HRESULT hres;
2631c2c66affSColin Finck 
2632c2c66affSColin Finck         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
2633c2c66affSColin Finck         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2634c2c66affSColin Finck 
2635c2c66affSColin Finck         if(!strcmp_wa(state, "complete"))
2636c2c66affSColin Finck             doc_complete = TRUE;
2637c2c66affSColin Finck 
2638c2c66affSColin Finck         SysFreeString(state);
2639c2c66affSColin Finck     }
2640c2c66affSColin Finck 
2641c2c66affSColin Finck     return S_OK;
2642c2c66affSColin Finck }
2643c2c66affSColin Finck 
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink * iface,DISPID dispID)2644c2c66affSColin Finck static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
2645c2c66affSColin Finck {
2646c2c66affSColin Finck     ok(0, "unexpected call\n");
2647c2c66affSColin Finck     return E_NOTIMPL;
2648c2c66affSColin Finck }
2649c2c66affSColin Finck 
2650c2c66affSColin Finck static const IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
2651c2c66affSColin Finck     PropertyNotifySink_QueryInterface,
2652c2c66affSColin Finck     PropertyNotifySink_AddRef,
2653c2c66affSColin Finck     PropertyNotifySink_Release,
2654c2c66affSColin Finck     PropertyNotifySink_OnChanged,
2655c2c66affSColin Finck     PropertyNotifySink_OnRequestEdit
2656c2c66affSColin Finck };
2657c2c66affSColin Finck 
2658c2c66affSColin Finck static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
2659c2c66affSColin Finck 
doc_load_string(IHTMLDocument2 * doc,const char * str)2660c2c66affSColin Finck static void doc_load_string(IHTMLDocument2 *doc, const char *str)
2661c2c66affSColin Finck {
2662c2c66affSColin Finck     IPersistStreamInit *init;
2663c2c66affSColin Finck     IStream *stream;
2664c2c66affSColin Finck     HGLOBAL mem;
2665c2c66affSColin Finck     SIZE_T len;
2666c2c66affSColin Finck 
2667c2c66affSColin Finck     notif_doc = doc;
2668c2c66affSColin Finck 
2669c2c66affSColin Finck     doc_complete = FALSE;
2670c2c66affSColin Finck     len = strlen(str);
2671c2c66affSColin Finck     mem = GlobalAlloc(0, len);
2672c2c66affSColin Finck     memcpy(mem, str, len);
2673c2c66affSColin Finck     CreateStreamOnHGlobal(mem, TRUE, &stream);
2674c2c66affSColin Finck 
2675c2c66affSColin Finck     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
2676c2c66affSColin Finck 
2677c2c66affSColin Finck     IPersistStreamInit_Load(init, stream);
2678c2c66affSColin Finck     IPersistStreamInit_Release(init);
2679c2c66affSColin Finck     IStream_Release(stream);
2680c2c66affSColin Finck }
2681c2c66affSColin Finck 
do_advise(IUnknown * unk,REFIID riid,IUnknown * unk_advise)2682c2c66affSColin Finck static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
2683c2c66affSColin Finck {
2684c2c66affSColin Finck     IConnectionPointContainer *container;
2685c2c66affSColin Finck     IConnectionPoint *cp;
2686c2c66affSColin Finck     DWORD cookie;
2687c2c66affSColin Finck     HRESULT hres;
2688c2c66affSColin Finck 
2689c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2690c2c66affSColin Finck     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2691c2c66affSColin Finck 
2692c2c66affSColin Finck     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2693c2c66affSColin Finck     IConnectionPointContainer_Release(container);
2694c2c66affSColin Finck     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2695c2c66affSColin Finck 
2696c2c66affSColin Finck     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
2697c2c66affSColin Finck     IConnectionPoint_Release(cp);
2698c2c66affSColin Finck     ok(hres == S_OK, "Advise failed: %08x\n", hres);
2699c2c66affSColin Finck }
2700c2c66affSColin Finck 
set_client_site(IHTMLDocument2 * doc,BOOL set)2701c2c66affSColin Finck static void set_client_site(IHTMLDocument2 *doc, BOOL set)
2702c2c66affSColin Finck {
2703c2c66affSColin Finck     IOleObject *oleobj;
2704c2c66affSColin Finck     HRESULT hres;
2705c2c66affSColin Finck 
2706c2c66affSColin Finck     if(!set && view) {
2707c2c66affSColin Finck         IOleDocumentView_Show(view, FALSE);
2708c2c66affSColin Finck         IOleDocumentView_CloseView(view, 0);
2709c2c66affSColin Finck         IOleDocumentView_SetInPlaceSite(view, NULL);
2710c2c66affSColin Finck         IOleDocumentView_Release(view);
2711c2c66affSColin Finck         view = NULL;
2712c2c66affSColin Finck     }
2713c2c66affSColin Finck 
2714c2c66affSColin Finck     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
2715c2c66affSColin Finck     ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
2716c2c66affSColin Finck 
2717c2c66affSColin Finck     hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
2718c2c66affSColin Finck     ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
2719c2c66affSColin Finck 
2720c2c66affSColin Finck     if(set) {
2721c2c66affSColin Finck         IHlinkTarget *hlink;
2722c2c66affSColin Finck 
2723c2c66affSColin Finck         hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
2724c2c66affSColin Finck         ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
2725c2c66affSColin Finck 
2726c2c66affSColin Finck         hres = IHlinkTarget_Navigate(hlink, 0, NULL);
2727c2c66affSColin Finck         ok(hres == S_OK, "Navgate failed: %08x\n", hres);
2728c2c66affSColin Finck 
2729c2c66affSColin Finck         IHlinkTarget_Release(hlink);
2730c2c66affSColin Finck     }
2731c2c66affSColin Finck 
2732c2c66affSColin Finck     IOleObject_Release(oleobj);
2733c2c66affSColin Finck }
create_document(void)2734c2c66affSColin Finck static IHTMLDocument2 *create_document(void)
2735c2c66affSColin Finck {
2736c2c66affSColin Finck     IHTMLDocument2 *doc;
2737c2c66affSColin Finck     HRESULT hres;
2738c2c66affSColin Finck 
2739c2c66affSColin Finck     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
2740c2c66affSColin Finck             &IID_IHTMLDocument2, (void**)&doc);
2741c2c66affSColin Finck     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
2742c2c66affSColin Finck     return SUCCEEDED(hres) ? doc : NULL;
2743c2c66affSColin Finck }
2744c2c66affSColin Finck 
2745c2c66affSColin Finck 
2746c2c66affSColin Finck typedef void (*testfunc_t)(IHTMLDocument2*);
2747c2c66affSColin Finck 
run_test(const char * str,testfunc_t test)2748c2c66affSColin Finck static void run_test(const char *str, testfunc_t test)
2749c2c66affSColin Finck {
2750c2c66affSColin Finck     IHTMLDocument2 *doc;
2751c2c66affSColin Finck     IHTMLElement *body = NULL;
2752c2c66affSColin Finck     MSG msg;
2753c2c66affSColin Finck     HRESULT hres;
2754c2c66affSColin Finck 
2755c2c66affSColin Finck     doc = create_document();
2756c2c66affSColin Finck     if (!doc)
2757c2c66affSColin Finck         return;
2758c2c66affSColin Finck     set_client_site(doc, TRUE);
2759c2c66affSColin Finck     doc_load_string(doc, str);
2760c2c66affSColin Finck     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2761c2c66affSColin Finck 
2762c2c66affSColin Finck     while(!doc_complete && GetMessageA(&msg, NULL, 0, 0)) {
2763c2c66affSColin Finck         TranslateMessage(&msg);
2764c2c66affSColin Finck         DispatchMessageA(&msg);
2765c2c66affSColin Finck     }
2766c2c66affSColin Finck 
2767c2c66affSColin Finck     hres = IHTMLDocument2_get_body(doc, &body);
2768c2c66affSColin Finck     ok(hres == S_OK, "get_body failed: %08x\n", hres);
2769c2c66affSColin Finck 
2770c2c66affSColin Finck     if(body) {
2771c2c66affSColin Finck         IHTMLElement_Release(body);
2772c2c66affSColin Finck 
2773c2c66affSColin Finck         hres = IHTMLDocument2_get_parentWindow(doc, &window);
2774c2c66affSColin Finck         ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2775c2c66affSColin Finck         ok(window != NULL, "window == NULL\n");
2776c2c66affSColin Finck 
2777c2c66affSColin Finck         test(doc);
2778c2c66affSColin Finck 
2779c2c66affSColin Finck         IHTMLWindow2_Release(window);
2780c2c66affSColin Finck         window = NULL;
2781c2c66affSColin Finck     }else {
2782c2c66affSColin Finck         skip("Could not get document body. Assuming no Gecko installed.\n");
2783c2c66affSColin Finck     }
2784c2c66affSColin Finck 
2785c2c66affSColin Finck     set_client_site(doc, FALSE);
2786c2c66affSColin Finck     IHTMLDocument2_Release(doc);
2787c2c66affSColin Finck }
2788c2c66affSColin Finck 
wnd_proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)2789c2c66affSColin Finck static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2790c2c66affSColin Finck {
2791c2c66affSColin Finck     return DefWindowProcA(hwnd, msg, wParam, lParam);
2792c2c66affSColin Finck }
2793c2c66affSColin Finck 
create_container_window(void)2794c2c66affSColin Finck static HWND create_container_window(void)
2795c2c66affSColin Finck {
2796c2c66affSColin Finck     static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
2797c2c66affSColin Finck     static WNDCLASSEXA wndclass = {
2798c2c66affSColin Finck         sizeof(WNDCLASSEXA),
2799c2c66affSColin Finck         0,
2800c2c66affSColin Finck         wnd_proc,
2801c2c66affSColin Finck         0, 0, NULL, NULL, NULL, NULL, NULL,
2802c2c66affSColin Finck         szHTMLDocumentTest,
2803c2c66affSColin Finck         NULL
2804c2c66affSColin Finck     };
2805c2c66affSColin Finck 
2806c2c66affSColin Finck     RegisterClassExA(&wndclass);
2807c2c66affSColin Finck     return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
2808c2c66affSColin Finck             WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
2809c2c66affSColin Finck             300, 300, NULL, NULL, NULL, NULL);
2810c2c66affSColin Finck }
2811c2c66affSColin Finck 
test_empty_document(void)2812c2c66affSColin Finck static void test_empty_document(void)
2813c2c66affSColin Finck {
2814c2c66affSColin Finck     HRESULT hres;
2815c2c66affSColin Finck     IHTMLWindow2 *window;
2816c2c66affSColin Finck     IHTMLDocument2 *windows_doc, *doc;
2817c2c66affSColin Finck     IConnectionPoint *cp;
2818c2c66affSColin Finck     DWORD cookie;
2819c2c66affSColin Finck 
2820c2c66affSColin Finck     doc = create_document();
2821c2c66affSColin Finck     if(!doc)
2822c2c66affSColin Finck         return;
2823c2c66affSColin Finck 
2824c2c66affSColin Finck     hres = IHTMLDocument2_get_parentWindow(doc, &window);
2825c2c66affSColin Finck     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2826c2c66affSColin Finck 
2827c2c66affSColin Finck     hres = IHTMLWindow2_get_document(window, &windows_doc);
2828c2c66affSColin Finck     IHTMLWindow2_Release(window);
2829c2c66affSColin Finck     ok(hres == S_OK, "get_document failed: %08x\n", hres);
2830c2c66affSColin Finck 
2831c2c66affSColin Finck     cookie = register_cp((IUnknown*)windows_doc, &IID_IDispatch, (IUnknown*)&div_onclick_disp);
2832c2c66affSColin Finck 
2833c2c66affSColin Finck     cp = get_cp((IUnknown*)doc, &IID_IDispatch);
2834c2c66affSColin Finck     hres = IConnectionPoint_Unadvise(cp, cookie);
2835c2c66affSColin Finck     IConnectionPoint_Release(cp);
2836c2c66affSColin Finck     ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
2837c2c66affSColin Finck 
2838c2c66affSColin Finck     IHTMLDocument2_Release(windows_doc);
2839c2c66affSColin Finck     IHTMLDocument2_Release(doc);
2840c2c66affSColin Finck }
2841c2c66affSColin Finck 
check_ie(void)2842c2c66affSColin Finck static BOOL check_ie(void)
2843c2c66affSColin Finck {
2844c2c66affSColin Finck     IHTMLDocument2 *doc;
2845c2c66affSColin Finck     IHTMLDocument5 *doc5;
2846c2c66affSColin Finck     IHTMLDocument7 *doc7;
2847c2c66affSColin Finck     HRESULT hres;
2848c2c66affSColin Finck 
2849c2c66affSColin Finck     doc = create_document();
2850c2c66affSColin Finck     if(!doc)
2851c2c66affSColin Finck         return FALSE;
2852c2c66affSColin Finck 
2853c2c66affSColin Finck     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument7, (void**)&doc7);
2854c2c66affSColin Finck     if(SUCCEEDED(hres)) {
2855c2c66affSColin Finck         is_ie9plus = TRUE;
2856c2c66affSColin Finck         IHTMLDocument7_Release(doc7);
2857c2c66affSColin Finck     }
2858c2c66affSColin Finck 
2859c2c66affSColin Finck     trace("is_ie9plus %x\n", is_ie9plus);
2860c2c66affSColin Finck 
2861c2c66affSColin Finck     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
2862c2c66affSColin Finck     if(SUCCEEDED(hres))
2863c2c66affSColin Finck         IHTMLDocument5_Release(doc5);
2864c2c66affSColin Finck 
2865c2c66affSColin Finck     IHTMLDocument2_Release(doc);
2866c2c66affSColin Finck     return SUCCEEDED(hres);
2867c2c66affSColin Finck }
2868c2c66affSColin Finck 
START_TEST(events)2869c2c66affSColin Finck START_TEST(events)
2870c2c66affSColin Finck {
2871c2c66affSColin Finck     CoInitialize(NULL);
2872c2c66affSColin Finck 
2873c2c66affSColin Finck     if(check_ie()) {
2874c2c66affSColin Finck         container_hwnd = create_container_window();
2875c2c66affSColin Finck 
2876c2c66affSColin Finck         if(winetest_interactive)
2877c2c66affSColin Finck             ShowWindow(container_hwnd, SW_SHOW);
2878c2c66affSColin Finck 
2879c2c66affSColin Finck         run_test(empty_doc_str, test_timeout);
2880c2c66affSColin Finck         run_test(click_doc_str, test_onclick);
2881c2c66affSColin Finck         run_test(readystate_doc_str, test_onreadystatechange);
2882c2c66affSColin Finck         run_test(img_doc_str, test_imgload);
2883c2c66affSColin Finck         run_test(input_doc_str, test_focus);
2884c2c66affSColin Finck         run_test(form_doc_str, test_submit);
2885c2c66affSColin Finck         run_test(iframe_doc_str, test_iframe_connections);
2886c2c66affSColin Finck 
2887c2c66affSColin Finck         test_empty_document();
2888c2c66affSColin Finck 
2889c2c66affSColin Finck         DestroyWindow(container_hwnd);
2890c2c66affSColin Finck     }else {
2891c2c66affSColin Finck         win_skip("Too old IE\n");
2892c2c66affSColin Finck     }
2893c2c66affSColin Finck 
2894c2c66affSColin Finck     CoUninitialize();
2895c2c66affSColin Finck }
2896