2 * Copyright 2009,2011 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
31 #include "wine/test.h"
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 IActiveScriptParseProcedure2_64_Release
43 #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
44 #define IActiveScriptParse_Release IActiveScriptParse32_Release
45 #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
46 #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
47 #define IActiveScriptParseProcedure2_Release IActiveScriptParseProcedure2_32_Release
51 extern const CLSID CLSID_VBScript
;
53 #define DEFINE_EXPECT(func) \
54 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
56 #define SET_EXPECT(func) \
57 expect_ ## func = TRUE
59 #define CHECK_EXPECT2(func) \
61 ok(expect_ ##func, "unexpected call " #func "\n"); \
62 called_ ## func = TRUE; \
65 #define CHECK_EXPECT(func) \
67 CHECK_EXPECT2(func); \
68 expect_ ## func = FALSE; \
71 #define CHECK_CALLED(func) \
73 ok(called_ ## func, "expected " #func "\n"); \
74 expect_ ## func = called_ ## func = FALSE; \
77 #define CLEAR_CALLED(func) \
78 expect_ ## func = called_ ## func = FALSE
80 DEFINE_EXPECT(CreateInstance
);
81 DEFINE_EXPECT(ProcessUrlAction
);
82 DEFINE_EXPECT(QueryCustomPolicy
);
83 DEFINE_EXPECT(reportSuccess
);
84 DEFINE_EXPECT(Host_QS_SecMgr
);
85 DEFINE_EXPECT(Caller_QS_SecMgr
);
86 DEFINE_EXPECT(QI_IObjectWithSite
);
87 DEFINE_EXPECT(SetSite
);
89 static const WCHAR testW
[] = {'t','e','s','t',0};
91 static HRESULT QS_SecMgr_hres
;
92 static HRESULT ProcessUrlAction_hres
;
93 static DWORD ProcessUrlAction_policy
;
94 static HRESULT CreateInstance_hres
;
95 static HRESULT QueryCustomPolicy_hres
;
96 static DWORD QueryCustomPolicy_psize
;
97 static DWORD QueryCustomPolicy_policy
;
98 static HRESULT QI_IDispatch_hres
;
99 static HRESULT QI_IObjectWithSite_hres
;
100 static HRESULT SetSite_hres
;
102 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
103 #define TESTOBJINST_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80647}"
105 static const GUID CLSID_TestObj
=
106 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
107 static const GUID CLSID_TestObjInst
=
108 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x47}};
110 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
111 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY
=
112 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
114 #define DISPID_TEST_REPORTSUCCESS 0x1000
116 #define DISPID_GLOBAL_OK 0x2000
118 #define VB_E_CANNOT_CREATE_OBJ 0x800a01ad
120 static BSTR
a2bstr(const char *str
)
125 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
126 ret
= SysAllocStringLen(NULL
, len
-1);
127 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
132 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
135 WideCharToMultiByte(CP_ACP
, 0, strw
, -1, buf
, sizeof(buf
), 0, 0);
136 return lstrcmpA(buf
, stra
);
139 static HRESULT WINAPI
ObjectWithSite_QueryInterface(IObjectWithSite
*iface
, REFIID riid
, void **ppv
)
141 ok(0, "unexpected call\n");
145 static ULONG WINAPI
ObjectWithSite_AddRef(IObjectWithSite
*iface
)
150 static ULONG WINAPI
ObjectWithSite_Release(IObjectWithSite
*iface
)
155 static HRESULT WINAPI
ObjectWithSite_SetSite(IObjectWithSite
*iface
, IUnknown
*pUnkSite
)
157 IServiceProvider
*sp
;
161 CHECK_EXPECT(SetSite
);
162 ok(pUnkSite
!= NULL
, "pUnkSite == NULL\n");
164 hres
= IUnknown_QueryInterface(pUnkSite
, &IID_IServiceProvider
, (void**)&sp
);
165 ok(hres
== S_OK
, "Could not get IServiceProvider iface: %08x\n", hres
);
166 IServiceProvider_Release(sp
);
171 static HRESULT WINAPI
ObjectWithSite_GetSite(IObjectWithSite
*iface
, REFIID riid
, void **ppvSite
)
173 ok(0, "unexpected call\n");
177 static const IObjectWithSiteVtbl ObjectWithSiteVtbl
= {
178 ObjectWithSite_QueryInterface
,
179 ObjectWithSite_AddRef
,
180 ObjectWithSite_Release
,
181 ObjectWithSite_SetSite
,
182 ObjectWithSite_GetSite
185 static IObjectWithSite ObjectWithSite
= { &ObjectWithSiteVtbl
};
187 static IObjectWithSite
*object_with_site
;
189 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
193 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
195 }else if(IsEqualGUID(riid
, &IID_IDispatch
) || IsEqualGUID(riid
, &IID_IDispatchEx
)) {
196 if(FAILED(QI_IDispatch_hres
))
197 return QI_IDispatch_hres
;
199 }else if(IsEqualGUID(&IID_IObjectWithSite
, riid
)) {
200 CHECK_EXPECT(QI_IObjectWithSite
);
201 if(FAILED(QI_IObjectWithSite_hres
))
202 return QI_IObjectWithSite_hres
;
203 *ppv
= object_with_site
;
204 }else if(IsEqualGUID(&IID_IObjectSafety
, riid
)) {
205 ok(0, "Unexpected IID_IObjectSafety query\n");
208 return *ppv
? S_OK
: E_NOINTERFACE
;
211 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
216 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
221 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
223 ok(0, "unexpected call\n");
227 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
228 LCID lcid
, ITypeInfo
**ppTInfo
)
230 ok(0, "unexpected call\n");
234 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
235 LPOLESTR
*rgszNames
, UINT cNames
,
236 LCID lcid
, DISPID
*rgDispId
)
238 ok(0, "unexpected call\n");
242 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
243 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
244 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
246 ok(0, "unexpected call\n");
250 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
252 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName
), grfdex
);
256 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
258 ok(0, "unexpected call\n");
262 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
264 ok(0, "unexpected call\n");
268 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
270 ok(0, "unexpected call\n");
274 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
276 ok(0, "unexpected call\n");
280 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
282 ok(0, "unexpected call\n");
286 static HRESULT WINAPI
Test_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
288 if(!strcmp_wa(bstrName
, "reportSuccess")) {
289 ok(grfdex
== fdexNameCaseInsensitive
, "grfdex = %x\n", grfdex
);
290 *pid
= DISPID_TEST_REPORTSUCCESS
;
294 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName
));
298 static HRESULT WINAPI
Test_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
299 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
302 case DISPID_TEST_REPORTSUCCESS
:
303 CHECK_EXPECT(reportSuccess
);
305 ok(wFlags
== INVOKE_FUNC
, "wFlags = %x\n", wFlags
);
306 ok(pdp
!= NULL
, "pdp == NULL\n");
307 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
308 ok(pdp
->cArgs
== 0, "cArgs = %d\n", pdp
->cArgs
);
309 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
310 ok(!pvarRes
, "pvarRes != NULL\n");
311 ok(pei
!= NULL
, "pei == NULL\n");
315 ok(0, "unexpected call\n");
322 static IDispatchExVtbl testObjVtbl
= {
323 DispatchEx_QueryInterface
,
326 DispatchEx_GetTypeInfoCount
,
327 DispatchEx_GetTypeInfo
,
328 DispatchEx_GetIDsOfNames
,
332 DispatchEx_DeleteMemberByName
,
333 DispatchEx_DeleteMemberByDispID
,
334 DispatchEx_GetMemberProperties
,
335 DispatchEx_GetMemberName
,
336 DispatchEx_GetNextDispID
,
337 DispatchEx_GetNameSpaceParent
340 static IDispatchEx testObj
= { &testObjVtbl
};
342 static HRESULT WINAPI
Global_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
344 if(!strcmp_wa(bstrName
, "ok")) {
345 ok(grfdex
== fdexNameCaseSensitive
, "grfdex = %x\n", grfdex
);
346 *pid
= DISPID_GLOBAL_OK
;
350 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName
));
354 static HRESULT WINAPI
Global_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
355 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
358 case DISPID_GLOBAL_OK
:
359 ok(wFlags
== INVOKE_FUNC
|| wFlags
== (INVOKE_FUNC
|INVOKE_PROPERTYGET
), "wFlags = %x\n", wFlags
);
360 ok(pdp
!= NULL
, "pdp == NULL\n");
361 ok(pdp
->rgvarg
!= NULL
, "rgvarg == NULL\n");
362 ok(!pdp
->rgdispidNamedArgs
, "rgdispidNamedArgs != NULL\n");
363 ok(pdp
->cArgs
== 2, "cArgs = %d\n", pdp
->cArgs
);
364 ok(!pdp
->cNamedArgs
, "cNamedArgs = %d\n", pdp
->cNamedArgs
);
365 ok(pei
!= NULL
, "pei == NULL\n");
367 ok(V_VT(pdp
->rgvarg
) == VT_BSTR
, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp
->rgvarg
));
368 ok(V_VT(pdp
->rgvarg
+1) == VT_BOOL
, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp
->rgvarg
));
369 ok(V_BOOL(pdp
->rgvarg
+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp
->rgvarg
)));
373 ok(0, "unexpected call\n");
380 static IDispatchExVtbl globalObjVtbl
= {
381 DispatchEx_QueryInterface
,
384 DispatchEx_GetTypeInfoCount
,
385 DispatchEx_GetTypeInfo
,
386 DispatchEx_GetIDsOfNames
,
390 DispatchEx_DeleteMemberByName
,
391 DispatchEx_DeleteMemberByDispID
,
392 DispatchEx_GetMemberProperties
,
393 DispatchEx_GetMemberName
,
394 DispatchEx_GetNextDispID
,
395 DispatchEx_GetNameSpaceParent
398 static IDispatchEx globalObj
= { &globalObjVtbl
};
400 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
402 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
)) {
407 /* TODO: IClassFactoryEx */
409 return E_NOINTERFACE
;
412 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
417 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
422 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
424 CHECK_EXPECT(CreateInstance
);
426 ok(!outer
, "outer = %p\n", outer
);
427 ok(IsEqualGUID(&IID_IUnknown
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
429 if(SUCCEEDED(CreateInstance_hres
))
431 return CreateInstance_hres
;
434 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
436 ok(0, "unexpected call\n");
440 static const IClassFactoryVtbl ClassFactoryVtbl
= {
441 ClassFactory_QueryInterface
,
443 ClassFactory_Release
,
444 ClassFactory_CreateInstance
,
445 ClassFactory_LockServer
448 static IClassFactory activex_cf
= { &ClassFactoryVtbl
};
450 static HRESULT WINAPI
InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager
*iface
, REFIID riid
, void **ppv
)
452 ok(0, "unexpected call\n");
453 return E_NOINTERFACE
;
456 static ULONG WINAPI
InternetHostSecurityManager_AddRef(IInternetHostSecurityManager
*iface
)
461 static ULONG WINAPI
InternetHostSecurityManager_Release(IInternetHostSecurityManager
*iface
)
466 static HRESULT WINAPI
InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager
*iface
, BYTE
*pbSecurityId
,
467 DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
469 ok(0, "unexpected call\n");
473 static HRESULT WINAPI
InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager
*iface
, DWORD dwAction
,
474 BYTE
*pPolicy
, DWORD cbPolicy
, BYTE
*pContext
, DWORD cbContext
, DWORD dwFlags
, DWORD dwReserved
)
476 CHECK_EXPECT(ProcessUrlAction
);
478 ok(dwAction
== URLACTION_ACTIVEX_RUN
, "dwAction = %x\n", dwAction
);
479 ok(pPolicy
!= NULL
, "pPolicy == NULL\n");
480 ok(cbPolicy
== sizeof(DWORD
), "cbPolicy = %d\n", cbPolicy
);
481 ok(pContext
!= NULL
, "pContext == NULL\n");
482 ok(cbContext
== sizeof(GUID
), "cbContext = %d\n", cbContext
);
483 ok(IsEqualGUID(pContext
, &CLSID_TestObj
), "pContext = %s\n", wine_dbgstr_guid((const IID
*)pContext
));
484 ok(!dwFlags
, "dwFlags = %x\n", dwFlags
);
485 ok(!dwReserved
, "dwReserved = %x\n", dwReserved
);
487 if(SUCCEEDED(ProcessUrlAction_hres
))
488 *(DWORD
*)pPolicy
= ProcessUrlAction_policy
;
489 return ProcessUrlAction_hres
;
492 static HRESULT WINAPI
InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager
*iface
, REFGUID guidKey
,
493 BYTE
**ppPolicy
, DWORD
*pcbPolicy
, BYTE
*pContext
, DWORD cbContext
, DWORD dwReserved
)
495 const struct CONFIRMSAFETY
*cs
= (const struct CONFIRMSAFETY
*)pContext
;
498 CHECK_EXPECT(QueryCustomPolicy
);
500 ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY
, guidKey
), "guidKey = %s\n", wine_dbgstr_guid(guidKey
));
502 ok(ppPolicy
!= NULL
, "ppPolicy == NULL\n");
503 ok(pcbPolicy
!= NULL
, "pcbPolicy == NULL\n");
504 ok(pContext
!= NULL
, "pContext == NULL\n");
505 ok(cbContext
== sizeof(struct CONFIRMSAFETY
), "cbContext = %d\n", cbContext
);
506 ok(!dwReserved
, "dwReserved = %x\n", dwReserved
);
509 ok(cs
->pUnk
!= NULL
, "cs->pUnk == NULL\n");
510 ok(!cs
->dwFlags
, "dwFlags = %x\n", cs
->dwFlags
);
512 if(FAILED(QueryCustomPolicy_hres
))
513 return QueryCustomPolicy_hres
;
515 ret
= CoTaskMemAlloc(QueryCustomPolicy_psize
);
516 *ppPolicy
= (BYTE
*)ret
;
517 *pcbPolicy
= QueryCustomPolicy_psize
;
518 memset(ret
, 0, QueryCustomPolicy_psize
);
519 if(QueryCustomPolicy_psize
>= sizeof(DWORD
))
520 *ret
= QueryCustomPolicy_policy
;
522 return QueryCustomPolicy_hres
;
525 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl
= {
526 InternetHostSecurityManager_QueryInterface
,
527 InternetHostSecurityManager_AddRef
,
528 InternetHostSecurityManager_Release
,
529 InternetHostSecurityManager_GetSecurityId
,
530 InternetHostSecurityManager_ProcessUrlAction
,
531 InternetHostSecurityManager_QueryCustomPolicy
534 static IInternetHostSecurityManager InternetHostSecurityManager
= { &InternetHostSecurityManagerVtbl
};
536 static IServiceProvider ServiceProvider
;
538 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
, REFIID riid
, void **ppv
)
540 ok(0, "unexpected call\n");
541 return E_NOINTERFACE
;
544 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
549 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
554 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
,
555 REFGUID guidService
, REFIID riid
, void **ppv
)
557 if(IsEqualGUID(&SID_GetCaller
, guidService
))
558 return E_NOINTERFACE
;
560 if(IsEqualGUID(&SID_SInternetHostSecurityManager
, guidService
)) {
561 if(iface
== &ServiceProvider
)
562 CHECK_EXPECT(Host_QS_SecMgr
);
564 CHECK_EXPECT(Caller_QS_SecMgr
);
565 ok(IsEqualGUID(&IID_IInternetHostSecurityManager
, riid
), "unexpected riid %s\n", wine_dbgstr_guid(riid
));
566 if(SUCCEEDED(QS_SecMgr_hres
))
567 *ppv
= &InternetHostSecurityManager
;
568 return QS_SecMgr_hres
;
571 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService
));
572 return E_NOINTERFACE
;
575 static IServiceProviderVtbl ServiceProviderVtbl
= {
576 ServiceProvider_QueryInterface
,
577 ServiceProvider_AddRef
,
578 ServiceProvider_Release
,
579 ServiceProvider_QueryService
582 static IServiceProvider ServiceProvider
= { &ServiceProviderVtbl
};
584 static HRESULT WINAPI
ActiveScriptSite_QueryInterface(IActiveScriptSite
*iface
, REFIID riid
, void **ppv
)
586 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
588 }else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
)) {
590 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
591 *ppv
= &ServiceProvider
;
594 return E_NOINTERFACE
;
597 IUnknown_AddRef((IUnknown
*)*ppv
);
601 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
606 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
611 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
613 *plcid
= GetUserDefaultLCID();
617 static HRESULT WINAPI
ActiveScriptSite_GetItemInfo(IActiveScriptSite
*iface
, LPCOLESTR pstrName
,
618 DWORD dwReturnMask
, IUnknown
**ppiunkItem
, ITypeInfo
**ppti
)
620 ok(dwReturnMask
== SCRIPTINFO_IUNKNOWN
, "unexpected dwReturnMask %x\n", dwReturnMask
);
621 ok(!ppti
, "ppti != NULL\n");
622 ok(!strcmp_wa(pstrName
, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName
));
624 *ppiunkItem
= (IUnknown
*)&globalObj
;
628 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
633 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
634 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
639 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
644 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
649 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
654 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
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
673 static IActiveScriptSite ActiveScriptSite
= { &ActiveScriptSiteVtbl
};
675 static void set_safety_options(IUnknown
*unk
, BOOL use_sec_mgr
)
677 IObjectSafety
*safety
;
678 DWORD supported
, enabled
, options_all
, options_set
;
681 hres
= IUnknown_QueryInterface(unk
, &IID_IObjectSafety
, (void**)&safety
);
682 ok(hres
== S_OK
, "Could not get IObjectSafety: %08x\n", hres
);
686 options_all
= INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
;
688 options_set
= options_all
;
690 options_set
= INTERFACE_USES_DISPEX
;
692 hres
= IObjectSafety_SetInterfaceSafetyOptions(safety
, &IID_IActiveScriptParse
, options_all
, options_set
);
693 ok(hres
== S_OK
, "SetInterfaceSafetyOptions failed: %08x\n", hres
);
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
);
701 IObjectSafety_Release(safety
);
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
)
710 str
= a2bstr(script
);
711 hres
= IActiveScriptParse_ParseScriptText(parser
, str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
713 ok_(__FILE__
,line
)(hres
== S_OK
, "ParseScriptText failed: %08x\n", hres
);
716 static HRESULT
parse_script_ae(IActiveScriptParse
*parser
, const char *script
)
721 str
= a2bstr(script
);
722 hres
= IActiveScriptParse_ParseScriptText(parser
, str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
728 static IActiveScriptParse
*create_script(BOOL use_sec_mgr
)
730 IActiveScriptParse
*parser
;
731 IActiveScript
*script
;
734 QS_SecMgr_hres
= S_OK
;
735 ProcessUrlAction_hres
= S_OK
;
736 ProcessUrlAction_policy
= URLPOLICY_ALLOW
;
737 CreateInstance_hres
= S_OK
;
738 QueryCustomPolicy_hres
= S_OK
;
739 QueryCustomPolicy_psize
= sizeof(DWORD
);
740 QueryCustomPolicy_policy
= URLPOLICY_ALLOW
;
741 QI_IDispatch_hres
= S_OK
;
742 QI_IObjectWithSite_hres
= S_OK
;
745 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
746 &IID_IActiveScript
, (void**)&script
);
747 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
751 set_safety_options((IUnknown
*)script
, use_sec_mgr
);
753 hres
= IActiveScript_QueryInterface(script
, &IID_IActiveScriptParse
, (void**)&parser
);
754 ok(hres
== S_OK
, "Could not get IActiveScriptParse: %08x\n", hres
);
756 hres
= IActiveScriptParse_InitNew(parser
);
757 ok(hres
== S_OK
, "InitNew failed: %08x\n", hres
);
759 hres
= IActiveScript_SetScriptSite(script
, &ActiveScriptSite
);
760 ok(hres
== S_OK
, "SetScriptSite failed: %08x\n", hres
);
762 hres
= IActiveScript_AddNamedItem(script
, testW
,
763 SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
);
764 ok(hres
== S_OK
, "AddNamedItem failed: %08x\n", hres
);
766 hres
= IActiveScript_SetScriptState(script
, SCRIPTSTATE_STARTED
);
767 ok(hres
== S_OK
, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres
);
769 IActiveScript_Release(script
);
774 static void test_CreateObject(void)
776 IActiveScriptParse
*parser
;
779 parser
= create_script(TRUE
);
781 SET_EXPECT(Host_QS_SecMgr
);
782 SET_EXPECT(ProcessUrlAction
);
783 SET_EXPECT(CreateInstance
);
784 SET_EXPECT(QueryCustomPolicy
);
785 SET_EXPECT(QI_IObjectWithSite
);
786 SET_EXPECT(reportSuccess
);
787 parse_script_a(parser
, "Call CreateObject(\"Wine.Test\").reportSuccess()");
788 CHECK_CALLED(Host_QS_SecMgr
);
789 CHECK_CALLED(ProcessUrlAction
);
790 CHECK_CALLED(CreateInstance
);
791 CHECK_CALLED(QueryCustomPolicy
);
792 CHECK_CALLED(QI_IObjectWithSite
);
793 CHECK_CALLED(reportSuccess
);
795 IActiveScriptParse_Release(parser
);
797 parser
= create_script(TRUE
);
799 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.TestABC\")");
800 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
802 IActiveScriptParse_Release(parser
);
804 parser
= create_script(TRUE
);
805 QS_SecMgr_hres
= E_NOINTERFACE
;
807 SET_EXPECT(Host_QS_SecMgr
);
808 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
809 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
810 CHECK_CALLED(Host_QS_SecMgr
);
812 IActiveScriptParse_Release(parser
);
814 parser
= create_script(TRUE
);
815 ProcessUrlAction_hres
= E_FAIL
;
817 SET_EXPECT(Host_QS_SecMgr
);
818 SET_EXPECT(ProcessUrlAction
);
819 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
820 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
821 CHECK_CALLED(Host_QS_SecMgr
);
822 CHECK_CALLED(ProcessUrlAction
);
824 IActiveScriptParse_Release(parser
);
826 parser
= create_script(TRUE
);
827 ProcessUrlAction_policy
= URLPOLICY_DISALLOW
;
829 SET_EXPECT(Host_QS_SecMgr
);
830 SET_EXPECT(ProcessUrlAction
);
831 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
832 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
833 CHECK_CALLED(Host_QS_SecMgr
);
834 CHECK_CALLED(ProcessUrlAction
);
836 IActiveScriptParse_Release(parser
);
838 parser
= create_script(TRUE
);
839 CreateInstance_hres
= E_FAIL
;
841 SET_EXPECT(Host_QS_SecMgr
);
842 SET_EXPECT(ProcessUrlAction
);
843 SET_EXPECT(CreateInstance
);
844 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
845 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
846 CHECK_CALLED(Host_QS_SecMgr
);
847 CHECK_CALLED(ProcessUrlAction
);
848 CHECK_CALLED(CreateInstance
);
850 IActiveScriptParse_Release(parser
);
852 parser
= create_script(TRUE
);
853 QueryCustomPolicy_hres
= E_FAIL
;
855 SET_EXPECT(Host_QS_SecMgr
);
856 SET_EXPECT(ProcessUrlAction
);
857 SET_EXPECT(CreateInstance
);
858 SET_EXPECT(QueryCustomPolicy
);
859 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
860 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
861 CHECK_CALLED(Host_QS_SecMgr
);
862 CHECK_CALLED(ProcessUrlAction
);
863 CHECK_CALLED(CreateInstance
);
864 CHECK_CALLED(QueryCustomPolicy
);
866 IActiveScriptParse_Release(parser
);
868 parser
= create_script(TRUE
);
869 QueryCustomPolicy_psize
= 6;
871 SET_EXPECT(Host_QS_SecMgr
);
872 SET_EXPECT(ProcessUrlAction
);
873 SET_EXPECT(CreateInstance
);
874 SET_EXPECT(QueryCustomPolicy
);
875 SET_EXPECT(QI_IObjectWithSite
);
876 SET_EXPECT(reportSuccess
);
877 parse_script_a(parser
, "Call CreateObject(\"Wine.Test\").reportSuccess()");
878 CHECK_CALLED(Host_QS_SecMgr
);
879 CHECK_CALLED(ProcessUrlAction
);
880 CHECK_CALLED(CreateInstance
);
881 CHECK_CALLED(QueryCustomPolicy
);
882 CHECK_CALLED(QI_IObjectWithSite
);
883 CHECK_CALLED(reportSuccess
);
885 IActiveScriptParse_Release(parser
);
887 parser
= create_script(TRUE
);
888 QueryCustomPolicy_policy
= URLPOLICY_DISALLOW
;
890 SET_EXPECT(Host_QS_SecMgr
);
891 SET_EXPECT(ProcessUrlAction
);
892 SET_EXPECT(CreateInstance
);
893 SET_EXPECT(QueryCustomPolicy
);
894 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
895 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
896 CHECK_CALLED(Host_QS_SecMgr
);
897 CHECK_CALLED(ProcessUrlAction
);
898 CHECK_CALLED(CreateInstance
);
899 CHECK_CALLED(QueryCustomPolicy
);
901 QueryCustomPolicy_psize
= 6;
903 SET_EXPECT(ProcessUrlAction
);
904 SET_EXPECT(CreateInstance
);
905 SET_EXPECT(QueryCustomPolicy
);
906 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
907 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
908 CHECK_CALLED(ProcessUrlAction
);
909 CHECK_CALLED(CreateInstance
);
910 CHECK_CALLED(QueryCustomPolicy
);
912 QueryCustomPolicy_policy
= URLPOLICY_ALLOW
;
913 QueryCustomPolicy_psize
= 3;
915 SET_EXPECT(ProcessUrlAction
);
916 SET_EXPECT(CreateInstance
);
917 SET_EXPECT(QueryCustomPolicy
);
918 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
919 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
920 CHECK_CALLED(ProcessUrlAction
);
921 CHECK_CALLED(CreateInstance
);
922 CHECK_CALLED(QueryCustomPolicy
);
924 IActiveScriptParse_Release(parser
);
926 parser
= create_script(FALSE
);
928 SET_EXPECT(CreateInstance
);
929 SET_EXPECT(QI_IObjectWithSite
);
930 SET_EXPECT(reportSuccess
);
931 parse_script_a(parser
, "Call CreateObject(\"Wine.Test\").reportSuccess()");
932 CHECK_CALLED(CreateInstance
);
933 CHECK_CALLED(QI_IObjectWithSite
);
934 CHECK_CALLED(reportSuccess
);
936 IActiveScriptParse_Release(parser
);
938 parser
= create_script(TRUE
);
939 object_with_site
= &ObjectWithSite
;
941 SET_EXPECT(Host_QS_SecMgr
);
942 SET_EXPECT(ProcessUrlAction
);
943 SET_EXPECT(CreateInstance
);
944 SET_EXPECT(QueryCustomPolicy
);
945 SET_EXPECT(QI_IObjectWithSite
);
947 SET_EXPECT(reportSuccess
);
948 parse_script_a(parser
, "Call CreateObject(\"Wine.Test\").reportSuccess()");
949 CHECK_CALLED(Host_QS_SecMgr
);
950 CHECK_CALLED(ProcessUrlAction
);
951 CHECK_CALLED(CreateInstance
);
952 CHECK_CALLED(QueryCustomPolicy
);
953 CHECK_CALLED(QI_IObjectWithSite
);
954 CHECK_CALLED(SetSite
);
955 CHECK_CALLED(reportSuccess
);
957 SetSite_hres
= E_FAIL
;
958 SET_EXPECT(ProcessUrlAction
);
959 SET_EXPECT(CreateInstance
);
960 SET_EXPECT(QueryCustomPolicy
);
961 SET_EXPECT(QI_IObjectWithSite
);
963 hres
= parse_script_ae(parser
, "Call CreateObject(\"Wine.Test\")");
964 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
965 CHECK_CALLED(ProcessUrlAction
);
966 CHECK_CALLED(CreateInstance
);
967 CHECK_CALLED(QueryCustomPolicy
);
968 CHECK_CALLED(QI_IObjectWithSite
);
969 CHECK_CALLED(SetSite
);
971 IActiveScriptParse_Release(parser
);
974 static void test_GetObject(void)
976 IActiveScriptParse
*parser
;
979 /* Never allowed with security manager */
980 parser
= create_script(TRUE
);
981 hres
= parse_script_ae(parser
, "Call GetObject(\"clsid:" TESTOBJINST_CLSID
"\").reportSuccess()");
982 ok(hres
== VB_E_CANNOT_CREATE_OBJ
, "hres = %08x\n", hres
);
983 IActiveScriptParse_Release(parser
);
985 parser
= create_script(FALSE
);
987 SET_EXPECT(QI_IObjectWithSite
);
989 SET_EXPECT(reportSuccess
);
990 hres
= parse_script_ae(parser
, "Call GetObject(\"clsid:" TESTOBJINST_CLSID
"\").reportSuccess()");
991 if(hres
== HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND
)) { /* Workaround for broken win2k */
992 win_skip("got unexpected error %08x\n", hres
);
993 CLEAR_CALLED(QI_IObjectWithSite
);
994 CLEAR_CALLED(SetSite
);
995 CLEAR_CALLED(reportSuccess
);
996 IActiveScriptParse_Release(parser
);
999 ok(hres
== S_OK
, "hres = %08x\n", hres
);
1000 CHECK_CALLED(QI_IObjectWithSite
);
1001 CHECK_CALLED(SetSite
);
1002 CHECK_CALLED(reportSuccess
);
1004 SetSite_hres
= E_FAIL
;
1005 SET_EXPECT(QI_IObjectWithSite
);
1006 SET_EXPECT(SetSite
);
1007 hres
= parse_script_ae(parser
, "Call GetObject(\"clsid:" TESTOBJINST_CLSID
"\").reportSuccess()");
1008 ok(hres
== E_FAIL
, "hres = %08x\n", hres
);
1009 CHECK_CALLED(QI_IObjectWithSite
);
1010 CHECK_CALLED(SetSite
);
1012 QI_IObjectWithSite_hres
= E_NOINTERFACE
;
1013 SET_EXPECT(QI_IObjectWithSite
);
1014 SET_EXPECT(reportSuccess
);
1015 parse_script_a(parser
, "Call GetObject(\"clsid:" TESTOBJINST_CLSID
"\").reportSuccess()");
1016 CHECK_CALLED(QI_IObjectWithSite
);
1017 CHECK_CALLED(reportSuccess
);
1019 IActiveScriptParse_Release(parser
);
1021 /* Invalid moniker */
1022 parser
= create_script(FALSE
);
1023 hres
= parse_script_ae(parser
, "Call GetObject(\"nonexistent:test\").reportSuccess()");
1024 ok(hres
== MK_E_SYNTAX
, "hres = %08x\n", hres
);
1025 IActiveScriptParse_Release(parser
);
1028 static BOOL
init_key(const char *key_name
, const char *def_value
, BOOL init
)
1034 RegDeleteKeyA(HKEY_CLASSES_ROOT
, key_name
);
1038 res
= RegCreateKeyA(HKEY_CLASSES_ROOT
, key_name
, &hkey
);
1039 if(res
!= ERROR_SUCCESS
)
1043 res
= RegSetValueA(hkey
, NULL
, REG_SZ
, def_value
, strlen(def_value
));
1047 return res
== ERROR_SUCCESS
;
1050 static BOOL
init_registry(BOOL init
)
1052 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID
, init
);
1055 static BOOL
register_activex(void)
1060 if(!init_registry(TRUE
)) {
1061 init_registry(FALSE
);
1065 hres
= CoRegisterClassObject(&CLSID_TestObj
, (IUnknown
*)&activex_cf
,
1066 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
1067 ok(hres
== S_OK
, "Could not register script engine: %08x\n", hres
);
1069 hres
= CoRegisterClassObject(&CLSID_TestObjInst
, (IUnknown
*)&testObj
,
1070 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
1071 ok(hres
== S_OK
, "Could not register script engine: %08x\n", hres
);
1076 static BOOL
check_vbscript(void)
1078 IActiveScriptParseProcedure2
*vbscript
;
1081 hres
= CoCreateInstance(&CLSID_VBScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
1082 &IID_IActiveScriptParseProcedure2
, (void**)&vbscript
);
1084 IActiveScriptParseProcedure2_Release(vbscript
);
1086 return hres
== S_OK
;
1090 START_TEST(createobj
)
1094 if(check_vbscript()) {
1095 if(register_activex()) {
1096 test_CreateObject();
1098 init_registry(FALSE
);
1100 skip("Could not register ActiveX object.\n");
1103 win_skip("Broken engine, probably too old\n");