mshtml: Initialize OLEINPLACEFRAMEINFO.cb for IOleInPlaceSite::GetWindowContext.
[wine] / dlls / mshtml / tests / script.c
1 /*
2  * Copyright 2008-2009 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "wininet.h"
30 #include "docobj.h"
31 #include "dispex.h"
32 #include "hlink.h"
33 #include "mshtml.h"
34 #include "mshtmhst.h"
35 #include "initguid.h"
36 #include "activscp.h"
37 #include "activdbg.h"
38 #include "objsafe.h"
39 #include "mshtmdid.h"
40 #include "mshtml_test.h"
41
42 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
43
44 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
45 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
46     {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
47
48 #ifdef _WIN64
49
50 #define CTXARG_T DWORDLONG
51 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
52 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
53
54 #else
55
56 #define CTXARG_T DWORD
57 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
58 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
59
60 #endif
61
62 #define DEFINE_EXPECT(func) \
63     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
64
65 #define SET_EXPECT(func) \
66     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
67
68 #define CHECK_EXPECT2(func) \
69     do { \
70         ok(expect_ ##func, "unexpected call " #func "\n"); \
71         called_ ## func = TRUE; \
72     }while(0)
73
74 #define CHECK_EXPECT(func) \
75     do { \
76         CHECK_EXPECT2(func); \
77         expect_ ## func = FALSE; \
78     }while(0)
79
80 #define CHECK_CALLED(func) \
81     do { \
82         ok(called_ ## func, "expected " #func "\n"); \
83         expect_ ## func = called_ ## func = FALSE; \
84     }while(0)
85
86 #define CHECK_CALLED_BROKEN(func) \
87     do { \
88         ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
89         expect_ ## func = called_ ## func = FALSE; \
90     }while(0)
91
92 #define CHECK_NOT_CALLED(func) \
93     do { \
94         ok(!called_ ## func, "unexpected " #func "\n"); \
95         expect_ ## func = called_ ## func = FALSE; \
96     }while(0)
97
98 #define CLEAR_CALLED(func) \
99     expect_ ## func = called_ ## func = FALSE
100
101
102 DEFINE_EXPECT(CreateInstance);
103 DEFINE_EXPECT(GetInterfaceSafetyOptions);
104 DEFINE_EXPECT(SetInterfaceSafetyOptions);
105 DEFINE_EXPECT(InitNew);
106 DEFINE_EXPECT(Close);
107 DEFINE_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
108 DEFINE_EXPECT(SetProperty_INVOKEVERSIONING);
109 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
110 DEFINE_EXPECT(SetScriptSite);
111 DEFINE_EXPECT(GetScriptState);
112 DEFINE_EXPECT(SetScriptState_STARTED);
113 DEFINE_EXPECT(SetScriptState_CONNECTED);
114 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
115 DEFINE_EXPECT(AddNamedItem);
116 DEFINE_EXPECT(ParseScriptText_script);
117 DEFINE_EXPECT(ParseScriptText_execScript);
118 DEFINE_EXPECT(GetScriptDispatch);
119 DEFINE_EXPECT(funcDisp);
120 DEFINE_EXPECT(script_divid_d);
121 DEFINE_EXPECT(script_testprop_d);
122 DEFINE_EXPECT(script_testprop_i);
123 DEFINE_EXPECT(script_testprop2_d);
124 DEFINE_EXPECT(AXQueryInterface_IActiveScript);
125 DEFINE_EXPECT(AXQueryInterface_IObjectSafety);
126 DEFINE_EXPECT(AXGetInterfaceSafetyOptions);
127 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
128 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
129 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
130 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
131 DEFINE_EXPECT(external_success);
132
133 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
134 #define TESTACTIVEX_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
135
136 #define DISPID_SCRIPT_TESTPROP   0x100000
137 #define DISPID_SCRIPT_TESTPROP2  0x100001
138
139 #define DISPID_EXTERNAL_OK             0x300000
140 #define DISPID_EXTERNAL_TRACE          0x300001
141 #define DISPID_EXTERNAL_REPORTSUCCESS  0x300002
142 #define DISPID_EXTERNAL_TODO_WINE_OK   0x300003
143
144 static const GUID CLSID_TestScript =
145     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
146 static const GUID CLSID_TestActiveX =
147     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
148
149 static IHTMLDocument2 *notif_doc;
150 static IOleDocumentView *view;
151 static IDispatchEx *window_dispex;
152 static BOOL doc_complete;
153 static IDispatch *script_disp;
154 static BOOL ax_objsafe;
155 static HWND container_hwnd;
156 static HRESULT ax_getopt_hres = S_OK, ax_setopt_dispex_hres = S_OK;
157 static HRESULT ax_setopt_disp_caller_hres = S_OK, ax_setopt_disp_data_hres = S_OK;
158 static BOOL skip_loadobject_tests;
159
160 static const char *debugstr_guid(REFIID riid)
161 {
162     static char buf[50];
163
164     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
165             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
166             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
167             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
168
169     return buf;
170 }
171
172 static int strcmp_wa(LPCWSTR strw, const char *stra)
173 {
174     CHAR buf[512];
175     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
176     return lstrcmpA(stra, buf);
177 }
178
179 static BSTR a2bstr(const char *str)
180 {
181     BSTR ret;
182     int len;
183
184     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
185     ret = SysAllocStringLen(NULL, len);
186     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
187
188     return ret;
189 }
190
191 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
192 {
193     HKEY hkey;
194     DWORD res;
195
196     if(!init) {
197         RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
198         return TRUE;
199     }
200
201     res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
202     if(res != ERROR_SUCCESS)
203         return FALSE;
204
205     if(def_value)
206         res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
207
208     RegCloseKey(hkey);
209
210     return res == ERROR_SUCCESS;
211 }
212
213 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
214         REFIID riid, void**ppv)
215 {
216     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
217         *ppv = iface;
218         return S_OK;
219     }
220
221     return E_NOINTERFACE;
222 }
223
224 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
225 {
226     return 2;
227 }
228
229 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
230 {
231     return 1;
232 }
233
234 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
235 {
236     if(dispID == DISPID_READYSTATE){
237         BSTR state;
238         HRESULT hres;
239
240         static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
241
242         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
243         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
244
245         if(!lstrcmpW(state, completeW))
246             doc_complete = TRUE;
247
248         SysFreeString(state);
249     }
250
251     return S_OK;
252 }
253
254 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
255 {
256     ok(0, "unexpected call\n");
257     return E_NOTIMPL;
258 }
259
260 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
261     PropertyNotifySink_QueryInterface,
262     PropertyNotifySink_AddRef,
263     PropertyNotifySink_Release,
264     PropertyNotifySink_OnChanged,
265     PropertyNotifySink_OnRequestEdit
266 };
267
268 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
269
270 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
271 {
272     *ppv = NULL;
273
274     if(IsEqualGUID(riid, &IID_IUnknown)
275        || IsEqualGUID(riid, &IID_IDispatch)
276        || IsEqualGUID(riid, &IID_IDispatchEx))
277         *ppv = iface;
278     else
279         return E_NOINTERFACE;
280
281     return S_OK;
282 }
283
284 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
285 {
286     return 2;
287 }
288
289 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
290 {
291     return 1;
292 }
293
294 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
295 {
296     ok(0, "unexpected call\n");
297     return E_NOTIMPL;
298 }
299
300 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
301                                               LCID lcid, ITypeInfo **ppTInfo)
302 {
303     ok(0, "unexpected call\n");
304     return E_NOTIMPL;
305 }
306
307 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
308                                                 LPOLESTR *rgszNames, UINT cNames,
309                                                 LCID lcid, DISPID *rgDispId)
310 {
311     ok(0, "unexpected call\n");
312     return E_NOTIMPL;
313 }
314
315 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
316                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
317                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
318 {
319     ok(0, "unexpected call\n");
320     return E_NOTIMPL;
321 }
322
323 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
324 {
325     ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
326     return E_NOTIMPL;
327 }
328
329 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
330 {
331     ok(0, "unexpected call\n");
332     return E_NOTIMPL;
333 }
334
335 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
336 {
337     ok(0, "unexpected call\n");
338     return E_NOTIMPL;
339 }
340
341 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
342 {
343     ok(0, "unexpected call\n");
344     return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
348 {
349     ok(0, "unexpected call\n");
350     return E_NOTIMPL;
351 }
352
353 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
354 {
355     ok(0, "unexpected call\n");
356     return E_NOTIMPL;
357 }
358
359 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
360 {
361     ok(0, "unexpected call\n");
362     return E_NOTIMPL;
363 }
364
365 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
366         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
367 {
368     CHECK_EXPECT(funcDisp);
369
370     ok(id == DISPID_VALUE, "id = %d\n", id);
371     ok(lcid == 0, "lcid = %x\n", lcid);
372     ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
373     ok(pdp != NULL, "pdp == NULL\n");
374     ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
375     ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
376     ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
377     ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
378     ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
379     ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
380     ok(pvarRes != NULL, "pvarRes == NULL\n");
381     ok(pei != NULL, "pei == NULL\n");
382     ok(!pspCaller, "pspCaller != NULL\n");
383
384     V_VT(pvarRes) = VT_I4;
385     V_I4(pvarRes) = 100;
386     return S_OK;
387 }
388
389 static IDispatchExVtbl testObjVtbl = {
390     DispatchEx_QueryInterface,
391     DispatchEx_AddRef,
392     DispatchEx_Release,
393     DispatchEx_GetTypeInfoCount,
394     DispatchEx_GetTypeInfo,
395     DispatchEx_GetIDsOfNames,
396     DispatchEx_Invoke,
397     DispatchEx_GetDispID,
398     funcDisp_InvokeEx,
399     DispatchEx_DeleteMemberByName,
400     DispatchEx_DeleteMemberByDispID,
401     DispatchEx_GetMemberProperties,
402     DispatchEx_GetMemberName,
403     DispatchEx_GetNextDispID,
404     DispatchEx_GetNameSpaceParent
405 };
406
407 static IDispatchEx funcDisp = { &testObjVtbl };
408
409 static HRESULT WINAPI scriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
410 {
411     if(!strcmp_wa(bstrName, "testProp")) {
412         CHECK_EXPECT(script_testprop_d);
413         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
414         *pid = DISPID_SCRIPT_TESTPROP;
415         return S_OK;
416     }
417
418     if(!strcmp_wa(bstrName, "testProp2")) {
419         CHECK_EXPECT(script_testprop2_d);
420         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
421         *pid = DISPID_SCRIPT_TESTPROP2;
422         return S_OK;
423     }
424
425     if(!strcmp_wa(bstrName, "divid")) {
426         CHECK_EXPECT(script_divid_d);
427         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
428         return E_FAIL;
429     }
430
431     ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
432     return E_NOTIMPL;
433 }
434
435 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
436         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
437 {
438     switch(id) {
439     case DISPID_SCRIPT_TESTPROP:
440         CHECK_EXPECT(script_testprop_i);
441
442         ok(lcid == 0, "lcid = %x\n", lcid);
443         ok(wFlags == DISPATCH_PROPERTYGET, "wFlags = %x\n", wFlags);
444         ok(pdp != NULL, "pdp == NULL\n");
445         ok(pdp->cArgs == 0, "pdp->cArgs = %d\n", pdp->cArgs);
446         ok(pdp->cNamedArgs == 0, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
447         ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs != NULL\n");
448         ok(!pdp->rgvarg, "rgvarg != NULL\n");
449         ok(pvarRes != NULL, "pvarRes == NULL\n");
450         ok(pei != NULL, "pei == NULL\n");
451         ok(!pspCaller, "pspCaller != NULL\n");
452
453         V_VT(pvarRes) = VT_NULL;
454         break;
455     default:
456         ok(0, "unexpected call\n");
457         return E_NOTIMPL;
458     }
459
460     return S_OK;
461 }
462
463 static IDispatchExVtbl scriptDispVtbl = {
464     DispatchEx_QueryInterface,
465     DispatchEx_AddRef,
466     DispatchEx_Release,
467     DispatchEx_GetTypeInfoCount,
468     DispatchEx_GetTypeInfo,
469     DispatchEx_GetIDsOfNames,
470     DispatchEx_Invoke,
471     scriptDisp_GetDispID,
472     scriptDisp_InvokeEx,
473     DispatchEx_DeleteMemberByName,
474     DispatchEx_DeleteMemberByDispID,
475     DispatchEx_GetMemberProperties,
476     DispatchEx_GetMemberName,
477     DispatchEx_GetNextDispID,
478     DispatchEx_GetNameSpaceParent
479 };
480
481 static IDispatchEx scriptDisp = { &scriptDispVtbl };
482
483 static HRESULT WINAPI externalDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
484 {
485     if(!strcmp_wa(bstrName, "ok")) {
486         *pid = DISPID_EXTERNAL_OK;
487         return S_OK;
488     }
489     if(!strcmp_wa(bstrName, "trace")) {
490         *pid = DISPID_EXTERNAL_TRACE;
491         return S_OK;
492     }
493     if(!strcmp_wa(bstrName, "reportSuccess")) {
494         *pid = DISPID_EXTERNAL_REPORTSUCCESS;
495         return S_OK;
496     }
497     if(!strcmp_wa(bstrName, "todo_wine_ok")) {
498         *pid = DISPID_EXTERNAL_TODO_WINE_OK;
499         return S_OK;
500     }
501
502     ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
503     return DISP_E_UNKNOWNNAME;
504 }
505
506 static HRESULT WINAPI externalDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
507         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
508 {
509     switch(id) {
510     case DISPID_EXTERNAL_OK:
511         ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
512         ok(pdp != NULL, "pdp == NULL\n");
513         ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
514         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
515         ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
516         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
517         ok(pei != NULL, "pei == NULL\n");
518
519         ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
520         ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
521         ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
522
523         return S_OK;
524
525      case DISPID_EXTERNAL_TRACE:
526         ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
527         ok(pdp != NULL, "pdp == NULL\n");
528         ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
529         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
530         ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
531         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
532         ok(!pvarRes, "pvarRes != NULL\n");
533         ok(pei != NULL, "pei == NULL\n");
534
535         ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
536         if(V_VT(pdp->rgvarg) == VT_BSTR)
537             trace("%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
538
539         return S_OK;
540
541     case DISPID_EXTERNAL_REPORTSUCCESS:
542         CHECK_EXPECT(external_success);
543
544         ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
545         ok(pdp != NULL, "pdp == NULL\n");
546         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
547         ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
548         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
549         ok(!pvarRes, "pvarRes != NULL\n");
550         ok(pei != NULL, "pei == NULL\n");
551
552         return S_OK;
553
554     case DISPID_EXTERNAL_TODO_WINE_OK:
555         ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
556         ok(pdp != NULL, "pdp == NULL\n");
557         ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
558         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
559         ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
560         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
561         ok(pei != NULL, "pei == NULL\n");
562
563         ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
564         ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
565         todo_wine
566         ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
567
568         return S_OK;
569
570     default:
571         ok(0, "unexpected call\n");
572         return E_NOTIMPL;
573     }
574
575     return S_OK;
576 }
577
578 static IDispatchExVtbl externalDispVtbl = {
579     DispatchEx_QueryInterface,
580     DispatchEx_AddRef,
581     DispatchEx_Release,
582     DispatchEx_GetTypeInfoCount,
583     DispatchEx_GetTypeInfo,
584     DispatchEx_GetIDsOfNames,
585     DispatchEx_Invoke,
586     externalDisp_GetDispID,
587     externalDisp_InvokeEx,
588     DispatchEx_DeleteMemberByName,
589     DispatchEx_DeleteMemberByDispID,
590     DispatchEx_GetMemberProperties,
591     DispatchEx_GetMemberName,
592     DispatchEx_GetNextDispID,
593     DispatchEx_GetNameSpaceParent
594 };
595
596 static IDispatchEx externalDisp = { &externalDispVtbl };
597
598 static HRESULT QueryInterface(REFIID,void**);
599
600 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
601 {
602     return QueryInterface(riid, ppv);
603 }
604
605 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
606 {
607     return 2;
608 }
609
610 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
611 {
612     return 1;
613 }
614
615 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
616         IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
617 {
618     return E_NOTIMPL;
619 }
620
621 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
622 {
623     return E_NOTIMPL;
624 }
625
626 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
627         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
628         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
629 {
630     return S_OK;
631 }
632
633 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
634 {
635     return S_OK;
636 }
637
638 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
639 {
640     return S_OK;
641 }
642
643 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
644 {
645     return E_NOTIMPL;
646 }
647
648 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
649 {
650     return E_NOTIMPL;
651 }
652
653 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
654 {
655     return S_OK;
656 }
657
658 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
659         IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
660 {
661     return E_NOTIMPL;
662 }
663
664 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
665         const GUID *pguidCmdGroup, DWORD nCmdID)
666 {
667     return E_NOTIMPL;
668 }
669
670 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
671         LPOLESTR *pchKey, DWORD dw)
672 {
673     return S_OK;
674 }
675
676 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
677         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
678 {
679     return E_NOTIMPL;
680 }
681
682 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
683 {
684     *ppDispatch = (IDispatch*)&externalDisp;
685     return S_OK;
686 }
687
688 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
689         OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
690 {
691     return S_FALSE;
692 }
693
694 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
695         IDataObject **ppPORet)
696 {
697     return E_NOTIMPL;
698 }
699
700 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
701         LPOLESTR *pchKey, DWORD dw)
702 {
703     return E_NOTIMPL;
704 }
705
706 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
707     DocHostUIHandler_QueryInterface,
708     DocHostUIHandler_AddRef,
709     DocHostUIHandler_Release,
710     DocHostUIHandler_ShowContextMenu,
711     DocHostUIHandler_GetHostInfo,
712     DocHostUIHandler_ShowUI,
713     DocHostUIHandler_HideUI,
714     DocHostUIHandler_UpdateUI,
715     DocHostUIHandler_EnableModeless,
716     DocHostUIHandler_OnDocWindowActivate,
717     DocHostUIHandler_OnFrameWindowActivate,
718     DocHostUIHandler_ResizeBorder,
719     DocHostUIHandler_TranslateAccelerator,
720     DocHostUIHandler_GetOptionKeyPath,
721     DocHostUIHandler_GetDropTarget,
722     DocHostUIHandler_GetExternal,
723     DocHostUIHandler_TranslateUrl,
724     DocHostUIHandler_FilterDataObject,
725     DocHostUIHandler_GetOverrideKeyPath
726 };
727
728 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
729
730 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
731 {
732     return E_NOINTERFACE;
733 }
734
735 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
736 {
737     return 2;
738 }
739
740 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
741 {
742     return 1;
743 }
744
745 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
746 {
747     return E_NOTIMPL;
748 }
749
750 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
751 {
752     return E_NOTIMPL;
753 }
754
755 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
756 {
757     return E_NOTIMPL;
758 }
759
760 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
761         LPCBORDERWIDTHS pborderwidths)
762 {
763     return E_NOTIMPL;
764 }
765
766 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
767         LPCBORDERWIDTHS pborderwidths)
768 {
769     return S_OK;
770 }
771
772 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
773         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
774 {
775     return S_OK;
776 }
777
778 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
779         LPOLEMENUGROUPWIDTHS lpMenuWidths)
780 {
781     return E_NOTIMPL;
782 }
783
784 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
785         HOLEMENU holemenu, HWND hwndActiveObject)
786 {
787     ok(0, "unexpected call\n");
788     return E_NOTIMPL;
789 }
790
791 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
792 {
793     ok(0, "unexpected call\n");
794     return E_NOTIMPL;
795 }
796
797 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
798 {
799     return S_OK;
800 }
801
802 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
803 {
804     return E_NOTIMPL;
805 }
806
807 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
808 {
809     ok(0, "unexpected call\n");
810     return E_NOTIMPL;
811 }
812
813 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
814     InPlaceFrame_QueryInterface,
815     InPlaceFrame_AddRef,
816     InPlaceFrame_Release,
817     InPlaceFrame_GetWindow,
818     InPlaceFrame_ContextSensitiveHelp,
819     InPlaceFrame_GetBorder,
820     InPlaceFrame_RequestBorderSpace,
821     InPlaceFrame_SetBorderSpace,
822     InPlaceFrame_SetActiveObject,
823     InPlaceFrame_InsertMenus,
824     InPlaceFrame_SetMenu,
825     InPlaceFrame_RemoveMenus,
826     InPlaceFrame_SetStatusText,
827     InPlaceFrame_EnableModeless,
828     InPlaceFrame_TranslateAccelerator
829 };
830
831 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
832
833 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
834 {
835     return QueryInterface(riid, ppv);
836 }
837
838 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
839 {
840     return 2;
841 }
842
843 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
844 {
845     return 1;
846 }
847
848 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
849 {
850     *phwnd = container_hwnd;
851     return S_OK;
852 }
853
854 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
855 {
856     ok(0, "unexpected call\n");
857     return E_NOTIMPL;
858 }
859
860 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
861 {
862     return S_OK;
863 }
864
865 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
866 {
867     return S_OK;
868 }
869
870 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
871 {
872     return S_OK;
873 }
874
875 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
876         IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
877         LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
878 {
879     static const RECT rect = {0,0,300,300};
880
881     *ppFrame = &InPlaceFrame;
882     *ppDoc = (IOleInPlaceUIWindow*)&InPlaceFrame;
883     *lprcPosRect = rect;
884     *lprcClipRect = rect;
885
886     ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
887     lpFrameInfo->fMDIApp = FALSE;
888     lpFrameInfo->hwndFrame = container_hwnd;
889     lpFrameInfo->haccel = NULL;
890     lpFrameInfo->cAccelEntries = 0;
891
892     return S_OK;
893 }
894
895 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
896 {
897     return E_NOTIMPL;
898 }
899
900 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
901 {
902     return S_OK;
903 }
904
905 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
906 {
907     return S_OK;
908 }
909
910 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
911 {
912     return E_NOTIMPL;
913 }
914
915 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
916 {
917     return E_NOTIMPL;
918 }
919
920 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
921 {
922     return E_NOTIMPL;
923 }
924
925 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
926     InPlaceSite_QueryInterface,
927     InPlaceSite_AddRef,
928     InPlaceSite_Release,
929     InPlaceSite_GetWindow,
930     InPlaceSite_ContextSensitiveHelp,
931     InPlaceSite_CanInPlaceActivate,
932     InPlaceSite_OnInPlaceActivate,
933     InPlaceSite_OnUIActivate,
934     InPlaceSite_GetWindowContext,
935     InPlaceSite_Scroll,
936     InPlaceSite_OnUIDeactivate,
937     InPlaceSite_OnInPlaceDeactivate,
938     InPlaceSite_DiscardUndoState,
939     InPlaceSite_DeactivateAndUndo,
940     InPlaceSite_OnPosRectChange,
941 };
942
943 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
944
945 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
946 {
947     return QueryInterface(riid, ppv);
948 }
949
950 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
951 {
952     return 2;
953 }
954
955 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
956 {
957     return 1;
958 }
959
960 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
961 {
962     ok(0, "unexpected call\n");
963     return E_NOTIMPL;
964 }
965
966 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
967         IMoniker **ppmon)
968 {
969     ok(0, "unexpected call\n");
970     return E_NOTIMPL;
971 }
972
973 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
974 {
975     return E_NOTIMPL;
976 }
977
978 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
979 {
980     ok(0, "unexpected call\n");
981     return E_NOTIMPL;
982 }
983
984 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
985 {
986     ok(0, "unexpected call\n");
987     return E_NOTIMPL;
988 }
989
990 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
991 {
992     ok(0, "unexpected call\n");
993     return E_NOTIMPL;
994 }
995
996 static const IOleClientSiteVtbl ClientSiteVtbl = {
997     ClientSite_QueryInterface,
998     ClientSite_AddRef,
999     ClientSite_Release,
1000     ClientSite_SaveObject,
1001     ClientSite_GetMoniker,
1002     ClientSite_GetContainer,
1003     ClientSite_ShowObject,
1004     ClientSite_OnShowWindow,
1005     ClientSite_RequestNewObjectLayout
1006 };
1007
1008 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1009
1010 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1011 {
1012     return QueryInterface(riid, ppv);
1013 }
1014
1015 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1016 {
1017     return 2;
1018 }
1019
1020 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1021 {
1022     return 1;
1023 }
1024
1025 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1026 {
1027     RECT rect = {0,0,300,300};
1028     IOleDocument *document;
1029     HRESULT hres;
1030
1031     hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1032     ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1033
1034     hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1035     IOleDocument_Release(document);
1036     ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1037
1038     hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1039     ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1040
1041     hres = IOleDocumentView_UIActivate(view, TRUE);
1042     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1043
1044     hres = IOleDocumentView_SetRect(view, &rect);
1045     ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1046
1047     hres = IOleDocumentView_Show(view, TRUE);
1048     ok(hres == S_OK, "Show failed: %08x\n", hres);
1049
1050     return S_OK;
1051 }
1052
1053 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1054     DocumentSite_QueryInterface,
1055     DocumentSite_AddRef,
1056     DocumentSite_Release,
1057     DocumentSite_ActivateMe
1058 };
1059
1060 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1061
1062 static HRESULT QueryInterface(REFIID riid, void **ppv)
1063 {
1064     *ppv = NULL;
1065
1066     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1067         *ppv = &ClientSite;
1068     else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1069         *ppv = &DocumentSite;
1070     else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1071         *ppv = &InPlaceSite;
1072     else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
1073         *ppv = &DocHostUIHandler;
1074
1075     return *ppv ? S_OK : E_NOINTERFACE;
1076 }
1077
1078 static IHTMLDocument2 *create_document(void)
1079 {
1080     IHTMLDocument2 *doc;
1081     IHTMLDocument5 *doc5;
1082     HRESULT hres;
1083
1084     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1085             &IID_IHTMLDocument2, (void**)&doc);
1086     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1087     if (hres != S_OK) return NULL;
1088
1089     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1090     if(FAILED(hres)) {
1091         win_skip("Could not get IHTMLDocument5, probably too old IE\n");
1092         IHTMLDocument2_Release(doc);
1093         return NULL;
1094     }
1095
1096     IHTMLDocument5_Release(doc5);
1097     return doc;
1098 }
1099
1100 static void load_string(IHTMLDocument2 *doc, const char *str)
1101 {
1102     IPersistStreamInit *init;
1103     IStream *stream;
1104     HGLOBAL mem;
1105     SIZE_T len;
1106
1107     doc_complete = FALSE;
1108     len = strlen(str);
1109     mem = GlobalAlloc(0, len);
1110     memcpy(mem, str, len);
1111     CreateStreamOnHGlobal(mem, TRUE, &stream);
1112
1113     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1114
1115     IPersistStreamInit_Load(init, stream);
1116     IPersistStreamInit_Release(init);
1117     IStream_Release(stream);
1118 }
1119
1120 static void do_advise(IHTMLDocument2 *doc, REFIID riid, IUnknown *unk_advise)
1121 {
1122     IConnectionPointContainer *container;
1123     IConnectionPoint *cp;
1124     DWORD cookie;
1125     HRESULT hres;
1126
1127     hres = IHTMLDocument2_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&container);
1128     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1129
1130     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1131     IConnectionPointContainer_Release(container);
1132     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1133
1134     notif_doc = doc;
1135
1136     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1137     IConnectionPoint_Release(cp);
1138     ok(hres == S_OK, "Advise failed: %08x\n", hres);
1139 }
1140
1141 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1142 {
1143     IOleObject *oleobj;
1144     HRESULT hres;
1145
1146     if(!set && view) {
1147         IOleDocumentView_Show(view, FALSE);
1148         IOleDocumentView_CloseView(view, 0);
1149         IOleDocumentView_SetInPlaceSite(view, NULL);
1150         IOleDocumentView_Release(view);
1151         view = NULL;
1152     }
1153
1154     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1155     ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1156
1157     hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1158     ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1159
1160     if(set) {
1161         IHlinkTarget *hlink;
1162
1163         hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1164         ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1165
1166         hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1167         ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1168
1169         IHlinkTarget_Release(hlink);
1170     }
1171
1172     IOleObject_Release(oleobj);
1173 }
1174
1175 typedef void (*domtest_t)(IHTMLDocument2*);
1176
1177 static void load_doc(IHTMLDocument2 *doc, const char *str)
1178 {
1179     IHTMLElement *body = NULL;
1180     MSG msg;
1181     HRESULT hres;
1182     static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
1183     DISPID dispID = -1;
1184     OLECHAR *name;
1185
1186     load_string(doc, str);
1187     do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1188
1189     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1190         TranslateMessage(&msg);
1191         DispatchMessage(&msg);
1192     }
1193
1194     hres = IHTMLDocument2_get_body(doc, &body);
1195     ok(hres == S_OK, "get_body failed: %08x\n", hres);
1196
1197     /* Check we can query for function on the IHTMLElementBody interface */
1198     name = (WCHAR*)ucPtr;
1199     hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
1200     ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
1201     ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
1202
1203     IHTMLElement_Release(body);
1204 }
1205
1206 static IActiveScriptSite *site;
1207 static SCRIPTSTATE state;
1208
1209 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1210 {
1211     *ppv = NULL;
1212     ok(0, "unexpected call %s\n", debugstr_guid(riid));
1213     return E_NOINTERFACE;
1214 }
1215
1216 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
1217 {
1218     return 2;
1219 }
1220
1221 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
1222 {
1223     return 1;
1224 }
1225
1226 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1227         DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1228 {
1229     CHECK_EXPECT(GetInterfaceSafetyOptions);
1230
1231     ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
1232     ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1233     ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1234
1235     *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1236     *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1237
1238     return S_OK;
1239 }
1240
1241 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1242         DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1243 {
1244     CHECK_EXPECT(SetInterfaceSafetyOptions);
1245
1246     ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
1247
1248     ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1249        "dwOptionSetMask=%x\n", dwOptionSetMask);
1250     ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1251        "dwEnabledOptions=%x\n", dwOptionSetMask);
1252
1253     return S_OK;
1254 }
1255
1256 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1257     ObjectSafety_QueryInterface,
1258     ObjectSafety_AddRef,
1259     ObjectSafety_Release,
1260     ObjectSafety_GetInterfaceSafetyOptions,
1261     ObjectSafety_SetInterfaceSafetyOptions
1262 };
1263
1264 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
1265
1266 static HRESULT WINAPI AXObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1267 {
1268     *ppv = NULL;
1269
1270     if(IsEqualGUID(&IID_IActiveScript, riid)) {
1271         CHECK_EXPECT(AXQueryInterface_IActiveScript);
1272         return E_NOINTERFACE;
1273     }
1274
1275     if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1276         CHECK_EXPECT2(AXQueryInterface_IObjectSafety);
1277         if(!ax_objsafe)
1278             return E_NOINTERFACE;
1279         *ppv = iface;
1280         return S_OK;
1281     }
1282
1283     ok(0, "unexpected call %s\n", debugstr_guid(riid));
1284     return E_NOINTERFACE;
1285 }
1286
1287 static HRESULT WINAPI AXObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1288         DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1289 {
1290     CHECK_EXPECT(AXGetInterfaceSafetyOptions);
1291
1292     ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
1293     ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1294     ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1295
1296     if(SUCCEEDED(ax_getopt_hres)) {
1297         *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1298         *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1299     }
1300
1301     return ax_getopt_hres;
1302 }
1303
1304 static HRESULT WINAPI AXObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1305         DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1306 {
1307     if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1308         switch(dwEnabledOptions) {
1309         case INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER:
1310             CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1311             break;
1312         case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1313             CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1314             break;
1315         default:
1316             ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1317         }
1318
1319         ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1320         return ax_setopt_dispex_hres;
1321     }
1322
1323     if(IsEqualGUID(&IID_IDispatch, riid)) {
1324         HRESULT hres;
1325
1326         switch(dwEnabledOptions) {
1327         case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1328             CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1329             hres = ax_setopt_disp_caller_hres;
1330             break;
1331         case INTERFACESAFE_FOR_UNTRUSTED_DATA:
1332             CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1333             hres = ax_setopt_disp_data_hres;
1334             break;
1335         default:
1336             ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1337             hres = E_FAIL;
1338         }
1339         ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1340         return hres;
1341     }
1342
1343     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1344     return E_NOINTERFACE;
1345 }
1346
1347 static const IObjectSafetyVtbl AXObjectSafetyVtbl = {
1348     AXObjectSafety_QueryInterface,
1349     ObjectSafety_AddRef,
1350     ObjectSafety_Release,
1351     AXObjectSafety_GetInterfaceSafetyOptions,
1352     AXObjectSafety_SetInterfaceSafetyOptions
1353 };
1354
1355 static IObjectSafety AXObjectSafety = { &AXObjectSafetyVtbl };
1356
1357 static BOOL set_safe_reg(BOOL safe_call, BOOL safe_data)
1358 {
1359     return init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95801-9882-11cf-9fa9-00aa006c42c4}",
1360                     NULL, safe_call)
1361         && init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95802-9882-11cf-9fa9-00aa006c42c4}",
1362                     NULL, safe_data);
1363 }
1364
1365 #define check_custom_policy(a,b,c,d) _check_custom_policy(__LINE__,a,b,c,d)
1366 static void _check_custom_policy(unsigned line, HRESULT hres, BYTE *ppolicy, DWORD policy_size, DWORD expolicy)
1367 {
1368     ok_(__FILE__,line)(hres == S_OK, "QueryCusromPolicy failed: %08x\n", hres);
1369     ok_(__FILE__,line)(policy_size == sizeof(DWORD), "policy_size = %d\n", policy_size);
1370     ok_(__FILE__,line)(*(DWORD*)ppolicy == expolicy, "policy = %x, expected %x\n", *(DWORD*)ppolicy, expolicy);
1371     CoTaskMemFree(ppolicy);
1372 }
1373
1374 static void test_security_reg(IInternetHostSecurityManager *sec_mgr, DWORD policy_caller, DWORD policy_load)
1375 {
1376     struct CONFIRMSAFETY cs;
1377     DWORD policy_size;
1378     BYTE *ppolicy;
1379     HRESULT hres;
1380
1381     cs.clsid = CLSID_TestActiveX;
1382     cs.pUnk = (IUnknown*)&AXObjectSafety;
1383
1384     cs.dwFlags = 0;
1385     ax_objsafe = FALSE;
1386     SET_EXPECT(AXQueryInterface_IActiveScript);
1387     SET_EXPECT(AXQueryInterface_IObjectSafety);
1388     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1389             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1390     CHECK_CALLED(AXQueryInterface_IActiveScript);
1391     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1392     check_custom_policy(hres, ppolicy, policy_size, policy_caller);
1393
1394     ax_objsafe = TRUE;
1395     SET_EXPECT(AXQueryInterface_IActiveScript);
1396     SET_EXPECT(AXQueryInterface_IObjectSafety);
1397     SET_EXPECT(AXGetInterfaceSafetyOptions);
1398     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1399     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1400             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1401     CHECK_CALLED(AXQueryInterface_IActiveScript);
1402     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1403     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1404     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1405     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1406
1407     if(skip_loadobject_tests)
1408         return;
1409
1410     cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1411     ax_objsafe = FALSE;
1412     SET_EXPECT(AXQueryInterface_IActiveScript);
1413     SET_EXPECT(AXQueryInterface_IObjectSafety);
1414     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1415             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1416     CHECK_CALLED(AXQueryInterface_IActiveScript);
1417     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1418     check_custom_policy(hres, ppolicy, policy_size, policy_load);
1419
1420     ax_objsafe = TRUE;
1421     SET_EXPECT(AXQueryInterface_IActiveScript);
1422     SET_EXPECT(AXQueryInterface_IObjectSafety);
1423     SET_EXPECT(AXGetInterfaceSafetyOptions);
1424     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1425     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1426     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1427             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1428     CHECK_CALLED(AXQueryInterface_IActiveScript);
1429     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1430     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1431     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1432     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1433     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1434 }
1435
1436 static void test_security(void)
1437 {
1438     IInternetHostSecurityManager *sec_mgr;
1439     IServiceProvider *sp;
1440     DWORD policy, policy_size;
1441     struct CONFIRMSAFETY cs;
1442     BYTE *ppolicy;
1443     HRESULT hres;
1444
1445     hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
1446     ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
1447
1448     hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager,
1449             &IID_IInternetHostSecurityManager, (void**)&sec_mgr);
1450     IServiceProvider_Release(sp);
1451     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1452
1453     hres = IInternetHostSecurityManager_ProcessUrlAction(sec_mgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
1454                                                          (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
1455     ok(hres == S_OK, "ProcessUrlAction failed: %08x\n", hres);
1456     ok(policy == URLPOLICY_ALLOW, "policy = %x\n", policy);
1457
1458     cs.clsid = CLSID_TestActiveX;
1459     cs.pUnk = (IUnknown*)&AXObjectSafety;
1460     cs.dwFlags = 0;
1461
1462     ax_objsafe = TRUE;
1463     SET_EXPECT(AXQueryInterface_IActiveScript);
1464     SET_EXPECT(AXQueryInterface_IObjectSafety);
1465     SET_EXPECT(AXGetInterfaceSafetyOptions);
1466     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1467     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1468             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1469     CHECK_CALLED(AXQueryInterface_IActiveScript);
1470     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1471     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1472     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1473     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1474
1475     cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1476     SET_EXPECT(AXQueryInterface_IActiveScript);
1477     SET_EXPECT(AXQueryInterface_IObjectSafety);
1478     SET_EXPECT(AXGetInterfaceSafetyOptions);
1479     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1480     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1481     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1482             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1483     CHECK_CALLED(AXQueryInterface_IActiveScript);
1484     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1485     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1486     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1487     if(called_AXSetInterfaceSafetyOptions_IDispatch_data) {
1488         CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1489     }else {
1490         win_skip("CONFIRMSAFETYACTION_LOADOBJECT flag not supported\n");
1491         skip_loadobject_tests = TRUE;
1492         CLEAR_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1493     }
1494     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1495
1496     cs.dwFlags = 0;
1497     ax_objsafe = FALSE;
1498     SET_EXPECT(AXQueryInterface_IActiveScript);
1499     SET_EXPECT(AXQueryInterface_IObjectSafety);
1500     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1501             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1502     CHECK_CALLED(AXQueryInterface_IActiveScript);
1503     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1504     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1505
1506     if(!skip_loadobject_tests) {
1507         cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1508         ax_objsafe = FALSE;
1509         SET_EXPECT(AXQueryInterface_IActiveScript);
1510         SET_EXPECT(AXQueryInterface_IObjectSafety);
1511         hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1512                 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1513         CHECK_CALLED(AXQueryInterface_IActiveScript);
1514         CHECK_CALLED(AXQueryInterface_IObjectSafety);
1515         check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1516     }
1517
1518     if(set_safe_reg(TRUE, FALSE)) {
1519         test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_DISALLOW);
1520
1521         set_safe_reg(FALSE, TRUE);
1522         test_security_reg(sec_mgr, URLPOLICY_DISALLOW, URLPOLICY_DISALLOW);
1523
1524         set_safe_reg(TRUE, TRUE);
1525         test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_ALLOW);
1526
1527         set_safe_reg(FALSE, FALSE);
1528     }else {
1529         skip("Could not set safety registry\n");
1530     }
1531
1532     ax_objsafe = TRUE;
1533
1534     cs.dwFlags = 0;
1535     ax_setopt_dispex_hres = E_NOINTERFACE;
1536     SET_EXPECT(AXQueryInterface_IActiveScript);
1537     SET_EXPECT(AXQueryInterface_IObjectSafety);
1538     SET_EXPECT(AXGetInterfaceSafetyOptions);
1539     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1540     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1541     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1542             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1543     CHECK_CALLED(AXQueryInterface_IActiveScript);
1544     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1545     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1546     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1547     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1548     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1549
1550     ax_setopt_dispex_hres = E_FAIL;
1551     ax_setopt_disp_caller_hres = E_NOINTERFACE;
1552     SET_EXPECT(AXQueryInterface_IActiveScript);
1553     SET_EXPECT(AXQueryInterface_IObjectSafety);
1554     SET_EXPECT(AXGetInterfaceSafetyOptions);
1555     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1556     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1557     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1558             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1559     CHECK_CALLED(AXQueryInterface_IActiveScript);
1560     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1561     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1562     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1563     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1564     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1565
1566     if(!skip_loadobject_tests) {
1567         cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1568         ax_setopt_dispex_hres = E_FAIL;
1569         ax_setopt_disp_caller_hres = E_NOINTERFACE;
1570         SET_EXPECT(AXQueryInterface_IActiveScript);
1571         SET_EXPECT(AXQueryInterface_IObjectSafety);
1572         SET_EXPECT(AXGetInterfaceSafetyOptions);
1573         SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1574         SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1575         hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1576                 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1577         CHECK_CALLED(AXQueryInterface_IActiveScript);
1578         CHECK_CALLED(AXQueryInterface_IObjectSafety);
1579         CHECK_CALLED(AXGetInterfaceSafetyOptions);
1580         CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1581         CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1582         check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1583     }
1584
1585     cs.dwFlags = 0;
1586     ax_setopt_dispex_hres = E_FAIL;
1587     ax_setopt_disp_caller_hres = S_OK;
1588     ax_getopt_hres = E_NOINTERFACE;
1589     SET_EXPECT(AXQueryInterface_IActiveScript);
1590     SET_EXPECT(AXQueryInterface_IObjectSafety);
1591     SET_EXPECT(AXGetInterfaceSafetyOptions);
1592     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1593     SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1594     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1595             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1596     CHECK_CALLED(AXQueryInterface_IActiveScript);
1597     CHECK_CALLED(AXQueryInterface_IObjectSafety);
1598     CHECK_CALLED(AXGetInterfaceSafetyOptions);
1599     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1600     CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1601     check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1602
1603     if(!skip_loadobject_tests) {
1604         cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1605         ax_setopt_dispex_hres = E_FAIL;
1606         ax_setopt_disp_caller_hres = S_OK;
1607         ax_setopt_disp_data_hres = E_FAIL;
1608         ax_getopt_hres = E_NOINTERFACE;
1609         SET_EXPECT(AXQueryInterface_IActiveScript);
1610         SET_EXPECT(AXQueryInterface_IObjectSafety);
1611         SET_EXPECT(AXGetInterfaceSafetyOptions);
1612         SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1613         SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1614         SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1615         hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1616                 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1617         CHECK_CALLED(AXQueryInterface_IActiveScript);
1618         CHECK_CALLED(AXQueryInterface_IObjectSafety);
1619         CHECK_CALLED(AXGetInterfaceSafetyOptions);
1620         CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1621         CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1622         CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1623         check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1624     }
1625
1626     IInternetHostSecurityManager_Release(sec_mgr);
1627 }
1628
1629 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
1630 {
1631     *ppv = NULL;
1632     ok(0, "unexpected call\n");
1633     return E_NOINTERFACE;
1634 }
1635
1636 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
1637 {
1638     return 2;
1639 }
1640
1641 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
1642 {
1643     return 1;
1644 }
1645
1646 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1647         VARIANT *pvarIndex, VARIANT *pvarValue)
1648 {
1649     ok(0, "unexpected call\n");
1650     return E_NOTIMPL;
1651 }
1652
1653 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1654         VARIANT *pvarIndex, VARIANT *pvarValue)
1655 {
1656     switch(dwProperty) {
1657     case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
1658         CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1659         ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1660         ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1661         break;
1662     case SCRIPTPROP_INVOKEVERSIONING:
1663         CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
1664         ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1665         ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
1666         break;
1667     case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
1668         CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
1669         ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1670         ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1671         break;
1672     default:
1673         ok(0, "unexpected property %x\n", dwProperty);
1674         return E_NOTIMPL;
1675     }
1676
1677     ok(!pvarIndex, "pvarIndex != NULL\n");
1678     ok(pvarValue != NULL, "pvarValue == NULL\n");
1679
1680     return S_OK;
1681 }
1682
1683 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
1684     ActiveScriptProperty_QueryInterface,
1685     ActiveScriptProperty_AddRef,
1686     ActiveScriptProperty_Release,
1687     ActiveScriptProperty_GetProperty,
1688     ActiveScriptProperty_SetProperty
1689 };
1690
1691 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
1692
1693 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
1694 {
1695     *ppv = NULL;
1696     ok(0, "unexpected call\n");
1697     return E_NOINTERFACE;
1698 }
1699
1700 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
1701 {
1702     return 2;
1703 }
1704
1705 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
1706 {
1707     return 1;
1708 }
1709
1710 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
1711         LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
1712         LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
1713         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
1714 {
1715     ok(0, "unexpected call\n");
1716     return E_NOTIMPL;
1717 }
1718
1719 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
1720     ActiveScriptParseProcedure_QueryInterface,
1721     ActiveScriptParseProcedure_AddRef,
1722     ActiveScriptParseProcedure_Release,
1723     ActiveScriptParseProcedure_ParseProcedureText
1724 };
1725
1726 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
1727
1728 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
1729 {
1730     *ppv = NULL;
1731     ok(0, "unexpected call\n");
1732     return E_NOINTERFACE;
1733 }
1734
1735 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
1736 {
1737     return 2;
1738 }
1739
1740 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
1741 {
1742     return 1;
1743 }
1744
1745 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
1746 {
1747     CHECK_EXPECT(InitNew);
1748     return S_OK;
1749 }
1750
1751 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
1752         LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
1753         LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
1754         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
1755         BSTR *pbstrName, EXCEPINFO *pexcepinfo)
1756 {
1757     ok(0, "unexpected call\n");
1758     return E_NOTIMPL;
1759 }
1760
1761 static HRESULT dispex_propput(IDispatchEx *obj, DISPID id, DWORD flags, VARIANT *var)
1762 {
1763     DISPID propput_arg = DISPID_PROPERTYPUT;
1764     DISPPARAMS dp = {var, &propput_arg, 1, 1};
1765     EXCEPINFO ei = {0};
1766
1767     return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT|flags, &dp, NULL, &ei, NULL);
1768 }
1769
1770 static void test_func(IDispatchEx *obj)
1771 {
1772     DISPID id;
1773     IDispatchEx *dispex;
1774     IDispatch *disp;
1775     EXCEPINFO ei;
1776     DISPPARAMS dp;
1777     BSTR str;
1778     VARIANT var;
1779     HRESULT hres;
1780
1781     str = a2bstr("toString");
1782     hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
1783     SysFreeString(str);
1784     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1785     ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
1786
1787     memset(&dp, 0, sizeof(dp));
1788     memset(&ei, 0, sizeof(ei));
1789     VariantInit(&var);
1790     hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1791     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1792     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
1793     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
1794     disp = V_DISPATCH(&var);
1795
1796     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1797     IDispatch_Release(disp);
1798     ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1799
1800     /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
1801
1802     memset(&dp, 0, sizeof(dp));
1803     memset(&ei, 0, sizeof(ei));
1804     VariantInit(&var);
1805     hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
1806     ok(hres == S_OK || broken(E_ACCESSDENIED), "InvokeEx failed: %08x\n", hres);
1807     if(SUCCEEDED(hres)) {
1808         ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1809         ok(!strcmp_wa(V_BSTR(&var), "[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
1810         VariantClear(&var);
1811     }
1812
1813     V_VT(&var) = VT_I4;
1814     V_I4(&var) = 100;
1815     hres = dispex_propput(obj, id, 0, &var);
1816     ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
1817
1818     IDispatchEx_Release(dispex);
1819 }
1820
1821 static void test_nextdispid(IDispatchEx *dispex)
1822 {
1823     DISPID last_id = DISPID_STARTENUM, id, dyn_id;
1824     BSTR name;
1825     VARIANT var;
1826     HRESULT hres;
1827
1828     name = a2bstr("dynVal");
1829     hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive|fdexNameEnsure, &dyn_id);
1830     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1831     SysFreeString(name);
1832
1833     V_VT(&var) = VT_EMPTY;
1834     hres = dispex_propput(dispex, dyn_id, 0, &var);
1835     ok(hres == S_OK, "dispex_propput failed: %08x\n", hres);
1836
1837     while(last_id != dyn_id) {
1838         hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, last_id, &id);
1839         ok(hres == S_OK, "GetNextDispID returned: %08x\n", hres);
1840         ok(id != DISPID_STARTENUM, "id == DISPID_STARTENUM\n");
1841         ok(id != DISPID_IOMNAVIGATOR_TOSTRING, "id == DISPID_IOMNAVIGATOR_TOSTRING\n");
1842
1843         hres = IDispatchEx_GetMemberName(dispex, id, &name);
1844         ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
1845
1846         if(id == dyn_id)
1847             ok(!strcmp_wa(name, "dynVal"), "name = %s\n", wine_dbgstr_w(name));
1848         else if(id == DISPID_IOMNAVIGATOR_PLATFORM)
1849             ok(!strcmp_wa(name, "platform"), "name = %s\n", wine_dbgstr_w(name));
1850
1851         SysFreeString(name);
1852         last_id = id;
1853     }
1854
1855     hres = IDispatchEx_GetNextDispID(dispex, 0, id, &id);
1856     ok(hres == S_FALSE, "GetNextDispID returned: %08x\n", hres);
1857     ok(id == DISPID_STARTENUM, "id != DISPID_STARTENUM\n");
1858 }
1859
1860 static void test_global_id(void)
1861 {
1862     VARIANT var;
1863     DISPPARAMS dp;
1864     EXCEPINFO ei;
1865     BSTR tmp;
1866     DISPID id;
1867     HRESULT hres;
1868
1869     SET_EXPECT(GetScriptDispatch);
1870     SET_EXPECT(script_divid_d);
1871     tmp = a2bstr("divid");
1872     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1873     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1874     SysFreeString(tmp);
1875     CHECK_CALLED(GetScriptDispatch);
1876     CHECK_CALLED(script_divid_d);
1877
1878     VariantInit(&var);
1879     memset(&ei, 0, sizeof(ei));
1880     memset(&dp, 0, sizeof(dp));
1881     hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1882     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1883     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d\n", V_VT(&var));
1884     VariantClear(&var);
1885 }
1886
1887 static void test_script_run(void)
1888 {
1889     IDispatchEx *document, *dispex;
1890     IHTMLWindow2 *window;
1891     IOmNavigator *navigator;
1892     IUnknown *unk;
1893     VARIANT var, arg;
1894     DISPPARAMS dp;
1895     EXCEPINFO ei;
1896     DISPID id;
1897     BSTR tmp;
1898     HRESULT hres;
1899
1900     static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
1901     static const WCHAR testW[] = {'t','e','s','t',0};
1902     static const WCHAR funcW[] = {'f','u','n','c',0};
1903
1904     SET_EXPECT(GetScriptDispatch);
1905
1906     tmp = SysAllocString(documentW);
1907     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1908     SysFreeString(tmp);
1909     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1910     ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
1911
1912     CHECK_CALLED(GetScriptDispatch);
1913
1914     VariantInit(&var);
1915     memset(&dp, 0, sizeof(dp));
1916     memset(&ei, 0, sizeof(ei));
1917
1918     hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1919     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1920     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
1921     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
1922
1923     hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
1924     VariantClear(&var);
1925     ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
1926
1927     tmp = SysAllocString(testW);
1928     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
1929     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1930     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
1931     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1932     SysFreeString(tmp);
1933
1934     id = 0;
1935     tmp = SysAllocString(testW);
1936     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
1937     SysFreeString(tmp);
1938     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1939     ok(id, "id == 0\n");
1940
1941     V_VT(&var) = VT_I4;
1942     V_I4(&var) = 100;
1943     hres = dispex_propput(document, id, 0, &var);
1944     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1945
1946     tmp = SysAllocString(testW);
1947     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
1948     SysFreeString(tmp);
1949     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1950
1951     VariantInit(&var);
1952     memset(&dp, 0, sizeof(dp));
1953     memset(&ei, 0, sizeof(ei));
1954     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1955     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1956     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1957     ok(V_I4(&var) == 100, "V_I4(&var) = %d\n", V_I4(&var));
1958
1959     V_VT(&var) = VT_I4;
1960     V_I4(&var) = 200;
1961     hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var);
1962     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1963
1964     VariantInit(&var);
1965     memset(&dp, 0, sizeof(dp));
1966     memset(&ei, 0, sizeof(ei));
1967     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1968     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1969     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1970     ok(V_I4(&var) == 200, "V_I4(&var) = %d\n", V_I4(&var));
1971
1972     memset(&dp, 0, sizeof(dp));
1973     memset(&ei, 0, sizeof(ei));
1974     V_VT(&var) = VT_I4;
1975     V_I4(&var) = 300;
1976     dp.cArgs = 1;
1977     dp.rgvarg = &var;
1978     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
1979     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1980
1981     VariantInit(&var);
1982     memset(&dp, 0, sizeof(dp));
1983     memset(&ei, 0, sizeof(ei));
1984     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1985     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1986     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1987     ok(V_I4(&var) == 300, "V_I4(&var) = %d\n", V_I4(&var));
1988
1989     V_VT(&var) = VT_BSTR;
1990     V_BSTR(&var) = NULL;
1991     dispex_propput(document, id, 0,&var);
1992
1993     VariantInit(&var);
1994     memset(&dp, 0, sizeof(dp));
1995     memset(&ei, 0, sizeof(ei));
1996     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1997     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1998     ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1999     ok(!V_BSTR(&var), "V_BSTR(&var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
2000
2001     unk = (void*)0xdeadbeef;
2002     hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
2003     ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
2004     ok(!unk, "unk=%p, expected NULL\n", unk);
2005
2006     id = 0;
2007     tmp = SysAllocString(funcW);
2008     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2009     SysFreeString(tmp);
2010     ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
2011     ok(id, "id == 0\n");
2012
2013     dp.cArgs = 1;
2014     dp.rgvarg = &var;
2015     dp.cNamedArgs = 0;
2016     dp.rgdispidNamedArgs = NULL;
2017     V_VT(&var) = VT_DISPATCH;
2018     V_DISPATCH(&var) = (IDispatch*)&funcDisp;
2019     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2020     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2021
2022     VariantInit(&var);
2023     memset(&dp, 0, sizeof(dp));
2024     memset(&ei, 0, sizeof(ei));
2025     V_VT(&arg) = VT_BOOL;
2026     V_BOOL(&arg) = VARIANT_TRUE;
2027     dp.cArgs = 1;
2028     dp.rgvarg = &arg;
2029
2030     SET_EXPECT(funcDisp);
2031     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
2032     CHECK_CALLED(funcDisp);
2033
2034     ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
2035     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2036     ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
2037
2038     IDispatchEx_Release(document);
2039
2040     hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
2041     ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
2042
2043     hres = IHTMLWindow2_get_navigator(window, &navigator);
2044     IHTMLWindow2_Release(window);
2045     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2046
2047     hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
2048     IOmNavigator_Release(navigator);
2049     ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2050
2051     test_func(dispex);
2052     test_nextdispid(dispex);
2053
2054     tmp = a2bstr("test");
2055     hres = IDispatchEx_DeleteMemberByName(dispex, tmp, fdexNameCaseSensitive);
2056     ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2057
2058     IDispatchEx_Release(dispex);
2059
2060     script_disp = (IDispatch*)&scriptDisp;
2061
2062     SET_EXPECT(GetScriptDispatch);
2063     SET_EXPECT(script_testprop_d);
2064     tmp = a2bstr("testProp");
2065     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2066     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2067     ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2068     CHECK_CALLED(GetScriptDispatch);
2069     CHECK_CALLED(script_testprop_d);
2070     SysFreeString(tmp);
2071
2072     tmp = a2bstr("testProp");
2073     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2074     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2075     ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2076     SysFreeString(tmp);
2077
2078     SET_EXPECT(GetScriptDispatch);
2079     SET_EXPECT(script_testprop_i);
2080     memset(&ei, 0, sizeof(ei));
2081     memset(&dp, 0, sizeof(dp));
2082     hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
2083     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2084     ok(V_VT(&var) == VT_NULL, "V_VT(var) = %d\n", V_VT(&var));
2085     CHECK_CALLED(GetScriptDispatch);
2086     CHECK_CALLED(script_testprop_i);
2087
2088     SET_EXPECT(GetScriptDispatch);
2089     SET_EXPECT(script_testprop2_d);
2090     tmp = a2bstr("testProp2");
2091     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2092     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2093     ok(id != DISPID_SCRIPT_TESTPROP2, "id == DISPID_SCRIPT_TESTPROP2\n");
2094     CHECK_CALLED(GetScriptDispatch);
2095     CHECK_CALLED(script_testprop2_d);
2096     SysFreeString(tmp);
2097
2098     tmp = a2bstr("test");
2099     hres = IDispatchEx_DeleteMemberByName(window_dispex, tmp, fdexNameCaseSensitive);
2100     ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2101
2102     test_global_id();
2103
2104     test_security();
2105 }
2106
2107 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
2108         LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
2109         LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
2110         DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
2111 {
2112     ok(!punkContext, "punkContext = %p\n", punkContext);
2113     ok(pvarResult != NULL, "pvarResult == NULL\n");
2114     ok(pexcepinfo != NULL, "pexcepinfo == NULL\n");
2115
2116     if(!strcmp_wa(pstrCode, "execScript call")) {
2117         CHECK_EXPECT(ParseScriptText_execScript);
2118         ok(!pstrItemName, "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2119         ok(!strcmp_wa(pstrDelimiter, "\""), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2120         ok(dwFlags == SCRIPTTEXT_ISVISIBLE, "dwFlags = %x\n", dwFlags);
2121
2122         V_VT(pvarResult) = VT_I4;
2123         V_I4(pvarResult) = 10;
2124         return S_OK;
2125     }else if(!strcmp_wa(pstrCode, "simple script")) {
2126         CHECK_EXPECT(ParseScriptText_script);
2127         ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2128         ok(!strcmp_wa(pstrDelimiter, "</SCRIPT>"), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2129         ok(dwFlags == (SCRIPTTEXT_ISVISIBLE|SCRIPTTEXT_HOSTMANAGESSOURCE), "dwFlags = %x\n", dwFlags);
2130
2131         test_script_run();
2132         return S_OK;
2133     }
2134
2135     ok(0, "unexpected script %s\n", wine_dbgstr_w(pstrCode));
2136     return E_FAIL;
2137 }
2138
2139 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
2140     ActiveScriptParse_QueryInterface,
2141     ActiveScriptParse_AddRef,
2142     ActiveScriptParse_Release,
2143     ActiveScriptParse_InitNew,
2144     ActiveScriptParse_AddScriptlet,
2145     ActiveScriptParse_ParseScriptText
2146 };
2147
2148 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
2149
2150 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
2151 {
2152     *ppv = NULL;
2153
2154     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
2155         *ppv = iface;
2156         return S_OK;
2157     }
2158
2159     if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
2160         *ppv = &ActiveScriptParse;
2161         return S_OK;
2162     }
2163
2164     if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
2165         *ppv = &ActiveScriptParseProcedure;
2166         return S_OK;
2167     }
2168
2169     if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
2170         *ppv = &ActiveScriptProperty;
2171         return S_OK;
2172     }
2173
2174     if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2175         *ppv = &ObjectSafety;
2176         return S_OK;
2177     }
2178
2179     if(IsEqualGUID(&IID_IActiveScriptDebug, riid))
2180         return E_NOINTERFACE;
2181
2182     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2183     return E_NOINTERFACE;
2184 }
2185
2186 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
2187 {
2188     return 2;
2189 }
2190
2191 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
2192 {
2193     return 1;
2194 }
2195
2196 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
2197 {
2198     IActiveScriptSiteInterruptPoll *poll;
2199     IActiveScriptSiteDebug *debug;
2200     IServiceProvider *service;
2201     ICanHandleException *canexpection;
2202     LCID lcid;
2203     HRESULT hres;
2204
2205     CHECK_EXPECT(SetScriptSite);
2206
2207     ok(pass != NULL, "pass == NULL\n");
2208
2209     hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
2210     ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
2211     if(FAILED(hres))
2212         IActiveScriptSiteInterruptPoll_Release(poll);
2213
2214     hres = IActiveScriptSite_GetLCID(pass, &lcid);
2215     ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
2216
2217     hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
2218     ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2219
2220     hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
2221     ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
2222     if(SUCCEEDED(hres))
2223         IActiveScriptSiteDebug32_Release(debug);
2224
2225     hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
2226     ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
2227
2228     hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
2229     ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2230     if(SUCCEEDED(hres))
2231         IServiceProvider_Release(service);
2232
2233     site = pass;
2234     IActiveScriptSite_AddRef(site);
2235     return S_OK;
2236 }
2237
2238 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
2239                                             void **ppvObject)
2240 {
2241     ok(0, "unexpected call\n");
2242     return E_NOTIMPL;
2243 }
2244
2245 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
2246 {
2247     HRESULT hres;
2248
2249     switch(ss) {
2250     case SCRIPTSTATE_STARTED:
2251         CHECK_EXPECT(SetScriptState_STARTED);
2252         break;
2253     case SCRIPTSTATE_CONNECTED:
2254         CHECK_EXPECT(SetScriptState_CONNECTED);
2255         break;
2256     case SCRIPTSTATE_DISCONNECTED:
2257         CHECK_EXPECT(SetScriptState_DISCONNECTED);
2258         break;
2259     default:
2260         ok(0, "unexpected state %d\n", ss);
2261         return E_NOTIMPL;
2262     }
2263
2264     hres = IActiveScriptSite_OnStateChange(site, (state = ss));
2265     ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2266
2267     return S_OK;
2268 }
2269
2270 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
2271 {
2272     CHECK_EXPECT(GetScriptState);
2273
2274     *pssState = state;
2275     return S_OK;
2276 }
2277
2278 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
2279 {
2280     CHECK_EXPECT(Close);
2281     return E_NOTIMPL;
2282 }
2283
2284 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
2285         LPCOLESTR pstrName, DWORD dwFlags)
2286 {
2287     IDispatch *disp;
2288     IUnknown *unk = NULL, *unk2;
2289     HRESULT hres;
2290
2291     static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
2292
2293     static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
2294
2295     CHECK_EXPECT(AddNamedItem);
2296
2297     ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
2298     ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
2299
2300     hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
2301     ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
2302     ok(unk != NULL, "unk == NULL\n");
2303
2304     hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
2305     ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
2306     if(SUCCEEDED(hres))
2307         IDispatch_Release(disp);
2308
2309     hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
2310     ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
2311     if(SUCCEEDED(hres))
2312         IUnknown_Release(unk2);
2313
2314     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
2315     ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
2316
2317     IUnknown_Release(unk);
2318     return S_OK;
2319 }
2320
2321 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
2322                                          DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
2323 {
2324     ok(0, "unexpected call\n");
2325     return E_NOTIMPL;
2326 }
2327
2328 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
2329                                                 IDispatch **ppdisp)
2330 {
2331     CHECK_EXPECT(GetScriptDispatch);
2332
2333     ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2334
2335     if(!script_disp)
2336         return E_NOTIMPL;
2337
2338     *ppdisp = script_disp;
2339     return S_OK;
2340 }
2341
2342 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
2343                                                        SCRIPTTHREADID *pstridThread)
2344 {
2345     ok(0, "unexpected call\n");
2346     return E_NOTIMPL;
2347 }
2348
2349 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
2350                                                 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
2351 {
2352     ok(0, "unexpected call\n");
2353     return E_NOTIMPL;
2354 }
2355
2356 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
2357         SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
2358 {
2359     ok(0, "unexpected call\n");
2360     return E_NOTIMPL;
2361 }
2362
2363 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
2364         SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
2365 {
2366     ok(0, "unexpected call\n");
2367     return E_NOTIMPL;
2368 }
2369
2370 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
2371 {
2372     ok(0, "unexpected call\n");
2373     return E_NOTIMPL;
2374 }
2375
2376 static const IActiveScriptVtbl ActiveScriptVtbl = {
2377     ActiveScript_QueryInterface,
2378     ActiveScript_AddRef,
2379     ActiveScript_Release,
2380     ActiveScript_SetScriptSite,
2381     ActiveScript_GetScriptSite,
2382     ActiveScript_SetScriptState,
2383     ActiveScript_GetScriptState,
2384     ActiveScript_Close,
2385     ActiveScript_AddNamedItem,
2386     ActiveScript_AddTypeLib,
2387     ActiveScript_GetScriptDispatch,
2388     ActiveScript_GetCurrentScriptThreadID,
2389     ActiveScript_GetScriptThreadID,
2390     ActiveScript_GetScriptThreadState,
2391     ActiveScript_InterruptScriptThread,
2392     ActiveScript_Clone
2393 };
2394
2395 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
2396
2397 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2398 {
2399     *ppv = NULL;
2400
2401     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2402         *ppv = iface;
2403         return S_OK;
2404     }
2405
2406     if(IsEqualGUID(&IID_IMarshal, riid))
2407         return E_NOINTERFACE;
2408     if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
2409         return E_NOINTERFACE;
2410
2411     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2412     return E_NOTIMPL;
2413 }
2414
2415 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2416 {
2417     return 2;
2418 }
2419
2420 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2421 {
2422     return 1;
2423 }
2424
2425 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2426 {
2427     CHECK_EXPECT(CreateInstance);
2428
2429     ok(!outer, "outer = %p\n", outer);
2430     ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
2431     *ppv = &ActiveScript;
2432     return S_OK;
2433 }
2434
2435 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2436 {
2437     ok(0, "unexpected call\n");
2438     return S_OK;
2439 }
2440
2441 static const IClassFactoryVtbl ClassFactoryVtbl = {
2442     ClassFactory_QueryInterface,
2443     ClassFactory_AddRef,
2444     ClassFactory_Release,
2445     ClassFactory_CreateInstance,
2446     ClassFactory_LockServer
2447 };
2448
2449 static IClassFactory script_cf = { &ClassFactoryVtbl };
2450
2451 static const char simple_script_str[] =
2452     "<html><head></head><body>"
2453     "<div id=\"divid\"></div>"
2454     "<script language=\"TestScript\">simple script</script>"
2455     "</body></html>";
2456
2457 static void test_exec_script(IHTMLDocument2 *doc)
2458 {
2459     IHTMLWindow2 *window;
2460     BSTR code, lang;
2461     VARIANT v;
2462     HRESULT hres;
2463
2464     hres = IHTMLDocument2_get_parentWindow(doc, &window);
2465     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2466
2467     code = a2bstr("execScript call");
2468     lang = a2bstr("TestScript");
2469
2470     SET_EXPECT(ParseScriptText_execScript);
2471     hres = IHTMLWindow2_execScript(window, code, lang, &v);
2472     ok(hres == S_OK, "execScript failed: %08x\n", hres);
2473     ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2474     ok(V_I4(&v) == 10, "V_I4(v) = %d\n", V_I4(&v));
2475     CHECK_CALLED(ParseScriptText_execScript);
2476     SysFreeString(lang);
2477
2478     lang = a2bstr("invalid");
2479     V_VT(&v) = 100;
2480     hres = IHTMLWindow2_execScript(window, code, lang, &v);
2481     ok(hres == CO_E_CLASSSTRING, "execScript failed: %08x, expected CO_E_CLASSSTRING\n", hres);
2482     ok(V_VT(&v) == 100, "V_VT(v) = %d\n", V_VT(&v));
2483     SysFreeString(lang);
2484     SysFreeString(code);
2485
2486     IHTMLWindow2_Release(window);
2487 }
2488
2489 static void test_simple_script(void)
2490 {
2491     IHTMLDocument2 *doc;
2492
2493     doc = create_document();
2494     if(!doc)
2495         return;
2496
2497     SET_EXPECT(CreateInstance);
2498     SET_EXPECT(GetInterfaceSafetyOptions);
2499     SET_EXPECT(SetInterfaceSafetyOptions);
2500     SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
2501     SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
2502     SET_EXPECT(InitNew);
2503     SET_EXPECT(SetScriptSite);
2504     SET_EXPECT(GetScriptState);
2505     SET_EXPECT(SetScriptState_STARTED);
2506     SET_EXPECT(AddNamedItem);
2507     SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
2508     SET_EXPECT(ParseScriptText_script);
2509     SET_EXPECT(SetScriptState_CONNECTED);
2510
2511     load_doc(doc, simple_script_str);
2512
2513     CHECK_CALLED(CreateInstance);
2514     CHECK_CALLED(GetInterfaceSafetyOptions);
2515     CHECK_CALLED(SetInterfaceSafetyOptions);
2516     CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
2517     CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
2518     CHECK_CALLED(InitNew);
2519     CHECK_CALLED(SetScriptSite);
2520     CHECK_CALLED(GetScriptState);
2521     CHECK_CALLED(SetScriptState_STARTED);
2522     CHECK_CALLED(AddNamedItem);
2523     CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
2524     CHECK_CALLED(ParseScriptText_script);
2525     CHECK_CALLED(SetScriptState_CONNECTED);
2526
2527     test_exec_script(doc);
2528
2529     if(site)
2530         IActiveScriptSite_Release(site);
2531     if(window_dispex)
2532         IDispatchEx_Release(window_dispex);
2533
2534     SET_EXPECT(SetScriptState_DISCONNECTED);
2535     SET_EXPECT(Close);
2536
2537     IHTMLDocument2_Release(doc);
2538
2539     CHECK_CALLED(SetScriptState_DISCONNECTED);
2540     CHECK_CALLED(Close);
2541 }
2542
2543 static void run_js_script(const char *test_name)
2544 {
2545     WCHAR url[INTERNET_MAX_URL_LENGTH];
2546     char urlA[INTERNET_MAX_URL_LENGTH];
2547     IPersistMoniker *persist;
2548     IHTMLDocument2 *doc;
2549     IMoniker *mon;
2550     MSG msg;
2551     HRESULT hres;
2552
2553     static const char res[] = "res://";
2554
2555     trace("running %s...\n", test_name);
2556
2557     doc = create_document();
2558     if(!doc)
2559         return;
2560
2561     set_client_site(doc, TRUE);
2562     do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2563
2564     lstrcpyA(urlA, res);
2565     GetModuleFileNameA(NULL, urlA + lstrlenA(res), sizeof(urlA) - lstrlenA(res));
2566     lstrcatA(urlA, "/");
2567     lstrcatA(urlA, test_name);
2568     MultiByteToWideChar(CP_ACP, 0, urlA, -1, url, sizeof(url)/sizeof(WCHAR));
2569
2570     hres = CreateURLMoniker(NULL, url, &mon);
2571     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2572
2573     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker, (void**)&persist);
2574     ok(hres == S_OK, "Could not get IPersistMoniker iface: %08x\n", hres);
2575
2576     hres = IPersistMoniker_Load(persist, FALSE, mon, NULL, 0);
2577     ok(hres == S_OK, "Load failed: %08x\n", hres);
2578
2579     IMoniker_Release(mon);
2580     IPersistMoniker_Release(persist);
2581
2582     SET_EXPECT(external_success);
2583
2584     while(!called_external_success && GetMessage(&msg, NULL, 0, 0)) {
2585         TranslateMessage(&msg);
2586         DispatchMessage(&msg);
2587     }
2588
2589     CHECK_CALLED(external_success);
2590
2591     set_client_site(doc, FALSE);
2592     IHTMLDocument2_Release(doc);
2593 }
2594
2595 static void run_js_tests(void)
2596 {
2597     run_js_script("jstest.html");
2598     run_js_script("exectest.html");
2599 }
2600
2601 static BOOL init_registry(BOOL init)
2602 {
2603     return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
2604         && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
2605                     NULL, init)
2606         && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
2607                     NULL, init);
2608 }
2609
2610 static BOOL register_script_engine(void)
2611 {
2612     DWORD regid;
2613     HRESULT hres;
2614
2615     if(!init_registry(TRUE)) {
2616         init_registry(FALSE);
2617         return FALSE;
2618     }
2619
2620     hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
2621                                  CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2622     ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
2623
2624     return TRUE;
2625 }
2626
2627 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2628 {
2629     return DefWindowProc(hwnd, msg, wParam, lParam);
2630 }
2631
2632 static HWND create_container_window(void)
2633 {
2634     static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
2635     static WNDCLASSEXA wndclass = {
2636         sizeof(WNDCLASSEXA),
2637         0,
2638         wnd_proc,
2639         0, 0, NULL, NULL, NULL, NULL, NULL,
2640         szHTMLDocumentTest,
2641         NULL
2642     };
2643
2644     RegisterClassExA(&wndclass);
2645     return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
2646             WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
2647             300, 300, NULL, NULL, NULL, NULL);
2648 }
2649
2650 START_TEST(script)
2651 {
2652     CoInitialize(NULL);
2653     container_hwnd = create_container_window();
2654
2655     if(winetest_interactive || ! is_ie_hardened()) {
2656         if(register_script_engine()) {
2657             test_simple_script();
2658             run_js_tests();
2659             init_registry(FALSE);
2660         }else {
2661             skip("Could not register TestScript engine\n");
2662         }
2663     }else {
2664         skip("IE running in Enhanced Security Configuration\n");
2665     }
2666
2667     DestroyWindow(container_hwnd);
2668     CoUninitialize();
2669 }