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