1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Copyright 2009 Jacek Caban for CodeWeavers
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
5c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
6c2c66affSColin Finck  * License as published by the Free Software Foundation; either
7c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
8c2c66affSColin Finck  *
9c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
10c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12c2c66affSColin Finck  * Lesser General Public License for more details.
13c2c66affSColin Finck  *
14c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
15c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
16c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17c2c66affSColin Finck  */
18c2c66affSColin Finck 
19c2c66affSColin Finck #include <stdio.h>
20c2c66affSColin Finck 
21c2c66affSColin Finck #define COBJMACROS
22c2c66affSColin Finck #define CONST_VTABLE
23c2c66affSColin Finck 
24c2c66affSColin Finck #include <ole2.h>
25c2c66affSColin Finck #include <dispex.h>
26c2c66affSColin Finck #include <activscp.h>
27c2c66affSColin Finck #include <objsafe.h>
28*e68a367aSAmine Khaldi #include <urlmon.h>
29*e68a367aSAmine Khaldi #include <mshtmhst.h>
30c2c66affSColin Finck 
31*e68a367aSAmine Khaldi #include "wine/test.h"
32c2c66affSColin Finck 
33c2c66affSColin Finck #ifdef _WIN64
34c2c66affSColin Finck 
35c2c66affSColin Finck #define IActiveScriptParse_QueryInterface IActiveScriptParse64_QueryInterface
36c2c66affSColin Finck #define IActiveScriptParse_Release IActiveScriptParse64_Release
37c2c66affSColin Finck #define IActiveScriptParse_InitNew IActiveScriptParse64_InitNew
38c2c66affSColin Finck #define IActiveScriptParse_ParseScriptText IActiveScriptParse64_ParseScriptText
39c2c66affSColin Finck #define IActiveScriptParseProcedure2_Release \
40c2c66affSColin Finck     IActiveScriptParseProcedure2_64_Release
41c2c66affSColin Finck #define IActiveScriptParseProcedure2_ParseProcedureText \
42c2c66affSColin Finck     IActiveScriptParseProcedure2_64_ParseProcedureText
43c2c66affSColin Finck 
44c2c66affSColin Finck #else
45c2c66affSColin Finck 
46c2c66affSColin Finck #define IActiveScriptParse_QueryInterface IActiveScriptParse32_QueryInterface
47c2c66affSColin Finck #define IActiveScriptParse_Release IActiveScriptParse32_Release
48c2c66affSColin Finck #define IActiveScriptParse_InitNew IActiveScriptParse32_InitNew
49c2c66affSColin Finck #define IActiveScriptParse_ParseScriptText IActiveScriptParse32_ParseScriptText
50c2c66affSColin Finck #define IActiveScriptParseProcedure2_Release \
51c2c66affSColin Finck     IActiveScriptParseProcedure2_32_Release
52c2c66affSColin Finck #define IActiveScriptParseProcedure2_ParseProcedureText \
53c2c66affSColin Finck     IActiveScriptParseProcedure2_32_ParseProcedureText
54c2c66affSColin Finck 
55c2c66affSColin Finck #endif
56c2c66affSColin Finck 
57c2c66affSColin Finck static const CLSID CLSID_JScript =
58c2c66affSColin Finck     {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
59c2c66affSColin Finck 
60c2c66affSColin Finck #define DEFINE_EXPECT(func) \
61c2c66affSColin Finck     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
62c2c66affSColin Finck 
63c2c66affSColin Finck #define SET_EXPECT(func) \
64c2c66affSColin Finck     expect_ ## func = TRUE
65c2c66affSColin Finck 
66c2c66affSColin Finck #define CHECK_EXPECT2(func) \
67c2c66affSColin Finck     do { \
68c2c66affSColin Finck         ok(expect_ ##func, "unexpected call " #func "\n"); \
69c2c66affSColin Finck         called_ ## func = TRUE; \
70c2c66affSColin Finck     }while(0)
71c2c66affSColin Finck 
72c2c66affSColin Finck #define CHECK_EXPECT(func) \
73c2c66affSColin Finck     do { \
74c2c66affSColin Finck         CHECK_EXPECT2(func); \
75c2c66affSColin Finck         expect_ ## func = FALSE; \
76c2c66affSColin Finck     }while(0)
77c2c66affSColin Finck 
78c2c66affSColin Finck #define CHECK_CALLED(func) \
79c2c66affSColin Finck     do { \
80c2c66affSColin Finck         ok(called_ ## func, "expected " #func "\n"); \
81c2c66affSColin Finck         expect_ ## func = called_ ## func = FALSE; \
82c2c66affSColin Finck     }while(0)
83c2c66affSColin Finck 
84c2c66affSColin Finck DEFINE_EXPECT(CreateInstance);
85c2c66affSColin Finck DEFINE_EXPECT(ProcessUrlAction);
86c2c66affSColin Finck DEFINE_EXPECT(QueryCustomPolicy);
87c2c66affSColin Finck DEFINE_EXPECT(reportSuccess);
88c2c66affSColin Finck DEFINE_EXPECT(Host_QS_SecMgr);
89c2c66affSColin Finck DEFINE_EXPECT(Caller_QS_SecMgr);
90c2c66affSColin Finck DEFINE_EXPECT(QI_IObjectWithSite);
91c2c66affSColin Finck DEFINE_EXPECT(SetSite);
92c2c66affSColin Finck 
93c2c66affSColin Finck static const WCHAR testW[] = {'t','e','s','t',0};
94c2c66affSColin Finck 
95c2c66affSColin Finck static HRESULT QS_SecMgr_hres;
96c2c66affSColin Finck static HRESULT ProcessUrlAction_hres;
97c2c66affSColin Finck static DWORD ProcessUrlAction_policy;
98c2c66affSColin Finck static HRESULT CreateInstance_hres;
99c2c66affSColin Finck static HRESULT QueryCustomPolicy_hres;
100c2c66affSColin Finck static DWORD QueryCustomPolicy_psize;
101c2c66affSColin Finck static DWORD QueryCustomPolicy_policy;
102c2c66affSColin Finck static HRESULT QI_IDispatch_hres;
103c2c66affSColin Finck static HRESULT SetSite_hres;
104c2c66affSColin Finck static BOOL AllowIServiceProvider;
105c2c66affSColin Finck 
106c2c66affSColin Finck #define TESTOBJ_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
107c2c66affSColin Finck 
108c2c66affSColin Finck static const GUID CLSID_TestObj =
109c2c66affSColin Finck     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
110c2c66affSColin Finck 
111c2c66affSColin Finck /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
112c2c66affSColin Finck const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
113c2c66affSColin Finck     {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
114c2c66affSColin Finck 
115c2c66affSColin Finck #define DISPID_TEST_REPORTSUCCESS    0x1000
116c2c66affSColin Finck 
117c2c66affSColin Finck #define DISPID_GLOBAL_OK             0x2000
118c2c66affSColin Finck 
a2bstr(const char * str)119c2c66affSColin Finck static BSTR a2bstr(const char *str)
120c2c66affSColin Finck {
121c2c66affSColin Finck     BSTR ret;
122c2c66affSColin Finck     int len;
123c2c66affSColin Finck 
124c2c66affSColin Finck     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
125c2c66affSColin Finck     ret = SysAllocStringLen(NULL, len-1);
126c2c66affSColin Finck     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
127c2c66affSColin Finck 
128c2c66affSColin Finck     return ret;
129c2c66affSColin Finck }
130c2c66affSColin Finck 
strcmp_wa(LPCWSTR strw,const char * stra)131c2c66affSColin Finck static int strcmp_wa(LPCWSTR strw, const char *stra)
132c2c66affSColin Finck {
133c2c66affSColin Finck     CHAR buf[512];
134c2c66affSColin Finck     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
135c2c66affSColin Finck     return lstrcmpA(buf, stra);
136c2c66affSColin Finck }
137c2c66affSColin Finck 
ObjectWithSite_QueryInterface(IObjectWithSite * iface,REFIID riid,void ** ppv)138c2c66affSColin Finck static HRESULT WINAPI ObjectWithSite_QueryInterface(IObjectWithSite *iface, REFIID riid, void **ppv)
139c2c66affSColin Finck {
140c2c66affSColin Finck     ok(0, "unexpected call\n");
141c2c66affSColin Finck     return E_NOTIMPL;
142c2c66affSColin Finck }
143c2c66affSColin Finck 
ObjectWithSite_AddRef(IObjectWithSite * iface)144c2c66affSColin Finck static ULONG WINAPI ObjectWithSite_AddRef(IObjectWithSite *iface)
145c2c66affSColin Finck {
146c2c66affSColin Finck     return 2;
147c2c66affSColin Finck }
148c2c66affSColin Finck 
ObjectWithSite_Release(IObjectWithSite * iface)149c2c66affSColin Finck static ULONG WINAPI ObjectWithSite_Release(IObjectWithSite *iface)
150c2c66affSColin Finck {
151c2c66affSColin Finck     return 1;
152c2c66affSColin Finck }
153c2c66affSColin Finck 
ObjectWithSite_SetSite(IObjectWithSite * iface,IUnknown * pUnkSite)154c2c66affSColin Finck static HRESULT WINAPI ObjectWithSite_SetSite(IObjectWithSite *iface, IUnknown *pUnkSite)
155c2c66affSColin Finck {
156c2c66affSColin Finck     IServiceProvider *sp;
157c2c66affSColin Finck     HRESULT hres;
158c2c66affSColin Finck 
159c2c66affSColin Finck 
160c2c66affSColin Finck     CHECK_EXPECT(SetSite);
161c2c66affSColin Finck     ok(pUnkSite != NULL, "pUnkSite == NULL\n");
162c2c66affSColin Finck 
163c2c66affSColin Finck     hres = IUnknown_QueryInterface(pUnkSite, &IID_IServiceProvider, (void**)&sp);
164c2c66affSColin Finck     ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
165c2c66affSColin Finck     IServiceProvider_Release(sp);
166c2c66affSColin Finck 
167c2c66affSColin Finck     return SetSite_hres;
168c2c66affSColin Finck }
169c2c66affSColin Finck 
ObjectWithSite_GetSite(IObjectWithSite * iface,REFIID riid,void ** ppvSite)170c2c66affSColin Finck static HRESULT WINAPI ObjectWithSite_GetSite(IObjectWithSite *iface, REFIID riid, void **ppvSite)
171c2c66affSColin Finck {
172c2c66affSColin Finck     ok(0, "unexpected call\n");
173c2c66affSColin Finck     return E_NOTIMPL;
174c2c66affSColin Finck }
175c2c66affSColin Finck 
176c2c66affSColin Finck static const IObjectWithSiteVtbl ObjectWithSiteVtbl = {
177c2c66affSColin Finck     ObjectWithSite_QueryInterface,
178c2c66affSColin Finck     ObjectWithSite_AddRef,
179c2c66affSColin Finck     ObjectWithSite_Release,
180c2c66affSColin Finck     ObjectWithSite_SetSite,
181c2c66affSColin Finck     ObjectWithSite_GetSite
182c2c66affSColin Finck };
183c2c66affSColin Finck 
184c2c66affSColin Finck static IObjectWithSite ObjectWithSite = { &ObjectWithSiteVtbl };
185c2c66affSColin Finck 
186c2c66affSColin Finck static IObjectWithSite *object_with_site;
187c2c66affSColin Finck 
DispatchEx_QueryInterface(IDispatchEx * iface,REFIID riid,void ** ppv)188c2c66affSColin Finck static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
189c2c66affSColin Finck {
190c2c66affSColin Finck     *ppv = NULL;
191c2c66affSColin Finck 
192c2c66affSColin Finck     if(IsEqualGUID(riid, &IID_IUnknown)) {
193c2c66affSColin Finck        *ppv = iface;
194c2c66affSColin Finck     }else if(IsEqualGUID(riid, &IID_IDispatch) || IsEqualGUID(riid, &IID_IDispatchEx)) {
195c2c66affSColin Finck         if(FAILED(QI_IDispatch_hres))
196c2c66affSColin Finck             return QI_IDispatch_hres;
197c2c66affSColin Finck         *ppv = iface;
198c2c66affSColin Finck     }else if(IsEqualGUID(&IID_IObjectWithSite, riid)) {
199c2c66affSColin Finck         CHECK_EXPECT(QI_IObjectWithSite);
200c2c66affSColin Finck         *ppv = object_with_site;
201c2c66affSColin Finck     }else if(IsEqualGUID(&IID_IObjectSafety, riid)) {
202c2c66affSColin Finck         ok(0, "Unexpected IID_IObjectSafety query\n");
203c2c66affSColin Finck     }
204c2c66affSColin Finck 
205c2c66affSColin Finck     return *ppv ? S_OK : E_NOINTERFACE;
206c2c66affSColin Finck }
207c2c66affSColin Finck 
DispatchEx_AddRef(IDispatchEx * iface)208c2c66affSColin Finck static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
209c2c66affSColin Finck {
210c2c66affSColin Finck     return 2;
211c2c66affSColin Finck }
212c2c66affSColin Finck 
DispatchEx_Release(IDispatchEx * iface)213c2c66affSColin Finck static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
214c2c66affSColin Finck {
215c2c66affSColin Finck     return 1;
216c2c66affSColin Finck }
217c2c66affSColin Finck 
DispatchEx_GetTypeInfoCount(IDispatchEx * iface,UINT * pctinfo)218c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
219c2c66affSColin Finck {
220c2c66affSColin Finck     ok(0, "unexpected call\n");
221c2c66affSColin Finck     return E_NOTIMPL;
222c2c66affSColin Finck }
223c2c66affSColin Finck 
DispatchEx_GetTypeInfo(IDispatchEx * iface,UINT iTInfo,LCID lcid,ITypeInfo ** ppTInfo)224c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
225c2c66affSColin Finck                                               LCID lcid, ITypeInfo **ppTInfo)
226c2c66affSColin Finck {
227c2c66affSColin Finck     ok(0, "unexpected call\n");
228c2c66affSColin Finck     return E_NOTIMPL;
229c2c66affSColin Finck }
230c2c66affSColin Finck 
DispatchEx_GetIDsOfNames(IDispatchEx * iface,REFIID riid,LPOLESTR * rgszNames,UINT cNames,LCID lcid,DISPID * rgDispId)231c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
232c2c66affSColin Finck                                                 LPOLESTR *rgszNames, UINT cNames,
233c2c66affSColin Finck                                                 LCID lcid, DISPID *rgDispId)
234c2c66affSColin Finck {
235c2c66affSColin Finck     ok(0, "unexpected call\n");
236c2c66affSColin Finck     return E_NOTIMPL;
237c2c66affSColin Finck }
238c2c66affSColin Finck 
DispatchEx_Invoke(IDispatchEx * iface,DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS * pDispParams,VARIANT * pVarResult,EXCEPINFO * pExcepInfo,UINT * puArgErr)239c2c66affSColin Finck static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
240c2c66affSColin Finck                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
241c2c66affSColin Finck                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
242c2c66affSColin Finck {
243c2c66affSColin Finck     ok(0, "unexpected call\n");
244c2c66affSColin Finck     return E_NOTIMPL;
245c2c66affSColin Finck }
246c2c66affSColin Finck 
DispatchEx_DeleteMemberByName(IDispatchEx * iface,BSTR bstrName,DWORD grfdex)247c2c66affSColin Finck static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
248c2c66affSColin Finck {
249c2c66affSColin Finck     ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
250c2c66affSColin Finck     return E_NOTIMPL;
251c2c66affSColin Finck }
252c2c66affSColin Finck 
DispatchEx_DeleteMemberByDispID(IDispatchEx * iface,DISPID id)253c2c66affSColin Finck static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
254c2c66affSColin Finck {
255c2c66affSColin Finck     ok(0, "unexpected call\n");
256c2c66affSColin Finck     return E_NOTIMPL;
257c2c66affSColin Finck }
258c2c66affSColin Finck 
DispatchEx_GetMemberProperties(IDispatchEx * iface,DISPID id,DWORD grfdexFetch,DWORD * pgrfdex)259c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
260c2c66affSColin Finck {
261c2c66affSColin Finck     ok(0, "unexpected call\n");
262c2c66affSColin Finck     return E_NOTIMPL;
263c2c66affSColin Finck }
264c2c66affSColin Finck 
DispatchEx_GetMemberName(IDispatchEx * iface,DISPID id,BSTR * pbstrName)265c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
266c2c66affSColin Finck {
267c2c66affSColin Finck     ok(0, "unexpected call\n");
268c2c66affSColin Finck     return E_NOTIMPL;
269c2c66affSColin Finck }
270c2c66affSColin Finck 
DispatchEx_GetNextDispID(IDispatchEx * iface,DWORD grfdex,DISPID id,DISPID * pid)271c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
272c2c66affSColin Finck {
273c2c66affSColin Finck     ok(0, "unexpected call\n");
274c2c66affSColin Finck     return E_NOTIMPL;
275c2c66affSColin Finck }
276c2c66affSColin Finck 
DispatchEx_GetNameSpaceParent(IDispatchEx * iface,IUnknown ** ppunk)277c2c66affSColin Finck static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
278c2c66affSColin Finck {
279c2c66affSColin Finck     ok(0, "unexpected call\n");
280c2c66affSColin Finck     return E_NOTIMPL;
281c2c66affSColin Finck }
282c2c66affSColin Finck 
Test_GetDispID(IDispatchEx * iface,BSTR bstrName,DWORD grfdex,DISPID * pid)283c2c66affSColin Finck static HRESULT WINAPI Test_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
284c2c66affSColin Finck {
285c2c66affSColin Finck     if(!strcmp_wa(bstrName, "reportSuccess")) {
286c2c66affSColin Finck         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
287c2c66affSColin Finck         *pid = DISPID_TEST_REPORTSUCCESS;
288c2c66affSColin Finck         return S_OK;
289c2c66affSColin Finck     }
290c2c66affSColin Finck 
291c2c66affSColin Finck     ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
292c2c66affSColin Finck     return E_NOTIMPL;
293c2c66affSColin Finck }
294c2c66affSColin Finck 
Test_InvokeEx(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)295c2c66affSColin Finck static HRESULT WINAPI Test_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
296c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
297c2c66affSColin Finck {
298c2c66affSColin Finck     switch(id) {
299c2c66affSColin Finck     case DISPID_TEST_REPORTSUCCESS:
300c2c66affSColin Finck         CHECK_EXPECT(reportSuccess);
301c2c66affSColin Finck 
302c2c66affSColin Finck         ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
303c2c66affSColin Finck         ok(pdp != NULL, "pdp == NULL\n");
304c2c66affSColin Finck         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
305c2c66affSColin Finck         ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
306c2c66affSColin Finck         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
307c2c66affSColin Finck         ok(!pvarRes, "pvarRes != NULL\n");
308c2c66affSColin Finck         ok(pei != NULL, "pei == NULL\n");
309c2c66affSColin Finck         break;
310c2c66affSColin Finck 
311c2c66affSColin Finck     default:
312c2c66affSColin Finck         ok(0, "unexpected call\n");
313c2c66affSColin Finck         return E_NOTIMPL;
314c2c66affSColin Finck     }
315c2c66affSColin Finck 
316c2c66affSColin Finck     return S_OK;
317c2c66affSColin Finck }
318c2c66affSColin Finck 
319c2c66affSColin Finck static IDispatchExVtbl testObjVtbl = {
320c2c66affSColin Finck     DispatchEx_QueryInterface,
321c2c66affSColin Finck     DispatchEx_AddRef,
322c2c66affSColin Finck     DispatchEx_Release,
323c2c66affSColin Finck     DispatchEx_GetTypeInfoCount,
324c2c66affSColin Finck     DispatchEx_GetTypeInfo,
325c2c66affSColin Finck     DispatchEx_GetIDsOfNames,
326c2c66affSColin Finck     DispatchEx_Invoke,
327c2c66affSColin Finck     Test_GetDispID,
328c2c66affSColin Finck     Test_InvokeEx,
329c2c66affSColin Finck     DispatchEx_DeleteMemberByName,
330c2c66affSColin Finck     DispatchEx_DeleteMemberByDispID,
331c2c66affSColin Finck     DispatchEx_GetMemberProperties,
332c2c66affSColin Finck     DispatchEx_GetMemberName,
333c2c66affSColin Finck     DispatchEx_GetNextDispID,
334c2c66affSColin Finck     DispatchEx_GetNameSpaceParent
335c2c66affSColin Finck };
336c2c66affSColin Finck 
337c2c66affSColin Finck static IDispatchEx testObj = { &testObjVtbl };
338c2c66affSColin Finck 
Global_GetDispID(IDispatchEx * iface,BSTR bstrName,DWORD grfdex,DISPID * pid)339c2c66affSColin Finck static HRESULT WINAPI Global_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
340c2c66affSColin Finck {
341c2c66affSColin Finck     if(!strcmp_wa(bstrName, "ok")) {
342c2c66affSColin Finck         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
343c2c66affSColin Finck         *pid = DISPID_GLOBAL_OK;
344c2c66affSColin Finck         return S_OK;
345c2c66affSColin Finck     }
346c2c66affSColin Finck 
347c2c66affSColin Finck     ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
348c2c66affSColin Finck     return E_NOTIMPL;
349c2c66affSColin Finck }
350c2c66affSColin Finck 
Global_InvokeEx(IDispatchEx * iface,DISPID id,LCID lcid,WORD wFlags,DISPPARAMS * pdp,VARIANT * pvarRes,EXCEPINFO * pei,IServiceProvider * pspCaller)351c2c66affSColin Finck static HRESULT WINAPI Global_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
352c2c66affSColin Finck         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
353c2c66affSColin Finck {
354c2c66affSColin Finck     switch(id) {
355c2c66affSColin Finck     case DISPID_GLOBAL_OK:
356c2c66affSColin Finck         ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
357c2c66affSColin Finck         ok(pdp != NULL, "pdp == NULL\n");
358c2c66affSColin Finck         ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
359c2c66affSColin Finck         ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
360c2c66affSColin Finck         ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
361c2c66affSColin Finck         ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
362c2c66affSColin Finck         ok(pei != NULL, "pei == NULL\n");
363c2c66affSColin Finck 
364c2c66affSColin Finck         ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
365c2c66affSColin Finck         ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
366c2c66affSColin Finck         ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
367c2c66affSColin Finck         break;
368c2c66affSColin Finck 
369c2c66affSColin Finck     default:
370c2c66affSColin Finck         ok(0, "unexpected call\n");
371c2c66affSColin Finck         return E_NOTIMPL;
372c2c66affSColin Finck     }
373c2c66affSColin Finck 
374c2c66affSColin Finck     return S_OK;
375c2c66affSColin Finck }
376c2c66affSColin Finck 
377c2c66affSColin Finck static IDispatchExVtbl globalObjVtbl = {
378c2c66affSColin Finck     DispatchEx_QueryInterface,
379c2c66affSColin Finck     DispatchEx_AddRef,
380c2c66affSColin Finck     DispatchEx_Release,
381c2c66affSColin Finck     DispatchEx_GetTypeInfoCount,
382c2c66affSColin Finck     DispatchEx_GetTypeInfo,
383c2c66affSColin Finck     DispatchEx_GetIDsOfNames,
384c2c66affSColin Finck     DispatchEx_Invoke,
385c2c66affSColin Finck     Global_GetDispID,
386c2c66affSColin Finck     Global_InvokeEx,
387c2c66affSColin Finck     DispatchEx_DeleteMemberByName,
388c2c66affSColin Finck     DispatchEx_DeleteMemberByDispID,
389c2c66affSColin Finck     DispatchEx_GetMemberProperties,
390c2c66affSColin Finck     DispatchEx_GetMemberName,
391c2c66affSColin Finck     DispatchEx_GetNextDispID,
392c2c66affSColin Finck     DispatchEx_GetNameSpaceParent
393c2c66affSColin Finck };
394c2c66affSColin Finck 
395c2c66affSColin Finck static IDispatchEx globalObj = { &globalObjVtbl };
396c2c66affSColin Finck 
ClassFactory_QueryInterface(IClassFactory * iface,REFIID riid,void ** ppv)397c2c66affSColin Finck static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
398c2c66affSColin Finck {
399c2c66affSColin Finck     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
400c2c66affSColin Finck         *ppv = iface;
401c2c66affSColin Finck         return S_OK;
402c2c66affSColin Finck     }
403c2c66affSColin Finck 
404c2c66affSColin Finck     /* TODO: IClassFactoryEx */
405c2c66affSColin Finck     *ppv = NULL;
406c2c66affSColin Finck     return E_NOINTERFACE;
407c2c66affSColin Finck }
408c2c66affSColin Finck 
ClassFactory_AddRef(IClassFactory * iface)409c2c66affSColin Finck static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
410c2c66affSColin Finck {
411c2c66affSColin Finck     return 2;
412c2c66affSColin Finck }
413c2c66affSColin Finck 
ClassFactory_Release(IClassFactory * iface)414c2c66affSColin Finck static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
415c2c66affSColin Finck {
416c2c66affSColin Finck     return 1;
417c2c66affSColin Finck }
418c2c66affSColin Finck 
ClassFactory_CreateInstance(IClassFactory * iface,IUnknown * outer,REFIID riid,void ** ppv)419c2c66affSColin Finck static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
420c2c66affSColin Finck {
421c2c66affSColin Finck     CHECK_EXPECT(CreateInstance);
422c2c66affSColin Finck 
423c2c66affSColin Finck     ok(!outer, "outer = %p\n", outer);
424c2c66affSColin Finck     ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
425c2c66affSColin Finck 
426c2c66affSColin Finck     if(SUCCEEDED(CreateInstance_hres))
427c2c66affSColin Finck         *ppv = &testObj;
428c2c66affSColin Finck     return CreateInstance_hres;
429c2c66affSColin Finck }
430c2c66affSColin Finck 
ClassFactory_LockServer(IClassFactory * iface,BOOL dolock)431c2c66affSColin Finck static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
432c2c66affSColin Finck {
433c2c66affSColin Finck     ok(0, "unexpected call\n");
434c2c66affSColin Finck     return S_OK;
435c2c66affSColin Finck }
436c2c66affSColin Finck 
437c2c66affSColin Finck static const IClassFactoryVtbl ClassFactoryVtbl = {
438c2c66affSColin Finck     ClassFactory_QueryInterface,
439c2c66affSColin Finck     ClassFactory_AddRef,
440c2c66affSColin Finck     ClassFactory_Release,
441c2c66affSColin Finck     ClassFactory_CreateInstance,
442c2c66affSColin Finck     ClassFactory_LockServer
443c2c66affSColin Finck };
444c2c66affSColin Finck 
445c2c66affSColin Finck static IClassFactory activex_cf = { &ClassFactoryVtbl };
446c2c66affSColin Finck 
InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager * iface,REFIID riid,void ** ppv)447c2c66affSColin Finck static HRESULT WINAPI InternetHostSecurityManager_QueryInterface(IInternetHostSecurityManager *iface, REFIID riid, void **ppv)
448c2c66affSColin Finck {
449c2c66affSColin Finck     ok(0, "unexpected call\n");
450c2c66affSColin Finck     return E_NOINTERFACE;
451c2c66affSColin Finck }
452c2c66affSColin Finck 
InternetHostSecurityManager_AddRef(IInternetHostSecurityManager * iface)453c2c66affSColin Finck static ULONG WINAPI InternetHostSecurityManager_AddRef(IInternetHostSecurityManager *iface)
454c2c66affSColin Finck {
455c2c66affSColin Finck     return 2;
456c2c66affSColin Finck }
457c2c66affSColin Finck 
InternetHostSecurityManager_Release(IInternetHostSecurityManager * iface)458c2c66affSColin Finck static ULONG WINAPI InternetHostSecurityManager_Release(IInternetHostSecurityManager *iface)
459c2c66affSColin Finck {
460c2c66affSColin Finck     return 1;
461c2c66affSColin Finck }
462c2c66affSColin Finck 
InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager * iface,BYTE * pbSecurityId,DWORD * pcbSecurityId,DWORD_PTR dwReserved)463c2c66affSColin Finck static HRESULT WINAPI InternetHostSecurityManager_GetSecurityId(IInternetHostSecurityManager *iface,  BYTE *pbSecurityId,
464c2c66affSColin Finck         DWORD *pcbSecurityId, DWORD_PTR dwReserved)
465c2c66affSColin Finck {
466c2c66affSColin Finck     ok(0, "unexpected call\n");
467c2c66affSColin Finck     return E_NOTIMPL;
468c2c66affSColin Finck }
469c2c66affSColin Finck 
InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager * iface,DWORD dwAction,BYTE * pPolicy,DWORD cbPolicy,BYTE * pContext,DWORD cbContext,DWORD dwFlags,DWORD dwReserved)470c2c66affSColin Finck static HRESULT WINAPI InternetHostSecurityManager_ProcessUrlAction(IInternetHostSecurityManager *iface, DWORD dwAction,
471c2c66affSColin Finck         BYTE *pPolicy, DWORD cbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
472c2c66affSColin Finck {
473c2c66affSColin Finck     CHECK_EXPECT(ProcessUrlAction);
474c2c66affSColin Finck 
475c2c66affSColin Finck     ok(dwAction == URLACTION_ACTIVEX_RUN, "dwAction = %x\n", dwAction);
476c2c66affSColin Finck     ok(pPolicy != NULL, "pPolicy == NULL\n");
477c2c66affSColin Finck     ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
478c2c66affSColin Finck     ok(pContext != NULL, "pContext == NULL\n");
479c2c66affSColin Finck     ok(cbContext == sizeof(GUID), "cbContext = %d\n", cbContext);
480c2c66affSColin Finck     ok(IsEqualGUID(pContext, &CLSID_TestObj), "pContext = %s\n", wine_dbgstr_guid((const IID*)pContext));
481c2c66affSColin Finck     ok(!dwFlags, "dwFlags = %x\n", dwFlags);
482c2c66affSColin Finck     ok(!dwReserved, "dwReserved = %x\n", dwReserved);
483c2c66affSColin Finck 
484c2c66affSColin Finck     if(SUCCEEDED(ProcessUrlAction_hres))
485c2c66affSColin Finck         *(DWORD*)pPolicy = ProcessUrlAction_policy;
486c2c66affSColin Finck     return ProcessUrlAction_hres;
487c2c66affSColin Finck }
488c2c66affSColin Finck 
InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager * iface,REFGUID guidKey,BYTE ** ppPolicy,DWORD * pcbPolicy,BYTE * pContext,DWORD cbContext,DWORD dwReserved)489c2c66affSColin Finck static HRESULT WINAPI InternetHostSecurityManager_QueryCustomPolicy(IInternetHostSecurityManager *iface, REFGUID guidKey,
490c2c66affSColin Finck         BYTE **ppPolicy, DWORD *pcbPolicy, BYTE *pContext, DWORD cbContext, DWORD dwReserved)
491c2c66affSColin Finck {
492c2c66affSColin Finck     const struct CONFIRMSAFETY *cs = (const struct CONFIRMSAFETY*)pContext;
493c2c66affSColin Finck     DWORD *ret;
494c2c66affSColin Finck 
495c2c66affSColin Finck     CHECK_EXPECT(QueryCustomPolicy);
496c2c66affSColin Finck 
497c2c66affSColin Finck     ok(IsEqualGUID(&GUID_CUSTOM_CONFIRMOBJECTSAFETY, guidKey), "guidKey = %s\n", wine_dbgstr_guid(guidKey));
498c2c66affSColin Finck 
499c2c66affSColin Finck     ok(ppPolicy != NULL, "ppPolicy == NULL\n");
500c2c66affSColin Finck     ok(pcbPolicy != NULL, "pcbPolicy == NULL\n");
501c2c66affSColin Finck     ok(pContext != NULL, "pContext == NULL\n");
502c2c66affSColin Finck     ok(cbContext == sizeof(struct CONFIRMSAFETY), "cbContext = %d\n", cbContext);
503c2c66affSColin Finck     ok(!dwReserved, "dwReserved = %x\n", dwReserved);
504c2c66affSColin Finck 
505c2c66affSColin Finck     /* TODO: CLSID */
506c2c66affSColin Finck     ok(cs->pUnk != NULL, "cs->pUnk == NULL\n");
507c2c66affSColin Finck     ok(!cs->dwFlags, "dwFlags = %x\n", cs->dwFlags);
508c2c66affSColin Finck 
509c2c66affSColin Finck     if(FAILED(QueryCustomPolicy_hres))
510c2c66affSColin Finck         return QueryCustomPolicy_hres;
511c2c66affSColin Finck 
512c2c66affSColin Finck     ret = CoTaskMemAlloc(QueryCustomPolicy_psize);
513c2c66affSColin Finck     *ppPolicy = (BYTE*)ret;
514c2c66affSColin Finck     *pcbPolicy = QueryCustomPolicy_psize;
515c2c66affSColin Finck     memset(ret, 0, QueryCustomPolicy_psize);
516c2c66affSColin Finck     if(QueryCustomPolicy_psize >= sizeof(DWORD))
517c2c66affSColin Finck         *ret = QueryCustomPolicy_policy;
518c2c66affSColin Finck 
519c2c66affSColin Finck     return QueryCustomPolicy_hres;
520c2c66affSColin Finck }
521c2c66affSColin Finck 
522c2c66affSColin Finck static const IInternetHostSecurityManagerVtbl InternetHostSecurityManagerVtbl = {
523c2c66affSColin Finck     InternetHostSecurityManager_QueryInterface,
524c2c66affSColin Finck     InternetHostSecurityManager_AddRef,
525c2c66affSColin Finck     InternetHostSecurityManager_Release,
526c2c66affSColin Finck     InternetHostSecurityManager_GetSecurityId,
527c2c66affSColin Finck     InternetHostSecurityManager_ProcessUrlAction,
528c2c66affSColin Finck     InternetHostSecurityManager_QueryCustomPolicy
529c2c66affSColin Finck };
530c2c66affSColin Finck 
531c2c66affSColin Finck static IInternetHostSecurityManager InternetHostSecurityManager = { &InternetHostSecurityManagerVtbl };
532c2c66affSColin Finck 
533c2c66affSColin Finck static IServiceProvider ServiceProvider;
534c2c66affSColin Finck 
ServiceProvider_QueryInterface(IServiceProvider * iface,REFIID riid,void ** ppv)535c2c66affSColin Finck static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
536c2c66affSColin Finck {
537c2c66affSColin Finck     ok(0, "unexpected call\n");
538c2c66affSColin Finck     return E_NOINTERFACE;
539c2c66affSColin Finck }
540c2c66affSColin Finck 
ServiceProvider_AddRef(IServiceProvider * iface)541c2c66affSColin Finck static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
542c2c66affSColin Finck {
543c2c66affSColin Finck     return 2;
544c2c66affSColin Finck }
545c2c66affSColin Finck 
ServiceProvider_Release(IServiceProvider * iface)546c2c66affSColin Finck static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
547c2c66affSColin Finck {
548c2c66affSColin Finck     return 1;
549c2c66affSColin Finck }
550c2c66affSColin Finck 
ServiceProvider_QueryService(IServiceProvider * iface,REFGUID guidService,REFIID riid,void ** ppv)551c2c66affSColin Finck static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
552c2c66affSColin Finck         REFGUID guidService, REFIID riid, void **ppv)
553c2c66affSColin Finck {
554c2c66affSColin Finck     if(IsEqualGUID(&SID_GetCaller, guidService))
555c2c66affSColin Finck         return E_NOINTERFACE;
556c2c66affSColin Finck 
557c2c66affSColin Finck     if(IsEqualGUID(&SID_SInternetHostSecurityManager, guidService)) {
558c2c66affSColin Finck         if(iface == &ServiceProvider)
559c2c66affSColin Finck             CHECK_EXPECT(Host_QS_SecMgr);
560c2c66affSColin Finck         else
561c2c66affSColin Finck             CHECK_EXPECT(Caller_QS_SecMgr);
562c2c66affSColin Finck         ok(IsEqualGUID(&IID_IInternetHostSecurityManager, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
563c2c66affSColin Finck         if(SUCCEEDED(QS_SecMgr_hres))
564c2c66affSColin Finck             *ppv = &InternetHostSecurityManager;
565c2c66affSColin Finck         return QS_SecMgr_hres;
566c2c66affSColin Finck     }
567c2c66affSColin Finck 
568c2c66affSColin Finck     ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
569c2c66affSColin Finck     return E_NOINTERFACE;
570c2c66affSColin Finck }
571c2c66affSColin Finck 
572c2c66affSColin Finck static IServiceProviderVtbl ServiceProviderVtbl = {
573c2c66affSColin Finck     ServiceProvider_QueryInterface,
574c2c66affSColin Finck     ServiceProvider_AddRef,
575c2c66affSColin Finck     ServiceProvider_Release,
576c2c66affSColin Finck     ServiceProvider_QueryService
577c2c66affSColin Finck };
578c2c66affSColin Finck 
579c2c66affSColin Finck static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
580c2c66affSColin Finck static IServiceProvider caller_sp = { &ServiceProviderVtbl };
581c2c66affSColin Finck 
ActiveScriptSite_QueryInterface(IActiveScriptSite * iface,REFIID riid,void ** ppv)582c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_QueryInterface(IActiveScriptSite *iface, REFIID riid, void **ppv)
583c2c66affSColin Finck {
584c2c66affSColin Finck     if(IsEqualGUID(&IID_IUnknown, riid)) {
585c2c66affSColin Finck         *ppv = iface;
586c2c66affSColin Finck     }else if(IsEqualGUID(&IID_IActiveScriptSite, riid)) {
587c2c66affSColin Finck         *ppv = iface;
588c2c66affSColin Finck     }else if(IsEqualGUID(&IID_IServiceProvider, riid) && AllowIServiceProvider) {
589c2c66affSColin Finck         *ppv = &ServiceProvider;
590c2c66affSColin Finck     }else {
591c2c66affSColin Finck         *ppv = NULL;
592c2c66affSColin Finck         return E_NOINTERFACE;
593c2c66affSColin Finck     }
594c2c66affSColin Finck 
595c2c66affSColin Finck     IUnknown_AddRef((IUnknown*)*ppv);
596c2c66affSColin Finck     return S_OK;
597c2c66affSColin Finck }
598c2c66affSColin Finck 
ActiveScriptSite_AddRef(IActiveScriptSite * iface)599c2c66affSColin Finck static ULONG WINAPI ActiveScriptSite_AddRef(IActiveScriptSite *iface)
600c2c66affSColin Finck {
601c2c66affSColin Finck     return 2;
602c2c66affSColin Finck }
603c2c66affSColin Finck 
ActiveScriptSite_Release(IActiveScriptSite * iface)604c2c66affSColin Finck static ULONG WINAPI ActiveScriptSite_Release(IActiveScriptSite *iface)
605c2c66affSColin Finck {
606c2c66affSColin Finck     return 1;
607c2c66affSColin Finck }
608c2c66affSColin Finck 
ActiveScriptSite_GetLCID(IActiveScriptSite * iface,LCID * plcid)609c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_GetLCID(IActiveScriptSite *iface, LCID *plcid)
610c2c66affSColin Finck {
611c2c66affSColin Finck     *plcid = GetUserDefaultLCID();
612c2c66affSColin Finck     return S_OK;
613c2c66affSColin Finck }
614c2c66affSColin Finck 
ActiveScriptSite_GetItemInfo(IActiveScriptSite * iface,LPCOLESTR pstrName,DWORD dwReturnMask,IUnknown ** ppiunkItem,ITypeInfo ** ppti)615c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_GetItemInfo(IActiveScriptSite *iface, LPCOLESTR pstrName,
616c2c66affSColin Finck         DWORD dwReturnMask, IUnknown **ppiunkItem, ITypeInfo **ppti)
617c2c66affSColin Finck {
618c2c66affSColin Finck     ok(dwReturnMask == SCRIPTINFO_IUNKNOWN, "unexpected dwReturnMask %x\n", dwReturnMask);
619c2c66affSColin Finck     ok(!ppti, "ppti != NULL\n");
620c2c66affSColin Finck     ok(!strcmp_wa(pstrName, "test"), "pstrName = %s\n", wine_dbgstr_w(pstrName));
621c2c66affSColin Finck 
622c2c66affSColin Finck     *ppiunkItem = (IUnknown*)&globalObj;
623c2c66affSColin Finck     return S_OK;
624c2c66affSColin Finck }
625c2c66affSColin Finck 
ActiveScriptSite_GetDocVersionString(IActiveScriptSite * iface,BSTR * pbstrVersion)626c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_GetDocVersionString(IActiveScriptSite *iface, BSTR *pbstrVersion)
627c2c66affSColin Finck {
628c2c66affSColin Finck     return E_NOTIMPL;
629c2c66affSColin Finck }
630c2c66affSColin Finck 
ActiveScriptSite_OnScriptTerminate(IActiveScriptSite * iface,const VARIANT * pvarResult,const EXCEPINFO * pexcepinfo)631c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_OnScriptTerminate(IActiveScriptSite *iface,
632c2c66affSColin Finck         const VARIANT *pvarResult, const EXCEPINFO *pexcepinfo)
633c2c66affSColin Finck {
634c2c66affSColin Finck     return E_NOTIMPL;
635c2c66affSColin Finck }
636c2c66affSColin Finck 
ActiveScriptSite_OnStateChange(IActiveScriptSite * iface,SCRIPTSTATE ssScriptState)637c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_OnStateChange(IActiveScriptSite *iface, SCRIPTSTATE ssScriptState)
638c2c66affSColin Finck {
639c2c66affSColin Finck     return E_NOTIMPL;
640c2c66affSColin Finck }
641c2c66affSColin Finck 
ActiveScriptSite_OnScriptError(IActiveScriptSite * iface,IActiveScriptError * pscripterror)642c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_OnScriptError(IActiveScriptSite *iface, IActiveScriptError *pscripterror)
643c2c66affSColin Finck {
644c2c66affSColin Finck     return E_NOTIMPL;
645c2c66affSColin Finck }
646c2c66affSColin Finck 
ActiveScriptSite_OnEnterScript(IActiveScriptSite * iface)647c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_OnEnterScript(IActiveScriptSite *iface)
648c2c66affSColin Finck {
649c2c66affSColin Finck     return E_NOTIMPL;
650c2c66affSColin Finck }
651c2c66affSColin Finck 
ActiveScriptSite_OnLeaveScript(IActiveScriptSite * iface)652c2c66affSColin Finck static HRESULT WINAPI ActiveScriptSite_OnLeaveScript(IActiveScriptSite *iface)
653c2c66affSColin Finck {
654c2c66affSColin Finck     return E_NOTIMPL;
655c2c66affSColin Finck }
656c2c66affSColin Finck 
657c2c66affSColin Finck #undef ACTSCPSITE_THIS
658c2c66affSColin Finck 
659c2c66affSColin Finck static const IActiveScriptSiteVtbl ActiveScriptSiteVtbl = {
660c2c66affSColin Finck     ActiveScriptSite_QueryInterface,
661c2c66affSColin Finck     ActiveScriptSite_AddRef,
662c2c66affSColin Finck     ActiveScriptSite_Release,
663c2c66affSColin Finck     ActiveScriptSite_GetLCID,
664c2c66affSColin Finck     ActiveScriptSite_GetItemInfo,
665c2c66affSColin Finck     ActiveScriptSite_GetDocVersionString,
666c2c66affSColin Finck     ActiveScriptSite_OnScriptTerminate,
667c2c66affSColin Finck     ActiveScriptSite_OnStateChange,
668c2c66affSColin Finck     ActiveScriptSite_OnScriptError,
669c2c66affSColin Finck     ActiveScriptSite_OnEnterScript,
670c2c66affSColin Finck     ActiveScriptSite_OnLeaveScript
671c2c66affSColin Finck };
672c2c66affSColin Finck 
673c2c66affSColin Finck static IActiveScriptSite ActiveScriptSite = { &ActiveScriptSiteVtbl };
674c2c66affSColin Finck 
set_safety_options(IUnknown * unk,BOOL use_sec_mgr)675c2c66affSColin Finck static void set_safety_options(IUnknown *unk, BOOL use_sec_mgr)
676c2c66affSColin Finck {
677c2c66affSColin Finck     IObjectSafety *safety;
678c2c66affSColin Finck     DWORD supported, enabled, options_all, options_set;
679c2c66affSColin Finck     HRESULT hres;
680c2c66affSColin Finck 
681c2c66affSColin Finck     hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
682c2c66affSColin Finck     ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
683c2c66affSColin Finck     if(FAILED(hres))
684c2c66affSColin Finck         return;
685c2c66affSColin Finck 
686c2c66affSColin Finck     options_all = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
687c2c66affSColin Finck     if(use_sec_mgr)
688c2c66affSColin Finck         options_set = options_all;
689c2c66affSColin Finck     else
690c2c66affSColin Finck         options_set = INTERFACE_USES_DISPEX;
691c2c66affSColin Finck 
692c2c66affSColin Finck     hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, options_all, options_set);
693c2c66affSColin Finck     ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
694c2c66affSColin Finck 
695c2c66affSColin Finck     supported = enabled = 0xdeadbeef;
696c2c66affSColin Finck     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
697c2c66affSColin Finck     ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
698c2c66affSColin Finck     ok(supported == options_all, "supported=%x, expected %x\n", supported, options_all);
699c2c66affSColin Finck     ok(enabled == options_set, "enabled=%x, expected %x\n", enabled, options_set);
700c2c66affSColin Finck 
701c2c66affSColin Finck     IObjectSafety_Release(safety);
702c2c66affSColin Finck }
703c2c66affSColin Finck 
704c2c66affSColin Finck #define parse_script_a(p,s) _parse_script_a(__LINE__,p,s)
_parse_script_a(unsigned line,IActiveScriptParse * parser,const char * script)705c2c66affSColin Finck static void _parse_script_a(unsigned line, IActiveScriptParse *parser, const char *script)
706c2c66affSColin Finck {
707c2c66affSColin Finck     BSTR str;
708c2c66affSColin Finck     HRESULT hres;
709c2c66affSColin Finck 
710c2c66affSColin Finck     str = a2bstr(script);
711c2c66affSColin Finck     hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
712c2c66affSColin Finck     SysFreeString(str);
713c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "ParseScriptText failed: %08x\n", hres);
714c2c66affSColin Finck }
715c2c66affSColin Finck 
create_script(BOOL skip_tests,BOOL use_sec_mgr)716c2c66affSColin Finck static IActiveScriptParse *create_script(BOOL skip_tests, BOOL use_sec_mgr)
717c2c66affSColin Finck {
718c2c66affSColin Finck     IActiveScriptParse *parser;
719c2c66affSColin Finck     IActiveScript *script;
720c2c66affSColin Finck     HRESULT hres;
721c2c66affSColin Finck 
722c2c66affSColin Finck     QS_SecMgr_hres = S_OK;
723c2c66affSColin Finck     ProcessUrlAction_hres = S_OK;
724c2c66affSColin Finck     ProcessUrlAction_policy = URLPOLICY_ALLOW;
725c2c66affSColin Finck     CreateInstance_hres = S_OK;
726c2c66affSColin Finck     QueryCustomPolicy_hres = S_OK;
727c2c66affSColin Finck     QueryCustomPolicy_psize = sizeof(DWORD);
728c2c66affSColin Finck     QueryCustomPolicy_policy = URLPOLICY_ALLOW;
729c2c66affSColin Finck     QI_IDispatch_hres = S_OK;
730c2c66affSColin Finck     SetSite_hres = S_OK;
731c2c66affSColin Finck     AllowIServiceProvider = TRUE;
732c2c66affSColin Finck 
733c2c66affSColin Finck     hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
734c2c66affSColin Finck             &IID_IActiveScript, (void**)&script);
735c2c66affSColin Finck     if(!skip_tests)
736c2c66affSColin Finck         ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
737c2c66affSColin Finck     if(FAILED(hres))
738c2c66affSColin Finck         return NULL;
739c2c66affSColin Finck 
740c2c66affSColin Finck     if(!skip_tests)
741c2c66affSColin Finck         set_safety_options((IUnknown*)script, use_sec_mgr);
742c2c66affSColin Finck 
743c2c66affSColin Finck     hres = IActiveScript_QueryInterface(script, &IID_IActiveScriptParse, (void**)&parser);
744c2c66affSColin Finck     ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
745c2c66affSColin Finck 
746c2c66affSColin Finck     hres = IActiveScriptParse_InitNew(parser);
747c2c66affSColin Finck     ok(hres == S_OK, "InitNew failed: %08x\n", hres);
748c2c66affSColin Finck 
749c2c66affSColin Finck     hres = IActiveScript_SetScriptSite(script, &ActiveScriptSite);
750c2c66affSColin Finck     ok(hres == S_OK, "SetScriptSite failed: %08x\n", hres);
751c2c66affSColin Finck 
752c2c66affSColin Finck     hres = IActiveScript_AddNamedItem(script, testW,
753c2c66affSColin Finck             SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS);
754c2c66affSColin Finck     ok(hres == S_OK, "AddNamedItem failed: %08x\n", hres);
755c2c66affSColin Finck 
756c2c66affSColin Finck     hres = IActiveScript_SetScriptState(script, SCRIPTSTATE_STARTED);
757c2c66affSColin Finck     ok(hres == S_OK, "SetScriptState(SCRIPTSTATE_STARTED) failed: %08x\n", hres);
758c2c66affSColin Finck 
759c2c66affSColin Finck     IActiveScript_Release(script);
760c2c66affSColin Finck 
761c2c66affSColin Finck     if(!skip_tests) {
762c2c66affSColin Finck         parse_script_a(parser,
763c2c66affSColin Finck                 "function testException(func, type, number) {\n"
764c2c66affSColin Finck                 "    try {\n"
765c2c66affSColin Finck                 "        func();\n"
766c2c66affSColin Finck                 "    }catch(e) {\n"
767c2c66affSColin Finck                 "        ok(e.name === type, 'e.name = ' + e.name + ', expected ' + type)\n"
768c2c66affSColin Finck                 "        ok(e.number === number, 'e.number = ' + e.number + ', expected ' + number);\n"
769c2c66affSColin Finck                 "        return;\n"
770c2c66affSColin Finck                 "    }\n"
771c2c66affSColin Finck                 "    ok(false, 'exception expected');\n"
772c2c66affSColin Finck                 "}");
773c2c66affSColin Finck     }
774c2c66affSColin Finck 
775c2c66affSColin Finck     return parser;
776c2c66affSColin Finck }
777c2c66affSColin Finck 
parse_procedure_a(IActiveScriptParse * parser,const char * src)778c2c66affSColin Finck static IDispatchEx *parse_procedure_a(IActiveScriptParse *parser, const char *src)
779c2c66affSColin Finck {
780c2c66affSColin Finck     IActiveScriptParseProcedure2 *parse_proc;
781c2c66affSColin Finck     IDispatchEx *dispex;
782c2c66affSColin Finck     IDispatch *disp;
783c2c66affSColin Finck     BSTR str;
784c2c66affSColin Finck     HRESULT hres;
785c2c66affSColin Finck 
786c2c66affSColin Finck     hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptParseProcedure2, (void**)&parse_proc);
787c2c66affSColin Finck     ok(hres == S_OK, "Could not get IActiveScriptParseProcedure2: %08x\n", hres);
788c2c66affSColin Finck 
789c2c66affSColin Finck     str = a2bstr(src);
790c2c66affSColin Finck     hres = IActiveScriptParseProcedure2_ParseProcedureText(parse_proc, str, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, &disp);
791c2c66affSColin Finck     SysFreeString(str);
792c2c66affSColin Finck     IActiveScriptParseProcedure2_Release(parse_proc);
793c2c66affSColin Finck     ok(hres == S_OK, "ParseProcedureText failed: %08x\n", hres);
794c2c66affSColin Finck     ok(disp != NULL, "disp == NULL\n");
795c2c66affSColin Finck 
796c2c66affSColin Finck     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
797c2c66affSColin Finck     IDispatch_Release(disp);
798c2c66affSColin Finck     ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
799c2c66affSColin Finck 
800c2c66affSColin Finck     return dispex;
801c2c66affSColin Finck }
802c2c66affSColin Finck 
803c2c66affSColin Finck #define call_procedure(p,c) _call_procedure(__LINE__,p,c)
_call_procedure(unsigned line,IDispatchEx * proc,IServiceProvider * caller)804c2c66affSColin Finck static void _call_procedure(unsigned line, IDispatchEx *proc, IServiceProvider *caller)
805c2c66affSColin Finck {
806c2c66affSColin Finck     DISPPARAMS dp = {NULL,NULL,0,0};
807c2c66affSColin Finck     EXCEPINFO ei = {0};
808c2c66affSColin Finck     HRESULT hres;
809c2c66affSColin Finck 
810c2c66affSColin Finck     hres = IDispatchEx_InvokeEx(proc, DISPID_VALUE, 0, DISPATCH_METHOD, &dp, NULL, &ei, caller);
811c2c66affSColin Finck     ok_(__FILE__,line)(hres == S_OK, "InvokeEx failed: %08x\n", hres);
812c2c66affSColin Finck 
813c2c66affSColin Finck }
814c2c66affSColin Finck 
test_ActiveXObject(void)815c2c66affSColin Finck static void test_ActiveXObject(void)
816c2c66affSColin Finck {
817c2c66affSColin Finck     IActiveScriptParse *parser;
818c2c66affSColin Finck     IDispatchEx *proc;
819c2c66affSColin Finck 
820c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
821c2c66affSColin Finck 
822c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
823c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
824c2c66affSColin Finck     SET_EXPECT(CreateInstance);
825c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
826c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
827c2c66affSColin Finck     SET_EXPECT(reportSuccess);
828c2c66affSColin Finck     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
829c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
830c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
831c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
832c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
833c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
834c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
835c2c66affSColin Finck 
836c2c66affSColin Finck     proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
837c2c66affSColin Finck 
838c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
839c2c66affSColin Finck     SET_EXPECT(CreateInstance);
840c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
841c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
842c2c66affSColin Finck     SET_EXPECT(reportSuccess);
843c2c66affSColin Finck     call_procedure(proc, NULL);
844c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
845c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
846c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
847c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
848c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
849c2c66affSColin Finck 
850c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
851c2c66affSColin Finck     SET_EXPECT(CreateInstance);
852c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
853c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
854c2c66affSColin Finck     SET_EXPECT(reportSuccess);
855c2c66affSColin Finck     call_procedure(proc, &caller_sp);
856c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
857c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
858c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
859c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
860c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
861c2c66affSColin Finck 
862c2c66affSColin Finck     IDispatchEx_Release(proc);
863c2c66affSColin Finck     IActiveScriptParse_Release(parser);
864c2c66affSColin Finck 
865c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
866c2c66affSColin Finck     proc = parse_procedure_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
867c2c66affSColin Finck 
868c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
869c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
870c2c66affSColin Finck     SET_EXPECT(CreateInstance);
871c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
872c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
873c2c66affSColin Finck     SET_EXPECT(reportSuccess);
874c2c66affSColin Finck     call_procedure(proc, &caller_sp);
875c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
876c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
877c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
878c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
879c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
880c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
881c2c66affSColin Finck 
882c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.TestABC'); }, 'Error', -2146827859);");
883c2c66affSColin Finck 
884c2c66affSColin Finck     IDispatchEx_Release(proc);
885c2c66affSColin Finck     IActiveScriptParse_Release(parser);
886c2c66affSColin Finck 
887c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
888c2c66affSColin Finck     QS_SecMgr_hres = E_NOINTERFACE;
889c2c66affSColin Finck 
890c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
891c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
892c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
893c2c66affSColin Finck 
894c2c66affSColin Finck     IActiveScriptParse_Release(parser);
895c2c66affSColin Finck 
896c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
897c2c66affSColin Finck     ProcessUrlAction_hres = E_FAIL;
898c2c66affSColin Finck 
899c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
900c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
901c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
902c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
903c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
904c2c66affSColin Finck 
905c2c66affSColin Finck     IActiveScriptParse_Release(parser);
906c2c66affSColin Finck 
907c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
908c2c66affSColin Finck     ProcessUrlAction_policy = URLPOLICY_DISALLOW;
909c2c66affSColin Finck 
910c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
911c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
912c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
913c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
914c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
915c2c66affSColin Finck 
916c2c66affSColin Finck     IActiveScriptParse_Release(parser);
917c2c66affSColin Finck 
918c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
919c2c66affSColin Finck     CreateInstance_hres = E_FAIL;
920c2c66affSColin Finck 
921c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
922c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
923c2c66affSColin Finck     SET_EXPECT(CreateInstance);
924c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
925c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
926c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
927c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
928c2c66affSColin Finck 
929c2c66affSColin Finck     IActiveScriptParse_Release(parser);
930c2c66affSColin Finck 
931c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
932c2c66affSColin Finck     QueryCustomPolicy_hres = E_FAIL;
933c2c66affSColin Finck 
934c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
935c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
936c2c66affSColin Finck     SET_EXPECT(CreateInstance);
937c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
938c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
939c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
940c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
941c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
942c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
943c2c66affSColin Finck 
944c2c66affSColin Finck     IActiveScriptParse_Release(parser);
945c2c66affSColin Finck 
946c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
947c2c66affSColin Finck     QueryCustomPolicy_psize = 6;
948c2c66affSColin Finck 
949c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
950c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
951c2c66affSColin Finck     SET_EXPECT(CreateInstance);
952c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
953c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
954c2c66affSColin Finck     SET_EXPECT(reportSuccess);
955c2c66affSColin Finck     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
956c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
957c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
958c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
959c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
960c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
961c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
962c2c66affSColin Finck 
963c2c66affSColin Finck     IActiveScriptParse_Release(parser);
964c2c66affSColin Finck 
965c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
966c2c66affSColin Finck     QueryCustomPolicy_policy = URLPOLICY_DISALLOW;
967c2c66affSColin Finck 
968c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
969c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
970c2c66affSColin Finck     SET_EXPECT(CreateInstance);
971c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
972c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
973c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
974c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
975c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
976c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
977c2c66affSColin Finck 
978c2c66affSColin Finck     QueryCustomPolicy_psize = 6;
979c2c66affSColin Finck 
980c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
981c2c66affSColin Finck     SET_EXPECT(CreateInstance);
982c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
983c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
984c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
985c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
986c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
987c2c66affSColin Finck 
988c2c66affSColin Finck     QueryCustomPolicy_policy = URLPOLICY_ALLOW;
989c2c66affSColin Finck     QueryCustomPolicy_psize = 3;
990c2c66affSColin Finck 
991c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
992c2c66affSColin Finck     SET_EXPECT(CreateInstance);
993c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
994c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
995c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
996c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
997c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
998c2c66affSColin Finck 
999c2c66affSColin Finck     IActiveScriptParse_Release(parser);
1000c2c66affSColin Finck 
1001c2c66affSColin Finck     parser = create_script(FALSE, FALSE);
1002c2c66affSColin Finck 
1003c2c66affSColin Finck     SET_EXPECT(CreateInstance);
1004c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
1005c2c66affSColin Finck     SET_EXPECT(reportSuccess);
1006c2c66affSColin Finck     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1007c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
1008c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
1009c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
1010c2c66affSColin Finck 
1011c2c66affSColin Finck     IActiveScriptParse_Release(parser);
1012c2c66affSColin Finck 
1013c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
1014c2c66affSColin Finck     object_with_site = &ObjectWithSite;
1015c2c66affSColin Finck 
1016c2c66affSColin Finck     SET_EXPECT(Host_QS_SecMgr);
1017c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
1018c2c66affSColin Finck     SET_EXPECT(CreateInstance);
1019c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
1020c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
1021c2c66affSColin Finck     SET_EXPECT(SetSite);
1022c2c66affSColin Finck     SET_EXPECT(reportSuccess);
1023c2c66affSColin Finck     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1024c2c66affSColin Finck     CHECK_CALLED(Host_QS_SecMgr);
1025c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
1026c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
1027c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
1028c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
1029c2c66affSColin Finck     CHECK_CALLED(SetSite);
1030c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
1031c2c66affSColin Finck 
1032c2c66affSColin Finck     SetSite_hres = E_FAIL;
1033c2c66affSColin Finck     SET_EXPECT(ProcessUrlAction);
1034c2c66affSColin Finck     SET_EXPECT(CreateInstance);
1035c2c66affSColin Finck     SET_EXPECT(QueryCustomPolicy);
1036c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
1037c2c66affSColin Finck     SET_EXPECT(SetSite);
1038c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1039c2c66affSColin Finck     CHECK_CALLED(ProcessUrlAction);
1040c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
1041c2c66affSColin Finck     CHECK_CALLED(QueryCustomPolicy);
1042c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
1043c2c66affSColin Finck     CHECK_CALLED(SetSite);
1044c2c66affSColin Finck 
1045c2c66affSColin Finck     IActiveScriptParse_Release(parser);
1046c2c66affSColin Finck 
1047c2c66affSColin Finck     /* No IServiceProvider Interface */
1048c2c66affSColin Finck     parser = create_script(FALSE, FALSE);
1049c2c66affSColin Finck     object_with_site = &ObjectWithSite;
1050c2c66affSColin Finck     AllowIServiceProvider = FALSE;
1051c2c66affSColin Finck 
1052c2c66affSColin Finck     SET_EXPECT(CreateInstance);
1053c2c66affSColin Finck     SET_EXPECT(QI_IObjectWithSite);
1054c2c66affSColin Finck     SET_EXPECT(reportSuccess);
1055c2c66affSColin Finck     SET_EXPECT(SetSite);
1056c2c66affSColin Finck     parse_script_a(parser, "(new ActiveXObject('Wine.Test')).reportSuccess();");
1057c2c66affSColin Finck     CHECK_CALLED(CreateInstance);
1058c2c66affSColin Finck     CHECK_CALLED(QI_IObjectWithSite);
1059c2c66affSColin Finck     CHECK_CALLED(reportSuccess);
1060c2c66affSColin Finck     CHECK_CALLED(SetSite);
1061c2c66affSColin Finck 
1062c2c66affSColin Finck     IActiveScriptParse_Release(parser);
1063c2c66affSColin Finck 
1064c2c66affSColin Finck     parser = create_script(FALSE, TRUE);
1065c2c66affSColin Finck     object_with_site = &ObjectWithSite;
1066c2c66affSColin Finck     AllowIServiceProvider = FALSE;
1067c2c66affSColin Finck 
1068c2c66affSColin Finck     parse_script_a(parser, "testException(function() { new ActiveXObject('Wine.Test'); }, 'Error', -2146827859);");
1069c2c66affSColin Finck 
1070c2c66affSColin Finck     IActiveScriptParse_Release(parser);
1071c2c66affSColin Finck }
1072c2c66affSColin Finck 
init_key(const char * key_name,const char * def_value,BOOL init)1073c2c66affSColin Finck static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1074c2c66affSColin Finck {
1075c2c66affSColin Finck     HKEY hkey;
1076c2c66affSColin Finck     DWORD res;
1077c2c66affSColin Finck 
1078c2c66affSColin Finck     if(!init) {
1079c2c66affSColin Finck         RegDeleteKeyA(HKEY_CLASSES_ROOT, key_name);
1080c2c66affSColin Finck         return TRUE;
1081c2c66affSColin Finck     }
1082c2c66affSColin Finck 
1083c2c66affSColin Finck     res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1084c2c66affSColin Finck     if(res != ERROR_SUCCESS)
1085c2c66affSColin Finck         return FALSE;
1086c2c66affSColin Finck 
1087c2c66affSColin Finck     if(def_value)
1088c2c66affSColin Finck         res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1089c2c66affSColin Finck 
1090c2c66affSColin Finck     RegCloseKey(hkey);
1091c2c66affSColin Finck 
1092c2c66affSColin Finck     return res == ERROR_SUCCESS;
1093c2c66affSColin Finck }
1094c2c66affSColin Finck 
init_registry(BOOL init)1095c2c66affSColin Finck static BOOL init_registry(BOOL init)
1096c2c66affSColin Finck {
1097c2c66affSColin Finck     return init_key("Wine.Test\\CLSID", TESTOBJ_CLSID, init);
1098c2c66affSColin Finck }
1099c2c66affSColin Finck 
register_activex(void)1100c2c66affSColin Finck static BOOL register_activex(void)
1101c2c66affSColin Finck {
1102c2c66affSColin Finck     DWORD regid;
1103c2c66affSColin Finck     HRESULT hres;
1104c2c66affSColin Finck 
1105c2c66affSColin Finck     if(!init_registry(TRUE)) {
1106c2c66affSColin Finck         init_registry(FALSE);
1107c2c66affSColin Finck         return FALSE;
1108c2c66affSColin Finck     }
1109c2c66affSColin Finck 
1110c2c66affSColin Finck     hres = CoRegisterClassObject(&CLSID_TestObj, (IUnknown *)&activex_cf,
1111c2c66affSColin Finck                                  CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1112c2c66affSColin Finck     ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
1113c2c66affSColin Finck 
1114c2c66affSColin Finck     return TRUE;
1115c2c66affSColin Finck }
1116c2c66affSColin Finck 
check_jscript(void)1117c2c66affSColin Finck static BOOL check_jscript(void)
1118c2c66affSColin Finck {
1119c2c66affSColin Finck     IActiveScriptProperty *script_prop;
1120c2c66affSColin Finck     IActiveScriptParse *parser;
1121c2c66affSColin Finck     BSTR str;
1122c2c66affSColin Finck     HRESULT hres;
1123c2c66affSColin Finck 
1124c2c66affSColin Finck     parser = create_script(TRUE, TRUE);
1125c2c66affSColin Finck     if(!parser)
1126c2c66affSColin Finck         return FALSE;
1127c2c66affSColin Finck 
1128c2c66affSColin Finck     str = a2bstr("if(!('localeCompare' in String.prototype)) throw 1;");
1129c2c66affSColin Finck     hres = IActiveScriptParse_ParseScriptText(parser, str, NULL, NULL, NULL, 0, 0, 0, NULL, NULL);
1130c2c66affSColin Finck     SysFreeString(str);
1131c2c66affSColin Finck 
1132c2c66affSColin Finck     if(hres == S_OK)
1133c2c66affSColin Finck         hres = IActiveScriptParse_QueryInterface(parser, &IID_IActiveScriptProperty, (void**)&script_prop);
1134c2c66affSColin Finck     IActiveScriptParse_Release(parser);
1135c2c66affSColin Finck     if(hres == S_OK)
1136c2c66affSColin Finck         IActiveScriptProperty_Release(script_prop);
1137c2c66affSColin Finck 
1138c2c66affSColin Finck     return hres == S_OK;
1139c2c66affSColin Finck }
1140c2c66affSColin Finck 
START_TEST(activex)1141c2c66affSColin Finck START_TEST(activex)
1142c2c66affSColin Finck {
1143c2c66affSColin Finck     CoInitialize(NULL);
1144c2c66affSColin Finck 
1145c2c66affSColin Finck     if(check_jscript()) {
1146c2c66affSColin Finck         if(register_activex()) {
1147c2c66affSColin Finck             test_ActiveXObject();
1148c2c66affSColin Finck             init_registry(FALSE);
1149c2c66affSColin Finck         }else {
1150c2c66affSColin Finck             skip("Could not register ActiveX object\n");
1151c2c66affSColin Finck         }
1152c2c66affSColin Finck     }else {
1153c2c66affSColin Finck         win_skip("Broken engine, probably too old\n");
1154c2c66affSColin Finck     }
1155c2c66affSColin Finck 
1156c2c66affSColin Finck     CoUninitialize();
1157c2c66affSColin Finck }
1158