mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / jscript / tests / activex.c
blob9b2d7b0b23b069ac3163b7dd10c8bd7cbc0e6d3f
1 /*
2 * Copyright 2009 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdio.h>
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <ole2.h>
25 #include <dispex.h>
26 #include <activscp.h>
27 #include <objsafe.h>
28 #include <urlmon.h>
29 #include <mshtmhst.h>
31 #include "wine/test.h"
33 #ifdef _WIN64
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
44 #else
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
55 #endif
57 static const CLSID CLSID_JScript =
58 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
60 #define DEFINE_EXPECT(func) \
61 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
63 #define SET_EXPECT(func) \
64 expect_ ## func = TRUE
66 #define CHECK_EXPECT2(func) \
67 do { \
68 ok(expect_ ##func, "unexpected call " #func "\n"); \
69 called_ ## func = TRUE; \
70 }while(0)
72 #define CHECK_EXPECT(func) \
73 do { \
74 CHECK_EXPECT2(func); \
75 expect_ ## func = FALSE; \
76 }while(0)
78 #define CHECK_CALLED(func) \
79 do { \
80 ok(called_ ## func, "expected " #func "\n"); \
81 expect_ ## func = called_ ## func = FALSE; \
82 }while(0)
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);
93 static HRESULT QS_SecMgr_hres;
94 static HRESULT ProcessUrlAction_hres;
95 static DWORD ProcessUrlAction_policy;
96 static HRESULT CreateInstance_hres;
97 static HRESULT QueryCustomPolicy_hres;
98 static DWORD QueryCustomPolicy_psize;
99 static DWORD QueryCustomPolicy_policy;
100 static HRESULT QI_IDispatch_hres;
101 static HRESULT SetSite_hres;
102 static BOOL AllowIServiceProvider;
104 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
106 static const GUID CLSID_TestObj =
107 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
109 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
110 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
111 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
113 #define DISPID_TEST_REPORTSUCCESS 0x1000
115 #define DISPID_GLOBAL_OK 0x2000
117 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
119 ok(0, "unexpected call\n");
120 return E_NOTIMPL;
123 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
125 return 2;
128 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
130 return 1;
133 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
135 IServiceProvider *sp;
136 HRESULT hres;
139 CHECK_EXPECT(SetSite);
140 ok(pUnkSite != NULL, "pUnkSite == NULL\n");
142 hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
143 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
144 IServiceProvider_Release(sp);
146 return SetSite_hres;
149 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
151 ok(0, "unexpected call\n");
152 return E_NOTIMPL;
155 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
156 ObjectWithSite_QueryInterface,
157 ObjectWithSite_AddRef,
158 ObjectWithSite_Release,
159 ObjectWithSite_SetSite,
160 ObjectWithSite_GetSite
163 static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
165 static IObjectWithSite *object_with_site;
167 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
169 *ppv = NULL;
171 if(IsEqualGUID(riid, &IID_IUnknown)) {
172 *ppv = iface;
173 }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
174 if(FAILED(QI_IDispatch_hres))
175 return QI_IDispatch_hres;
176 *ppv = iface;
177 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
178 CHECK_EXPECT(QI_IObjectWithSite);
179 *ppv = object_with_site;
180 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
181 ok(0, "Unexpected IID_IObjectSafety query\n");
184 return *ppv ? S_OK : E_NOINTERFACE;
187 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
189 return 2;
192 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
194 return 1;
197 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
199 ok(0, "unexpected call\n");
200 return E_NOTIMPL;
203 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
205 return E_NOTIMPL;
208 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
209 LPOLESTR *rgszNames, UINT cNames,
210 LCID lcid, DISPID *rgDispId)
212 ok(0, "unexpected call\n");
213 return E_NOTIMPL;
216 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
217 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
218 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
220 ok(0, "unexpected call\n");
221 return E_NOTIMPL;
224 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
226 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
227 return E_NOTIMPL;
230 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
232 ok(0, "unexpected call\n");
233 return E_NOTIMPL;
236 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
238 ok(0, "unexpected call\n");
239 return E_NOTIMPL;
242 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
244 ok(0, "unexpected call\n");
245 return E_NOTIMPL;
248 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
250 ok(0, "unexpected call\n");
251 return E_NOTIMPL;
254 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
256 ok(0, "unexpected call\n");
257 return E_NOTIMPL;
260 static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
262 if(!lstrcmpW(bstrName, L"reportSuccess")) {
263 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
264 *pid = DISPID_TEST_REPORTSUCCESS;
265 return S_OK;
268 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
269 return E_NOTIMPL;
272 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
273 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
275 switch(id) {
276 case DISPID_TEST_REPORTSUCCESS:
277 CHECK_EXPECT(reportSuccess);
279 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
280 ok(pdp != NULL, "pdp == NULL\n");
281 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
282 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
283 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
284 ok(!pvarRes, "pvarRes != NULL\n");
285 ok(pei != NULL, "pei == NULL\n");
286 break;
288 default:
289 ok(0, "unexpected call\n");
290 return E_NOTIMPL;
293 return S_OK;
296 static IDispatchExVtbl testObjVtbl = {
297 DispatchEx_QueryInterface,
298 DispatchEx_AddRef,
299 DispatchEx_Release,
300 DispatchEx_GetTypeInfoCount,
301 DispatchEx_GetTypeInfo,
302 DispatchEx_GetIDsOfNames,
303 DispatchEx_Invoke,
304 Test_GetDispID,
305 Test_InvokeEx,
306 DispatchEx_DeleteMemberByName,
307 DispatchEx_DeleteMemberByDispID,
308 DispatchEx_GetMemberProperties,
309 DispatchEx_GetMemberName,
310 DispatchEx_GetNextDispID,
311 DispatchEx_GetNameSpaceParent
314 static IDispatchEx testObj = { &testObjVtbl };
316 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
318 if(!lstrcmpW(bstrName, L"ok")) {
319 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
320 *pid = DISPID_GLOBAL_OK;
321 return S_OK;
324 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
325 return E_NOTIMPL;
328 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
329 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
331 switch(id) {
332 case DISPID_GLOBAL_OK:
333 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
334 ok(pdp != NULL, "pdp == NULL\n");
335 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
336 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
337 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
338 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
339 ok(pei != NULL, "pei == NULL\n");
341 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
342 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
343 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
344 break;
346 default:
347 ok(0, "unexpected call\n");
348 return E_NOTIMPL;
351 return S_OK;
354 static IDispatchExVtbl globalObjVtbl = {
355 DispatchEx_QueryInterface,
356 DispatchEx_AddRef,
357 DispatchEx_Release,
358 DispatchEx_GetTypeInfoCount,
359 DispatchEx_GetTypeInfo,
360 DispatchEx_GetIDsOfNames,
361 DispatchEx_Invoke,
362 Global_GetDispID,
363 Global_InvokeEx,
364 DispatchEx_DeleteMemberByName,
365 DispatchEx_DeleteMemberByDispID,
366 DispatchEx_GetMemberProperties,
367 DispatchEx_GetMemberName,
368 DispatchEx_GetNextDispID,
369 DispatchEx_GetNameSpaceParent
372 static IDispatchEx globalObj = { &globalObjVtbl };
374 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
376 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
377 *ppv = iface;
378 return S_OK;
381 /* TODO: IClassFactoryEx */
382 *ppv = NULL;
383 return E_NOINTERFACE;
386 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
388 return 2;
391 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
393 return 1;
396 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
398 CHECK_EXPECT(CreateInstance);
400 ok(!outer, "outer = %p\n", outer);
401 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
403 if(SUCCEEDED(CreateInstance_hres))
404 *ppv = &testObj;
405 return CreateInstance_hres;
408 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
410 ok(0, "unexpected call\n");
411 return S_OK;
414 static const IClassFactoryVtbl ClassFactoryVtbl = {
415 ClassFactory_QueryInterface,
416 ClassFactory_AddRef,
417 ClassFactory_Release,
418 ClassFactory_CreateInstance,
419 ClassFactory_LockServer
422 static IClassFactory activex_cf = { &ClassFactoryVtbl };
424 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
426 ok(0, "unexpected call\n");
427 return E_NOINTERFACE;
430 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
432 return 2;
435 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
437 return 1;
440 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
441 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
443 ok(0, "unexpected call\n");
444 return E_NOTIMPL;
447 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
448 BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
450 CHECK_EXPECT(ProcessUrlAction);
452 ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
453 ok(pPolicy != NULL, "pPolicy == NULL\n");
454 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
455 ok(pContext != NULL, "pContext == NULL\n");
456 ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
457 ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", wine_dbgstr_guid((const IID*)pContext));
458 ok(!dwFlags, "dwFlags = %x\n", dwFlags);
459 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
461 if(SUCCEEDED(ProcessUrlAction_hres))
462 *(DWORD*)pPolicy = ProcessUrlAction_policy;
463 return ProcessUrlAction_hres;
466 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
467 BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
469 const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
470 DWORD *ret;
472 CHECK_EXPECT(QueryCustomPolicy);
474 ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", wine_dbgstr_guid(guidKey));
476 ok(ppPolicy != NULL, "ppPolicy == NULL\n");
477 ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
478 ok(pContext != NULL, "pContext == NULL\n");
479 ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
480 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
482 /* TODO: CLSID */
483 ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
484 ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
486 if(FAILED(QueryCustomPolicy_hres))
487 return QueryCustomPolicy_hres;
489 ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
490 *ppPolicy = (BYTE*)ret;
491 *pcbPolicy = QueryCustomPolicy_psize;
492 memset(ret, 0, QueryCustomPolicy_psize);
493 if(QueryCustomPolicy_psize >= sizeof(DWORD))
494 *ret = QueryCustomPolicy_policy;
496 return QueryCustomPolicy_hres;
499 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
500 InternetHostSecurityManager_QueryInterface,
501 InternetHostSecurityManager_AddRef,
502 InternetHostSecurityManager_Release,
503 InternetHostSecurityManager_GetSecurityId,
504 InternetHostSecurityManager_ProcessUrlAction,
505 InternetHostSecurityManager_QueryCustomPolicy
508 static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
510 static IServiceProvider ServiceProvider;
512 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
514 ok(0, "unexpected call\n");
515 return E_NOINTERFACE;
518 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
520 return 2;
523 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
525 return 1;
528 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
529 REFGUID guidService, REFIID riid, void **ppv)
531 if(IsEqualGUID(&SID_GetCaller, guidService))
532 return E_NOINTERFACE;
534 if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
535 if(iface == &ServiceProvider)
536 CHECK_EXPECT(Host_QS_SecMgr);
537 else
538 CHECK_EXPECT(Caller_QS_SecMgr);
539 ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
540 if(SUCCEEDED(QS_SecMgr_hres))
541 *ppv = &InternetHostSecurityManager;
542 return QS_SecMgr_hres;
545 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
546 return E_NOINTERFACE;
549 static IServiceProviderVtbl ServiceProviderVtbl = {
550 ServiceProvider_QueryInterface,
551 ServiceProvider_AddRef,
552 ServiceProvider_Release,
553 ServiceProvider_QueryService
556 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
557 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
559 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
561 if(IsEqualGUID(&IID_IUnknown, riid)) {
562 *ppv = iface;
563 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
564 *ppv = iface;
565 }else if(IsEqualGUID(&IID_IServiceProvider, riid) && AllowIServiceProvider) {
566 *ppv = &ServiceProvider;
567 }else {
568 *ppv = NULL;
569 return E_NOINTERFACE;
572 IUnknown_AddRef((IUnknown*)*ppv);
573 return S_OK;
576 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
578 return 2;
581 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
583 return 1;
586 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
588 *plcid = GetUserDefaultLCID();
589 return S_OK;
592 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
593 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
595 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
596 ok(!ppti, "ppti != NULL\n");
597 ok(!lstrcmpW(pstrName, L"test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
599 *ppiunkItem = (IUnknown*)&globalObj;
600 return S_OK;
603 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
605 return E_NOTIMPL;
608 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
609 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
611 return E_NOTIMPL;
614 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
616 return E_NOTIMPL;
619 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
621 return E_NOTIMPL;
624 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
626 return E_NOTIMPL;
629 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
631 return E_NOTIMPL;
634 #undef ACTSCPSITE_THIS
636 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
637 ActiveScriptSite_QueryInterface,
638 ActiveScriptSite_AddRef,
639 ActiveScriptSite_Release,
640 ActiveScriptSite_GetLCID,
641 ActiveScriptSite_GetItemInfo,
642 ActiveScriptSite_GetDocVersionString,
643 ActiveScriptSite_OnScriptTerminate,
644 ActiveScriptSite_OnStateChange,
645 ActiveScriptSite_OnScriptError,
646 ActiveScriptSite_OnEnterScript,
647 ActiveScriptSite_OnLeaveScript
650 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
652 static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
654 IObjectSafety *safety;
655 DWORD supported, enabled, options_all, options_set;
656 HRESULT hres;
658 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
659 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
660 if(FAILED(hres))
661 return;
663 options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
664 if(use_sec_mgr)
665 options_set = options_all;
666 else
667 options_set = INTERFACE_USES_DISPEX;
669 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
670 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
672 supported = enabled = 0xdeadbeef;
673 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
674 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
675 ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
676 ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
678 IObjectSafety_Release(safety);
681 #define parse_script(p,s) _parse_script(__LINE__,p,s)
682 static void _parse_script(unsigned line, IActiveScriptParse *parser, const WCHAR *script)
684 HRESULT hres;
686 hres = IActiveScriptParse_ParseScriptText(parser, script, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
687 ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
690 static IActiveScriptParse *create_script(BOOL skip_tests, BOOL use_sec_mgr)
692 IActiveScriptParse *parser;
693 IActiveScript *script;
694 HRESULT hres;
696 QS_SecMgr_hres = S_OK;
697 ProcessUrlAction_hres = S_OK;
698 ProcessUrlAction_policy = URLPOLICY_ALLOW;
699 CreateInstance_hres = S_OK;
700 QueryCustomPolicy_hres = S_OK;
701 QueryCustomPolicy_psize = sizeof(DWORD);
702 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
703 QI_IDispatch_hres = S_OK;
704 SetSite_hres = S_OK;
705 AllowIServiceProvider = TRUE;
707 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
708 &IID_IActiveScript, (void**)&script);
709 if(!skip_tests)
710 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
711 if(FAILED(hres))
712 return NULL;
714 if(!skip_tests)
715 set_safety_options((IUnknown*)script, use_sec_mgr);
717 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
718 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
720 hres = IActiveScriptParse_InitNew(parser);
721 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
723 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
724 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
726 hres = IActiveScript_AddNamedItem(script, L"test",
727 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
728 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
730 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
731 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
733 IActiveScript_Release(script);
735 if(!skip_tests) {
736 parse_script(parser,
737 L"function testException(func, type, number) {\n"
738 L" try {\n"
739 L" func();\n"
740 L" }catch(e) {\n"
741 L" ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n"
742 L" ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n"
743 L" return;\n"
744 L" }\n"
745 L" ok(false, 'exception expected');\n"
746 L"}");
749 return parser;
752 static IDispatchEx *parse_procedure(IActiveScriptParse *parser, const WCHAR *src)
754 IActiveScriptParseProcedure2 *parse_proc;
755 IDispatchEx *dispex;
756 IDispatch *disp;
757 HRESULT hres;
759 hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
760 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2: %08x\n", hres);
762 hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, src, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, &disp);
763 IActiveScriptParseProcedure2_Release(parse_proc);
764 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
765 ok(disp != NULL, "disp == NULL\n");
767 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
768 IDispatch_Release(disp);
769 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
771 return dispex;
774 #define call_procedure(p,c) _call_procedure(__LINE__,p,c)
775 static void _call_procedure(unsigned line, IDispatchEx *proc, IServiceProvider *caller)
777 DISPPARAMS dp = {NULL,NULL,0,0};
778 EXCEPINFO ei = {0};
779 HRESULT hres;
781 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, NULL, &ei, caller);
782 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
786 static void test_ActiveXObject(void)
788 IActiveScriptParse *parser;
789 IDispatchEx *proc;
791 parser = create_script(FALSE, TRUE);
793 SET_EXPECT(Host_QS_SecMgr);
794 SET_EXPECT(ProcessUrlAction);
795 SET_EXPECT(CreateInstance);
796 SET_EXPECT(QueryCustomPolicy);
797 SET_EXPECT(QI_IObjectWithSite);
798 SET_EXPECT(reportSuccess);
799 parse_script(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
800 CHECK_CALLED(Host_QS_SecMgr);
801 CHECK_CALLED(ProcessUrlAction);
802 CHECK_CALLED(CreateInstance);
803 CHECK_CALLED(QueryCustomPolicy);
804 CHECK_CALLED(QI_IObjectWithSite);
805 CHECK_CALLED(reportSuccess);
807 proc = parse_procedure(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
809 SET_EXPECT(ProcessUrlAction);
810 SET_EXPECT(CreateInstance);
811 SET_EXPECT(QueryCustomPolicy);
812 SET_EXPECT(QI_IObjectWithSite);
813 SET_EXPECT(reportSuccess);
814 call_procedure(proc, NULL);
815 CHECK_CALLED(ProcessUrlAction);
816 CHECK_CALLED(CreateInstance);
817 CHECK_CALLED(QueryCustomPolicy);
818 CHECK_CALLED(QI_IObjectWithSite);
819 CHECK_CALLED(reportSuccess);
821 SET_EXPECT(ProcessUrlAction);
822 SET_EXPECT(CreateInstance);
823 SET_EXPECT(QueryCustomPolicy);
824 SET_EXPECT(QI_IObjectWithSite);
825 SET_EXPECT(reportSuccess);
826 call_procedure(proc, &caller_sp);
827 CHECK_CALLED(ProcessUrlAction);
828 CHECK_CALLED(CreateInstance);
829 CHECK_CALLED(QueryCustomPolicy);
830 CHECK_CALLED(QI_IObjectWithSite);
831 CHECK_CALLED(reportSuccess);
833 IDispatchEx_Release(proc);
834 IActiveScriptParse_Release(parser);
836 parser = create_script(FALSE, TRUE);
837 proc = parse_procedure(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
839 SET_EXPECT(Host_QS_SecMgr);
840 SET_EXPECT(ProcessUrlAction);
841 SET_EXPECT(CreateInstance);
842 SET_EXPECT(QueryCustomPolicy);
843 SET_EXPECT(QI_IObjectWithSite);
844 SET_EXPECT(reportSuccess);
845 call_procedure(proc, &caller_sp);
846 CHECK_CALLED(Host_QS_SecMgr);
847 CHECK_CALLED(ProcessUrlAction);
848 CHECK_CALLED(CreateInstance);
849 CHECK_CALLED(QueryCustomPolicy);
850 CHECK_CALLED(QI_IObjectWithSite);
851 CHECK_CALLED(reportSuccess);
853 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);");
855 IDispatchEx_Release(proc);
856 IActiveScriptParse_Release(parser);
858 parser = create_script(FALSE, TRUE);
859 QS_SecMgr_hres = E_NOINTERFACE;
861 SET_EXPECT(Host_QS_SecMgr);
862 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
863 CHECK_CALLED(Host_QS_SecMgr);
865 IActiveScriptParse_Release(parser);
867 parser = create_script(FALSE, TRUE);
868 ProcessUrlAction_hres = E_FAIL;
870 SET_EXPECT(Host_QS_SecMgr);
871 SET_EXPECT(ProcessUrlAction);
872 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
873 CHECK_CALLED(Host_QS_SecMgr);
874 CHECK_CALLED(ProcessUrlAction);
876 IActiveScriptParse_Release(parser);
878 parser = create_script(FALSE, TRUE);
879 ProcessUrlAction_policy = URLPOLICY_DISALLOW;
881 SET_EXPECT(Host_QS_SecMgr);
882 SET_EXPECT(ProcessUrlAction);
883 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
884 CHECK_CALLED(Host_QS_SecMgr);
885 CHECK_CALLED(ProcessUrlAction);
887 IActiveScriptParse_Release(parser);
889 parser = create_script(FALSE, TRUE);
890 CreateInstance_hres = E_FAIL;
892 SET_EXPECT(Host_QS_SecMgr);
893 SET_EXPECT(ProcessUrlAction);
894 SET_EXPECT(CreateInstance);
895 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
896 CHECK_CALLED(Host_QS_SecMgr);
897 CHECK_CALLED(ProcessUrlAction);
898 CHECK_CALLED(CreateInstance);
900 IActiveScriptParse_Release(parser);
902 parser = create_script(FALSE, TRUE);
903 QueryCustomPolicy_hres = E_FAIL;
905 SET_EXPECT(Host_QS_SecMgr);
906 SET_EXPECT(ProcessUrlAction);
907 SET_EXPECT(CreateInstance);
908 SET_EXPECT(QueryCustomPolicy);
909 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
910 CHECK_CALLED(Host_QS_SecMgr);
911 CHECK_CALLED(ProcessUrlAction);
912 CHECK_CALLED(CreateInstance);
913 CHECK_CALLED(QueryCustomPolicy);
915 IActiveScriptParse_Release(parser);
917 parser = create_script(FALSE, TRUE);
918 QueryCustomPolicy_psize = 6;
920 SET_EXPECT(Host_QS_SecMgr);
921 SET_EXPECT(ProcessUrlAction);
922 SET_EXPECT(CreateInstance);
923 SET_EXPECT(QueryCustomPolicy);
924 SET_EXPECT(QI_IObjectWithSite);
925 SET_EXPECT(reportSuccess);
926 parse_script(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
927 CHECK_CALLED(Host_QS_SecMgr);
928 CHECK_CALLED(ProcessUrlAction);
929 CHECK_CALLED(CreateInstance);
930 CHECK_CALLED(QueryCustomPolicy);
931 CHECK_CALLED(QI_IObjectWithSite);
932 CHECK_CALLED(reportSuccess);
934 IActiveScriptParse_Release(parser);
936 parser = create_script(FALSE, TRUE);
937 QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
939 SET_EXPECT(Host_QS_SecMgr);
940 SET_EXPECT(ProcessUrlAction);
941 SET_EXPECT(CreateInstance);
942 SET_EXPECT(QueryCustomPolicy);
943 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
944 CHECK_CALLED(Host_QS_SecMgr);
945 CHECK_CALLED(ProcessUrlAction);
946 CHECK_CALLED(CreateInstance);
947 CHECK_CALLED(QueryCustomPolicy);
949 QueryCustomPolicy_psize = 6;
951 SET_EXPECT(ProcessUrlAction);
952 SET_EXPECT(CreateInstance);
953 SET_EXPECT(QueryCustomPolicy);
954 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
955 CHECK_CALLED(ProcessUrlAction);
956 CHECK_CALLED(CreateInstance);
957 CHECK_CALLED(QueryCustomPolicy);
959 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
960 QueryCustomPolicy_psize = 3;
962 SET_EXPECT(ProcessUrlAction);
963 SET_EXPECT(CreateInstance);
964 SET_EXPECT(QueryCustomPolicy);
965 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
966 CHECK_CALLED(ProcessUrlAction);
967 CHECK_CALLED(CreateInstance);
968 CHECK_CALLED(QueryCustomPolicy);
970 IActiveScriptParse_Release(parser);
972 parser = create_script(FALSE, FALSE);
974 SET_EXPECT(CreateInstance);
975 SET_EXPECT(QI_IObjectWithSite);
976 SET_EXPECT(reportSuccess);
977 parse_script(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
978 CHECK_CALLED(CreateInstance);
979 CHECK_CALLED(QI_IObjectWithSite);
980 CHECK_CALLED(reportSuccess);
982 IActiveScriptParse_Release(parser);
984 parser = create_script(FALSE, TRUE);
985 object_with_site = &ObjectWithSite;
987 SET_EXPECT(Host_QS_SecMgr);
988 SET_EXPECT(ProcessUrlAction);
989 SET_EXPECT(CreateInstance);
990 SET_EXPECT(QueryCustomPolicy);
991 SET_EXPECT(QI_IObjectWithSite);
992 SET_EXPECT(SetSite);
993 SET_EXPECT(reportSuccess);
994 parse_script(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
995 CHECK_CALLED(Host_QS_SecMgr);
996 CHECK_CALLED(ProcessUrlAction);
997 CHECK_CALLED(CreateInstance);
998 CHECK_CALLED(QueryCustomPolicy);
999 CHECK_CALLED(QI_IObjectWithSite);
1000 CHECK_CALLED(SetSite);
1001 CHECK_CALLED(reportSuccess);
1003 SetSite_hres = E_FAIL;
1004 SET_EXPECT(ProcessUrlAction);
1005 SET_EXPECT(CreateInstance);
1006 SET_EXPECT(QueryCustomPolicy);
1007 SET_EXPECT(QI_IObjectWithSite);
1008 SET_EXPECT(SetSite);
1009 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1010 CHECK_CALLED(ProcessUrlAction);
1011 CHECK_CALLED(CreateInstance);
1012 CHECK_CALLED(QueryCustomPolicy);
1013 CHECK_CALLED(QI_IObjectWithSite);
1014 CHECK_CALLED(SetSite);
1016 IActiveScriptParse_Release(parser);
1018 /* No IServiceProvider Interface */
1019 parser = create_script(FALSE, FALSE);
1020 object_with_site = &ObjectWithSite;
1021 AllowIServiceProvider = FALSE;
1023 SET_EXPECT(CreateInstance);
1024 SET_EXPECT(QI_IObjectWithSite);
1025 SET_EXPECT(reportSuccess);
1026 SET_EXPECT(SetSite);
1027 parse_script(parser, L"(new ActiveXObject('Wine.Test')).reportSuccess();");
1028 CHECK_CALLED(CreateInstance);
1029 CHECK_CALLED(QI_IObjectWithSite);
1030 CHECK_CALLED(reportSuccess);
1031 CHECK_CALLED(SetSite);
1033 IActiveScriptParse_Release(parser);
1035 parser = create_script(FALSE, TRUE);
1036 object_with_site = &ObjectWithSite;
1037 AllowIServiceProvider = FALSE;
1039 parse_script(parser, L"testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1041 IActiveScriptParse_Release(parser);
1044 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1046 HKEY hkey;
1047 DWORD res;
1049 if(!init) {
1050 RegDeleteKeyA(HKEY_CLASSES_ROOT, key_name);
1051 return TRUE;
1054 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1055 if(res != ERROR_SUCCESS)
1056 return FALSE;
1058 if(def_value)
1059 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1061 RegCloseKey(hkey);
1063 return res == ERROR_SUCCESS;
1066 static BOOL init_registry(BOOL init)
1068 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1071 static BOOL register_activex(void)
1073 DWORD regid;
1074 HRESULT hres;
1076 if(!init_registry(TRUE)) {
1077 init_registry(FALSE);
1078 return FALSE;
1081 hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1082 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1083 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1085 return TRUE;
1088 static BOOL check_jscript(void)
1090 IActiveScriptProperty *script_prop;
1091 IActiveScriptParse *parser;
1092 HRESULT hres;
1094 parser = create_script(TRUE, TRUE);
1095 if(!parser)
1096 return FALSE;
1098 hres = IActiveScriptParse_ParseScriptText(parser, L"if(!('localeCompare' in String.prototype)) throw 1;",
1099 NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1100 if(hres == S_OK)
1101 hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptProperty, (void**)&script_prop);
1102 IActiveScriptParse_Release(parser);
1103 if(hres == S_OK)
1104 IActiveScriptProperty_Release(script_prop);
1106 return hres == S_OK;
1109 START_TEST(activex)
1111 CoInitialize(NULL);
1113 if(check_jscript()) {
1114 if(register_activex()) {
1115 test_ActiveXObject();
1116 init_registry(FALSE);
1117 }else {
1118 skip("Could not register ActiveX object\n");
1120 }else {
1121 win_skip("Broken engine, probably too old\n");
1124 CoUninitialize();