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
31 #include "wine/test.h"
33 static const CLSID CLSID_JScript =
34 {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
36 #define DEFINE_EXPECT(func) \
37 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39 #define SET_EXPECT(func) \
40 expect_ ## func = TRUE
42 #define SET_CALLED(func) \
43 called_ ## func = TRUE
45 #define CHECK_EXPECT2(func) \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
51 #define CHECK_EXPECT(func) \
53 CHECK_EXPECT2(func); \
54 expect_ ## func = FALSE; \
57 #define CHECK_CALLED(func) \
59 ok(called_ ## func, "expected " #func "\n"); \
60 expect_ ## func = called_ ## func = FALSE; \
63 DEFINE_EXPECT(CreateInstance);
64 DEFINE_EXPECT(ProcessUrlAction);
65 DEFINE_EXPECT(QueryCustomPolicy);
66 DEFINE_EXPECT(reportSuccess);
67 DEFINE_EXPECT(Host_QS_SecMgr);
68 DEFINE_EXPECT(Caller_QS_SecMgr);
69 DEFINE_EXPECT(QI_IObjectWithSite);
70 DEFINE_EXPECT(SetSite);
72 static const WCHAR testW[] = {'t','e','s','t',0};
74 static HRESULT QS_SecMgr_hres;
75 static HRESULT ProcessUrlAction_hres;
76 static DWORD ProcessUrlAction_policy;
77 static HRESULT CreateInstance_hres;
78 static HRESULT QueryCustomPolicy_hres;
79 static DWORD QueryCustomPolicy_psize;
80 static DWORD QueryCustomPolicy_policy;
81 static HRESULT QI_IDispatch_hres;
82 static HRESULT SetSite_hres;
84 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
86 static const GUID CLSID_TestObj =
87 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
89 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
90 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
91 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
93 #define DISPID_TEST_REPORTSUCCESS 0x1000
95 #define DISPID_GLOBAL_OK 0x2000
97 static const char *debugstr_guid(REFIID riid)
101 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
102 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
103 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
104 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
109 static BSTR a2bstr(const char *str)
114 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
115 ret = SysAllocStringLen(NULL, len-1);
116 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
121 static int strcmp_wa(LPCWSTR strw, const char *stra)
124 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
125 return lstrcmpA(buf, stra);
128 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
130 ok(0, "unexpected call\n");
134 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
139 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
144 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
146 IServiceProvider *sp;
150 CHECK_EXPECT(SetSite);
151 ok(pUnkSite != NULL, "pUnkSite == NULL\n");
153 hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
154 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
155 IServiceProvider_Release(sp);
160 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
162 ok(0, "unexpected call\n");
166 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
167 ObjectWithSite_QueryInterface,
168 ObjectWithSite_AddRef,
169 ObjectWithSite_Release,
170 ObjectWithSite_SetSite,
171 ObjectWithSite_GetSite
174 static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
176 static IObjectWithSite *object_with_site;
178 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
182 if(IsEqualGUID(riid, &IID_IUnknown)) {
184 }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
185 if(FAILED(QI_IDispatch_hres))
186 return QI_IDispatch_hres;
188 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
189 CHECK_EXPECT(QI_IObjectWithSite);
190 *ppv = object_with_site;
191 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
192 ok(0, "Unexpected IID_IObjectSafety query\n");
195 return *ppv ? S_OK : E_NOINTERFACE;
198 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
203 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
208 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
210 ok(0, "unexpected call\n");
214 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
215 LCID lcid, ITypeInfo **ppTInfo)
217 ok(0, "unexpected call\n");
221 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
222 LPOLESTR *rgszNames, UINT cNames,
223 LCID lcid, DISPID *rgDispId)
225 ok(0, "unexpected call\n");
229 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
230 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
231 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
233 ok(0, "unexpected call\n");
237 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
239 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
243 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
245 ok(0, "unexpected call\n");
249 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
251 ok(0, "unexpected call\n");
255 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
257 ok(0, "unexpected call\n");
261 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
263 ok(0, "unexpected call\n");
267 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
269 ok(0, "unexpected call\n");
273 static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
275 if(!strcmp_wa(bstrName, "reportSuccess")) {
276 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
277 *pid = DISPID_TEST_REPORTSUCCESS;
281 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
285 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
286 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
289 case DISPID_TEST_REPORTSUCCESS:
290 CHECK_EXPECT(reportSuccess);
292 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
293 ok(pdp != NULL, "pdp == NULL\n");
294 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
295 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
296 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
297 ok(!pvarRes, "pvarRes != NULL\n");
298 ok(pei != NULL, "pei == NULL\n");
302 ok(0, "unexpected call\n");
309 static IDispatchExVtbl testObjVtbl = {
310 DispatchEx_QueryInterface,
313 DispatchEx_GetTypeInfoCount,
314 DispatchEx_GetTypeInfo,
315 DispatchEx_GetIDsOfNames,
319 DispatchEx_DeleteMemberByName,
320 DispatchEx_DeleteMemberByDispID,
321 DispatchEx_GetMemberProperties,
322 DispatchEx_GetMemberName,
323 DispatchEx_GetNextDispID,
324 DispatchEx_GetNameSpaceParent
327 static IDispatchEx testObj = { &testObjVtbl };
329 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
331 if(!strcmp_wa(bstrName, "ok")) {
332 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
333 *pid = DISPID_GLOBAL_OK;
337 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
341 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
342 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
345 case DISPID_GLOBAL_OK:
346 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
347 ok(pdp != NULL, "pdp == NULL\n");
348 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
349 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
350 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
351 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
352 ok(pei != NULL, "pei == NULL\n");
354 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
355 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
356 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
360 ok(0, "unexpected call\n");
367 static IDispatchExVtbl globalObjVtbl = {
368 DispatchEx_QueryInterface,
371 DispatchEx_GetTypeInfoCount,
372 DispatchEx_GetTypeInfo,
373 DispatchEx_GetIDsOfNames,
377 DispatchEx_DeleteMemberByName,
378 DispatchEx_DeleteMemberByDispID,
379 DispatchEx_GetMemberProperties,
380 DispatchEx_GetMemberName,
381 DispatchEx_GetNextDispID,
382 DispatchEx_GetNameSpaceParent
385 static IDispatchEx globalObj = { &globalObjVtbl };
387 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
389 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
394 /* TODO: IClassFactoryEx */
396 return E_NOINTERFACE;
399 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
404 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
409 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
411 CHECK_EXPECT(CreateInstance);
413 ok(!outer, "outer = %p\n", outer);
414 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
416 if(SUCCEEDED(CreateInstance_hres))
418 return CreateInstance_hres;
421 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
423 ok(0, "unexpected call\n");
427 static const IClassFactoryVtbl ClassFactoryVtbl = {
428 ClassFactory_QueryInterface,
430 ClassFactory_Release,
431 ClassFactory_CreateInstance,
432 ClassFactory_LockServer
435 static IClassFactory activex_cf = { &ClassFactoryVtbl };
437 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
439 ok(0, "unexpected call\n");
440 return E_NOINTERFACE;
443 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
448 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
453 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
454 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
456 ok(0, "unexpected call\n");
460 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
461 BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
463 CHECK_EXPECT(ProcessUrlAction);
465 ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
466 ok(pPolicy != NULL, "pPolicy == NULL\n");
467 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
468 ok(pContext != NULL, "pContext == NULL\n");
469 ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
470 ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", debugstr_guid((const IID*)pContext));
471 ok(!dwFlags, "dwFlags = %x\n", dwFlags);
472 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
474 if(SUCCEEDED(ProcessUrlAction_hres))
475 *(DWORD*)pPolicy = ProcessUrlAction_policy;
476 return ProcessUrlAction_hres;
479 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
480 BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
482 const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
485 CHECK_EXPECT(QueryCustomPolicy);
487 ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", debugstr_guid(guidKey));
489 ok(ppPolicy != NULL, "ppPolicy == NULL\n");
490 ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
491 ok(pContext != NULL, "pContext == NULL\n");
492 ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
493 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
496 ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
497 ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
499 if(FAILED(QueryCustomPolicy_hres))
500 return QueryCustomPolicy_hres;
502 ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
503 *ppPolicy = (BYTE*)ret;
504 *pcbPolicy = QueryCustomPolicy_psize;
505 memset(ret, 0, QueryCustomPolicy_psize);
506 if(QueryCustomPolicy_psize >= sizeof(DWORD))
507 *ret = QueryCustomPolicy_policy;
509 return QueryCustomPolicy_hres;
512 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
513 InternetHostSecurityManager_QueryInterface,
514 InternetHostSecurityManager_AddRef,
515 InternetHostSecurityManager_Release,
516 InternetHostSecurityManager_GetSecurityId,
517 InternetHostSecurityManager_ProcessUrlAction,
518 InternetHostSecurityManager_QueryCustomPolicy
521 static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
523 static IServiceProvider ServiceProvider;
525 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
527 ok(0, "unexpected call\n");
528 return E_NOINTERFACE;
531 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
536 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
541 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
542 REFGUID guidService, REFIID riid, void **ppv)
544 if(IsEqualGUID(&SID_GetCaller, guidService))
545 return E_NOINTERFACE;
547 if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
548 if(iface == &ServiceProvider)
549 CHECK_EXPECT(Host_QS_SecMgr);
551 CHECK_EXPECT(Caller_QS_SecMgr);
552 ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", debugstr_guid(riid));
553 if(SUCCEEDED(QS_SecMgr_hres))
554 *ppv = &InternetHostSecurityManager;
555 return QS_SecMgr_hres;
558 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
559 return E_NOINTERFACE;
562 static IServiceProviderVtbl ServiceProviderVtbl = {
563 ServiceProvider_QueryInterface,
564 ServiceProvider_AddRef,
565 ServiceProvider_Release,
566 ServiceProvider_QueryService
569 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
570 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
572 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
574 if(IsEqualGUID(&IID_IUnknown, riid)) {
576 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
578 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
579 *ppv = &ServiceProvider;
582 return E_NOINTERFACE;
585 IUnknown_AddRef((IUnknown*)*ppv);
589 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
594 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
599 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
601 *plcid = GetUserDefaultLCID();
605 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
606 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
608 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
609 ok(!ppti, "ppti != NULL\n");
610 ok(!strcmp_wa(pstrName, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
612 *ppiunkItem = (IUnknown*)&globalObj;
616 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
621 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
622 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
627 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
632 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
637 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
642 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
647 #undef ACTSCPSITE_THIS
649 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
650 ActiveScriptSite_QueryInterface,
651 ActiveScriptSite_AddRef,
652 ActiveScriptSite_Release,
653 ActiveScriptSite_GetLCID,
654 ActiveScriptSite_GetItemInfo,
655 ActiveScriptSite_GetDocVersionString,
656 ActiveScriptSite_OnScriptTerminate,
657 ActiveScriptSite_OnStateChange,
658 ActiveScriptSite_OnScriptError,
659 ActiveScriptSite_OnEnterScript,
660 ActiveScriptSite_OnLeaveScript
663 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
665 static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
667 IObjectSafety *safety;
668 DWORD supported, enabled, options_all, options_set;
671 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
672 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
676 options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
678 options_set = options_all;
680 options_set = INTERFACE_USES_DISPEX;
682 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
683 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
685 supported = enabled = 0xdeadbeef;
686 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
687 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
688 ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
689 ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
691 IObjectSafety_Release(safety);
694 #define parse_script_a(p,s) _parse_script_a(__LINE__,p,s)
695 static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const char *script)
700 str = a2bstr(script);
701 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
703 ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
706 static IActiveScriptParse *create_script(BOOL skip_tests, BOOL use_sec_mgr)
708 IActiveScriptParse *parser;
709 IActiveScript *script;
712 QS_SecMgr_hres = S_OK;
713 ProcessUrlAction_hres = S_OK;
714 ProcessUrlAction_policy = URLPOLICY_ALLOW;
715 CreateInstance_hres = S_OK;
716 QueryCustomPolicy_hres = S_OK;
717 QueryCustomPolicy_psize = sizeof(DWORD);
718 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
719 QI_IDispatch_hres = S_OK;
722 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
723 &IID_IActiveScript, (void**)&script);
725 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
730 set_safety_options((IUnknown*)script, use_sec_mgr);
732 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
733 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
735 hres = IActiveScriptParse64_InitNew(parser);
736 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
738 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
739 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
741 hres = IActiveScript_AddNamedItem(script, testW,
742 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
743 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
745 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
746 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
748 IActiveScript_Release(script);
751 parse_script_a(parser,
752 "function testException(func, type, number) {\n"
756 " ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n"
757 " ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n"
760 " ok(false, 'exception expected');\n"
767 static IDispatchEx *parse_procedure_a(IActiveScriptParse *parser, const char *src)
769 IActiveScriptParseProcedure2 *parse_proc;
775 hres = IUnknown_QueryInterface(parser, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
776 ok(hres == S_OK, "Coult not get IActiveScriptParseProcedure2: %08x\n", hres);
779 hres = IActiveScriptParseProcedure2_64_ParseProcedureText(parse_proc, str, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, &disp);
781 IUnknown_Release(parse_proc);
782 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
783 ok(disp != NULL, "disp == NULL\n");
785 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
786 IDispatch_Release(dispex);
787 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
792 #define call_procedure(p,c) _call_procedure(__LINE__,p,c)
793 static void _call_procedure(unsigned line, IDispatchEx *proc, IServiceProvider *caller)
795 DISPPARAMS dp = {NULL,NULL,0,0};
799 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, NULL, &ei, caller);
800 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
804 static void test_ActiveXObject(void)
806 IActiveScriptParse *parser;
809 parser = create_script(FALSE, TRUE);
811 SET_EXPECT(Host_QS_SecMgr);
812 SET_EXPECT(ProcessUrlAction);
813 SET_EXPECT(CreateInstance);
814 SET_EXPECT(QueryCustomPolicy);
815 SET_EXPECT(QI_IObjectWithSite);
816 SET_EXPECT(reportSuccess);
817 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
818 CHECK_CALLED(Host_QS_SecMgr);
819 CHECK_CALLED(ProcessUrlAction);
820 CHECK_CALLED(CreateInstance);
821 CHECK_CALLED(QueryCustomPolicy);
822 CHECK_CALLED(QI_IObjectWithSite);
823 CHECK_CALLED(reportSuccess);
825 proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
827 SET_EXPECT(ProcessUrlAction);
828 SET_EXPECT(CreateInstance);
829 SET_EXPECT(QueryCustomPolicy);
830 SET_EXPECT(QI_IObjectWithSite);
831 SET_EXPECT(reportSuccess);
832 call_procedure(proc, NULL);
833 CHECK_CALLED(ProcessUrlAction);
834 CHECK_CALLED(CreateInstance);
835 CHECK_CALLED(QueryCustomPolicy);
836 CHECK_CALLED(QI_IObjectWithSite);
837 CHECK_CALLED(reportSuccess);
839 SET_EXPECT(ProcessUrlAction);
840 SET_EXPECT(CreateInstance);
841 SET_EXPECT(QueryCustomPolicy);
842 SET_EXPECT(QI_IObjectWithSite);
843 SET_EXPECT(reportSuccess);
844 call_procedure(proc, &caller_sp);
845 CHECK_CALLED(ProcessUrlAction);
846 CHECK_CALLED(CreateInstance);
847 CHECK_CALLED(QueryCustomPolicy);
848 CHECK_CALLED(QI_IObjectWithSite);
849 CHECK_CALLED(reportSuccess);
851 IDispatchEx_Release(proc);
852 IUnknown_Release(parser);
854 parser = create_script(FALSE, TRUE);
855 proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
857 SET_EXPECT(Host_QS_SecMgr);
858 SET_EXPECT(ProcessUrlAction);
859 SET_EXPECT(CreateInstance);
860 SET_EXPECT(QueryCustomPolicy);
861 SET_EXPECT(QI_IObjectWithSite);
862 SET_EXPECT(reportSuccess);
863 call_procedure(proc, &caller_sp);
864 CHECK_CALLED(Host_QS_SecMgr);
865 CHECK_CALLED(ProcessUrlAction);
866 CHECK_CALLED(CreateInstance);
867 CHECK_CALLED(QueryCustomPolicy);
868 CHECK_CALLED(QI_IObjectWithSite);
869 CHECK_CALLED(reportSuccess);
871 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);");
873 IDispatchEx_Release(proc);
874 IUnknown_Release(parser);
876 parser = create_script(FALSE, TRUE);
877 QS_SecMgr_hres = E_NOINTERFACE;
879 SET_EXPECT(Host_QS_SecMgr);
880 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
881 CHECK_CALLED(Host_QS_SecMgr);
883 IUnknown_Release(parser);
885 parser = create_script(FALSE, TRUE);
886 ProcessUrlAction_hres = E_FAIL;
888 SET_EXPECT(Host_QS_SecMgr);
889 SET_EXPECT(ProcessUrlAction);
890 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
891 CHECK_CALLED(Host_QS_SecMgr);
892 CHECK_CALLED(ProcessUrlAction);
894 IUnknown_Release(parser);
896 parser = create_script(FALSE, TRUE);
897 ProcessUrlAction_policy = URLPOLICY_DISALLOW;
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);
905 IUnknown_Release(parser);
907 parser = create_script(FALSE, TRUE);
908 CreateInstance_hres = E_FAIL;
910 SET_EXPECT(Host_QS_SecMgr);
911 SET_EXPECT(ProcessUrlAction);
912 SET_EXPECT(CreateInstance);
913 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
914 CHECK_CALLED(Host_QS_SecMgr);
915 CHECK_CALLED(ProcessUrlAction);
916 CHECK_CALLED(CreateInstance);
918 IUnknown_Release(parser);
920 parser = create_script(FALSE, TRUE);
921 QueryCustomPolicy_hres = E_FAIL;
923 SET_EXPECT(Host_QS_SecMgr);
924 SET_EXPECT(ProcessUrlAction);
925 SET_EXPECT(CreateInstance);
926 SET_EXPECT(QueryCustomPolicy);
927 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
928 CHECK_CALLED(Host_QS_SecMgr);
929 CHECK_CALLED(ProcessUrlAction);
930 CHECK_CALLED(CreateInstance);
931 CHECK_CALLED(QueryCustomPolicy);
933 IUnknown_Release(parser);
935 parser = create_script(FALSE, TRUE);
936 QueryCustomPolicy_psize = 6;
938 SET_EXPECT(Host_QS_SecMgr);
939 SET_EXPECT(ProcessUrlAction);
940 SET_EXPECT(CreateInstance);
941 SET_EXPECT(QueryCustomPolicy);
942 SET_EXPECT(QI_IObjectWithSite);
943 SET_EXPECT(reportSuccess);
944 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
945 CHECK_CALLED(Host_QS_SecMgr);
946 CHECK_CALLED(ProcessUrlAction);
947 CHECK_CALLED(CreateInstance);
948 CHECK_CALLED(QueryCustomPolicy);
949 CHECK_CALLED(QI_IObjectWithSite);
950 CHECK_CALLED(reportSuccess);
952 IUnknown_Release(parser);
954 parser = create_script(FALSE, TRUE);
955 QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
957 SET_EXPECT(Host_QS_SecMgr);
958 SET_EXPECT(ProcessUrlAction);
959 SET_EXPECT(CreateInstance);
960 SET_EXPECT(QueryCustomPolicy);
961 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
962 CHECK_CALLED(Host_QS_SecMgr);
963 CHECK_CALLED(ProcessUrlAction);
964 CHECK_CALLED(CreateInstance);
965 CHECK_CALLED(QueryCustomPolicy);
967 QueryCustomPolicy_psize = 6;
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(ProcessUrlAction);
974 CHECK_CALLED(CreateInstance);
975 CHECK_CALLED(QueryCustomPolicy);
977 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
978 QueryCustomPolicy_psize = 3;
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);
988 IUnknown_Release(parser);
990 parser = create_script(FALSE, FALSE);
992 SET_EXPECT(CreateInstance);
993 SET_EXPECT(QI_IObjectWithSite);
994 SET_EXPECT(reportSuccess);
995 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
996 CHECK_CALLED(CreateInstance);
997 CHECK_CALLED(QI_IObjectWithSite);
998 CHECK_CALLED(reportSuccess);
1000 IUnknown_Release(parser);
1002 parser = create_script(FALSE, TRUE);
1003 object_with_site = &ObjectWithSite;
1005 SET_EXPECT(Host_QS_SecMgr);
1006 SET_EXPECT(ProcessUrlAction);
1007 SET_EXPECT(CreateInstance);
1008 SET_EXPECT(QueryCustomPolicy);
1009 SET_EXPECT(QI_IObjectWithSite);
1010 SET_EXPECT(SetSite);
1011 SET_EXPECT(reportSuccess);
1012 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1013 CHECK_CALLED(Host_QS_SecMgr);
1014 CHECK_CALLED(ProcessUrlAction);
1015 CHECK_CALLED(CreateInstance);
1016 CHECK_CALLED(QueryCustomPolicy);
1017 CHECK_CALLED(QI_IObjectWithSite);
1018 CHECK_CALLED(SetSite);
1019 CHECK_CALLED(reportSuccess);
1021 SetSite_hres = E_FAIL;
1022 SET_EXPECT(ProcessUrlAction);
1023 SET_EXPECT(CreateInstance);
1024 SET_EXPECT(QueryCustomPolicy);
1025 SET_EXPECT(QI_IObjectWithSite);
1026 SET_EXPECT(SetSite);
1027 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1028 CHECK_CALLED(ProcessUrlAction);
1029 CHECK_CALLED(CreateInstance);
1030 CHECK_CALLED(QueryCustomPolicy);
1031 CHECK_CALLED(QI_IObjectWithSite);
1032 CHECK_CALLED(SetSite);
1034 IUnknown_Release(parser);
1037 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1043 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1047 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1048 if(res != ERROR_SUCCESS)
1052 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1056 return res == ERROR_SUCCESS;
1059 static BOOL init_registry(BOOL init)
1061 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1064 static BOOL register_activex(void)
1069 if(!init_registry(TRUE)) {
1070 init_registry(FALSE);
1074 hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1075 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1076 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1081 static BOOL check_jscript(void)
1083 IActiveScriptProperty *script_prop;
1084 IActiveScriptParse *parser;
1088 parser = create_script(TRUE, TRUE);
1092 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1093 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1097 hres = IUnknown_QueryInterface(parser, &IID_IActiveScriptProperty, (void**)&script_prop);
1098 IUnknown_Release(parser);
1100 IActiveScriptProperty_Release(script_prop);
1102 return hres == S_OK;
1109 if(check_jscript()) {
1112 test_ActiveXObject();
1114 init_registry(FALSE);
1116 win_skip("Broken engine, probably too old\n");