1 /*
2  * Copyright 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 #include <stdio.h>
20 
21 #define COBJMACROS
22 #define CONST_VTABLE
23 
24 #include <ole2.h>
25 #include <dispex.h>
26 #include <activscp.h>
27 #include <objsafe.h>
28 #include <urlmon.h>
29 #include <mshtmhst.h>
30 
31 #include "wine/test.h"
32 
33 #ifdef _WIN64
34 
35 #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
36 #define IActiveScriptParse_Release IActiveScriptParse64_Release
37 #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
38 #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
39 #define IActiveScriptParseProcedure2_Release \
40     IActiveScriptParseProcedure2_64_Release
41 #define IActiveScriptParseProcedure2_ParseProcedureText \
42     IActiveScriptParseProcedure2_64_ParseProcedureText
43 
44 #else
45 
46 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
47 #define IActiveScriptParse_Release IActiveScriptParse32_Release
48 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
49 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
50 #define IActiveScriptParseProcedure2_Release \
51     IActiveScriptParseProcedure2_32_Release
52 #define IActiveScriptParseProcedure2_ParseProcedureText \
53     IActiveScriptParseProcedure2_32_ParseProcedureText
54 
55 #endif
56 
57 static const CLSID CLSID_JScript =
58     {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
59 
60 #define DEFINE_EXPECT(func) \
61     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
62 
63 #define SET_EXPECT(func) \
64     expect_ ## func = TRUE
65 
66 #define CHECK_EXPECT2(func) \
67     do { \
68         ok(expect_ ##func, "unexpected call " #func "\n"); \
69         called_ ## func = TRUE; \
70     }while(0)
71 
72 #define CHECK_EXPECT(func) \
73     do { \
74         CHECK_EXPECT2(func); \
75         expect_ ## func = FALSE; \
76     }while(0)
77 
78 #define CHECK_CALLED(func) \
79     do { \
80         ok(called_ ## func, "expected " #func "\n"); \
81         expect_ ## func = called_ ## func = FALSE; \
82     }while(0)
83 
84 DEFINE_EXPECT(CreateInstance);
85 DEFINE_EXPECT(ProcessUrlAction);
86 DEFINE_EXPECT(QueryCustomPolicy);
87 DEFINE_EXPECT(reportSuccess);
88 DEFINE_EXPECT(Host_QS_SecMgr);
89 DEFINE_EXPECT(Caller_QS_SecMgr);
90 DEFINE_EXPECT(QI_IObjectWithSite);
91 DEFINE_EXPECT(SetSite);
92 
93 static const WCHAR testW[] = {'t','e','s','t',0};
94 
95 static HRESULT QS_SecMgr_hres;
96 static HRESULT ProcessUrlAction_hres;
97 static DWORD ProcessUrlAction_policy;
98 static HRESULT CreateInstance_hres;
99 static HRESULT QueryCustomPolicy_hres;
100 static DWORD QueryCustomPolicy_psize;
101 static DWORD QueryCustomPolicy_policy;
102 static HRESULT QI_IDispatch_hres;
103 static HRESULT SetSite_hres;
104 static BOOL AllowIServiceProvider;
105 
106 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
107 
108 static const GUID CLSID_TestObj =
109     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
110 
111 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
112 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
113     {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
114 
115 #define DISPID_TEST_REPORTSUCCESS    0x1000
116 
117 #define DISPID_GLOBAL_OK             0x2000
118 
119 static BSTR a2bstr(const char *str)
120 {
121     BSTR ret;
122     int len;
123 
124     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
125     ret = SysAllocStringLen(NULL, len-1);
126     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
127 
128     return ret;
129 }
130 
131 static int strcmp_wa(LPCWSTR strw, const char *stra)
132 {
133     CHAR buf[512];
134     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
135     return lstrcmpA(buf, stra);
136 }
137 
138 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
139 {
140     ok(0, "unexpected call\n");
141     return E_NOTIMPL;
142 }
143 
144 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
145 {
146     return 2;
147 }
148 
149 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
150 {
151     return 1;
152 }
153 
154 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
155 {
156     IServiceProvider *sp;
157     HRESULT hres;
158 
159 
160     CHECK_EXPECT(SetSite);
161     ok(pUnkSite != NULL, "pUnkSite == NULL\n");
162 
163     hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
164     ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
165     IServiceProvider_Release(sp);
166 
167     return SetSite_hres;
168 }
169 
170 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
171 {
172     ok(0, "unexpected call\n");
173     return E_NOTIMPL;
174 }
175 
176 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
177     ObjectWithSite_QueryInterface,
178     ObjectWithSite_AddRef,
179     ObjectWithSite_Release,
180     ObjectWithSite_SetSite,
181     ObjectWithSite_GetSite
182 };
183 
184 static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
185 
186 static IObjectWithSite *object_with_site;
187 
188 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
189 {
190     *ppv = NULL;
191 
192     if(IsEqualGUID(riid, &IID_IUnknown)) {
193        *ppv = iface;
194     }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
195         if(FAILED(QI_IDispatch_hres))
196             return QI_IDispatch_hres;
197         *ppv = iface;
198     }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
199         CHECK_EXPECT(QI_IObjectWithSite);
200         *ppv = object_with_site;
201     }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
202         ok(0, "Unexpected IID_IObjectSafety query\n");
203     }
204 
205     return *ppv ? S_OK : E_NOINTERFACE;
206 }
207 
208 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
209 {
210     return 2;
211 }
212 
213 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
214 {
215     return 1;
216 }
217 
218 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
219 {
220     ok(0, "unexpected call\n");
221     return E_NOTIMPL;
222 }
223 
224 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
225                                               LCID lcid, ITypeInfo **ppTInfo)
226 {
227     ok(0, "unexpected call\n");
228     return E_NOTIMPL;
229 }
230 
231 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
232                                                 LPOLESTR *rgszNames, UINT cNames,
233                                                 LCID lcid, DISPID *rgDispId)
234 {
235     ok(0, "unexpected call\n");
236     return E_NOTIMPL;
237 }
238 
239 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
240                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
241                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
242 {
243     ok(0, "unexpected call\n");
244     return E_NOTIMPL;
245 }
246 
247 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
248 {
249     ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
250     return E_NOTIMPL;
251 }
252 
253 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
254 {
255     ok(0, "unexpected call\n");
256     return E_NOTIMPL;
257 }
258 
259 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
260 {
261     ok(0, "unexpected call\n");
262     return E_NOTIMPL;
263 }
264 
265 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
266 {
267     ok(0, "unexpected call\n");
268     return E_NOTIMPL;
269 }
270 
271 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
272 {
273     ok(0, "unexpected call\n");
274     return E_NOTIMPL;
275 }
276 
277 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
278 {
279     ok(0, "unexpected call\n");
280     return E_NOTIMPL;
281 }
282 
283 static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
284 {
285     if(!strcmp_wa(bstrName, "reportSuccess")) {
286         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
287         *pid = DISPID_TEST_REPORTSUCCESS;
288         return S_OK;
289     }
290 
291     ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
292     return E_NOTIMPL;
293 }
294 
295 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
296         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
297 {
298     switch(id) {
299     case DISPID_TEST_REPORTSUCCESS:
300         CHECK_EXPECT(reportSuccess);
301 
302         ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
303         ok(pdp != NULL, "pdp == NULL\n");
304         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
305         ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
306         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
307         ok(!pvarRes, "pvarRes != NULL\n");
308         ok(pei != NULL, "pei == NULL\n");
309         break;
310 
311     default:
312         ok(0, "unexpected call\n");
313         return E_NOTIMPL;
314     }
315 
316     return S_OK;
317 }
318 
319 static IDispatchExVtbl testObjVtbl = {
320     DispatchEx_QueryInterface,
321     DispatchEx_AddRef,
322     DispatchEx_Release,
323     DispatchEx_GetTypeInfoCount,
324     DispatchEx_GetTypeInfo,
325     DispatchEx_GetIDsOfNames,
326     DispatchEx_Invoke,
327     Test_GetDispID,
328     Test_InvokeEx,
329     DispatchEx_DeleteMemberByName,
330     DispatchEx_DeleteMemberByDispID,
331     DispatchEx_GetMemberProperties,
332     DispatchEx_GetMemberName,
333     DispatchEx_GetNextDispID,
334     DispatchEx_GetNameSpaceParent
335 };
336 
337 static IDispatchEx testObj = { &testObjVtbl };
338 
339 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
340 {
341     if(!strcmp_wa(bstrName, "ok")) {
342         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
343         *pid = DISPID_GLOBAL_OK;
344         return S_OK;
345     }
346 
347     ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
348     return E_NOTIMPL;
349 }
350 
351 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
352         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
353 {
354     switch(id) {
355     case DISPID_GLOBAL_OK:
356         ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
357         ok(pdp != NULL, "pdp == NULL\n");
358         ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
359         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
360         ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
361         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
362         ok(pei != NULL, "pei == NULL\n");
363 
364         ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
365         ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
366         ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
367         break;
368 
369     default:
370         ok(0, "unexpected call\n");
371         return E_NOTIMPL;
372     }
373 
374     return S_OK;
375 }
376 
377 static IDispatchExVtbl globalObjVtbl = {
378     DispatchEx_QueryInterface,
379     DispatchEx_AddRef,
380     DispatchEx_Release,
381     DispatchEx_GetTypeInfoCount,
382     DispatchEx_GetTypeInfo,
383     DispatchEx_GetIDsOfNames,
384     DispatchEx_Invoke,
385     Global_GetDispID,
386     Global_InvokeEx,
387     DispatchEx_DeleteMemberByName,
388     DispatchEx_DeleteMemberByDispID,
389     DispatchEx_GetMemberProperties,
390     DispatchEx_GetMemberName,
391     DispatchEx_GetNextDispID,
392     DispatchEx_GetNameSpaceParent
393 };
394 
395 static IDispatchEx globalObj = { &globalObjVtbl };
396 
397 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
398 {
399     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
400         *ppv = iface;
401         return S_OK;
402     }
403 
404     /* TODO: IClassFactoryEx */
405     *ppv = NULL;
406     return E_NOINTERFACE;
407 }
408 
409 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
410 {
411     return 2;
412 }
413 
414 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
415 {
416     return 1;
417 }
418 
419 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
420 {
421     CHECK_EXPECT(CreateInstance);
422 
423     ok(!outer, "outer = %p\n", outer);
424     ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
425 
426     if(SUCCEEDED(CreateInstance_hres))
427         *ppv = &testObj;
428     return CreateInstance_hres;
429 }
430 
431 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
432 {
433     ok(0, "unexpected call\n");
434     return S_OK;
435 }
436 
437 static const IClassFactoryVtbl ClassFactoryVtbl = {
438     ClassFactory_QueryInterface,
439     ClassFactory_AddRef,
440     ClassFactory_Release,
441     ClassFactory_CreateInstance,
442     ClassFactory_LockServer
443 };
444 
445 static IClassFactory activex_cf = { &ClassFactoryVtbl };
446 
447 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
448 {
449     ok(0, "unexpected call\n");
450     return E_NOINTERFACE;
451 }
452 
453 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
454 {
455     return 2;
456 }
457 
458 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
459 {
460     return 1;
461 }
462 
463 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface,  BYTE *pbSecurityId,
464         DWORD *pcbSecurityId, DWORD_PTR dwReserved)
465 {
466     ok(0, "unexpected call\n");
467     return E_NOTIMPL;
468 }
469 
470 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
471         BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
472 {
473     CHECK_EXPECT(ProcessUrlAction);
474 
475     ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
476     ok(pPolicy != NULL, "pPolicy == NULL\n");
477     ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
478     ok(pContext != NULL, "pContext == NULL\n");
479     ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
480     ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", wine_dbgstr_guid((const IID*)pContext));
481     ok(!dwFlags, "dwFlags = %x\n", dwFlags);
482     ok(!dwReserved, "dwReserved = %x\n", dwReserved);
483 
484     if(SUCCEEDED(ProcessUrlAction_hres))
485         *(DWORD*)pPolicy = ProcessUrlAction_policy;
486     return ProcessUrlAction_hres;
487 }
488 
489 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
490         BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
491 {
492     const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
493     DWORD *ret;
494 
495     CHECK_EXPECT(QueryCustomPolicy);
496 
497     ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", wine_dbgstr_guid(guidKey));
498 
499     ok(ppPolicy != NULL, "ppPolicy == NULL\n");
500     ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
501     ok(pContext != NULL, "pContext == NULL\n");
502     ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
503     ok(!dwReserved, "dwReserved = %x\n", dwReserved);
504 
505     /* TODO: CLSID */
506     ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
507     ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
508 
509     if(FAILED(QueryCustomPolicy_hres))
510         return QueryCustomPolicy_hres;
511 
512     ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
513     *ppPolicy = (BYTE*)ret;
514     *pcbPolicy = QueryCustomPolicy_psize;
515     memset(ret, 0, QueryCustomPolicy_psize);
516     if(QueryCustomPolicy_psize >= sizeof(DWORD))
517         *ret = QueryCustomPolicy_policy;
518 
519     return QueryCustomPolicy_hres;
520 }
521 
522 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
523     InternetHostSecurityManager_QueryInterface,
524     InternetHostSecurityManager_AddRef,
525     InternetHostSecurityManager_Release,
526     InternetHostSecurityManager_GetSecurityId,
527     InternetHostSecurityManager_ProcessUrlAction,
528     InternetHostSecurityManager_QueryCustomPolicy
529 };
530 
531 static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
532 
533 static IServiceProvider ServiceProvider;
534 
535 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
536 {
537     ok(0, "unexpected call\n");
538     return E_NOINTERFACE;
539 }
540 
541 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
542 {
543     return 2;
544 }
545 
546 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
547 {
548     return 1;
549 }
550 
551 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
552         REFGUID guidService, REFIID riid, void **ppv)
553 {
554     if(IsEqualGUID(&SID_GetCaller, guidService))
555         return E_NOINTERFACE;
556 
557     if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
558         if(iface == &ServiceProvider)
559             CHECK_EXPECT(Host_QS_SecMgr);
560         else
561             CHECK_EXPECT(Caller_QS_SecMgr);
562         ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
563         if(SUCCEEDED(QS_SecMgr_hres))
564             *ppv = &InternetHostSecurityManager;
565         return QS_SecMgr_hres;
566     }
567 
568     ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
569     return E_NOINTERFACE;
570 }
571 
572 static IServiceProviderVtbl ServiceProviderVtbl = {
573     ServiceProvider_QueryInterface,
574     ServiceProvider_AddRef,
575     ServiceProvider_Release,
576     ServiceProvider_QueryService
577 };
578 
579 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
580 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
581 
582 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
583 {
584     if(IsEqualGUID(&IID_IUnknown, riid)) {
585         *ppv = iface;
586     }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
587         *ppv = iface;
588     }else if(IsEqualGUID(&IID_IServiceProvider, riid) && AllowIServiceProvider) {
589         *ppv = &ServiceProvider;
590     }else {
591         *ppv = NULL;
592         return E_NOINTERFACE;
593     }
594 
595     IUnknown_AddRef((IUnknown*)*ppv);
596     return S_OK;
597 }
598 
599 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
600 {
601     return 2;
602 }
603 
604 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
605 {
606     return 1;
607 }
608 
609 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
610 {
611     *plcid = GetUserDefaultLCID();
612     return S_OK;
613 }
614 
615 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
616         DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
617 {
618     ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
619     ok(!ppti, "ppti != NULL\n");
620     ok(!strcmp_wa(pstrName, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
621 
622     *ppiunkItem = (IUnknown*)&globalObj;
623     return S_OK;
624 }
625 
626 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
627 {
628     return E_NOTIMPL;
629 }
630 
631 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
632         const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
633 {
634     return E_NOTIMPL;
635 }
636 
637 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
638 {
639     return E_NOTIMPL;
640 }
641 
642 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
643 {
644     return E_NOTIMPL;
645 }
646 
647 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
648 {
649     return E_NOTIMPL;
650 }
651 
652 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
653 {
654     return E_NOTIMPL;
655 }
656 
657 #undef ACTSCPSITE_THIS
658 
659 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
660     ActiveScriptSite_QueryInterface,
661     ActiveScriptSite_AddRef,
662     ActiveScriptSite_Release,
663     ActiveScriptSite_GetLCID,
664     ActiveScriptSite_GetItemInfo,
665     ActiveScriptSite_GetDocVersionString,
666     ActiveScriptSite_OnScriptTerminate,
667     ActiveScriptSite_OnStateChange,
668     ActiveScriptSite_OnScriptError,
669     ActiveScriptSite_OnEnterScript,
670     ActiveScriptSite_OnLeaveScript
671 };
672 
673 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
674 
675 static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
676 {
677     IObjectSafety *safety;
678     DWORD supported, enabled, options_all, options_set;
679     HRESULT hres;
680 
681     hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
682     ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
683     if(FAILED(hres))
684         return;
685 
686     options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
687     if(use_sec_mgr)
688         options_set = options_all;
689     else
690         options_set = INTERFACE_USES_DISPEX;
691 
692     hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
693     ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
694 
695     supported = enabled = 0xdeadbeef;
696     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
697     ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
698     ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
699     ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
700 
701     IObjectSafety_Release(safety);
702 }
703 
704 #define parse_script_a(p,s) _parse_script_a(__LINE__,p,s)
705 static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const char *script)
706 {
707     BSTR str;
708     HRESULT hres;
709 
710     str = a2bstr(script);
711     hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
712     SysFreeString(str);
713     ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
714 }
715 
716 static IActiveScriptParse *create_script(BOOL skip_tests, BOOL use_sec_mgr)
717 {
718     IActiveScriptParse *parser;
719     IActiveScript *script;
720     HRESULT hres;
721 
722     QS_SecMgr_hres = S_OK;
723     ProcessUrlAction_hres = S_OK;
724     ProcessUrlAction_policy = URLPOLICY_ALLOW;
725     CreateInstance_hres = S_OK;
726     QueryCustomPolicy_hres = S_OK;
727     QueryCustomPolicy_psize = sizeof(DWORD);
728     QueryCustomPolicy_policy = URLPOLICY_ALLOW;
729     QI_IDispatch_hres = S_OK;
730     SetSite_hres = S_OK;
731     AllowIServiceProvider = TRUE;
732 
733     hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
734             &IID_IActiveScript, (void**)&script);
735     if(!skip_tests)
736         ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
737     if(FAILED(hres))
738         return NULL;
739 
740     if(!skip_tests)
741         set_safety_options((IUnknown*)script, use_sec_mgr);
742 
743     hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
744     ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
745 
746     hres = IActiveScriptParse_InitNew(parser);
747     ok(hres == S_OK, "InitNew failed: %08x\n", hres);
748 
749     hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
750     ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
751 
752     hres = IActiveScript_AddNamedItem(script, testW,
753             SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
754     ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
755 
756     hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
757     ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
758 
759     IActiveScript_Release(script);
760 
761     if(!skip_tests) {
762         parse_script_a(parser,
763                 "function testException(func, type, number) {\n"
764                 "    try {\n"
765                 "        func();\n"
766                 "    }catch(e) {\n"
767                 "        ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n"
768                 "        ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n"
769                 "        return;\n"
770                 "    }\n"
771                 "    ok(false, 'exception expected');\n"
772                 "}");
773     }
774 
775     return parser;
776 }
777 
778 static IDispatchEx *parse_procedure_a(IActiveScriptParse *parser, const char *src)
779 {
780     IActiveScriptParseProcedure2 *parse_proc;
781     IDispatchEx *dispex;
782     IDispatch *disp;
783     BSTR str;
784     HRESULT hres;
785 
786     hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
787     ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2: %08x\n", hres);
788 
789     str = a2bstr(src);
790     hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, str, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, &disp);
791     SysFreeString(str);
792     IActiveScriptParseProcedure2_Release(parse_proc);
793     ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
794     ok(disp != NULL, "disp == NULL\n");
795 
796     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
797     IDispatch_Release(disp);
798     ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
799 
800     return dispex;
801 }
802 
803 #define call_procedure(p,c) _call_procedure(__LINE__,p,c)
804 static void _call_procedure(unsigned line, IDispatchEx *proc, IServiceProvider *caller)
805 {
806     DISPPARAMS dp = {NULL,NULL,0,0};
807     EXCEPINFO ei = {0};
808     HRESULT hres;
809 
810     hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, NULL, &ei, caller);
811     ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
812 
813 }
814 
815 static void test_ActiveXObject(void)
816 {
817     IActiveScriptParse *parser;
818     IDispatchEx *proc;
819 
820     parser = create_script(FALSE, TRUE);
821 
822     SET_EXPECT(Host_QS_SecMgr);
823     SET_EXPECT(ProcessUrlAction);
824     SET_EXPECT(CreateInstance);
825     SET_EXPECT(QueryCustomPolicy);
826     SET_EXPECT(QI_IObjectWithSite);
827     SET_EXPECT(reportSuccess);
828     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
829     CHECK_CALLED(Host_QS_SecMgr);
830     CHECK_CALLED(ProcessUrlAction);
831     CHECK_CALLED(CreateInstance);
832     CHECK_CALLED(QueryCustomPolicy);
833     CHECK_CALLED(QI_IObjectWithSite);
834     CHECK_CALLED(reportSuccess);
835 
836     proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
837 
838     SET_EXPECT(ProcessUrlAction);
839     SET_EXPECT(CreateInstance);
840     SET_EXPECT(QueryCustomPolicy);
841     SET_EXPECT(QI_IObjectWithSite);
842     SET_EXPECT(reportSuccess);
843     call_procedure(proc, NULL);
844     CHECK_CALLED(ProcessUrlAction);
845     CHECK_CALLED(CreateInstance);
846     CHECK_CALLED(QueryCustomPolicy);
847     CHECK_CALLED(QI_IObjectWithSite);
848     CHECK_CALLED(reportSuccess);
849 
850     SET_EXPECT(ProcessUrlAction);
851     SET_EXPECT(CreateInstance);
852     SET_EXPECT(QueryCustomPolicy);
853     SET_EXPECT(QI_IObjectWithSite);
854     SET_EXPECT(reportSuccess);
855     call_procedure(proc, &caller_sp);
856     CHECK_CALLED(ProcessUrlAction);
857     CHECK_CALLED(CreateInstance);
858     CHECK_CALLED(QueryCustomPolicy);
859     CHECK_CALLED(QI_IObjectWithSite);
860     CHECK_CALLED(reportSuccess);
861 
862     IDispatchEx_Release(proc);
863     IActiveScriptParse_Release(parser);
864 
865     parser = create_script(FALSE, TRUE);
866     proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
867 
868     SET_EXPECT(Host_QS_SecMgr);
869     SET_EXPECT(ProcessUrlAction);
870     SET_EXPECT(CreateInstance);
871     SET_EXPECT(QueryCustomPolicy);
872     SET_EXPECT(QI_IObjectWithSite);
873     SET_EXPECT(reportSuccess);
874     call_procedure(proc, &caller_sp);
875     CHECK_CALLED(Host_QS_SecMgr);
876     CHECK_CALLED(ProcessUrlAction);
877     CHECK_CALLED(CreateInstance);
878     CHECK_CALLED(QueryCustomPolicy);
879     CHECK_CALLED(QI_IObjectWithSite);
880     CHECK_CALLED(reportSuccess);
881 
882     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);");
883 
884     IDispatchEx_Release(proc);
885     IActiveScriptParse_Release(parser);
886 
887     parser = create_script(FALSE, TRUE);
888     QS_SecMgr_hres = E_NOINTERFACE;
889 
890     SET_EXPECT(Host_QS_SecMgr);
891     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
892     CHECK_CALLED(Host_QS_SecMgr);
893 
894     IActiveScriptParse_Release(parser);
895 
896     parser = create_script(FALSE, TRUE);
897     ProcessUrlAction_hres = E_FAIL;
898 
899     SET_EXPECT(Host_QS_SecMgr);
900     SET_EXPECT(ProcessUrlAction);
901     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
902     CHECK_CALLED(Host_QS_SecMgr);
903     CHECK_CALLED(ProcessUrlAction);
904 
905     IActiveScriptParse_Release(parser);
906 
907     parser = create_script(FALSE, TRUE);
908     ProcessUrlAction_policy = URLPOLICY_DISALLOW;
909 
910     SET_EXPECT(Host_QS_SecMgr);
911     SET_EXPECT(ProcessUrlAction);
912     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
913     CHECK_CALLED(Host_QS_SecMgr);
914     CHECK_CALLED(ProcessUrlAction);
915 
916     IActiveScriptParse_Release(parser);
917 
918     parser = create_script(FALSE, TRUE);
919     CreateInstance_hres = E_FAIL;
920 
921     SET_EXPECT(Host_QS_SecMgr);
922     SET_EXPECT(ProcessUrlAction);
923     SET_EXPECT(CreateInstance);
924     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
925     CHECK_CALLED(Host_QS_SecMgr);
926     CHECK_CALLED(ProcessUrlAction);
927     CHECK_CALLED(CreateInstance);
928 
929     IActiveScriptParse_Release(parser);
930 
931     parser = create_script(FALSE, TRUE);
932     QueryCustomPolicy_hres = E_FAIL;
933 
934     SET_EXPECT(Host_QS_SecMgr);
935     SET_EXPECT(ProcessUrlAction);
936     SET_EXPECT(CreateInstance);
937     SET_EXPECT(QueryCustomPolicy);
938     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
939     CHECK_CALLED(Host_QS_SecMgr);
940     CHECK_CALLED(ProcessUrlAction);
941     CHECK_CALLED(CreateInstance);
942     CHECK_CALLED(QueryCustomPolicy);
943 
944     IActiveScriptParse_Release(parser);
945 
946     parser = create_script(FALSE, TRUE);
947     QueryCustomPolicy_psize = 6;
948 
949     SET_EXPECT(Host_QS_SecMgr);
950     SET_EXPECT(ProcessUrlAction);
951     SET_EXPECT(CreateInstance);
952     SET_EXPECT(QueryCustomPolicy);
953     SET_EXPECT(QI_IObjectWithSite);
954     SET_EXPECT(reportSuccess);
955     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
956     CHECK_CALLED(Host_QS_SecMgr);
957     CHECK_CALLED(ProcessUrlAction);
958     CHECK_CALLED(CreateInstance);
959     CHECK_CALLED(QueryCustomPolicy);
960     CHECK_CALLED(QI_IObjectWithSite);
961     CHECK_CALLED(reportSuccess);
962 
963     IActiveScriptParse_Release(parser);
964 
965     parser = create_script(FALSE, TRUE);
966     QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
967 
968     SET_EXPECT(Host_QS_SecMgr);
969     SET_EXPECT(ProcessUrlAction);
970     SET_EXPECT(CreateInstance);
971     SET_EXPECT(QueryCustomPolicy);
972     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
973     CHECK_CALLED(Host_QS_SecMgr);
974     CHECK_CALLED(ProcessUrlAction);
975     CHECK_CALLED(CreateInstance);
976     CHECK_CALLED(QueryCustomPolicy);
977 
978     QueryCustomPolicy_psize = 6;
979 
980     SET_EXPECT(ProcessUrlAction);
981     SET_EXPECT(CreateInstance);
982     SET_EXPECT(QueryCustomPolicy);
983     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
984     CHECK_CALLED(ProcessUrlAction);
985     CHECK_CALLED(CreateInstance);
986     CHECK_CALLED(QueryCustomPolicy);
987 
988     QueryCustomPolicy_policy = URLPOLICY_ALLOW;
989     QueryCustomPolicy_psize = 3;
990 
991     SET_EXPECT(ProcessUrlAction);
992     SET_EXPECT(CreateInstance);
993     SET_EXPECT(QueryCustomPolicy);
994     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
995     CHECK_CALLED(ProcessUrlAction);
996     CHECK_CALLED(CreateInstance);
997     CHECK_CALLED(QueryCustomPolicy);
998 
999     IActiveScriptParse_Release(parser);
1000 
1001     parser = create_script(FALSE, FALSE);
1002 
1003     SET_EXPECT(CreateInstance);
1004     SET_EXPECT(QI_IObjectWithSite);
1005     SET_EXPECT(reportSuccess);
1006     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1007     CHECK_CALLED(CreateInstance);
1008     CHECK_CALLED(QI_IObjectWithSite);
1009     CHECK_CALLED(reportSuccess);
1010 
1011     IActiveScriptParse_Release(parser);
1012 
1013     parser = create_script(FALSE, TRUE);
1014     object_with_site = &ObjectWithSite;
1015 
1016     SET_EXPECT(Host_QS_SecMgr);
1017     SET_EXPECT(ProcessUrlAction);
1018     SET_EXPECT(CreateInstance);
1019     SET_EXPECT(QueryCustomPolicy);
1020     SET_EXPECT(QI_IObjectWithSite);
1021     SET_EXPECT(SetSite);
1022     SET_EXPECT(reportSuccess);
1023     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1024     CHECK_CALLED(Host_QS_SecMgr);
1025     CHECK_CALLED(ProcessUrlAction);
1026     CHECK_CALLED(CreateInstance);
1027     CHECK_CALLED(QueryCustomPolicy);
1028     CHECK_CALLED(QI_IObjectWithSite);
1029     CHECK_CALLED(SetSite);
1030     CHECK_CALLED(reportSuccess);
1031 
1032     SetSite_hres = E_FAIL;
1033     SET_EXPECT(ProcessUrlAction);
1034     SET_EXPECT(CreateInstance);
1035     SET_EXPECT(QueryCustomPolicy);
1036     SET_EXPECT(QI_IObjectWithSite);
1037     SET_EXPECT(SetSite);
1038     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1039     CHECK_CALLED(ProcessUrlAction);
1040     CHECK_CALLED(CreateInstance);
1041     CHECK_CALLED(QueryCustomPolicy);
1042     CHECK_CALLED(QI_IObjectWithSite);
1043     CHECK_CALLED(SetSite);
1044 
1045     IActiveScriptParse_Release(parser);
1046 
1047     /* No IServiceProvider Interface */
1048     parser = create_script(FALSE, FALSE);
1049     object_with_site = &ObjectWithSite;
1050     AllowIServiceProvider = FALSE;
1051 
1052     SET_EXPECT(CreateInstance);
1053     SET_EXPECT(QI_IObjectWithSite);
1054     SET_EXPECT(reportSuccess);
1055     SET_EXPECT(SetSite);
1056     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1057     CHECK_CALLED(CreateInstance);
1058     CHECK_CALLED(QI_IObjectWithSite);
1059     CHECK_CALLED(reportSuccess);
1060     CHECK_CALLED(SetSite);
1061 
1062     IActiveScriptParse_Release(parser);
1063 
1064     parser = create_script(FALSE, TRUE);
1065     object_with_site = &ObjectWithSite;
1066     AllowIServiceProvider = FALSE;
1067 
1068     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1069 
1070     IActiveScriptParse_Release(parser);
1071 }
1072 
1073 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1074 {
1075     HKEY hkey;
1076     DWORD res;
1077 
1078     if(!init) {
1079         RegDeleteKeyA(HKEY_CLASSES_ROOT, key_name);
1080         return TRUE;
1081     }
1082 
1083     res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1084     if(res != ERROR_SUCCESS)
1085         return FALSE;
1086 
1087     if(def_value)
1088         res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1089 
1090     RegCloseKey(hkey);
1091 
1092     return res == ERROR_SUCCESS;
1093 }
1094 
1095 static BOOL init_registry(BOOL init)
1096 {
1097     return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1098 }
1099 
1100 static BOOL register_activex(void)
1101 {
1102     DWORD regid;
1103     HRESULT hres;
1104 
1105     if(!init_registry(TRUE)) {
1106         init_registry(FALSE);
1107         return FALSE;
1108     }
1109 
1110     hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1111                                  CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1112     ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1113 
1114     return TRUE;
1115 }
1116 
1117 static BOOL check_jscript(void)
1118 {
1119     IActiveScriptProperty *script_prop;
1120     IActiveScriptParse *parser;
1121     BSTR str;
1122     HRESULT hres;
1123 
1124     parser = create_script(TRUE, TRUE);
1125     if(!parser)
1126         return FALSE;
1127 
1128     str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1129     hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1130     SysFreeString(str);
1131 
1132     if(hres == S_OK)
1133         hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptProperty, (void**)&script_prop);
1134     IActiveScriptParse_Release(parser);
1135     if(hres == S_OK)
1136         IActiveScriptProperty_Release(script_prop);
1137 
1138     return hres == S_OK;
1139 }
1140 
1141 START_TEST(activex)
1142 {
1143     CoInitialize(NULL);
1144 
1145     if(check_jscript()) {
1146         if(register_activex()) {
1147             test_ActiveXObject();
1148             init_registry(FALSE);
1149         }else {
1150             skip("Could not register ActiveX object\n");
1151         }
1152     }else {
1153         win_skip("Broken engine, probably too old\n");
1154     }
1155 
1156     CoUninitialize();
1157 }
1158