Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / jscript / tests / activex.c
blobdc90d91f87f26010d305afb69bb73bb594493dfb
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 CHECK_EXPECT2(func) \
43 do { \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
46 }while(0)
48 #define CHECK_EXPECT(func) \
49 do { \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
52 }while(0)
54 #define CHECK_CALLED(func) \
55 do { \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
58 }while(0)
60 DEFINE_EXPECT(CreateInstance);
61 DEFINE_EXPECT(ProcessUrlAction);
62 DEFINE_EXPECT(QueryCustomPolicy);
63 DEFINE_EXPECT(reportSuccess);
64 DEFINE_EXPECT(Host_QS_SecMgr);
65 DEFINE_EXPECT(Caller_QS_SecMgr);
66 DEFINE_EXPECT(QI_IObjectWithSite);
67 DEFINE_EXPECT(SetSite);
69 static const WCHAR testW[] = {'t','e','s','t',0};
71 static HRESULT QS_SecMgr_hres;
72 static HRESULT ProcessUrlAction_hres;
73 static DWORD ProcessUrlAction_policy;
74 static HRESULT CreateInstance_hres;
75 static HRESULT QueryCustomPolicy_hres;
76 static DWORD QueryCustomPolicy_psize;
77 static DWORD QueryCustomPolicy_policy;
78 static HRESULT QI_IDispatch_hres;
79 static HRESULT SetSite_hres;
80 static BOOL AllowIServiceProvider;
82 #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
84 static const GUID CLSID_TestObj =
85 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
87 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
88 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
89 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
91 #define DISPID_TEST_REPORTSUCCESS 0x1000
93 #define DISPID_GLOBAL_OK 0x2000
95 static const char *debugstr_guid(REFIID riid)
97 static char buf[50];
99 sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
100 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
101 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
102 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
104 return buf;
107 static BSTR a2bstr(const char *str)
109 BSTR ret;
110 int len;
112 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
113 ret = SysAllocStringLen(NULL, len-1);
114 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
116 return ret;
119 static int strcmp_wa(LPCWSTR strw, const char *stra)
121 CHAR buf[512];
122 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
123 return lstrcmpA(buf, stra);
126 static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
128 ok(0, "unexpected call\n");
129 return E_NOTIMPL;
132 static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
134 return 2;
137 static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
139 return 1;
142 static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
144 IServiceProvider *sp;
145 HRESULT hres;
148 CHECK_EXPECT(SetSite);
149 ok(pUnkSite != NULL, "pUnkSite == NULL\n");
151 hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
152 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
153 IServiceProvider_Release(sp);
155 return SetSite_hres;
158 static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
160 ok(0, "unexpected call\n");
161 return E_NOTIMPL;
164 static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
165 ObjectWithSite_QueryInterface,
166 ObjectWithSite_AddRef,
167 ObjectWithSite_Release,
168 ObjectWithSite_SetSite,
169 ObjectWithSite_GetSite
172 static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
174 static IObjectWithSite *object_with_site;
176 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
178 *ppv = NULL;
180 if(IsEqualGUID(riid, &IID_IUnknown)) {
181 *ppv = iface;
182 }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
183 if(FAILED(QI_IDispatch_hres))
184 return QI_IDispatch_hres;
185 *ppv = iface;
186 }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
187 CHECK_EXPECT(QI_IObjectWithSite);
188 *ppv = object_with_site;
189 }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
190 ok(0, "Unexpected IID_IObjectSafety query\n");
193 return *ppv ? S_OK : E_NOINTERFACE;
196 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
198 return 2;
201 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
203 return 1;
206 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
208 ok(0, "unexpected call\n");
209 return E_NOTIMPL;
212 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
213 LCID lcid, ITypeInfo **ppTInfo)
215 ok(0, "unexpected call\n");
216 return E_NOTIMPL;
219 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
220 LPOLESTR *rgszNames, UINT cNames,
221 LCID lcid, DISPID *rgDispId)
223 ok(0, "unexpected call\n");
224 return E_NOTIMPL;
227 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
228 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
229 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
231 ok(0, "unexpected call\n");
232 return E_NOTIMPL;
235 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
237 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
238 return E_NOTIMPL;
241 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
243 ok(0, "unexpected call\n");
244 return E_NOTIMPL;
247 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
249 ok(0, "unexpected call\n");
250 return E_NOTIMPL;
253 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
255 ok(0, "unexpected call\n");
256 return E_NOTIMPL;
259 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
261 ok(0, "unexpected call\n");
262 return E_NOTIMPL;
265 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
267 ok(0, "unexpected call\n");
268 return E_NOTIMPL;
271 static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
273 if(!strcmp_wa(bstrName, "reportSuccess")) {
274 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
275 *pid = DISPID_TEST_REPORTSUCCESS;
276 return S_OK;
279 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
280 return E_NOTIMPL;
283 static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
284 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
286 switch(id) {
287 case DISPID_TEST_REPORTSUCCESS:
288 CHECK_EXPECT(reportSuccess);
290 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
291 ok(pdp != NULL, "pdp == NULL\n");
292 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
293 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
294 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
295 ok(!pvarRes, "pvarRes != NULL\n");
296 ok(pei != NULL, "pei == NULL\n");
297 break;
299 default:
300 ok(0, "unexpected call\n");
301 return E_NOTIMPL;
304 return S_OK;
307 static IDispatchExVtbl testObjVtbl = {
308 DispatchEx_QueryInterface,
309 DispatchEx_AddRef,
310 DispatchEx_Release,
311 DispatchEx_GetTypeInfoCount,
312 DispatchEx_GetTypeInfo,
313 DispatchEx_GetIDsOfNames,
314 DispatchEx_Invoke,
315 Test_GetDispID,
316 Test_InvokeEx,
317 DispatchEx_DeleteMemberByName,
318 DispatchEx_DeleteMemberByDispID,
319 DispatchEx_GetMemberProperties,
320 DispatchEx_GetMemberName,
321 DispatchEx_GetNextDispID,
322 DispatchEx_GetNameSpaceParent
325 static IDispatchEx testObj = { &testObjVtbl };
327 static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
329 if(!strcmp_wa(bstrName, "ok")) {
330 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
331 *pid = DISPID_GLOBAL_OK;
332 return S_OK;
335 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
336 return E_NOTIMPL;
339 static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
340 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
342 switch(id) {
343 case DISPID_GLOBAL_OK:
344 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
345 ok(pdp != NULL, "pdp == NULL\n");
346 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
347 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
348 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
349 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
350 ok(pei != NULL, "pei == NULL\n");
352 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
353 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
354 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
355 break;
357 default:
358 ok(0, "unexpected call\n");
359 return E_NOTIMPL;
362 return S_OK;
365 static IDispatchExVtbl globalObjVtbl = {
366 DispatchEx_QueryInterface,
367 DispatchEx_AddRef,
368 DispatchEx_Release,
369 DispatchEx_GetTypeInfoCount,
370 DispatchEx_GetTypeInfo,
371 DispatchEx_GetIDsOfNames,
372 DispatchEx_Invoke,
373 Global_GetDispID,
374 Global_InvokeEx,
375 DispatchEx_DeleteMemberByName,
376 DispatchEx_DeleteMemberByDispID,
377 DispatchEx_GetMemberProperties,
378 DispatchEx_GetMemberName,
379 DispatchEx_GetNextDispID,
380 DispatchEx_GetNameSpaceParent
383 static IDispatchEx globalObj = { &globalObjVtbl };
385 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
387 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
388 *ppv = iface;
389 return S_OK;
392 /* TODO: IClassFactoryEx */
393 *ppv = NULL;
394 return E_NOINTERFACE;
397 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
399 return 2;
402 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
404 return 1;
407 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
409 CHECK_EXPECT(CreateInstance);
411 ok(!outer, "outer = %p\n", outer);
412 ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
414 if(SUCCEEDED(CreateInstance_hres))
415 *ppv = &testObj;
416 return CreateInstance_hres;
419 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
421 ok(0, "unexpected call\n");
422 return S_OK;
425 static const IClassFactoryVtbl ClassFactoryVtbl = {
426 ClassFactory_QueryInterface,
427 ClassFactory_AddRef,
428 ClassFactory_Release,
429 ClassFactory_CreateInstance,
430 ClassFactory_LockServer
433 static IClassFactory activex_cf = { &ClassFactoryVtbl };
435 static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
437 ok(0, "unexpected call\n");
438 return E_NOINTERFACE;
441 static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
443 return 2;
446 static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
448 return 1;
451 static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface, BYTE *pbSecurityId,
452 DWORD *pcbSecurityId, DWORD_PTR dwReserved)
454 ok(0, "unexpected call\n");
455 return E_NOTIMPL;
458 static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
459 BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
461 CHECK_EXPECT(ProcessUrlAction);
463 ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
464 ok(pPolicy != NULL, "pPolicy == NULL\n");
465 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
466 ok(pContext != NULL, "pContext == NULL\n");
467 ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
468 ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", debugstr_guid((const IID*)pContext));
469 ok(!dwFlags, "dwFlags = %x\n", dwFlags);
470 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
472 if(SUCCEEDED(ProcessUrlAction_hres))
473 *(DWORD*)pPolicy = ProcessUrlAction_policy;
474 return ProcessUrlAction_hres;
477 static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
478 BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
480 const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
481 DWORD *ret;
483 CHECK_EXPECT(QueryCustomPolicy);
485 ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", debugstr_guid(guidKey));
487 ok(ppPolicy != NULL, "ppPolicy == NULL\n");
488 ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
489 ok(pContext != NULL, "pContext == NULL\n");
490 ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
491 ok(!dwReserved, "dwReserved = %x\n", dwReserved);
493 /* TODO: CLSID */
494 ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
495 ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
497 if(FAILED(QueryCustomPolicy_hres))
498 return QueryCustomPolicy_hres;
500 ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
501 *ppPolicy = (BYTE*)ret;
502 *pcbPolicy = QueryCustomPolicy_psize;
503 memset(ret, 0, QueryCustomPolicy_psize);
504 if(QueryCustomPolicy_psize >= sizeof(DWORD))
505 *ret = QueryCustomPolicy_policy;
507 return QueryCustomPolicy_hres;
510 static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
511 InternetHostSecurityManager_QueryInterface,
512 InternetHostSecurityManager_AddRef,
513 InternetHostSecurityManager_Release,
514 InternetHostSecurityManager_GetSecurityId,
515 InternetHostSecurityManager_ProcessUrlAction,
516 InternetHostSecurityManager_QueryCustomPolicy
519 static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
521 static IServiceProvider ServiceProvider;
523 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
525 ok(0, "unexpected call\n");
526 return E_NOINTERFACE;
529 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
531 return 2;
534 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
536 return 1;
539 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
540 REFGUID guidService, REFIID riid, void **ppv)
542 if(IsEqualGUID(&SID_GetCaller, guidService))
543 return E_NOINTERFACE;
545 if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
546 if(iface == &ServiceProvider)
547 CHECK_EXPECT(Host_QS_SecMgr);
548 else
549 CHECK_EXPECT(Caller_QS_SecMgr);
550 ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", debugstr_guid(riid));
551 if(SUCCEEDED(QS_SecMgr_hres))
552 *ppv = &InternetHostSecurityManager;
553 return QS_SecMgr_hres;
556 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
557 return E_NOINTERFACE;
560 static IServiceProviderVtbl ServiceProviderVtbl = {
561 ServiceProvider_QueryInterface,
562 ServiceProvider_AddRef,
563 ServiceProvider_Release,
564 ServiceProvider_QueryService
567 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
568 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
570 static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
572 if(IsEqualGUID(&IID_IUnknown, riid)) {
573 *ppv = iface;
574 }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
575 *ppv = iface;
576 }else if(IsEqualGUID(&IID_IServiceProvider, riid) && AllowIServiceProvider) {
577 *ppv = &ServiceProvider;
578 }else {
579 *ppv = NULL;
580 return E_NOINTERFACE;
583 IUnknown_AddRef((IUnknown*)*ppv);
584 return S_OK;
587 static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
589 return 2;
592 static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
594 return 1;
597 static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
599 *plcid = GetUserDefaultLCID();
600 return S_OK;
603 static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
604 DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
606 ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
607 ok(!ppti, "ppti != NULL\n");
608 ok(!strcmp_wa(pstrName, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
610 *ppiunkItem = (IUnknown*)&globalObj;
611 return S_OK;
614 static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
616 return E_NOTIMPL;
619 static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
620 const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
622 return E_NOTIMPL;
625 static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
627 return E_NOTIMPL;
630 static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
632 return E_NOTIMPL;
635 static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
637 return E_NOTIMPL;
640 static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
642 return E_NOTIMPL;
645 #undef ACTSCPSITE_THIS
647 static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
648 ActiveScriptSite_QueryInterface,
649 ActiveScriptSite_AddRef,
650 ActiveScriptSite_Release,
651 ActiveScriptSite_GetLCID,
652 ActiveScriptSite_GetItemInfo,
653 ActiveScriptSite_GetDocVersionString,
654 ActiveScriptSite_OnScriptTerminate,
655 ActiveScriptSite_OnStateChange,
656 ActiveScriptSite_OnScriptError,
657 ActiveScriptSite_OnEnterScript,
658 ActiveScriptSite_OnLeaveScript
661 static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
663 static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
665 IObjectSafety *safety;
666 DWORD supported, enabled, options_all, options_set;
667 HRESULT hres;
669 hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
670 ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
671 if(FAILED(hres))
672 return;
674 options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
675 if(use_sec_mgr)
676 options_set = options_all;
677 else
678 options_set = INTERFACE_USES_DISPEX;
680 hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
681 ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
683 supported = enabled = 0xdeadbeef;
684 hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
685 ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
686 ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
687 ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
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(BOOL skip_tests, BOOL use_sec_mgr)
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;
719 AllowIServiceProvider = TRUE;
721 hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
722 &IID_IActiveScript, (void**)&script);
723 if(!skip_tests)
724 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
725 if(FAILED(hres))
726 return NULL;
728 if(!skip_tests)
729 set_safety_options((IUnknown*)script, use_sec_mgr);
731 hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
732 ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
734 hres = IActiveScriptParse64_InitNew(parser);
735 ok(hres == S_OK, "InitNew failed: %08x\n", hres);
737 hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
738 ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
740 hres = IActiveScript_AddNamedItem(script, testW,
741 SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
742 ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
744 hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
745 ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
747 IActiveScript_Release(script);
749 if(!skip_tests) {
750 parse_script_a(parser,
751 "function testException(func, type, number) {\n"
752 " try {\n"
753 " func();\n"
754 " }catch(e) {\n"
755 " ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n"
756 " ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n"
757 " return;\n"
758 " }\n"
759 " ok(false, 'exception expected');\n"
760 "}");
763 return parser;
766 static IDispatchEx *parse_procedure_a(IActiveScriptParse *parser, const char *src)
768 IActiveScriptParseProcedure2 *parse_proc;
769 IDispatchEx *dispex;
770 IDispatch *disp;
771 BSTR str;
772 HRESULT hres;
774 hres = IUnknown_QueryInterface(parser, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
775 ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2: %08x\n", hres);
777 str = a2bstr(src);
778 hres = IActiveScriptParseProcedure2_64_ParseProcedureText(parse_proc, str, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, &disp);
779 SysFreeString(str);
780 IUnknown_Release(parse_proc);
781 ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
782 ok(disp != NULL, "disp == NULL\n");
784 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
785 IDispatch_Release(dispex);
786 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
788 return dispex;
791 #define call_procedure(p,c) _call_procedure(__LINE__,p,c)
792 static void _call_procedure(unsigned line, IDispatchEx *proc, IServiceProvider *caller)
794 DISPPARAMS dp = {NULL,NULL,0,0};
795 EXCEPINFO ei = {0};
796 HRESULT hres;
798 hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, NULL, &ei, caller);
799 ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
803 static void test_ActiveXObject(void)
805 IActiveScriptParse *parser;
806 IDispatchEx *proc;
808 parser = create_script(FALSE, TRUE);
810 SET_EXPECT(Host_QS_SecMgr);
811 SET_EXPECT(ProcessUrlAction);
812 SET_EXPECT(CreateInstance);
813 SET_EXPECT(QueryCustomPolicy);
814 SET_EXPECT(QI_IObjectWithSite);
815 SET_EXPECT(reportSuccess);
816 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
817 CHECK_CALLED(Host_QS_SecMgr);
818 CHECK_CALLED(ProcessUrlAction);
819 CHECK_CALLED(CreateInstance);
820 CHECK_CALLED(QueryCustomPolicy);
821 CHECK_CALLED(QI_IObjectWithSite);
822 CHECK_CALLED(reportSuccess);
824 proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
826 SET_EXPECT(ProcessUrlAction);
827 SET_EXPECT(CreateInstance);
828 SET_EXPECT(QueryCustomPolicy);
829 SET_EXPECT(QI_IObjectWithSite);
830 SET_EXPECT(reportSuccess);
831 call_procedure(proc, NULL);
832 CHECK_CALLED(ProcessUrlAction);
833 CHECK_CALLED(CreateInstance);
834 CHECK_CALLED(QueryCustomPolicy);
835 CHECK_CALLED(QI_IObjectWithSite);
836 CHECK_CALLED(reportSuccess);
838 SET_EXPECT(ProcessUrlAction);
839 SET_EXPECT(CreateInstance);
840 SET_EXPECT(QueryCustomPolicy);
841 SET_EXPECT(QI_IObjectWithSite);
842 SET_EXPECT(reportSuccess);
843 call_procedure(proc, &caller_sp);
844 CHECK_CALLED(ProcessUrlAction);
845 CHECK_CALLED(CreateInstance);
846 CHECK_CALLED(QueryCustomPolicy);
847 CHECK_CALLED(QI_IObjectWithSite);
848 CHECK_CALLED(reportSuccess);
850 IDispatchEx_Release(proc);
851 IUnknown_Release(parser);
853 parser = create_script(FALSE, TRUE);
854 proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
856 SET_EXPECT(Host_QS_SecMgr);
857 SET_EXPECT(ProcessUrlAction);
858 SET_EXPECT(CreateInstance);
859 SET_EXPECT(QueryCustomPolicy);
860 SET_EXPECT(QI_IObjectWithSite);
861 SET_EXPECT(reportSuccess);
862 call_procedure(proc, &caller_sp);
863 CHECK_CALLED(Host_QS_SecMgr);
864 CHECK_CALLED(ProcessUrlAction);
865 CHECK_CALLED(CreateInstance);
866 CHECK_CALLED(QueryCustomPolicy);
867 CHECK_CALLED(QI_IObjectWithSite);
868 CHECK_CALLED(reportSuccess);
870 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);");
872 IDispatchEx_Release(proc);
873 IUnknown_Release(parser);
875 parser = create_script(FALSE, TRUE);
876 QS_SecMgr_hres = E_NOINTERFACE;
878 SET_EXPECT(Host_QS_SecMgr);
879 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
880 CHECK_CALLED(Host_QS_SecMgr);
882 IUnknown_Release(parser);
884 parser = create_script(FALSE, TRUE);
885 ProcessUrlAction_hres = E_FAIL;
887 SET_EXPECT(Host_QS_SecMgr);
888 SET_EXPECT(ProcessUrlAction);
889 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
890 CHECK_CALLED(Host_QS_SecMgr);
891 CHECK_CALLED(ProcessUrlAction);
893 IUnknown_Release(parser);
895 parser = create_script(FALSE, TRUE);
896 ProcessUrlAction_policy = URLPOLICY_DISALLOW;
898 SET_EXPECT(Host_QS_SecMgr);
899 SET_EXPECT(ProcessUrlAction);
900 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
901 CHECK_CALLED(Host_QS_SecMgr);
902 CHECK_CALLED(ProcessUrlAction);
904 IUnknown_Release(parser);
906 parser = create_script(FALSE, TRUE);
907 CreateInstance_hres = E_FAIL;
909 SET_EXPECT(Host_QS_SecMgr);
910 SET_EXPECT(ProcessUrlAction);
911 SET_EXPECT(CreateInstance);
912 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
913 CHECK_CALLED(Host_QS_SecMgr);
914 CHECK_CALLED(ProcessUrlAction);
915 CHECK_CALLED(CreateInstance);
917 IUnknown_Release(parser);
919 parser = create_script(FALSE, TRUE);
920 QueryCustomPolicy_hres = E_FAIL;
922 SET_EXPECT(Host_QS_SecMgr);
923 SET_EXPECT(ProcessUrlAction);
924 SET_EXPECT(CreateInstance);
925 SET_EXPECT(QueryCustomPolicy);
926 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
927 CHECK_CALLED(Host_QS_SecMgr);
928 CHECK_CALLED(ProcessUrlAction);
929 CHECK_CALLED(CreateInstance);
930 CHECK_CALLED(QueryCustomPolicy);
932 IUnknown_Release(parser);
934 parser = create_script(FALSE, TRUE);
935 QueryCustomPolicy_psize = 6;
937 SET_EXPECT(Host_QS_SecMgr);
938 SET_EXPECT(ProcessUrlAction);
939 SET_EXPECT(CreateInstance);
940 SET_EXPECT(QueryCustomPolicy);
941 SET_EXPECT(QI_IObjectWithSite);
942 SET_EXPECT(reportSuccess);
943 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
944 CHECK_CALLED(Host_QS_SecMgr);
945 CHECK_CALLED(ProcessUrlAction);
946 CHECK_CALLED(CreateInstance);
947 CHECK_CALLED(QueryCustomPolicy);
948 CHECK_CALLED(QI_IObjectWithSite);
949 CHECK_CALLED(reportSuccess);
951 IUnknown_Release(parser);
953 parser = create_script(FALSE, TRUE);
954 QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
956 SET_EXPECT(Host_QS_SecMgr);
957 SET_EXPECT(ProcessUrlAction);
958 SET_EXPECT(CreateInstance);
959 SET_EXPECT(QueryCustomPolicy);
960 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
961 CHECK_CALLED(Host_QS_SecMgr);
962 CHECK_CALLED(ProcessUrlAction);
963 CHECK_CALLED(CreateInstance);
964 CHECK_CALLED(QueryCustomPolicy);
966 QueryCustomPolicy_psize = 6;
968 SET_EXPECT(ProcessUrlAction);
969 SET_EXPECT(CreateInstance);
970 SET_EXPECT(QueryCustomPolicy);
971 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
972 CHECK_CALLED(ProcessUrlAction);
973 CHECK_CALLED(CreateInstance);
974 CHECK_CALLED(QueryCustomPolicy);
976 QueryCustomPolicy_policy = URLPOLICY_ALLOW;
977 QueryCustomPolicy_psize = 3;
979 SET_EXPECT(ProcessUrlAction);
980 SET_EXPECT(CreateInstance);
981 SET_EXPECT(QueryCustomPolicy);
982 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
983 CHECK_CALLED(ProcessUrlAction);
984 CHECK_CALLED(CreateInstance);
985 CHECK_CALLED(QueryCustomPolicy);
987 IUnknown_Release(parser);
989 parser = create_script(FALSE, FALSE);
991 SET_EXPECT(CreateInstance);
992 SET_EXPECT(QI_IObjectWithSite);
993 SET_EXPECT(reportSuccess);
994 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
995 CHECK_CALLED(CreateInstance);
996 CHECK_CALLED(QI_IObjectWithSite);
997 CHECK_CALLED(reportSuccess);
999 IUnknown_Release(parser);
1001 parser = create_script(FALSE, TRUE);
1002 object_with_site = &ObjectWithSite;
1004 SET_EXPECT(Host_QS_SecMgr);
1005 SET_EXPECT(ProcessUrlAction);
1006 SET_EXPECT(CreateInstance);
1007 SET_EXPECT(QueryCustomPolicy);
1008 SET_EXPECT(QI_IObjectWithSite);
1009 SET_EXPECT(SetSite);
1010 SET_EXPECT(reportSuccess);
1011 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1012 CHECK_CALLED(Host_QS_SecMgr);
1013 CHECK_CALLED(ProcessUrlAction);
1014 CHECK_CALLED(CreateInstance);
1015 CHECK_CALLED(QueryCustomPolicy);
1016 CHECK_CALLED(QI_IObjectWithSite);
1017 CHECK_CALLED(SetSite);
1018 CHECK_CALLED(reportSuccess);
1020 SetSite_hres = E_FAIL;
1021 SET_EXPECT(ProcessUrlAction);
1022 SET_EXPECT(CreateInstance);
1023 SET_EXPECT(QueryCustomPolicy);
1024 SET_EXPECT(QI_IObjectWithSite);
1025 SET_EXPECT(SetSite);
1026 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1027 CHECK_CALLED(ProcessUrlAction);
1028 CHECK_CALLED(CreateInstance);
1029 CHECK_CALLED(QueryCustomPolicy);
1030 CHECK_CALLED(QI_IObjectWithSite);
1031 CHECK_CALLED(SetSite);
1033 IUnknown_Release(parser);
1035 /* No IServiceProvider Interface */
1036 parser = create_script(FALSE, FALSE);
1037 object_with_site = &ObjectWithSite;
1038 AllowIServiceProvider = FALSE;
1040 SET_EXPECT(CreateInstance);
1041 SET_EXPECT(QI_IObjectWithSite);
1042 SET_EXPECT(reportSuccess);
1043 SET_EXPECT(SetSite);
1044 parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1045 CHECK_CALLED(CreateInstance);
1046 CHECK_CALLED(QI_IObjectWithSite);
1047 CHECK_CALLED(reportSuccess);
1048 CHECK_CALLED(SetSite);
1050 IUnknown_Release(parser);
1052 parser = create_script(FALSE, TRUE);
1053 object_with_site = &ObjectWithSite;
1054 AllowIServiceProvider = FALSE;
1056 parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1058 IUnknown_Release(parser);
1061 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1063 HKEY hkey;
1064 DWORD res;
1066 if(!init) {
1067 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1068 return TRUE;
1071 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1072 if(res != ERROR_SUCCESS)
1073 return FALSE;
1075 if(def_value)
1076 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1078 RegCloseKey(hkey);
1080 return res == ERROR_SUCCESS;
1083 static BOOL init_registry(BOOL init)
1085 return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1088 static BOOL register_activex(void)
1090 DWORD regid;
1091 HRESULT hres;
1093 if(!init_registry(TRUE)) {
1094 init_registry(FALSE);
1095 return FALSE;
1098 hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1099 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1100 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1102 return TRUE;
1105 static BOOL check_jscript(void)
1107 IActiveScriptProperty *script_prop;
1108 IActiveScriptParse *parser;
1109 BSTR str;
1110 HRESULT hres;
1112 parser = create_script(TRUE, TRUE);
1113 if(!parser)
1114 return FALSE;
1116 str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1117 hres = IActiveScriptParse64_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1118 SysFreeString(str);
1120 if(hres == S_OK)
1121 hres = IUnknown_QueryInterface(parser, &IID_IActiveScriptProperty, (void**)&script_prop);
1122 IUnknown_Release(parser);
1123 if(hres == S_OK)
1124 IActiveScriptProperty_Release(script_prop);
1126 return hres == S_OK;
1129 START_TEST(activex)
1131 CoInitialize(NULL);
1133 if(check_jscript()) {
1134 register_activex();
1136 test_ActiveXObject();
1138 init_registry(FALSE);
1139 }else {
1140 win_skip("Broken engine, probably too old\n");
1143 CoUninitialize();