mshtml: Added support for accessing elements id by global properties.
[wine] / dlls / mshtml / tests / script.c
1 /*
2  * Copyright 2008-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 COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "dispex.h"
30 #include "mshtml.h"
31 #include "initguid.h"
32 #include "activscp.h"
33 #include "activdbg.h"
34 #include "objsafe.h"
35 #include "mshtmdid.h"
36 #include "mshtml_test.h"
37
38 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
39
40 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
41 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
42     {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
43
44 #ifdef _WIN64
45
46 #define CTXARG_T DWORDLONG
47 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
48 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
49
50 #else
51
52 #define CTXARG_T DWORD
53 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
54 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
55
56 #endif
57
58 #define DEFINE_EXPECT(func) \
59     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
60
61 #define SET_EXPECT(func) \
62     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
63
64 #define CHECK_EXPECT2(func) \
65     do { \
66         ok(expect_ ##func, "unexpected call " #func "\n"); \
67         called_ ## func = TRUE; \
68     }while(0)
69
70 #define CHECK_EXPECT(func) \
71     do { \
72         CHECK_EXPECT2(func); \
73         expect_ ## func = FALSE; \
74     }while(0)
75
76 #define CHECK_CALLED(func) \
77     do { \
78         ok(called_ ## func, "expected " #func "\n"); \
79         expect_ ## func = called_ ## func = FALSE; \
80     }while(0)
81
82 #define CHECK_CALLED_BROKEN(func) \
83     do { \
84         ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
85         expect_ ## func = called_ ## func = FALSE; \
86     }while(0)
87
88 #define CHECK_NOT_CALLED(func) \
89     do { \
90         ok(!called_ ## func, "unexpected " #func "\n"); \
91         expect_ ## func = called_ ## func = FALSE; \
92     }while(0)
93
94 #define CLEAR_CALLED(func) \
95     expect_ ## func = called_ ## func = FALSE
96
97
98 DEFINE_EXPECT(CreateInstance);
99 DEFINE_EXPECT(GetInterfaceSafetyOptions);
100 DEFINE_EXPECT(SetInterfaceSafetyOptions);
101 DEFINE_EXPECT(InitNew);
102 DEFINE_EXPECT(Close);
103 DEFINE_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
104 DEFINE_EXPECT(SetProperty_INVOKEVERSIONING);
105 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
106 DEFINE_EXPECT(SetScriptSite);
107 DEFINE_EXPECT(GetScriptState);
108 DEFINE_EXPECT(SetScriptState_STARTED);
109 DEFINE_EXPECT(SetScriptState_CONNECTED);
110 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
111 DEFINE_EXPECT(AddNamedItem);
112 DEFINE_EXPECT(ParseScriptText);
113 DEFINE_EXPECT(GetScriptDispatch);
114 DEFINE_EXPECT(funcDisp);
115 DEFINE_EXPECT(script_divid_d);
116 DEFINE_EXPECT(script_testprop_d);
117 DEFINE_EXPECT(script_testprop_i);
118 DEFINE_EXPECT(AXQueryInterface_IActiveScript);
119 DEFINE_EXPECT(AXQueryInterface_IObjectSafety);
120 DEFINE_EXPECT(AXGetInterfaceSafetyOptions);
121 DEFINE_EXPECT(AXSetInterfaceSafetyOptions);
122
123 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
124
125 #define DISPID_SCRIPT_TESTPROP   0x100000
126
127 static const GUID CLSID_TestScript =
128     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
129 static const GUID CLSID_TestActiveX =
130     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
131
132 static IHTMLDocument2 *notif_doc;
133 static IDispatchEx *window_dispex;
134 static BOOL doc_complete;
135 static IDispatch *script_disp;
136
137 static const char *debugstr_guid(REFIID riid)
138 {
139     static char buf[50];
140
141     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
142             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
143             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
144             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
145
146     return buf;
147 }
148
149 static int strcmp_wa(LPCWSTR strw, const char *stra)
150 {
151     CHAR buf[512];
152     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
153     return lstrcmpA(stra, buf);
154 }
155
156 static BSTR a2bstr(const char *str)
157 {
158     BSTR ret;
159     int len;
160
161     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
162     ret = SysAllocStringLen(NULL, len);
163     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
164
165     return ret;
166 }
167
168 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
169         REFIID riid, void**ppv)
170 {
171     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
172         *ppv = iface;
173         return S_OK;
174     }
175
176     return E_NOINTERFACE;
177 }
178
179 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
180 {
181     return 2;
182 }
183
184 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
185 {
186     return 1;
187 }
188
189 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
190 {
191     if(dispID == DISPID_READYSTATE){
192         BSTR state;
193         HRESULT hres;
194
195         static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
196
197         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
198         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
199
200         if(!lstrcmpW(state, completeW))
201             doc_complete = TRUE;
202
203         SysFreeString(state);
204     }
205
206     return S_OK;
207 }
208
209 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
210 {
211     ok(0, "unexpected call\n");
212     return E_NOTIMPL;
213 }
214
215 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
216     PropertyNotifySink_QueryInterface,
217     PropertyNotifySink_AddRef,
218     PropertyNotifySink_Release,
219     PropertyNotifySink_OnChanged,
220     PropertyNotifySink_OnRequestEdit
221 };
222
223 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
224
225 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
226 {
227     *ppv = NULL;
228
229     if(IsEqualGUID(riid, &IID_IUnknown)
230        || IsEqualGUID(riid, &IID_IDispatch)
231        || IsEqualGUID(riid, &IID_IDispatchEx))
232         *ppv = iface;
233     else
234         return E_NOINTERFACE;
235
236     return S_OK;
237 }
238
239 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
240 {
241     return 2;
242 }
243
244 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
245 {
246     return 1;
247 }
248
249 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
250 {
251     ok(0, "unexpected call\n");
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
256                                               LCID lcid, ITypeInfo **ppTInfo)
257 {
258     ok(0, "unexpected call\n");
259     return E_NOTIMPL;
260 }
261
262 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
263                                                 LPOLESTR *rgszNames, UINT cNames,
264                                                 LCID lcid, DISPID *rgDispId)
265 {
266     ok(0, "unexpected call\n");
267     return E_NOTIMPL;
268 }
269
270 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
271                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
272                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
273 {
274     ok(0, "unexpected call\n");
275     return E_NOTIMPL;
276 }
277
278 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
279 {
280     ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
281     return E_NOTIMPL;
282 }
283
284 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
285 {
286     ok(0, "unexpected call\n");
287     return E_NOTIMPL;
288 }
289
290 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
291 {
292     ok(0, "unexpected call\n");
293     return E_NOTIMPL;
294 }
295
296 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
297 {
298     ok(0, "unexpected call\n");
299     return E_NOTIMPL;
300 }
301
302 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
303 {
304     ok(0, "unexpected call\n");
305     return E_NOTIMPL;
306 }
307
308 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
309 {
310     ok(0, "unexpected call\n");
311     return E_NOTIMPL;
312 }
313
314 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
315 {
316     ok(0, "unexpected call\n");
317     return E_NOTIMPL;
318 }
319
320 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
321         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
322 {
323     CHECK_EXPECT(funcDisp);
324
325     ok(id == DISPID_VALUE, "id = %d\n", id);
326     ok(lcid == 0, "lcid = %x\n", lcid);
327     ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
328     ok(pdp != NULL, "pdp == NULL\n");
329     ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
330     ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
331     ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
332     ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
333     ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
334     ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
335     ok(pvarRes != NULL, "pvarRes == NULL\n");
336     ok(pei != NULL, "pei == NULL\n");
337     ok(!pspCaller, "pspCaller != NULL\n");
338
339     V_VT(pvarRes) = VT_I4;
340     V_I4(pvarRes) = 100;
341     return S_OK;
342 }
343
344 static IDispatchExVtbl testObjVtbl = {
345     DispatchEx_QueryInterface,
346     DispatchEx_AddRef,
347     DispatchEx_Release,
348     DispatchEx_GetTypeInfoCount,
349     DispatchEx_GetTypeInfo,
350     DispatchEx_GetIDsOfNames,
351     DispatchEx_Invoke,
352     DispatchEx_GetDispID,
353     funcDisp_InvokeEx,
354     DispatchEx_DeleteMemberByName,
355     DispatchEx_DeleteMemberByDispID,
356     DispatchEx_GetMemberProperties,
357     DispatchEx_GetMemberName,
358     DispatchEx_GetNextDispID,
359     DispatchEx_GetNameSpaceParent
360 };
361
362 static IDispatchEx funcDisp = { &testObjVtbl };
363
364 static HRESULT WINAPI scriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
365 {
366     if(!strcmp_wa(bstrName, "testProp")) {
367         CHECK_EXPECT(script_testprop_d);
368         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
369         *pid = DISPID_SCRIPT_TESTPROP;
370         return S_OK;
371     }
372
373     if(!strcmp_wa(bstrName, "divid")) {
374         CHECK_EXPECT(script_divid_d);
375         ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
376         return E_FAIL;
377     }
378
379     ok(0, "unexpected call\b");
380     return E_NOTIMPL;
381 }
382
383 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
384         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
385 {
386     switch(id) {
387     case DISPID_SCRIPT_TESTPROP:
388         CHECK_EXPECT(script_testprop_i);
389
390         ok(lcid == 0, "lcid = %x\n", lcid);
391         ok(wFlags == DISPATCH_PROPERTYGET, "wFlags = %x\n", wFlags);
392         ok(pdp != NULL, "pdp == NULL\n");
393         ok(pdp->cArgs == 0, "pdp->cArgs = %d\n", pdp->cArgs);
394         ok(pdp->cNamedArgs == 0, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
395         ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs != NULL\n");
396         ok(!pdp->rgvarg, "rgvarg != NULL\n");
397         ok(pvarRes != NULL, "pvarRes == NULL\n");
398         ok(pei != NULL, "pei == NULL\n");
399         ok(!pspCaller, "pspCaller != NULL\n");
400
401         V_VT(pvarRes) = VT_NULL;
402         break;
403     default:
404         ok(0, "unexpected call\n");
405         return E_NOTIMPL;
406     }
407
408     return S_OK;
409 }
410
411 static IDispatchExVtbl scriptDispVtbl = {
412     DispatchEx_QueryInterface,
413     DispatchEx_AddRef,
414     DispatchEx_Release,
415     DispatchEx_GetTypeInfoCount,
416     DispatchEx_GetTypeInfo,
417     DispatchEx_GetIDsOfNames,
418     DispatchEx_Invoke,
419     scriptDisp_GetDispID,
420     scriptDisp_InvokeEx,
421     DispatchEx_DeleteMemberByName,
422     DispatchEx_DeleteMemberByDispID,
423     DispatchEx_GetMemberProperties,
424     DispatchEx_GetMemberName,
425     DispatchEx_GetNextDispID,
426     DispatchEx_GetNameSpaceParent
427 };
428
429 static IDispatchEx scriptDisp = { &scriptDispVtbl };
430
431 static IHTMLDocument2 *create_document(void)
432 {
433     IHTMLDocument2 *doc;
434     HRESULT hres;
435
436     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
437             &IID_IHTMLDocument2, (void**)&doc);
438     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
439
440     return doc;
441 }
442
443 static IHTMLDocument2 *create_doc_with_string(const char *str)
444 {
445     IPersistStreamInit *init;
446     IStream *stream;
447     IHTMLDocument2 *doc;
448     HGLOBAL mem;
449     SIZE_T len;
450
451     notif_doc = doc = create_document();
452     if(!doc)
453         return NULL;
454
455     doc_complete = FALSE;
456     len = strlen(str);
457     mem = GlobalAlloc(0, len);
458     memcpy(mem, str, len);
459     CreateStreamOnHGlobal(mem, TRUE, &stream);
460
461     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
462
463     IPersistStreamInit_Load(init, stream);
464     IPersistStreamInit_Release(init);
465     IStream_Release(stream);
466
467     return doc;
468 }
469
470 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
471 {
472     IConnectionPointContainer *container;
473     IConnectionPoint *cp;
474     DWORD cookie;
475     HRESULT hres;
476
477     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
478     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
479
480     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
481     IConnectionPointContainer_Release(container);
482     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
483
484     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
485     IConnectionPoint_Release(cp);
486     ok(hres == S_OK, "Advise failed: %08x\n", hres);
487 }
488
489 typedef void (*domtest_t)(IHTMLDocument2*);
490
491 static IHTMLDocument2 *create_and_load_doc(const char *str)
492 {
493     IHTMLDocument2 *doc;
494     IHTMLElement *body = NULL;
495     ULONG ref;
496     MSG msg;
497     HRESULT hres;
498     static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
499     DISPID dispID = -1;
500     OLECHAR *name;
501
502
503     doc = create_doc_with_string(str);
504     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
505
506     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
507         TranslateMessage(&msg);
508         DispatchMessage(&msg);
509     }
510
511     hres = IHTMLDocument2_get_body(doc, &body);
512     ok(hres == S_OK, "get_body failed: %08x\n", hres);
513
514     if(!body) {
515         skip("Could not get document body. Assuming no Gecko installed.\n");
516         ref = IHTMLDocument2_Release(doc);
517         ok(!ref, "ref = %d\n", ref);
518         return NULL;
519     }
520
521     /* Check we can query for function on the IHTMLElementBody interface */
522     name = (WCHAR*)ucPtr;
523     hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
524     ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
525     ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
526
527     IHTMLElement_Release(body);
528     return doc;
529 }
530
531 static IActiveScriptSite *site;
532 static SCRIPTSTATE state;
533
534 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
535 {
536     *ppv = NULL;
537     ok(0, "unexpected call %s\n", debugstr_guid(riid));
538     return E_NOINTERFACE;
539 }
540
541 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
542 {
543     return 2;
544 }
545
546 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
547 {
548     return 1;
549 }
550
551 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
552         DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
553 {
554     CHECK_EXPECT(GetInterfaceSafetyOptions);
555
556     ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
557     ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
558     ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
559
560     *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
561     *pdwEnabledOptions = INTERFACE_USES_DISPEX;
562
563     return S_OK;
564 }
565
566 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
567         DWORD dwOptionSetMask, DWORD dwEnabledOptions)
568 {
569     CHECK_EXPECT(SetInterfaceSafetyOptions);
570
571     ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
572
573     ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
574        "dwOptionSetMask=%x\n", dwOptionSetMask);
575     ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
576        "dwEnabledOptions=%x\n", dwOptionSetMask);
577
578     return S_OK;
579 }
580
581 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
582     ObjectSafety_QueryInterface,
583     ObjectSafety_AddRef,
584     ObjectSafety_Release,
585     ObjectSafety_GetInterfaceSafetyOptions,
586     ObjectSafety_SetInterfaceSafetyOptions
587 };
588
589 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
590
591 static HRESULT WINAPI AXObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
592 {
593     *ppv = NULL;
594
595     if(IsEqualGUID(&IID_IActiveScript, riid)) {
596         CHECK_EXPECT(AXQueryInterface_IActiveScript);
597         return E_NOINTERFACE;
598     }
599
600     if(IsEqualGUID(&IID_IObjectSafety, riid)) {
601         CHECK_EXPECT(AXQueryInterface_IObjectSafety);
602         *ppv = iface;
603         return S_OK;
604     }
605
606     ok(0, "unexpected call %s\n", debugstr_guid(riid));
607     return E_NOINTERFACE;
608 }
609
610 static HRESULT WINAPI AXObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
611         DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
612 {
613     CHECK_EXPECT(AXGetInterfaceSafetyOptions);
614
615     ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
616     ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
617     ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
618
619     *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
620     *pdwEnabledOptions = INTERFACE_USES_DISPEX;
621
622     return S_OK;
623 }
624
625 static HRESULT WINAPI AXObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
626         DWORD dwOptionSetMask, DWORD dwEnabledOptions)
627 {
628     CHECK_EXPECT(AXSetInterfaceSafetyOptions);
629
630     ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
631
632     ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER),
633        "dwOptionSetMask=%x\n", dwOptionSetMask);
634     ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER),
635        "dwEnabledOptions=%x\n", dwOptionSetMask);
636
637     return S_OK;
638 }
639
640 static const IObjectSafetyVtbl AXObjectSafetyVtbl = {
641     AXObjectSafety_QueryInterface,
642     ObjectSafety_AddRef,
643     ObjectSafety_Release,
644     AXObjectSafety_GetInterfaceSafetyOptions,
645     AXObjectSafety_SetInterfaceSafetyOptions
646 };
647
648 static IObjectSafety AXObjectSafety = { &AXObjectSafetyVtbl };
649
650 static void test_security(void)
651 {
652     IInternetHostSecurityManager *sec_mgr;
653     IServiceProvider *sp;
654     DWORD policy, policy_size;
655     struct CONFIRMSAFETY cs;
656     BYTE *ppolicy;
657     HRESULT hres;
658
659     hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
660     ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
661
662     hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager,
663             &IID_IInternetHostSecurityManager, (void**)&sec_mgr);
664     IServiceProvider_Release(sp);
665     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
666
667     hres = IInternetHostSecurityManager_ProcessUrlAction(sec_mgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
668                                                          (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
669     ok(hres == S_OK, "ProcessUrlAction failed: %08x\n", hres);
670     ok(policy == URLPOLICY_ALLOW, "policy = %x\n", policy);
671
672     cs.clsid = CLSID_TestActiveX;
673     cs.pUnk = (IUnknown*)&AXObjectSafety;
674     cs.dwFlags = 0;
675
676     SET_EXPECT(AXQueryInterface_IActiveScript);
677     SET_EXPECT(AXQueryInterface_IObjectSafety);
678     SET_EXPECT(AXGetInterfaceSafetyOptions);
679     SET_EXPECT(AXSetInterfaceSafetyOptions);
680     hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
681             &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
682     CHECK_CALLED(AXQueryInterface_IActiveScript);
683     CHECK_CALLED(AXQueryInterface_IObjectSafety);
684     CHECK_CALLED(AXGetInterfaceSafetyOptions);
685     CHECK_CALLED(AXSetInterfaceSafetyOptions);
686
687     ok(hres == S_OK, "QueryCusromPolicy failed: %08x\n", hres);
688     ok(policy_size == sizeof(DWORD), "policy_size = %d\n", policy_size);
689     ok(*(DWORD*)ppolicy == URLPOLICY_ALLOW, "policy = %x\n", *(DWORD*)ppolicy);
690     CoTaskMemFree(ppolicy);
691
692     IInternetHostSecurityManager_Release(sec_mgr);
693 }
694
695 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
696 {
697     *ppv = NULL;
698     ok(0, "unexpected call\n");
699     return E_NOINTERFACE;
700 }
701
702 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
703 {
704     return 2;
705 }
706
707 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
708 {
709     return 1;
710 }
711
712 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
713         VARIANT *pvarIndex, VARIANT *pvarValue)
714 {
715     ok(0, "unexpected call\n");
716     return E_NOTIMPL;
717 }
718
719 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
720         VARIANT *pvarIndex, VARIANT *pvarValue)
721 {
722     switch(dwProperty) {
723     case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
724         CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
725         ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
726         ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
727         break;
728     case SCRIPTPROP_INVOKEVERSIONING:
729         CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
730         ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
731         ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
732         break;
733     case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
734         CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
735         ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
736         ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
737         break;
738     default:
739         ok(0, "unexpected property %x\n", dwProperty);
740         return E_NOTIMPL;
741     }
742
743     ok(!pvarIndex, "pvarIndex != NULL\n");
744     ok(pvarValue != NULL, "pvarValue == NULL\n");
745
746     return S_OK;
747 }
748
749 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
750     ActiveScriptProperty_QueryInterface,
751     ActiveScriptProperty_AddRef,
752     ActiveScriptProperty_Release,
753     ActiveScriptProperty_GetProperty,
754     ActiveScriptProperty_SetProperty
755 };
756
757 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
758
759 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
760 {
761     *ppv = NULL;
762     ok(0, "unexpected call\n");
763     return E_NOINTERFACE;
764 }
765
766 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
767 {
768     return 2;
769 }
770
771 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
772 {
773     return 1;
774 }
775
776 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
777         LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
778         LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
779         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
780 {
781     ok(0, "unexpected call\n");
782     return E_NOTIMPL;
783 }
784
785 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
786     ActiveScriptParseProcedure_QueryInterface,
787     ActiveScriptParseProcedure_AddRef,
788     ActiveScriptParseProcedure_Release,
789     ActiveScriptParseProcedure_ParseProcedureText
790 };
791
792 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
793
794 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
795 {
796     *ppv = NULL;
797     ok(0, "unexpected call\n");
798     return E_NOINTERFACE;
799 }
800
801 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
802 {
803     return 2;
804 }
805
806 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
807 {
808     return 1;
809 }
810
811 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
812 {
813     CHECK_EXPECT(InitNew);
814     return S_OK;
815 }
816
817 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
818         LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
819         LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
820         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
821         BSTR *pbstrName, EXCEPINFO *pexcepinfo)
822 {
823     ok(0, "unexpected call\n");
824     return E_NOTIMPL;
825 }
826
827 static HRESULT dispex_propput(IDispatchEx *obj, DISPID id, DWORD flags, VARIANT *var)
828 {
829     DISPID propput_arg = DISPID_PROPERTYPUT;
830     DISPPARAMS dp = {var, &propput_arg, 1, 1};
831     EXCEPINFO ei = {0};
832
833     return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT|flags, &dp, NULL, &ei, NULL);
834 }
835
836 static void test_func(IDispatchEx *obj)
837 {
838     DISPID id;
839     IDispatchEx *dispex;
840     IDispatch *disp;
841     EXCEPINFO ei;
842     DISPPARAMS dp;
843     BSTR str;
844     VARIANT var;
845     HRESULT hres;
846
847     str = a2bstr("toString");
848     hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
849     SysFreeString(str);
850     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
851     ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
852
853     memset(&dp, 0, sizeof(dp));
854     memset(&ei, 0, sizeof(ei));
855     VariantInit(&var);
856     hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
857     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
858     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
859     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
860     disp = V_DISPATCH(&var);
861
862     hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
863     IDispatch_Release(disp);
864     ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
865
866     /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
867
868     memset(&dp, 0, sizeof(dp));
869     memset(&ei, 0, sizeof(ei));
870     VariantInit(&var);
871     hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
872     ok(hres == S_OK || broken(E_ACCESSDENIED), "InvokeEx failed: %08x\n", hres);
873     if(SUCCEEDED(hres)) {
874         ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
875         ok(!strcmp_wa(V_BSTR(&var), "[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
876         VariantClear(&var);
877     }
878
879     V_VT(&var) = VT_I4;
880     V_I4(&var) = 100;
881     hres = dispex_propput(obj, id, 0, &var);
882     ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
883
884     IDispatchEx_Release(dispex);
885 }
886
887 static void test_nextdispid(IDispatchEx *dispex)
888 {
889     DISPID last_id = DISPID_STARTENUM, id, dyn_id;
890     BSTR name;
891     VARIANT var;
892     HRESULT hres;
893
894     name = a2bstr("dynVal");
895     hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive|fdexNameEnsure, &dyn_id);
896     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
897     SysFreeString(name);
898
899     V_VT(&var) = VT_EMPTY;
900     hres = dispex_propput(dispex, dyn_id, 0, &var);
901
902     while(last_id != dyn_id) {
903         hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, last_id, &id);
904         ok(hres == S_OK, "GetNextDispID returned: %08x\n", hres);
905         ok(id != DISPID_STARTENUM, "id == DISPID_STARTENUM\n");
906         ok(id != DISPID_IOMNAVIGATOR_TOSTRING, "id == DISPID_IOMNAVIGATOR_TOSTRING\n");
907
908         hres = IDispatchEx_GetMemberName(dispex, id, &name);
909         ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
910
911         if(id == dyn_id)
912             ok(!strcmp_wa(name, "dynVal"), "name = %s\n", wine_dbgstr_w(name));
913         else if(id == DISPID_IOMNAVIGATOR_PLATFORM)
914             ok(!strcmp_wa(name, "platform"), "name = %s\n", wine_dbgstr_w(name));
915
916         SysFreeString(name);
917         last_id = id;
918     }
919
920     hres = IDispatchEx_GetNextDispID(dispex, 0, id, &id);
921     ok(hres == S_FALSE, "GetNextDispID returned: %08x\n", hres);
922     ok(id == DISPID_STARTENUM, "id != DISPID_STARTENUM\n");
923 }
924
925 static void test_global_id(void)
926 {
927     VARIANT var;
928     DISPPARAMS dp;
929     EXCEPINFO ei;
930     BSTR tmp;
931     DISPID id;
932     HRESULT hres;
933
934     SET_EXPECT(GetScriptDispatch);
935     SET_EXPECT(script_divid_d);
936     tmp = a2bstr("divid");
937     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
938     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
939     SysFreeString(tmp);
940     CHECK_CALLED(GetScriptDispatch);
941     CHECK_CALLED(script_divid_d);
942
943     VariantInit(&var);
944     memset(&ei, 0, sizeof(ei));
945     memset(&dp, 0, sizeof(dp));
946     hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
947     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
948     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d\n", V_VT(&var));
949     VariantClear(&var);
950 }
951
952 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
953         LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
954         LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
955         DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
956 {
957     IDispatchEx *document, *dispex;
958     IHTMLWindow2 *window;
959     IOmNavigator *navigator;
960     IUnknown *unk;
961     VARIANT var, arg;
962     DISPPARAMS dp;
963     EXCEPINFO ei;
964     DISPID id;
965     BSTR tmp;
966     HRESULT hres;
967
968     static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
969     static const WCHAR testW[] = {'t','e','s','t',0};
970     static const WCHAR funcW[] = {'f','u','n','c',0};
971
972     CHECK_EXPECT(ParseScriptText);
973
974     SET_EXPECT(GetScriptDispatch);
975
976     tmp = SysAllocString(documentW);
977     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
978     SysFreeString(tmp);
979     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
980     ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
981
982     CHECK_CALLED(GetScriptDispatch);
983
984     VariantInit(&var);
985     memset(&dp, 0, sizeof(dp));
986     memset(&ei, 0, sizeof(ei));
987
988     hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
989     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
990     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
991     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
992
993     hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
994     VariantClear(&var);
995     ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
996
997     tmp = SysAllocString(testW);
998     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
999     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1000     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
1001     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1002     SysFreeString(tmp);
1003
1004     id = 0;
1005     tmp = SysAllocString(testW);
1006     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
1007     SysFreeString(tmp);
1008     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1009     ok(id, "id == 0\n");
1010
1011     V_VT(&var) = VT_I4;
1012     V_I4(&var) = 100;
1013     hres = dispex_propput(document, id, 0, &var);
1014     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1015
1016     tmp = SysAllocString(testW);
1017     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
1018     SysFreeString(tmp);
1019     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1020
1021     VariantInit(&var);
1022     memset(&dp, 0, sizeof(dp));
1023     memset(&ei, 0, sizeof(ei));
1024     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1025     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1026     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1027     ok(V_I4(&var) == 100, "V_I4(&var) = %d\n", V_I4(&var));
1028
1029     V_VT(&var) = VT_I4;
1030     V_I4(&var) = 200;
1031     hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var);
1032     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1033
1034     VariantInit(&var);
1035     memset(&dp, 0, sizeof(dp));
1036     memset(&ei, 0, sizeof(ei));
1037     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1038     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1039     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1040     ok(V_I4(&var) == 200, "V_I4(&var) = %d\n", V_I4(&var));
1041
1042     memset(&dp, 0, sizeof(dp));
1043     memset(&ei, 0, sizeof(ei));
1044     V_VT(&var) = VT_I4;
1045     V_I4(&var) = 300;
1046     dp.cArgs = 1;
1047     dp.rgvarg = &var;
1048     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
1049     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1050
1051     VariantInit(&var);
1052     memset(&dp, 0, sizeof(dp));
1053     memset(&ei, 0, sizeof(ei));
1054     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1055     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1056     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1057     ok(V_I4(&var) == 300, "V_I4(&var) = %d\n", V_I4(&var));
1058
1059     unk = (void*)0xdeadbeef;
1060     hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
1061     ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
1062     ok(!unk, "unk=%p, expected NULL\n", unk);
1063
1064     id = 0;
1065     tmp = SysAllocString(funcW);
1066     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
1067     SysFreeString(tmp);
1068     ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
1069     ok(id, "id == 0\n");
1070
1071     dp.cArgs = 1;
1072     dp.rgvarg = &var;
1073     dp.cNamedArgs = 0;
1074     dp.rgdispidNamedArgs = NULL;
1075     V_VT(&var) = VT_DISPATCH;
1076     V_DISPATCH(&var) = (IDispatch*)&funcDisp;
1077     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
1078     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1079
1080     VariantInit(&var);
1081     memset(&dp, 0, sizeof(dp));
1082     memset(&ei, 0, sizeof(ei));
1083     V_VT(&arg) = VT_BOOL;
1084     V_BOOL(&arg) = VARIANT_TRUE;
1085     dp.cArgs = 1;
1086     dp.rgvarg = &arg;
1087
1088     SET_EXPECT(funcDisp);
1089     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
1090     CHECK_CALLED(funcDisp);
1091
1092     ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
1093     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1094     ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
1095
1096     IDispatchEx_Release(document);
1097
1098     hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
1099     ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
1100
1101     hres = IHTMLWindow2_get_navigator(window, &navigator);
1102     IHTMLWindow2_Release(window);
1103     ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1104
1105     hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
1106     IOmNavigator_Release(navigator);
1107     ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1108
1109     test_func(dispex);
1110     test_nextdispid(dispex);
1111     IDispatchEx_Release(dispex);
1112
1113     script_disp = (IDispatch*)&scriptDisp;
1114
1115     SET_EXPECT(GetScriptDispatch);
1116     SET_EXPECT(script_testprop_d);
1117     tmp = a2bstr("testProp");
1118     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1119     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1120     ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
1121     CHECK_CALLED(GetScriptDispatch);
1122     CHECK_CALLED(script_testprop_d);
1123     SysFreeString(tmp);
1124
1125     tmp = a2bstr("testProp");
1126     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1127     ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1128     ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
1129     SysFreeString(tmp);
1130
1131     SET_EXPECT(GetScriptDispatch);
1132     SET_EXPECT(script_testprop_i);
1133     memset(&ei, 0, sizeof(ei));
1134     memset(&dp, 0, sizeof(dp));
1135     hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1136     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1137     ok(V_VT(&var) == VT_NULL, "V_VT(var) = %d\n", V_VT(&var));
1138     CHECK_CALLED(GetScriptDispatch);
1139     CHECK_CALLED(script_testprop_i);
1140
1141     test_global_id();
1142
1143     test_security();
1144
1145     return S_OK;
1146 }
1147
1148 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
1149     ActiveScriptParse_QueryInterface,
1150     ActiveScriptParse_AddRef,
1151     ActiveScriptParse_Release,
1152     ActiveScriptParse_InitNew,
1153     ActiveScriptParse_AddScriptlet,
1154     ActiveScriptParse_ParseScriptText
1155 };
1156
1157 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
1158
1159 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
1160 {
1161     *ppv = NULL;
1162
1163     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
1164         *ppv = iface;
1165         return S_OK;
1166     }
1167
1168     if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
1169         *ppv = &ActiveScriptParse;
1170         return S_OK;
1171     }
1172
1173     if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
1174         *ppv = &ActiveScriptParseProcedure;
1175         return S_OK;
1176     }
1177
1178     if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
1179         *ppv = &ActiveScriptProperty;
1180         return S_OK;
1181     }
1182
1183     if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1184         *ppv = &ObjectSafety;
1185         return S_OK;
1186     }
1187
1188     if(IsEqualGUID(&IID_IActiveScriptDebug, riid))
1189         return E_NOINTERFACE;
1190
1191     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1192     return E_NOINTERFACE;
1193 }
1194
1195 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
1196 {
1197     return 2;
1198 }
1199
1200 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
1201 {
1202     return 1;
1203 }
1204
1205 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
1206 {
1207     IActiveScriptSiteInterruptPoll *poll;
1208     IActiveScriptSiteDebug *debug;
1209     IServiceProvider *service;
1210     ICanHandleException *canexpection;
1211     LCID lcid;
1212     HRESULT hres;
1213
1214     CHECK_EXPECT(SetScriptSite);
1215
1216     ok(pass != NULL, "pass == NULL\n");
1217
1218     hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
1219     ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
1220     if(FAILED(hres))
1221         IActiveScriptSiteInterruptPoll_Release(poll);
1222
1223     hres = IActiveScriptSite_GetLCID(pass, &lcid);
1224     ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
1225
1226     hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
1227     ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
1228
1229     hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
1230     ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
1231     if(SUCCEEDED(hres))
1232         IActiveScriptSiteDebug32_Release(debug);
1233
1234     hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
1235     ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
1236
1237     hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
1238     ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
1239     if(SUCCEEDED(hres))
1240         IServiceProvider_Release(service);
1241
1242     site = pass;
1243     IActiveScriptSite_AddRef(site);
1244     return S_OK;
1245 }
1246
1247 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
1248                                             void **ppvObject)
1249 {
1250     ok(0, "unexpected call\n");
1251     return E_NOTIMPL;
1252 }
1253
1254 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
1255 {
1256     HRESULT hres;
1257
1258     switch(ss) {
1259     case SCRIPTSTATE_STARTED:
1260         CHECK_EXPECT(SetScriptState_STARTED);
1261         break;
1262     case SCRIPTSTATE_CONNECTED:
1263         CHECK_EXPECT(SetScriptState_CONNECTED);
1264         break;
1265     case SCRIPTSTATE_DISCONNECTED:
1266         CHECK_EXPECT(SetScriptState_DISCONNECTED);
1267         break;
1268     default:
1269         ok(0, "unexpected state %d\n", ss);
1270         return E_NOTIMPL;
1271     }
1272
1273     hres = IActiveScriptSite_OnStateChange(site, (state = ss));
1274     return S_OK;
1275 }
1276
1277 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
1278 {
1279     CHECK_EXPECT(GetScriptState);
1280
1281     *pssState = state;
1282     return S_OK;
1283 }
1284
1285 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
1286 {
1287     CHECK_EXPECT(Close);
1288     return E_NOTIMPL;
1289 }
1290
1291 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
1292         LPCOLESTR pstrName, DWORD dwFlags)
1293 {
1294     IDispatch *disp;
1295     IUnknown *unk = NULL, *unk2;
1296     HRESULT hres;
1297
1298     static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
1299
1300     static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
1301
1302     CHECK_EXPECT(AddNamedItem);
1303
1304     ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
1305     ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
1306
1307     hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
1308     ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
1309     ok(unk != NULL, "unk == NULL\n");
1310
1311     hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
1312     ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
1313     if(SUCCEEDED(hres))
1314         IDispatch_Release(disp);
1315
1316     hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
1317     ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
1318     if(SUCCEEDED(hres))
1319         IUnknown_Release(unk2);
1320
1321     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
1322     ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
1323
1324     IUnknown_Release(unk);
1325     return S_OK;
1326 }
1327
1328 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
1329                                          DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
1330 {
1331     ok(0, "unexpected call\n");
1332     return E_NOTIMPL;
1333 }
1334
1335 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
1336                                                 IDispatch **ppdisp)
1337 {
1338     CHECK_EXPECT(GetScriptDispatch);
1339
1340     ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
1341
1342     if(!script_disp)
1343         return E_NOTIMPL;
1344
1345     *ppdisp = script_disp;
1346     return S_OK;
1347 }
1348
1349 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
1350                                                        SCRIPTTHREADID *pstridThread)
1351 {
1352     ok(0, "unexpected call\n");
1353     return E_NOTIMPL;
1354 }
1355
1356 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
1357                                                 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
1358 {
1359     ok(0, "unexpected call\n");
1360     return E_NOTIMPL;
1361 }
1362
1363 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
1364         SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
1365 {
1366     ok(0, "unexpected call\n");
1367     return E_NOTIMPL;
1368 }
1369
1370 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
1371         SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
1372 {
1373     ok(0, "unexpected call\n");
1374     return E_NOTIMPL;
1375 }
1376
1377 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
1378 {
1379     ok(0, "unexpected call\n");
1380     return E_NOTIMPL;
1381 }
1382
1383 static const IActiveScriptVtbl ActiveScriptVtbl = {
1384     ActiveScript_QueryInterface,
1385     ActiveScript_AddRef,
1386     ActiveScript_Release,
1387     ActiveScript_SetScriptSite,
1388     ActiveScript_GetScriptSite,
1389     ActiveScript_SetScriptState,
1390     ActiveScript_GetScriptState,
1391     ActiveScript_Close,
1392     ActiveScript_AddNamedItem,
1393     ActiveScript_AddTypeLib,
1394     ActiveScript_GetScriptDispatch,
1395     ActiveScript_GetCurrentScriptThreadID,
1396     ActiveScript_GetScriptThreadID,
1397     ActiveScript_GetScriptThreadState,
1398     ActiveScript_InterruptScriptThread,
1399     ActiveScript_Clone
1400 };
1401
1402 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
1403
1404 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1405 {
1406     *ppv = NULL;
1407
1408     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1409         *ppv = iface;
1410         return S_OK;
1411     }
1412
1413     if(IsEqualGUID(&IID_IMarshal, riid))
1414         return E_NOINTERFACE;
1415     if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1416         return E_NOINTERFACE;
1417
1418     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1419     return E_NOTIMPL;
1420 }
1421
1422 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1423 {
1424     return 2;
1425 }
1426
1427 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1428 {
1429     return 1;
1430 }
1431
1432 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1433 {
1434     CHECK_EXPECT(CreateInstance);
1435
1436     ok(!outer, "outer = %p\n", outer);
1437     ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
1438     *ppv = &ActiveScript;
1439     return S_OK;
1440 }
1441
1442 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1443 {
1444     ok(0, "unexpected call\n");
1445     return S_OK;
1446 }
1447
1448 static const IClassFactoryVtbl ClassFactoryVtbl = {
1449     ClassFactory_QueryInterface,
1450     ClassFactory_AddRef,
1451     ClassFactory_Release,
1452     ClassFactory_CreateInstance,
1453     ClassFactory_LockServer
1454 };
1455
1456 static IClassFactory script_cf = { &ClassFactoryVtbl };
1457
1458 static const char simple_script_str[] =
1459     "<html><head></head><body>"
1460     "<div id=\"divid\"></div>"
1461     "<script language=\"TestScript\">simple script</script>"
1462     "</body></html>";
1463
1464 static void test_simple_script(void)
1465 {
1466     IHTMLDocument2 *doc;
1467
1468     SET_EXPECT(CreateInstance);
1469     SET_EXPECT(GetInterfaceSafetyOptions);
1470     SET_EXPECT(SetInterfaceSafetyOptions);
1471     SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
1472     SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1473     SET_EXPECT(InitNew);
1474     SET_EXPECT(SetScriptSite);
1475     SET_EXPECT(GetScriptState);
1476     SET_EXPECT(SetScriptState_STARTED);
1477     SET_EXPECT(AddNamedItem);
1478     SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
1479     SET_EXPECT(ParseScriptText);
1480     SET_EXPECT(SetScriptState_CONNECTED);
1481
1482     doc = create_and_load_doc(simple_script_str);
1483     if(!doc) return;
1484
1485     CHECK_CALLED(CreateInstance);
1486     CHECK_CALLED(GetInterfaceSafetyOptions);
1487     CHECK_CALLED(SetInterfaceSafetyOptions);
1488     CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
1489     CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
1490     CHECK_CALLED(InitNew);
1491     CHECK_CALLED(SetScriptSite);
1492     CHECK_CALLED(GetScriptState);
1493     CHECK_CALLED(SetScriptState_STARTED);
1494     CHECK_CALLED(AddNamedItem);
1495     CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
1496     CHECK_CALLED(ParseScriptText);
1497     CHECK_CALLED(SetScriptState_CONNECTED);
1498
1499     if(site)
1500         IActiveScriptSite_Release(site);
1501     if(window_dispex)
1502         IDispatchEx_Release(window_dispex);
1503
1504     SET_EXPECT(SetScriptState_DISCONNECTED);
1505     SET_EXPECT(Close);
1506
1507     IHTMLDocument2_Release(doc);
1508
1509     CHECK_CALLED(SetScriptState_DISCONNECTED);
1510     CHECK_CALLED(Close);
1511 }
1512
1513 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1514 {
1515     HKEY hkey;
1516     DWORD res;
1517
1518     if(!init) {
1519         RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1520         return TRUE;
1521     }
1522
1523     res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1524     if(res != ERROR_SUCCESS)
1525         return FALSE;
1526
1527     if(def_value)
1528         res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1529
1530     RegCloseKey(hkey);
1531
1532     return res == ERROR_SUCCESS;
1533 }
1534
1535 static BOOL init_registry(BOOL init)
1536 {
1537     return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1538         && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1539                     NULL, init)
1540         && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1541                     NULL, init);
1542 }
1543
1544 static BOOL register_script_engine(void)
1545 {
1546     DWORD regid;
1547     HRESULT hres;
1548
1549     if(!init_registry(TRUE)) {
1550         init_registry(FALSE);
1551         return FALSE;
1552     }
1553
1554     hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1555                                  CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1556     ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1557
1558     return TRUE;
1559 }
1560
1561 static void gecko_installer_workaround(BOOL disable)
1562 {
1563     HKEY hkey;
1564     DWORD res;
1565
1566     static BOOL has_url = FALSE;
1567     static char url[2048];
1568
1569     if(!disable && !has_url)
1570         return;
1571
1572     res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1573     if(res != ERROR_SUCCESS)
1574         return;
1575
1576     if(disable) {
1577         DWORD type, size = sizeof(url);
1578
1579         res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1580         if(res == ERROR_SUCCESS && type == REG_SZ)
1581             has_url = TRUE;
1582
1583         RegDeleteValue(hkey, "GeckoUrl");
1584     }else {
1585         RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1586     }
1587
1588     RegCloseKey(hkey);
1589 }
1590
1591 START_TEST(script)
1592 {
1593     gecko_installer_workaround(TRUE);
1594     CoInitialize(NULL);
1595
1596     if(winetest_interactive || ! is_ie_hardened()) {
1597         if(register_script_engine()) {
1598             test_simple_script();
1599             init_registry(FALSE);
1600         }else {
1601             skip("Could not register TestScript engine\n");
1602         }
1603     }else {
1604         skip("IE running in Enhanced Security Configuration\n");
1605     }
1606
1607     CoUninitialize();
1608     gecko_installer_workaround(FALSE);
1609 }