2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
37 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
41 #define CTXARG_T DWORDLONG
42 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
43 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
47 #define CTXARG_T DWORD
48 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
49 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
53 #define DEFINE_EXPECT(func) \
54 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
56 #define SET_EXPECT(func) \
57 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
59 #define CHECK_EXPECT2(func) \
61 ok(expect_ ##func, "unexpected call " #func "\n"); \
62 called_ ## func = TRUE; \
65 #define CHECK_EXPECT(func) \
67 CHECK_EXPECT2(func); \
68 expect_ ## func = FALSE; \
71 #define CHECK_CALLED(func) \
73 ok(called_ ## func, "expected " #func "\n"); \
74 expect_ ## func = called_ ## func = FALSE; \
77 #define CHECK_CALLED_BROKEN(func) \
79 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
80 expect_ ## func = called_ ## func = FALSE; \
83 #define CHECK_NOT_CALLED(func) \
85 ok(!called_ ## func, "unexpected " #func "\n"); \
86 expect_ ## func = called_ ## func = FALSE; \
89 #define CLEAR_CALLED(func) \
90 expect_ ## func = called_ ## func = FALSE
93 DEFINE_EXPECT(CreateInstance);
94 DEFINE_EXPECT(GetInterfaceSafetyOptions);
95 DEFINE_EXPECT(SetInterfaceSafetyOptions);
96 DEFINE_EXPECT(InitNew);
98 DEFINE_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
99 DEFINE_EXPECT(SetProperty_INVOKEVERSIONING);
100 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
101 DEFINE_EXPECT(SetScriptSite);
102 DEFINE_EXPECT(GetScriptState);
103 DEFINE_EXPECT(SetScriptState_STARTED);
104 DEFINE_EXPECT(SetScriptState_CONNECTED);
105 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
106 DEFINE_EXPECT(AddNamedItem);
107 DEFINE_EXPECT(ParseScriptText);
108 DEFINE_EXPECT(GetScriptDispatch);
109 DEFINE_EXPECT(funcDisp);
111 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
113 static const GUID CLSID_TestScript =
114 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
116 static IHTMLDocument2 *notif_doc;
117 static IDispatchEx *window_dispex;
118 static BOOL doc_complete;
120 static const char *debugstr_guid(REFIID riid)
124 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
125 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
126 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
127 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
132 static int strcmp_wa(LPCWSTR strw, const char *stra)
135 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
136 return lstrcmpA(stra, buf);
139 static BSTR a2bstr(const char *str)
144 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
145 ret = SysAllocStringLen(NULL, len);
146 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
151 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
152 REFIID riid, void**ppv)
154 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
159 return E_NOINTERFACE;
162 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
167 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
172 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
174 if(dispID == DISPID_READYSTATE){
178 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
180 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
181 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
183 if(!lstrcmpW(state, completeW))
186 SysFreeString(state);
192 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
194 ok(0, "unexpected call\n");
198 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
199 PropertyNotifySink_QueryInterface,
200 PropertyNotifySink_AddRef,
201 PropertyNotifySink_Release,
202 PropertyNotifySink_OnChanged,
203 PropertyNotifySink_OnRequestEdit
206 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
208 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
212 if(IsEqualGUID(riid, &IID_IUnknown)
213 || IsEqualGUID(riid, &IID_IDispatch)
214 || IsEqualGUID(riid, &IID_IDispatchEx))
217 return E_NOINTERFACE;
222 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
227 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
232 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
234 ok(0, "unexpected call\n");
238 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
239 LCID lcid, ITypeInfo **ppTInfo)
241 ok(0, "unexpected call\n");
245 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
246 LPOLESTR *rgszNames, UINT cNames,
247 LCID lcid, DISPID *rgDispId)
249 ok(0, "unexpected call\n");
253 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
254 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
255 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
257 ok(0, "unexpected call\n");
261 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
263 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
267 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
269 ok(0, "unexpected call\n");
273 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
275 ok(0, "unexpected call\n");
279 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
281 ok(0, "unexpected call\n");
285 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
287 ok(0, "unexpected call\n");
291 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
293 ok(0, "unexpected call\n");
297 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
299 ok(0, "unexpected call\n");
303 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
304 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
306 CHECK_EXPECT(funcDisp);
308 ok(id == DISPID_VALUE, "id = %d\n", id);
309 ok(lcid == 0, "lcid = %x\n", lcid);
310 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
311 ok(pdp != NULL, "pdp == NULL\n");
312 ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
313 ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
314 ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
315 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
316 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
317 ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
318 ok(pvarRes != NULL, "pvarRes == NULL\n");
319 ok(pei != NULL, "pei == NULL\n");
320 ok(!pspCaller, "pspCaller != NULL\n");
322 V_VT(pvarRes) = VT_I4;
327 static IDispatchExVtbl testObjVtbl = {
328 DispatchEx_QueryInterface,
331 DispatchEx_GetTypeInfoCount,
332 DispatchEx_GetTypeInfo,
333 DispatchEx_GetIDsOfNames,
335 DispatchEx_GetDispID,
337 DispatchEx_DeleteMemberByName,
338 DispatchEx_DeleteMemberByDispID,
339 DispatchEx_GetMemberProperties,
340 DispatchEx_GetMemberName,
341 DispatchEx_GetNextDispID,
342 DispatchEx_GetNameSpaceParent
345 static IDispatchEx funcDisp = { &testObjVtbl };
347 static IHTMLDocument2 *create_document(void)
352 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
353 &IID_IHTMLDocument2, (void**)&doc);
354 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
359 static IHTMLDocument2 *create_doc_with_string(const char *str)
361 IPersistStreamInit *init;
367 notif_doc = doc = create_document();
371 doc_complete = FALSE;
373 mem = GlobalAlloc(0, len);
374 memcpy(mem, str, len);
375 CreateStreamOnHGlobal(mem, TRUE, &stream);
377 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
379 IPersistStreamInit_Load(init, stream);
380 IPersistStreamInit_Release(init);
381 IStream_Release(stream);
386 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
388 IConnectionPointContainer *container;
389 IConnectionPoint *cp;
393 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
394 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
396 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
397 IConnectionPointContainer_Release(container);
398 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
400 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
401 IConnectionPoint_Release(cp);
402 ok(hres == S_OK, "Advise failed: %08x\n", hres);
405 typedef void (*domtest_t)(IHTMLDocument2*);
407 static IHTMLDocument2 *create_and_load_doc(const char *str)
410 IHTMLElement *body = NULL;
414 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
419 doc = create_doc_with_string(str);
420 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
422 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
423 TranslateMessage(&msg);
424 DispatchMessage(&msg);
427 hres = IHTMLDocument2_get_body(doc, &body);
428 ok(hres == S_OK, "get_body failed: %08x\n", hres);
431 skip("Could not get document body. Assuming no Gecko installed.\n");
432 ref = IHTMLDocument2_Release(doc);
433 ok(!ref, "ref = %d\n", ref);
437 /* Check we can query for function on the IHTMLElementBody interface */
438 name = (WCHAR*)ucPtr;
439 hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
440 ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
441 ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
443 IHTMLElement_Release(body);
447 static IActiveScriptSite *site;
448 static SCRIPTSTATE state;
450 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
453 ok(0, "unexpected call\n");
454 return E_NOINTERFACE;
457 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
462 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
467 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
468 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
470 CHECK_EXPECT(GetInterfaceSafetyOptions);
472 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
473 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
474 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
476 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
477 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
482 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
483 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
485 CHECK_EXPECT(SetInterfaceSafetyOptions);
487 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
489 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
490 "dwOptionSetMask=%x\n", dwOptionSetMask);
491 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
492 "dwEnabledOptions=%x\n", dwOptionSetMask);
497 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
498 ObjectSafety_QueryInterface,
500 ObjectSafety_Release,
501 ObjectSafety_GetInterfaceSafetyOptions,
502 ObjectSafety_SetInterfaceSafetyOptions
505 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
507 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
510 ok(0, "unexpected call\n");
511 return E_NOINTERFACE;
514 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
519 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
524 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
525 VARIANT *pvarIndex, VARIANT *pvarValue)
527 ok(0, "unexpected call\n");
531 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
532 VARIANT *pvarIndex, VARIANT *pvarValue)
535 case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
536 CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
537 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
538 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
540 case SCRIPTPROP_INVOKEVERSIONING:
541 CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
542 ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
543 ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
545 case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
546 CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
547 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
548 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
551 ok(0, "unexpected property %x\n", dwProperty);
555 ok(!pvarIndex, "pvarIndex != NULL\n");
556 ok(pvarValue != NULL, "pvarValue == NULL\n");
561 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
562 ActiveScriptProperty_QueryInterface,
563 ActiveScriptProperty_AddRef,
564 ActiveScriptProperty_Release,
565 ActiveScriptProperty_GetProperty,
566 ActiveScriptProperty_SetProperty
569 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
571 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
574 ok(0, "unexpected call\n");
575 return E_NOINTERFACE;
578 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
583 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
588 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
589 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
590 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
591 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
593 ok(0, "unexpected call\n");
597 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
598 ActiveScriptParseProcedure_QueryInterface,
599 ActiveScriptParseProcedure_AddRef,
600 ActiveScriptParseProcedure_Release,
601 ActiveScriptParseProcedure_ParseProcedureText
604 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
606 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
609 ok(0, "unexpected call\n");
610 return E_NOINTERFACE;
613 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
618 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
623 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
625 CHECK_EXPECT(InitNew);
629 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
630 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
631 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
632 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
633 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
635 ok(0, "unexpected call\n");
639 static void test_func(IDispatchEx *obj)
641 DISPID id, propput_arg = DISPID_PROPERTYPUT;
650 str = a2bstr("toString");
651 hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
653 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
654 ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
656 memset(&dp, 0, sizeof(dp));
657 memset(&ei, 0, sizeof(ei));
659 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
660 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
661 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
662 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
663 disp = V_DISPATCH(&var);
665 memset(&dp, 0, sizeof(dp));
666 memset(&ei, 0, sizeof(ei));
668 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
669 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
670 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
671 ok(V_DISPATCH(&var) == disp, "V_DISPATCH(var) != disp\n");
674 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
675 IDispatch_Release(disp);
676 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
678 /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
680 memset(&dp, 0, sizeof(dp));
681 memset(&ei, 0, sizeof(ei));
683 hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
684 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
685 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
686 ok(!strcmp_wa(V_BSTR(&var), "[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
692 dp.rgdispidNamedArgs = &propput_arg;
695 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
696 ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
698 IDispatchEx_Release(dispex);
701 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
702 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
703 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
704 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
706 IDispatchEx *document, *dispex;
707 IHTMLWindow2 *window;
708 IOmNavigator *navigator;
713 DISPID id, named_arg = DISPID_PROPERTYPUT;
717 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
718 static const WCHAR testW[] = {'t','e','s','t',0};
719 static const WCHAR funcW[] = {'f','u','n','c',0};
721 CHECK_EXPECT(ParseScriptText);
723 SET_EXPECT(GetScriptDispatch);
725 tmp = SysAllocString(documentW);
726 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
728 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
729 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
731 todo_wine CHECK_CALLED(GetScriptDispatch);
734 memset(&dp, 0, sizeof(dp));
735 memset(&ei, 0, sizeof(ei));
737 hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
738 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
739 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
740 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
742 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
744 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
746 tmp = SysAllocString(testW);
747 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
748 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
749 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
750 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
754 tmp = SysAllocString(testW);
755 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
757 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
763 dp.rgdispidNamedArgs = &named_arg;
767 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
768 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
770 tmp = SysAllocString(testW);
771 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
773 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
776 memset(&dp, 0, sizeof(dp));
777 memset(&ei, 0, sizeof(ei));
778 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
779 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
780 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
781 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
783 unk = (void*)0xdeadbeef;
784 hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
785 ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
786 ok(!unk, "unk=%p, expected NULL\n", unk);
789 tmp = SysAllocString(funcW);
790 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
792 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
798 dp.rgdispidNamedArgs = NULL;
799 V_VT(&var) = VT_DISPATCH;
800 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
802 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
803 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
806 memset(&dp, 0, sizeof(dp));
807 memset(&ei, 0, sizeof(ei));
808 V_VT(&arg) = VT_BOOL;
809 V_BOOL(&arg) = VARIANT_TRUE;
813 SET_EXPECT(funcDisp);
814 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
815 CHECK_CALLED(funcDisp);
817 ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
818 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
819 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
821 IDispatchEx_Release(document);
823 hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
824 ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
826 hres = IHTMLWindow2_get_navigator(window, &navigator);
827 IHTMLWindow2_Release(window);
828 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
830 hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
831 IOmNavigator_Release(navigator);
832 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
835 IDispatchEx_Release(dispex);
840 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
841 ActiveScriptParse_QueryInterface,
842 ActiveScriptParse_AddRef,
843 ActiveScriptParse_Release,
844 ActiveScriptParse_InitNew,
845 ActiveScriptParse_AddScriptlet,
846 ActiveScriptParse_ParseScriptText
849 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
851 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
855 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
860 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
861 *ppv = &ActiveScriptParse;
865 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
866 *ppv = &ActiveScriptParseProcedure;
870 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
871 *ppv = &ActiveScriptProperty;
875 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
876 *ppv = &ObjectSafety;
880 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
881 return E_NOINTERFACE;
884 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
889 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
894 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
896 IActiveScriptSiteInterruptPoll *poll;
897 IActiveScriptSiteDebug *debug;
898 IServiceProvider *service;
899 ICanHandleException *canexpection;
903 CHECK_EXPECT(SetScriptSite);
905 ok(pass != NULL, "pass == NULL\n");
907 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
908 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
910 IActiveScriptSiteInterruptPoll_Release(poll);
912 hres = IActiveScriptSite_GetLCID(pass, &lcid);
913 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
915 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
916 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
918 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
919 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
921 IActiveScriptSiteDebug32_Release(debug);
923 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
924 ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
926 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
927 todo_wine ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
929 IServiceProvider_Release(service);
932 IActiveScriptSite_AddRef(site);
936 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
939 ok(0, "unexpected call\n");
943 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
948 case SCRIPTSTATE_STARTED:
949 CHECK_EXPECT(SetScriptState_STARTED);
951 case SCRIPTSTATE_CONNECTED:
952 CHECK_EXPECT(SetScriptState_CONNECTED);
954 case SCRIPTSTATE_DISCONNECTED:
955 CHECK_EXPECT(SetScriptState_DISCONNECTED);
958 ok(0, "unexpected state %d\n", ss);
962 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
966 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
968 CHECK_EXPECT(GetScriptState);
974 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
980 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
981 LPCOLESTR pstrName, DWORD dwFlags)
984 IUnknown *unk = NULL, *unk2;
987 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
989 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
991 CHECK_EXPECT(AddNamedItem);
993 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
994 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
996 hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
997 ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
998 ok(unk != NULL, "unk == NULL\n");
1000 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
1001 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
1003 IDispatch_Release(disp);
1005 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
1006 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
1008 IUnknown_Release(unk2);
1010 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
1011 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
1013 IUnknown_Release(unk);
1017 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
1018 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
1020 ok(0, "unexpected call\n");
1024 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
1027 CHECK_EXPECT(GetScriptDispatch);
1031 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
1032 SCRIPTTHREADID *pstridThread)
1034 ok(0, "unexpected call\n");
1038 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
1039 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
1041 ok(0, "unexpected call\n");
1045 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
1046 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
1048 ok(0, "unexpected call\n");
1052 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
1053 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
1055 ok(0, "unexpected call\n");
1059 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
1061 ok(0, "unexpected call\n");
1065 static const IActiveScriptVtbl ActiveScriptVtbl = {
1066 ActiveScript_QueryInterface,
1067 ActiveScript_AddRef,
1068 ActiveScript_Release,
1069 ActiveScript_SetScriptSite,
1070 ActiveScript_GetScriptSite,
1071 ActiveScript_SetScriptState,
1072 ActiveScript_GetScriptState,
1074 ActiveScript_AddNamedItem,
1075 ActiveScript_AddTypeLib,
1076 ActiveScript_GetScriptDispatch,
1077 ActiveScript_GetCurrentScriptThreadID,
1078 ActiveScript_GetScriptThreadID,
1079 ActiveScript_GetScriptThreadState,
1080 ActiveScript_InterruptScriptThread,
1084 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
1086 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1090 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1095 if(IsEqualGUID(&IID_IMarshal, riid))
1096 return E_NOINTERFACE;
1097 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1098 return E_NOINTERFACE;
1100 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1104 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1109 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1114 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1116 CHECK_EXPECT(CreateInstance);
1118 ok(!outer, "outer = %p\n", outer);
1119 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
1120 *ppv = &ActiveScript;
1124 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1126 ok(0, "unexpected call\n");
1130 static const IClassFactoryVtbl ClassFactoryVtbl = {
1131 ClassFactory_QueryInterface,
1132 ClassFactory_AddRef,
1133 ClassFactory_Release,
1134 ClassFactory_CreateInstance,
1135 ClassFactory_LockServer
1138 static IClassFactory script_cf = { &ClassFactoryVtbl };
1140 static const char simple_script_str[] =
1141 "<html><head></head><body>"
1142 "<script language=\"TestScript\">simple script</script>"
1145 static void test_simple_script(void)
1147 IHTMLDocument2 *doc;
1149 SET_EXPECT(CreateInstance);
1150 SET_EXPECT(GetInterfaceSafetyOptions);
1151 SET_EXPECT(SetInterfaceSafetyOptions);
1152 SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
1153 SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1154 SET_EXPECT(InitNew);
1155 SET_EXPECT(SetScriptSite);
1156 SET_EXPECT(GetScriptState);
1157 SET_EXPECT(SetScriptState_STARTED);
1158 SET_EXPECT(AddNamedItem);
1159 SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
1160 SET_EXPECT(ParseScriptText);
1161 SET_EXPECT(SetScriptState_CONNECTED);
1163 doc = create_and_load_doc(simple_script_str);
1166 CHECK_CALLED(CreateInstance);
1167 CHECK_CALLED(GetInterfaceSafetyOptions);
1168 CHECK_CALLED(SetInterfaceSafetyOptions);
1169 CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
1170 CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
1171 CHECK_CALLED(InitNew);
1172 CHECK_CALLED(SetScriptSite);
1173 CHECK_CALLED(GetScriptState);
1174 CHECK_CALLED(SetScriptState_STARTED);
1175 CHECK_CALLED(AddNamedItem);
1176 CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
1177 CHECK_CALLED(ParseScriptText);
1178 CHECK_CALLED(SetScriptState_CONNECTED);
1181 IActiveScriptSite_Release(site);
1183 IDispatchEx_Release(window_dispex);
1185 SET_EXPECT(SetScriptState_DISCONNECTED);
1188 IHTMLDocument2_Release(doc);
1190 CHECK_CALLED(SetScriptState_DISCONNECTED);
1191 CHECK_CALLED(Close);
1194 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1200 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1204 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1205 if(res != ERROR_SUCCESS)
1209 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1213 return res == ERROR_SUCCESS;
1216 static BOOL init_registry(BOOL init)
1218 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1219 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1221 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1225 static BOOL register_script_engine(void)
1230 if(!init_registry(TRUE)) {
1231 init_registry(FALSE);
1235 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1236 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1237 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1242 static void gecko_installer_workaround(BOOL disable)
1247 static BOOL has_url = FALSE;
1248 static char url[2048];
1250 if(!disable && !has_url)
1253 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1254 if(res != ERROR_SUCCESS)
1258 DWORD type, size = sizeof(url);
1260 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1261 if(res == ERROR_SUCCESS && type == REG_SZ)
1264 RegDeleteValue(hkey, "GeckoUrl");
1266 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1272 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
1273 /* Note: this code is duplicated in dlls/mshtml/tests/dom.c, dlls/mshtml/tests/script.c and dlls/urlmon/tests/sec_mgr.c */
1274 static BOOL is_ie_hardened(void)
1277 DWORD ie_harden, type, size;
1280 if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
1281 0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
1282 size = sizeof(DWORD);
1283 if (RegQueryValueEx(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
1284 type != REG_DWORD) {
1287 RegCloseKey(zone_map);
1290 return ie_harden != 0;
1295 gecko_installer_workaround(TRUE);
1298 if(winetest_interactive || ! is_ie_hardened()) {
1299 if(register_script_engine()) {
1300 test_simple_script();
1301 init_registry(FALSE);
1303 skip("Could not register TestScript engine\n");
1306 skip("IE running in Enhanced Security Configuration\n");
1310 gecko_installer_workaround(FALSE);