shell32: Add printers CLSID to test, clean up a bit.
[wine/testsucceed.git] / dlls / jscript / tests / activex.c
blobba3f8bd2d76ebfea3e7a849480d947cdabf446cf
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 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) \
46 do { \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
49 }while(0)
51 #define CHECK_EXPECT(func) \
52 do { \
53 CHECK_EXPECT2(func); \
54 expect_ ## func = FALSE; \
55 }while(0)
57 #define CHECK_CALLED(func) \
58 do { \
59 ok(called_ ## func, "expected " #func "\n"); \
60 expect_ ## func = called_ ## func = FALSE; \
61 }while(0)
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)
99 static char buf[50];
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]);
106 return buf;
109 static BSTR a2bstr(const char *str)
111 BSTR ret;
112 int len;
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);
118 return ret;
121 static int strcmp_wa(LPCWSTR strw, const char *stra)
123 CHAR buf[512];
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");
131 return E_NOTIMPL;
134 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
136 return 2;
139 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
141 return 1;
144 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
146 IServiceProvider *sp;
147 HRESULT hres;
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);
157 return SetSite_hres;
160 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
162 ok(0, "unexpected call\n");
163 return E_NOTIMPL;
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)
180 *ppv = NULL;
182 if(IsEqualGUID(riid, &IID_IUnknown)) {
183 *ppv = iface;
184 }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
185 if(FAILED(QI_IDispatch_hres))
186 return QI_IDispatch_hres;
187 *ppv = iface;
188 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
189 CHECK_EXPECT(QI_IObjectWithSite);
190 *ppv = object_with_site;
191 }else {
192 return E_NOINTERFACE;
195 return *ppv ? S_OK : E_NOINTERFACE;
198 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
200 return 2;
203 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
205 return 1;
208 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
210 ok(0, "unexpected call\n");
211 return E_NOTIMPL;
214 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
215 LCID lcid, ITypeInfo **ppTInfo)
217 ok(0, "unexpected call\n");
218 return E_NOTIMPL;
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");
226 return E_NOTIMPL;
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");
234 return E_NOTIMPL;
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);
240 return E_NOTIMPL;
243 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
245 ok(0, "unexpected call\n");
246 return E_NOTIMPL;
249 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
251 ok(0, "unexpected call\n");
252 return E_NOTIMPL;
255 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
257 ok(0, "unexpected call\n");
258 return E_NOTIMPL;
261 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
263 ok(0, "unexpected call\n");
264 return E_NOTIMPL;
267 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
269 ok(0, "unexpected call\n");
270 return E_NOTIMPL;
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;
278 return S_OK;
281 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
282 return E_NOTIMPL;
285 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
286 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
288 switch(id) {
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");
299 break;
301 default:
302 ok(0, "unexpected call\n");
303 return E_NOTIMPL;
306 return S_OK;
309 static IDispatchExVtbl testObjVtbl = {
310 DispatchEx_QueryInterface,
311 DispatchEx_AddRef,
312 DispatchEx_Release,
313 DispatchEx_GetTypeInfoCount,
314 DispatchEx_GetTypeInfo,
315 DispatchEx_GetIDsOfNames,
316 DispatchEx_Invoke,
317 Test_GetDispID,
318 Test_InvokeEx,
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;
334 return S_OK;
337 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
338 return E_NOTIMPL;
341 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
342 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
344 switch(id) {
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)));
357 break;
359 default:
360 ok(0, "unexpected call\n");
361 return E_NOTIMPL;
364 return S_OK;
367 static IDispatchExVtbl globalObjVtbl = {
368 DispatchEx_QueryInterface,
369 DispatchEx_AddRef,
370 DispatchEx_Release,
371 DispatchEx_GetTypeInfoCount,
372 DispatchEx_GetTypeInfo,
373 DispatchEx_GetIDsOfNames,
374 DispatchEx_Invoke,
375 Global_GetDispID,
376 Global_InvokeEx,
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)) {
390 *ppv = iface;
391 return S_OK;
394 /* TODO: IClassFactoryEx */
395 *ppv = NULL;
396 return E_NOINTERFACE;
399 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
401 return 2;
404 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
406 return 1;
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))
417 *ppv = &testObj;
418 return CreateInstance_hres;
421 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
423 ok(0, "unexpected call\n");
424 return S_OK;
427 static const IClassFactoryVtbl ClassFactoryVtbl = {
428 ClassFactory_QueryInterface,
429 ClassFactory_AddRef,
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)
445 return 2;
448 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
450 return 1;
453 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
454 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
456 ok(0, "unexpected call\n");
457 return E_NOTIMPL;
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;
483 DWORD *ret;
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);
495 /* TODO: CLSID */
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)
533 return 2;
536 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
538 return 1;
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);
550 else
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)) {
575 *ppv = iface;
576 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
577 *ppv = iface;
578 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
579 *ppv = &ServiceProvider;
580 }else {
581 *ppv = NULL;
582 return E_NOINTERFACE;
585 IUnknown_AddRef((IUnknown*)*ppv);
586 return S_OK;
589 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
591 return 2;
594 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
596 return 1;
599 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
601 *plcid = GetUserDefaultLCID();
602 return S_OK;
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;
613 return S_OK;
616 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
618 return E_NOTIMPL;
621 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
622 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
624 return E_NOTIMPL;
627 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
629 return E_NOTIMPL;
632 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
634 return E_NOTIMPL;
637 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
639 return E_NOTIMPL;
642 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
644 return E_NOTIMPL;
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)
667 IObjectSafety *safety;
668 DWORD supported, enabled;
669 HRESULT hres;
671 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
672 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
673 if(FAILED(hres))
674 return;
676 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
677 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
678 INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
679 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
681 supported = enabled = 0xdeadbeef;
682 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
683 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
684 ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
685 "supported=%x\n", supported);
686 ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
687 "enabled=%x\n", enabled);
689 IObjectSafety_Release(safety);
692 #define parse_script_a(p,s) _parse_script_a(__LINE__,p,s)
693 static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const char *script)
695 BSTR str;
696 HRESULT hres;
698 str = a2bstr(script);
699 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
700 SysFreeString(str);
701 ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
704 static IActiveScriptParse *create_script(void)
706 IActiveScriptParse *parser;
707 IActiveScript *script;
708 HRESULT hres;
710 QS_SecMgr_hres = S_OK;
711 ProcessUrlAction_hres = S_OK;
712 ProcessUrlAction_policy = URLPOLICY_ALLOW;
713 CreateInstance_hres = S_OK;
714 QueryCustomPolicy_hres = S_OK;
715 QueryCustomPolicy_psize = sizeof(DWORD);
716 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
717 QI_IDispatch_hres = S_OK;
718 SetSite_hres = S_OK;
720 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
721 &IID_IActiveScript, (void**)&script);
722 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
723 if(FAILED(hres))
724 return NULL;
726 set_safety_options((IUnknown*)script);
728 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
729 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
731 hres = IActiveScriptParse64_InitNew(parser);
732 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
734 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
735 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
737 hres = IActiveScript_AddNamedItem(script, testW,
738 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
739 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
741 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
742 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
744 IActiveScript_Release(script);
746 parse_script_a(parser,
747 "function testException(func, type, number) {\n"
748 "try {\n"
749 " func();\n"
750 "}catch(e) {\n"
751 " ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n"
752 " ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n"
753 " return;\n"
755 "ok(false, 'exception expected');\n"
756 "}");
758 return parser;
761 static IDispatchEx *parse_procedure_a(IActiveScriptParse *parser, const char *src)
763 IActiveScriptParseProcedure2 *parse_proc;
764 IDispatchEx *dispex;
765 IDispatch *disp;
766 BSTR str;
767 HRESULT hres;
769 hres = IUnknown_QueryInterface(parser, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
770 ok(hres == S_OK, "Coult not get IActiveScriptParseProcedure2: %08x\n", hres);
772 str = a2bstr(src);
773 hres = IActiveScriptParseProcedure2_64_ParseProcedureText(parse_proc, str, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, &disp);
774 SysFreeString(str);
775 IUnknown_Release(parse_proc);
776 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
777 ok(disp != NULL, "disp == NULL\n");
779 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
780 IDispatch_Release(dispex);
781 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
783 return dispex;
786 #define call_procedure(p,c) _call_procedure(__LINE__,p,c)
787 static void _call_procedure(unsigned line, IDispatchEx *proc, IServiceProvider *caller)
789 DISPPARAMS dp = {NULL,NULL,0,0};
790 EXCEPINFO ei = {0};
791 HRESULT hres;
793 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, NULL, &ei, caller);
794 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
798 static void test_ActiveXObject(void)
800 IActiveScriptParse *parser;
801 IDispatchEx *proc;
803 parser = create_script();
805 SET_EXPECT(Host_QS_SecMgr);
806 SET_EXPECT(ProcessUrlAction);
807 SET_EXPECT(CreateInstance);
808 SET_EXPECT(QueryCustomPolicy);
809 SET_EXPECT(QI_IObjectWithSite);
810 SET_EXPECT(reportSuccess);
811 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
812 CHECK_CALLED(Host_QS_SecMgr);
813 CHECK_CALLED(ProcessUrlAction);
814 CHECK_CALLED(CreateInstance);
815 CHECK_CALLED(QueryCustomPolicy);
816 CHECK_CALLED(QI_IObjectWithSite);
817 CHECK_CALLED(reportSuccess);
819 proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).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, NULL);
827 CHECK_CALLED(ProcessUrlAction);
828 CHECK_CALLED(CreateInstance);
829 CHECK_CALLED(QueryCustomPolicy);
830 CHECK_CALLED(QI_IObjectWithSite);
831 CHECK_CALLED(reportSuccess);
833 SET_EXPECT(ProcessUrlAction);
834 SET_EXPECT(CreateInstance);
835 SET_EXPECT(QueryCustomPolicy);
836 SET_EXPECT(QI_IObjectWithSite);
837 SET_EXPECT(reportSuccess);
838 call_procedure(proc, &caller_sp);
839 CHECK_CALLED(ProcessUrlAction);
840 CHECK_CALLED(CreateInstance);
841 CHECK_CALLED(QueryCustomPolicy);
842 CHECK_CALLED(QI_IObjectWithSite);
843 CHECK_CALLED(reportSuccess);
845 IDispatchEx_Release(proc);
846 IUnknown_Release(parser);
848 parser = create_script();
849 proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
851 SET_EXPECT(Host_QS_SecMgr);
852 SET_EXPECT(ProcessUrlAction);
853 SET_EXPECT(CreateInstance);
854 SET_EXPECT(QueryCustomPolicy);
855 SET_EXPECT(QI_IObjectWithSite);
856 SET_EXPECT(reportSuccess);
857 call_procedure(proc, &caller_sp);
858 CHECK_CALLED(Host_QS_SecMgr);
859 CHECK_CALLED(ProcessUrlAction);
860 CHECK_CALLED(CreateInstance);
861 CHECK_CALLED(QueryCustomPolicy);
862 CHECK_CALLED(QI_IObjectWithSite);
863 CHECK_CALLED(reportSuccess);
865 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);");
867 IDispatchEx_Release(proc);
868 IUnknown_Release(parser);
870 parser = create_script();
871 QS_SecMgr_hres = E_NOINTERFACE;
873 SET_EXPECT(Host_QS_SecMgr);
874 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
875 CHECK_CALLED(Host_QS_SecMgr);
877 IUnknown_Release(parser);
879 parser = create_script();
880 ProcessUrlAction_hres = E_FAIL;
882 SET_EXPECT(Host_QS_SecMgr);
883 SET_EXPECT(ProcessUrlAction);
884 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
885 CHECK_CALLED(Host_QS_SecMgr);
886 CHECK_CALLED(ProcessUrlAction);
888 IUnknown_Release(parser);
890 parser = create_script();
891 ProcessUrlAction_policy = URLPOLICY_DISALLOW;
893 SET_EXPECT(Host_QS_SecMgr);
894 SET_EXPECT(ProcessUrlAction);
895 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
896 CHECK_CALLED(Host_QS_SecMgr);
897 CHECK_CALLED(ProcessUrlAction);
899 IUnknown_Release(parser);
901 parser = create_script();
902 CreateInstance_hres = E_FAIL;
904 SET_EXPECT(Host_QS_SecMgr);
905 SET_EXPECT(ProcessUrlAction);
906 SET_EXPECT(CreateInstance);
907 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
908 CHECK_CALLED(Host_QS_SecMgr);
909 CHECK_CALLED(ProcessUrlAction);
910 CHECK_CALLED(CreateInstance);
912 IUnknown_Release(parser);
914 parser = create_script();
915 QueryCustomPolicy_hres = E_FAIL;
917 SET_EXPECT(Host_QS_SecMgr);
918 SET_EXPECT(ProcessUrlAction);
919 SET_EXPECT(CreateInstance);
920 SET_EXPECT(QueryCustomPolicy);
921 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
922 CHECK_CALLED(Host_QS_SecMgr);
923 CHECK_CALLED(ProcessUrlAction);
924 CHECK_CALLED(CreateInstance);
925 CHECK_CALLED(QueryCustomPolicy);
927 IUnknown_Release(parser);
929 parser = create_script();
930 QueryCustomPolicy_psize = 6;
932 SET_EXPECT(Host_QS_SecMgr);
933 SET_EXPECT(ProcessUrlAction);
934 SET_EXPECT(CreateInstance);
935 SET_EXPECT(QueryCustomPolicy);
936 SET_EXPECT(QI_IObjectWithSite);
937 SET_EXPECT(reportSuccess);
938 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
939 CHECK_CALLED(Host_QS_SecMgr);
940 CHECK_CALLED(ProcessUrlAction);
941 CHECK_CALLED(CreateInstance);
942 CHECK_CALLED(QueryCustomPolicy);
943 CHECK_CALLED(QI_IObjectWithSite);
944 CHECK_CALLED(reportSuccess);
946 IUnknown_Release(parser);
948 parser = create_script();
949 QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
951 SET_EXPECT(Host_QS_SecMgr);
952 SET_EXPECT(ProcessUrlAction);
953 SET_EXPECT(CreateInstance);
954 SET_EXPECT(QueryCustomPolicy);
955 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
956 CHECK_CALLED(Host_QS_SecMgr);
957 CHECK_CALLED(ProcessUrlAction);
958 CHECK_CALLED(CreateInstance);
959 CHECK_CALLED(QueryCustomPolicy);
961 QueryCustomPolicy_psize = 6;
963 SET_EXPECT(ProcessUrlAction);
964 SET_EXPECT(CreateInstance);
965 SET_EXPECT(QueryCustomPolicy);
966 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
967 CHECK_CALLED(ProcessUrlAction);
968 CHECK_CALLED(CreateInstance);
969 CHECK_CALLED(QueryCustomPolicy);
971 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
972 QueryCustomPolicy_psize = 3;
974 SET_EXPECT(ProcessUrlAction);
975 SET_EXPECT(CreateInstance);
976 SET_EXPECT(QueryCustomPolicy);
977 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
978 CHECK_CALLED(ProcessUrlAction);
979 CHECK_CALLED(CreateInstance);
980 CHECK_CALLED(QueryCustomPolicy);
982 IUnknown_Release(parser);
984 parser = create_script();
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_a(parser, "(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_a(parser, "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 IUnknown_Release(parser);
1019 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1021 HKEY hkey;
1022 DWORD res;
1024 if(!init) {
1025 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1026 return TRUE;
1029 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1030 if(res != ERROR_SUCCESS)
1031 return FALSE;
1033 if(def_value)
1034 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1036 RegCloseKey(hkey);
1038 return res == ERROR_SUCCESS;
1041 static BOOL init_registry(BOOL init)
1043 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1046 static BOOL register_activex(void)
1048 DWORD regid;
1049 HRESULT hres;
1051 if(!init_registry(TRUE)) {
1052 init_registry(FALSE);
1053 return FALSE;
1056 hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1057 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1058 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1060 return TRUE;
1063 static BOOL check_jscript(void)
1065 IActiveScriptParse *parser;
1066 BSTR str;
1067 HRESULT hres;
1069 parser = create_script();
1070 if(!parser)
1071 return FALSE;
1073 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1074 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1075 SysFreeString(str);
1076 IUnknown_Release(parser);
1078 return hres == S_OK;
1081 START_TEST(activex)
1083 CoInitialize(NULL);
1085 if(check_jscript()) {
1086 register_activex();
1088 test_ActiveXObject();
1090 init_registry(FALSE);
1091 }else {
1092 win_skip("Broken engine, probably too old\n");
1095 CoUninitialize();