activscp.idl: Added IActiveScriptParseProcedure*64 interfaces and use it on Win64.
[wine] / dlls / mshtml / tests / script.c
1 /*
2  * Copyright 2008 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
37 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
38
39 #ifdef _WIN64
40
41 #define CTXARG_T DWORDLONG
42 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
43 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
44
45 #else
46
47 #define CTXARG_T DWORD
48 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
49 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
50
51 #endif
52
53 #define DEFINE_EXPECT(func) \
54     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
55
56 #define SET_EXPECT(func) \
57     do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
58
59 #define CHECK_EXPECT2(func) \
60     do { \
61         ok(expect_ ##func, "unexpected call " #func "\n"); \
62         called_ ## func = TRUE; \
63     }while(0)
64
65 #define CHECK_EXPECT(func) \
66     do { \
67         CHECK_EXPECT2(func); \
68         expect_ ## func = FALSE; \
69     }while(0)
70
71 #define CHECK_CALLED(func) \
72     do { \
73         ok(called_ ## func, "expected " #func "\n"); \
74         expect_ ## func = called_ ## func = FALSE; \
75     }while(0)
76
77 #define CHECK_NOT_CALLED(func) \
78     do { \
79         ok(!called_ ## func, "unexpected " #func "\n"); \
80         expect_ ## func = called_ ## func = FALSE; \
81     }while(0)
82
83 #define CLEAR_CALLED(func) \
84     expect_ ## func = called_ ## func = FALSE
85
86
87 DEFINE_EXPECT(CreateInstance);
88 DEFINE_EXPECT(GetInterfaceSafetyOptions);
89 DEFINE_EXPECT(SetInterfaceSafetyOptions);
90 DEFINE_EXPECT(InitNew);
91 DEFINE_EXPECT(Close);
92 DEFINE_EXPECT(SetProperty);
93 DEFINE_EXPECT(SetScriptSite);
94 DEFINE_EXPECT(GetScriptState);
95 DEFINE_EXPECT(SetScriptState_STARTED);
96 DEFINE_EXPECT(SetScriptState_CONNECTED);
97 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
98 DEFINE_EXPECT(AddNamedItem);
99 DEFINE_EXPECT(ParseScriptText);
100 DEFINE_EXPECT(GetScriptDispatch);
101 DEFINE_EXPECT(funcDisp);
102
103 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
104
105 static const GUID CLSID_TestScript =
106     {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
107
108 static IHTMLDocument2 *notif_doc;
109 static IDispatchEx *window_dispex;
110 static BOOL doc_complete;
111
112 static const char *debugstr_w(LPCWSTR str)
113 {
114     static char buf[1024];
115     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
116     return buf;
117 }
118
119 static const char *debugstr_guid(REFIID riid)
120 {
121     static char buf[50];
122
123     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
124             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
125             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
126             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
127
128     return buf;
129 }
130
131 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
132         REFIID riid, void**ppv)
133 {
134     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
135         *ppv = iface;
136         return S_OK;
137     }
138
139     return E_NOINTERFACE;
140 }
141
142 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
143 {
144     return 2;
145 }
146
147 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
148 {
149     return 1;
150 }
151
152 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
153 {
154     if(dispID == DISPID_READYSTATE){
155         BSTR state;
156         HRESULT hres;
157
158         static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
159
160         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
161         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
162
163         if(!lstrcmpW(state, completeW))
164             doc_complete = TRUE;
165
166         SysFreeString(state);
167     }
168
169     return S_OK;
170 }
171
172 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
173 {
174     ok(0, "unexpected call\n");
175     return E_NOTIMPL;
176 }
177
178 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
179     PropertyNotifySink_QueryInterface,
180     PropertyNotifySink_AddRef,
181     PropertyNotifySink_Release,
182     PropertyNotifySink_OnChanged,
183     PropertyNotifySink_OnRequestEdit
184 };
185
186 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
187
188 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
189 {
190     *ppv = NULL;
191
192     if(IsEqualGUID(riid, &IID_IUnknown)
193        || IsEqualGUID(riid, &IID_IDispatch)
194        || IsEqualGUID(riid, &IID_IDispatchEx))
195         *ppv = iface;
196     else
197         return E_NOINTERFACE;
198
199     return S_OK;
200 }
201
202 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
203 {
204     return 2;
205 }
206
207 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
208 {
209     return 1;
210 }
211
212 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
213 {
214     ok(0, "unexpected call\n");
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
219                                               LCID lcid, ITypeInfo **ppTInfo)
220 {
221     ok(0, "unexpected call\n");
222     return E_NOTIMPL;
223 }
224
225 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
226                                                 LPOLESTR *rgszNames, UINT cNames,
227                                                 LCID lcid, DISPID *rgDispId)
228 {
229     ok(0, "unexpected call\n");
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
234                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
235                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
236 {
237     ok(0, "unexpected call\n");
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
242 {
243     ok(0, "unexpected call %s %x\n", debugstr_w(bstrName), grfdex);
244     return E_NOTIMPL;
245 }
246
247 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
248 {
249     ok(0, "unexpected call\n");
250     return E_NOTIMPL;
251 }
252
253 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
254 {
255     ok(0, "unexpected call\n");
256     return E_NOTIMPL;
257 }
258
259 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
260 {
261     ok(0, "unexpected call\n");
262     return E_NOTIMPL;
263 }
264
265 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
266 {
267     ok(0, "unexpected call\n");
268     return E_NOTIMPL;
269 }
270
271 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
272 {
273     ok(0, "unexpected call\n");
274     return E_NOTIMPL;
275 }
276
277 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
278 {
279     ok(0, "unexpected call\n");
280     return E_NOTIMPL;
281 }
282
283 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
284         VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
285 {
286     CHECK_EXPECT(funcDisp);
287
288     ok(id == DISPID_VALUE, "id = %d\n", id);
289     ok(lcid == 0, "lcid = %x\n", lcid);
290     ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
291     ok(pdp != NULL, "pdp == NULL\n");
292     ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
293     ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
294     ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
295     ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
296     ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
297     ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
298     ok(pvarRes != NULL, "pvarRes == NULL\n");
299     ok(pei != NULL, "pei == NULL\n");
300     ok(!pspCaller, "pspCaller != NULL\n");
301
302     V_VT(pvarRes) = VT_I4;
303     V_I4(pvarRes) = 100;
304     return S_OK;
305 }
306
307 static IDispatchExVtbl testObjVtbl = {
308     DispatchEx_QueryInterface,
309     DispatchEx_AddRef,
310     DispatchEx_Release,
311     DispatchEx_GetTypeInfoCount,
312     DispatchEx_GetTypeInfo,
313     DispatchEx_GetIDsOfNames,
314     DispatchEx_Invoke,
315     DispatchEx_GetDispID,
316     funcDisp_InvokeEx,
317     DispatchEx_DeleteMemberByName,
318     DispatchEx_DeleteMemberByDispID,
319     DispatchEx_GetMemberProperties,
320     DispatchEx_GetMemberName,
321     DispatchEx_GetNextDispID,
322     DispatchEx_GetNameSpaceParent
323 };
324
325 static IDispatchEx funcDisp = { &testObjVtbl };
326
327 static IHTMLDocument2 *create_document(void)
328 {
329     IHTMLDocument2 *doc;
330     HRESULT hres;
331
332     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
333             &IID_IHTMLDocument2, (void**)&doc);
334     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
335
336     return doc;
337 }
338
339 static IHTMLDocument2 *create_doc_with_string(const char *str)
340 {
341     IPersistStreamInit *init;
342     IStream *stream;
343     IHTMLDocument2 *doc;
344     HGLOBAL mem;
345     SIZE_T len;
346
347     notif_doc = doc = create_document();
348     if(!doc)
349         return NULL;
350
351     doc_complete = FALSE;
352     len = strlen(str);
353     mem = GlobalAlloc(0, len);
354     memcpy(mem, str, len);
355     CreateStreamOnHGlobal(mem, TRUE, &stream);
356
357     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
358
359     IPersistStreamInit_Load(init, stream);
360     IPersistStreamInit_Release(init);
361     IStream_Release(stream);
362
363     return doc;
364 }
365
366 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
367 {
368     IConnectionPointContainer *container;
369     IConnectionPoint *cp;
370     DWORD cookie;
371     HRESULT hres;
372
373     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
374     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
375
376     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
377     IConnectionPointContainer_Release(container);
378     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
379
380     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
381     IConnectionPoint_Release(cp);
382     ok(hres == S_OK, "Advise failed: %08x\n", hres);
383 }
384
385 typedef void (*domtest_t)(IHTMLDocument2*);
386
387 static IHTMLDocument2 *create_and_load_doc(const char *str)
388 {
389     IHTMLDocument2 *doc;
390     IHTMLElement *body = NULL;
391     ULONG ref;
392     MSG msg;
393     HRESULT hres;
394     static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
395     DISPID dispID = -1;
396     OLECHAR *name;
397
398
399     doc = create_doc_with_string(str);
400     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
401
402     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
403         TranslateMessage(&msg);
404         DispatchMessage(&msg);
405     }
406
407     hres = IHTMLDocument2_get_body(doc, &body);
408     ok(hres == S_OK, "get_body failed: %08x\n", hres);
409
410     if(!body) {
411         skip("Could not get document body. Assuming no Gecko installed.\n");
412         ref = IHTMLDocument2_Release(doc);
413         ok(!ref, "ref = %d\n", ref);
414         return NULL;
415     }
416
417     /* Check we can query for function on the IHTMLElementBody interface */
418     name = (WCHAR*)ucPtr;
419     hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
420     ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
421     ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
422
423     IHTMLElement_Release(body);
424     return doc;
425 }
426
427 static IActiveScriptSite *site;
428 static SCRIPTSTATE state;
429
430 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
431 {
432     *ppv = NULL;
433     ok(0, "unexpected call\n");
434     return E_NOINTERFACE;
435 }
436
437 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
438 {
439     return 2;
440 }
441
442 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
443 {
444     return 1;
445 }
446
447 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
448         DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
449 {
450     CHECK_EXPECT(GetInterfaceSafetyOptions);
451
452     ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
453     ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
454     ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
455
456     *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
457     *pdwEnabledOptions = INTERFACE_USES_DISPEX;
458
459     return S_OK;
460 }
461
462 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
463         DWORD dwOptionSetMask, DWORD dwEnabledOptions)
464 {
465     CHECK_EXPECT(SetInterfaceSafetyOptions);
466
467     ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
468
469     ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
470        "dwOptionSetMask=%x\n", dwOptionSetMask);
471     ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
472        "dwEnabledOptions=%x\n", dwOptionSetMask);
473
474     return S_OK;
475 }
476
477 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
478     ObjectSafety_QueryInterface,
479     ObjectSafety_AddRef,
480     ObjectSafety_Release,
481     ObjectSafety_GetInterfaceSafetyOptions,
482     ObjectSafety_SetInterfaceSafetyOptions
483 };
484
485 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
486
487 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
488 {
489     *ppv = NULL;
490     ok(0, "unexpected call\n");
491     return E_NOINTERFACE;
492 }
493
494 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
495 {
496     return 2;
497 }
498
499 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
500 {
501     return 1;
502 }
503
504 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
505         VARIANT *pvarIndex, VARIANT *pvarValue)
506 {
507     ok(0, "unexpected call\n");
508     return E_NOTIMPL;
509 }
510
511 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
512         VARIANT *pvarIndex, VARIANT *pvarValue)
513 {
514     CHECK_EXPECT(SetProperty);
515
516     ok(dwProperty == SCRIPTPROP_HACK_TRIDENTEVENTSINK, "unexpected property %d\n", dwProperty);
517     ok(!pvarIndex, "pvarIndex != NULL\n");
518     ok(pvarValue != NULL, "pvarValue == NULL\n");
519     ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
520     ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
521
522     return E_NOTIMPL;
523 }
524
525 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
526     ActiveScriptProperty_QueryInterface,
527     ActiveScriptProperty_AddRef,
528     ActiveScriptProperty_Release,
529     ActiveScriptProperty_GetProperty,
530     ActiveScriptProperty_SetProperty
531 };
532
533 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
534
535 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
536 {
537     *ppv = NULL;
538     ok(0, "unexpected call\n");
539     return E_NOINTERFACE;
540 }
541
542 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
543 {
544     return 2;
545 }
546
547 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
548 {
549     return 1;
550 }
551
552 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
553         LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
554         LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
555         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
556 {
557     ok(0, "unexpected call\n");
558     return E_NOTIMPL;
559 }
560
561 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
562     ActiveScriptParseProcedure_QueryInterface,
563     ActiveScriptParseProcedure_AddRef,
564     ActiveScriptParseProcedure_Release,
565     ActiveScriptParseProcedure_ParseProcedureText
566 };
567
568 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
569
570 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
571 {
572     *ppv = NULL;
573     ok(0, "unexpected call\n");
574     return E_NOINTERFACE;
575 }
576
577 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
578 {
579     return 2;
580 }
581
582 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
583 {
584     return 1;
585 }
586
587 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
588 {
589     CHECK_EXPECT(InitNew);
590     return S_OK;
591 }
592
593 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
594         LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
595         LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
596         CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
597         BSTR *pbstrName, EXCEPINFO *pexcepinfo)
598 {
599     ok(0, "unexpected call\n");
600     return E_NOTIMPL;
601 }
602
603 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
604         LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
605         LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
606         DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
607 {
608     IDispatchEx *document;
609     IUnknown *unk;
610     VARIANT var, arg;
611     DISPPARAMS dp;
612     EXCEPINFO ei;
613     DISPID id, named_arg = DISPID_PROPERTYPUT;
614     BSTR tmp;
615     HRESULT hres;
616
617     static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
618     static const WCHAR testW[] = {'t','e','s','t',0};
619     static const WCHAR funcW[] = {'f','u','n','c',0};
620
621     CHECK_EXPECT(ParseScriptText);
622
623     SET_EXPECT(GetScriptDispatch);
624
625     tmp = SysAllocString(documentW);
626     hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
627     SysFreeString(tmp);
628     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
629     ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
630
631     todo_wine CHECK_CALLED(GetScriptDispatch);
632
633     VariantInit(&var);
634     memset(&dp, 0, sizeof(dp));
635     memset(&ei, 0, sizeof(ei));
636
637     hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
638     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
639     ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
640     ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
641
642     hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
643     VariantClear(&var);
644     ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
645
646     tmp = SysAllocString(testW);
647     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
648     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
649     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
650     ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
651     SysFreeString(tmp);
652
653     id = 0;
654     tmp = SysAllocString(testW);
655     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
656     SysFreeString(tmp);
657     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
658     ok(id, "id == 0\n");
659
660     dp.cArgs = 1;
661     dp.rgvarg = &var;
662     dp.cNamedArgs = 1;
663     dp.rgdispidNamedArgs = &named_arg;
664     V_VT(&var) = VT_I4;
665     V_I4(&var) = 100;
666
667     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
668     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
669
670     tmp = SysAllocString(testW);
671     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
672     SysFreeString(tmp);
673     ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
674
675     VariantInit(&var);
676     memset(&dp, 0, sizeof(dp));
677     memset(&ei, 0, sizeof(ei));
678     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
679     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
680     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
681     ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
682
683     unk = (void*)0xdeadbeef;
684     hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
685     ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
686     ok(!unk, "unk=%p, expected NULL\n", unk);
687
688     id = 0;
689     tmp = SysAllocString(funcW);
690     hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
691     SysFreeString(tmp);
692     ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
693     ok(id, "id == 0\n");
694
695     dp.cArgs = 1;
696     dp.rgvarg = &var;
697     dp.cNamedArgs = 0;
698     dp.rgdispidNamedArgs = NULL;
699     V_VT(&var) = VT_DISPATCH;
700     V_DISPATCH(&var) = (IDispatch*)&funcDisp;
701
702     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
703     ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
704
705     VariantInit(&var);
706     memset(&dp, 0, sizeof(dp));
707     memset(&ei, 0, sizeof(ei));
708     V_VT(&arg) = VT_BOOL;
709     V_BOOL(&arg) = VARIANT_TRUE;
710     dp.cArgs = 1;
711     dp.rgvarg = &arg;
712
713     SET_EXPECT(funcDisp);
714     hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
715     CHECK_CALLED(funcDisp);
716
717     ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
718     ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
719     ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
720
721     IDispatchEx_Release(document);
722
723     return S_OK;
724 }
725
726 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
727     ActiveScriptParse_QueryInterface,
728     ActiveScriptParse_AddRef,
729     ActiveScriptParse_Release,
730     ActiveScriptParse_InitNew,
731     ActiveScriptParse_AddScriptlet,
732     ActiveScriptParse_ParseScriptText
733 };
734
735 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
736
737 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
738 {
739     *ppv = NULL;
740
741     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
742         *ppv = iface;
743         return S_OK;
744     }
745
746     if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
747         *ppv = &ActiveScriptParse;
748         return S_OK;
749     }
750
751     if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
752         *ppv = &ActiveScriptParseProcedure;
753         return S_OK;
754     }
755
756     if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
757         *ppv = &ActiveScriptProperty;
758         return S_OK;
759     }
760
761     if(IsEqualGUID(&IID_IObjectSafety, riid)) {
762         *ppv = &ObjectSafety;
763         return S_OK;
764     }
765
766     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
767     return E_NOINTERFACE;
768 }
769
770 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
771 {
772     return 2;
773 }
774
775 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
776 {
777     return 1;
778 }
779
780 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
781 {
782     IActiveScriptSiteInterruptPoll *poll;
783     IActiveScriptSiteDebug *debug;
784     IServiceProvider *service;
785     ICanHandleException *canexpection;
786     LCID lcid;
787     HRESULT hres;
788
789     CHECK_EXPECT(SetScriptSite);
790
791     ok(pass != NULL, "pass == NULL\n");
792
793     hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
794     ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
795     if(FAILED(hres))
796         IActiveScriptSiteInterruptPoll_Release(poll);
797
798     hres = IActiveScriptSite_GetLCID(pass, &lcid);
799     ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
800
801     hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
802     ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
803
804     hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
805     ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
806     if(SUCCEEDED(hres))
807         IActiveScriptSiteDebug32_Release(debug);
808
809     hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
810     ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
811
812     hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
813     todo_wine ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
814     if(SUCCEEDED(hres))
815         IServiceProvider_Release(service);
816
817     site = pass;
818     IActiveScriptSite_AddRef(site);
819     return S_OK;
820 }
821
822 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
823                                             void **ppvObject)
824 {
825     ok(0, "unexpected call\n");
826     return E_NOTIMPL;
827 }
828
829 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
830 {
831     HRESULT hres;
832
833     switch(ss) {
834     case SCRIPTSTATE_STARTED:
835         CHECK_EXPECT(SetScriptState_STARTED);
836         break;
837     case SCRIPTSTATE_CONNECTED:
838         CHECK_EXPECT(SetScriptState_CONNECTED);
839         break;
840     case SCRIPTSTATE_DISCONNECTED:
841         CHECK_EXPECT(SetScriptState_DISCONNECTED);
842         break;
843     default:
844         ok(0, "unexpected state %d\n", ss);
845         return E_NOTIMPL;
846     }
847
848     hres = IActiveScriptSite_OnStateChange(site, (state = ss));
849     return S_OK;
850 }
851
852 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
853 {
854     CHECK_EXPECT(GetScriptState);
855
856     *pssState = state;
857     return S_OK;
858 }
859
860 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
861 {
862     CHECK_EXPECT(Close);
863     return E_NOTIMPL;
864 }
865
866 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
867         LPCOLESTR pstrName, DWORD dwFlags)
868 {
869     IDispatch *disp;
870     IUnknown *unk = NULL, *unk2;
871     HRESULT hres;
872
873     static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
874
875     static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
876
877     CHECK_EXPECT(AddNamedItem);
878
879     ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", debugstr_w(pstrName));
880     ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
881
882     hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
883     ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
884     ok(unk != NULL, "unk == NULL\n");
885
886     hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
887     ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
888     if(SUCCEEDED(hres))
889         IDispatch_Release(disp);
890
891     hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
892     ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
893     if(SUCCEEDED(hres))
894         IUnknown_Release(unk2);
895
896     hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
897     ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
898
899     IUnknown_Release(unk);
900     return S_OK;
901 }
902
903 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
904                                          DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
905 {
906     ok(0, "unexpected call\n");
907     return E_NOTIMPL;
908 }
909
910 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
911                                                 IDispatch **ppdisp)
912 {
913     CHECK_EXPECT(GetScriptDispatch);
914     return E_NOTIMPL;
915 }
916
917 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
918                                                        SCRIPTTHREADID *pstridThread)
919 {
920     ok(0, "unexpected call\n");
921     return E_NOTIMPL;
922 }
923
924 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
925                                                 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
926 {
927     ok(0, "unexpected call\n");
928     return E_NOTIMPL;
929 }
930
931 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
932         SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
933 {
934     ok(0, "unexpected call\n");
935     return E_NOTIMPL;
936 }
937
938 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
939         SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
940 {
941     ok(0, "unexpected call\n");
942     return E_NOTIMPL;
943 }
944
945 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
946 {
947     ok(0, "unexpected call\n");
948     return E_NOTIMPL;
949 }
950
951 static const IActiveScriptVtbl ActiveScriptVtbl = {
952     ActiveScript_QueryInterface,
953     ActiveScript_AddRef,
954     ActiveScript_Release,
955     ActiveScript_SetScriptSite,
956     ActiveScript_GetScriptSite,
957     ActiveScript_SetScriptState,
958     ActiveScript_GetScriptState,
959     ActiveScript_Close,
960     ActiveScript_AddNamedItem,
961     ActiveScript_AddTypeLib,
962     ActiveScript_GetScriptDispatch,
963     ActiveScript_GetCurrentScriptThreadID,
964     ActiveScript_GetScriptThreadID,
965     ActiveScript_GetScriptThreadState,
966     ActiveScript_InterruptScriptThread,
967     ActiveScript_Clone
968 };
969
970 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
971
972 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
973 {
974     *ppv = NULL;
975
976     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
977         *ppv = iface;
978         return S_OK;
979     }
980
981     if(IsEqualGUID(&IID_IMarshal, riid))
982         return E_NOINTERFACE;
983     if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
984         return E_NOINTERFACE;
985
986     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
987     return E_NOTIMPL;
988 }
989
990 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
991 {
992     return 2;
993 }
994
995 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
996 {
997     return 1;
998 }
999
1000 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1001 {
1002     CHECK_EXPECT(CreateInstance);
1003
1004     ok(!outer, "outer = %p\n", outer);
1005     ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
1006     *ppv = &ActiveScript;
1007     return S_OK;
1008 }
1009
1010 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1011 {
1012     ok(0, "unexpected call\n");
1013     return S_OK;
1014 }
1015
1016 static const IClassFactoryVtbl ClassFactoryVtbl = {
1017     ClassFactory_QueryInterface,
1018     ClassFactory_AddRef,
1019     ClassFactory_Release,
1020     ClassFactory_CreateInstance,
1021     ClassFactory_LockServer
1022 };
1023
1024 static IClassFactory script_cf = { &ClassFactoryVtbl };
1025
1026 static const char simple_script_str[] =
1027     "<html><head></head><body>"
1028     "<script language=\"TestScript\">simple script</script>"
1029     "</body></html>";
1030
1031 static void test_simple_script(void)
1032 {
1033     IHTMLDocument2 *doc;
1034
1035     SET_EXPECT(CreateInstance);
1036     SET_EXPECT(GetInterfaceSafetyOptions);
1037     SET_EXPECT(SetInterfaceSafetyOptions);
1038     SET_EXPECT(SetProperty);
1039     SET_EXPECT(InitNew);
1040     SET_EXPECT(SetScriptSite);
1041     SET_EXPECT(GetScriptState);
1042     SET_EXPECT(SetScriptState_STARTED);
1043     SET_EXPECT(AddNamedItem);
1044     SET_EXPECT(ParseScriptText);
1045     SET_EXPECT(SetScriptState_CONNECTED);
1046
1047     doc = create_and_load_doc(simple_script_str);
1048     if(!doc) return;
1049
1050     CHECK_CALLED(CreateInstance);
1051     CHECK_CALLED(GetInterfaceSafetyOptions);
1052     CHECK_CALLED(SetInterfaceSafetyOptions);
1053     CHECK_CALLED(SetProperty);
1054     CHECK_CALLED(InitNew);
1055     CHECK_CALLED(SetScriptSite);
1056     CHECK_CALLED(GetScriptState);
1057     CHECK_CALLED(SetScriptState_STARTED);
1058     CHECK_CALLED(AddNamedItem);
1059     CHECK_CALLED(ParseScriptText);
1060     CHECK_CALLED(SetScriptState_CONNECTED);
1061
1062     if(site)
1063         IActiveScriptSite_Release(site);
1064     if(window_dispex)
1065         IDispatchEx_Release(window_dispex);
1066
1067     SET_EXPECT(SetScriptState_DISCONNECTED);
1068     SET_EXPECT(Close);
1069
1070     IHTMLDocument2_Release(doc);
1071
1072     CHECK_CALLED(SetScriptState_DISCONNECTED);
1073     CHECK_CALLED(Close);
1074 }
1075
1076 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1077 {
1078     HKEY hkey;
1079     DWORD res;
1080
1081     if(!init) {
1082         RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1083         return TRUE;
1084     }
1085
1086     res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1087     if(res != ERROR_SUCCESS)
1088         return FALSE;
1089
1090     if(def_value)
1091         res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1092
1093     RegCloseKey(hkey);
1094
1095     return res == ERROR_SUCCESS;
1096 }
1097
1098 static BOOL init_registry(BOOL init)
1099 {
1100     return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1101         && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1102                     NULL, init)
1103         && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1104                     NULL, init);
1105 }
1106
1107 static BOOL register_script_engine(void)
1108 {
1109     DWORD regid;
1110     HRESULT hres;
1111
1112     if(!init_registry(TRUE)) {
1113         init_registry(FALSE);
1114         return FALSE;
1115     }
1116
1117     hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1118                                  CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1119     ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1120
1121     return TRUE;
1122 }
1123
1124 static void gecko_installer_workaround(BOOL disable)
1125 {
1126     HKEY hkey;
1127     DWORD res;
1128
1129     static BOOL has_url = FALSE;
1130     static char url[2048];
1131
1132     if(!disable && !has_url)
1133         return;
1134
1135     res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1136     if(res != ERROR_SUCCESS)
1137         return;
1138
1139     if(disable) {
1140         DWORD type, size = sizeof(url);
1141
1142         res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1143         if(res == ERROR_SUCCESS && type == REG_SZ)
1144             has_url = TRUE;
1145
1146         RegDeleteValue(hkey, "GeckoUrl");
1147     }else {
1148         RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1149     }
1150
1151     RegCloseKey(hkey);
1152 }
1153
1154 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
1155 /* Note: this code is duplicated in dlls/mshtml/tests/dom.c, dlls/mshtml/tests/script.c and dlls/urlmon/tests/misc.c */
1156 static BOOL is_ie_hardened(void)
1157 {
1158     HKEY zone_map;
1159     DWORD ie_harden, type, size;
1160
1161     ie_harden = 0;
1162     if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
1163                     0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
1164         size = sizeof(DWORD);
1165         if (RegQueryValueEx(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
1166             type != REG_DWORD) {
1167             ie_harden = 0;
1168         }
1169     RegCloseKey(zone_map);
1170     }
1171
1172     return ie_harden != 0;
1173 }
1174
1175 START_TEST(script)
1176 {
1177     gecko_installer_workaround(TRUE);
1178     CoInitialize(NULL);
1179
1180     if(winetest_interactive || ! is_ie_hardened()) {
1181         if(register_script_engine()) {
1182             test_simple_script();
1183             init_registry(FALSE);
1184         }else {
1185             skip("Could not register TestScript engine\n");
1186         }
1187     }else {
1188         skip("IE running in Enhanced Security Configuration\n");
1189     }
1190
1191     CoUninitialize();
1192     gecko_installer_workaround(FALSE);
1193 }