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 CHECK_EXPECT2(func) \
44 ok(expect_ ##func, "unexpected call " #func "\n"); \
45 called_ ## func = TRUE; \
48 #define CHECK_EXPECT(func) \
50 CHECK_EXPECT2(func); \
51 expect_ ## func = FALSE; \
54 #define CHECK_CALLED(func) \
56 ok(called_ ## func, "expected " #func "\n"); \
57 expect_ ## func = called_ ## func = FALSE; \
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
)
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]);
107 static BSTR
a2bstr(const char *str
)
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
);
119 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
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");
132 static ULONG WINAPI
ObjectWithSite_AddRef(IObjectWithSite
*iface
)
137 static ULONG WINAPI
ObjectWithSite_Release(IObjectWithSite
*iface
)
142 static HRESULT WINAPI
ObjectWithSite_SetSite(IObjectWithSite
*iface
, IUnknown
*pUnkSite
)
144 IServiceProvider
*sp
;
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
);
158 static HRESULT WINAPI
ObjectWithSite_GetSite(IObjectWithSite
*iface
, REFIID riid
, void **ppvSite
)
160 ok(0, "unexpected call\n");
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
)
180 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
182 }else if(IsEqualGUID(riid
, &IID_IDispatch
) || IsEqualGUID(riid
, &IID_IDispatchEx
)) {
183 if(FAILED(QI_IDispatch_hres
))
184 return QI_IDispatch_hres
;
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
)
201 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
206 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
208 ok(0, "unexpected call\n");
212 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
213 LCID lcid
, ITypeInfo
**ppTInfo
)
215 ok(0, "unexpected call\n");
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");
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");
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
);
241 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
243 ok(0, "unexpected call\n");
247 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
249 ok(0, "unexpected call\n");
253 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
255 ok(0, "unexpected call\n");
259 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
261 ok(0, "unexpected call\n");
265 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
267 ok(0, "unexpected call\n");
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
;
279 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName
));
283 static HRESULT WINAPI
Test_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
284 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
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");
300 ok(0, "unexpected call\n");
307 static IDispatchExVtbl testObjVtbl
= {
308 DispatchEx_QueryInterface
,
311 DispatchEx_GetTypeInfoCount
,
312 DispatchEx_GetTypeInfo
,
313 DispatchEx_GetIDsOfNames
,
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
;
335 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName
));
339 static HRESULT WINAPI
Global_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
340 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
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
)));
358 ok(0, "unexpected call\n");
365 static IDispatchExVtbl globalObjVtbl
= {
366 DispatchEx_QueryInterface
,
369 DispatchEx_GetTypeInfoCount
,
370 DispatchEx_GetTypeInfo
,
371 DispatchEx_GetIDsOfNames
,
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
)) {
392 /* TODO: IClassFactoryEx */
394 return E_NOINTERFACE
;
397 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
402 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
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
))
416 return CreateInstance_hres
;
419 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
421 ok(0, "unexpected call\n");
425 static const IClassFactoryVtbl ClassFactoryVtbl
= {
426 ClassFactory_QueryInterface
,
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
)
446 static ULONG WINAPI
InternetHostSecurityManager_Release(IInternetHostSecurityManager
*iface
)
451 static HRESULT WINAPI
InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager
*iface
, BYTE
*pbSecurityId
,
452 DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
454 ok(0, "unexpected call\n");
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
;
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
);
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
)
534 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
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
);
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
)) {
574 }else if(IsEqualGUID(&IID_IActiveScriptSite
, riid
)) {
576 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
) && AllowIServiceProvider
) {
577 *ppv
= &ServiceProvider
;
580 return E_NOINTERFACE
;
583 IUnknown_AddRef((IUnknown
*)*ppv
);
587 static ULONG WINAPI
ActiveScriptSite_AddRef(IActiveScriptSite
*iface
)
592 static ULONG WINAPI
ActiveScriptSite_Release(IActiveScriptSite
*iface
)
597 static HRESULT WINAPI
ActiveScriptSite_GetLCID(IActiveScriptSite
*iface
, LCID
*plcid
)
599 *plcid
= GetUserDefaultLCID();
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
;
614 static HRESULT WINAPI
ActiveScriptSite_GetDocVersionString(IActiveScriptSite
*iface
, BSTR
*pbstrVersion
)
619 static HRESULT WINAPI
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite
*iface
,
620 const VARIANT
*pvarResult
, const EXCEPINFO
*pexcepinfo
)
625 static HRESULT WINAPI
ActiveScriptSite_OnStateChange(IActiveScriptSite
*iface
, SCRIPTSTATE ssScriptState
)
630 static HRESULT WINAPI
ActiveScriptSite_OnScriptError(IActiveScriptSite
*iface
, IActiveScriptError
*pscripterror
)
635 static HRESULT WINAPI
ActiveScriptSite_OnEnterScript(IActiveScriptSite
*iface
)
640 static HRESULT WINAPI
ActiveScriptSite_OnLeaveScript(IActiveScriptSite
*iface
)
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
;
669 hres
= IUnknown_QueryInterface(unk
, &IID_IObjectSafety
, (void**)&safety
);
670 ok(hres
== S_OK
, "Could not get IObjectSafety: %08x\n", hres
);
674 options_all
= INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
;
676 options_set
= options_all
;
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
)
698 str
= a2bstr(script
);
699 hres
= IActiveScriptParse64_ParseScriptText(parser
, str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
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
;
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
;
719 AllowIServiceProvider
= TRUE
;
721 hres
= CoCreateInstance(&CLSID_JScript
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
722 &IID_IActiveScript
, (void**)&script
);
724 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
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
);
750 parse_script_a(parser
,
751 "function testException(func, type, number) {\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"
759 " ok(false, 'exception expected');\n"
766 static IDispatchEx
*parse_procedure_a(IActiveScriptParse
*parser
, const char *src
)
768 IActiveScriptParseProcedure2
*parse_proc
;
774 hres
= IUnknown_QueryInterface(parser
, &IID_IActiveScriptParseProcedure2
, (void**)&parse_proc
);
775 ok(hres
== S_OK
, "Could not get IActiveScriptParseProcedure2: %08x\n", hres
);
778 hres
= IActiveScriptParseProcedure2_64_ParseProcedureText(parse_proc
, str
, NULL
, NULL
, NULL
, NULL
, NULL
, 0, 0, 0, &disp
);
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
);
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};
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
;
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
)
1067 RegDeleteKey(HKEY_CLASSES_ROOT
, key_name
);
1071 res
= RegCreateKeyA(HKEY_CLASSES_ROOT
, key_name
, &hkey
);
1072 if(res
!= ERROR_SUCCESS
)
1076 res
= RegSetValueA(hkey
, NULL
, REG_SZ
, def_value
, strlen(def_value
));
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)
1093 if(!init_registry(TRUE
)) {
1094 init_registry(FALSE
);
1098 hres
= CoRegisterClassObject(&CLSID_TestObj
, (IUnknown
*)&activex_cf
,
1099 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
1100 ok(hres
== S_OK
, "Could not register script engine: %08x\n", hres
);
1105 static BOOL
check_jscript(void)
1107 IActiveScriptProperty
*script_prop
;
1108 IActiveScriptParse
*parser
;
1112 parser
= create_script(TRUE
, TRUE
);
1116 str
= a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1117 hres
= IActiveScriptParse64_ParseScriptText(parser
, str
, NULL
, NULL
, NULL
, 0, 0, 0, NULL
, NULL
);
1121 hres
= IUnknown_QueryInterface(parser
, &IID_IActiveScriptProperty
, (void**)&script_prop
);
1122 IUnknown_Release(parser
);
1124 IActiveScriptProperty_Release(script_prop
);
1126 return hres
== S_OK
;
1133 if(check_jscript()) {
1136 test_ActiveXObject();
1138 init_registry(FALSE
);
1140 win_skip("Broken engine, probably too old\n");