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_NOT_CALLED(func) \
79 ok(!called_ ## func, "unexpected " #func "\n"); \
80 expect_ ## func = called_ ## func = FALSE; \
83 #define CLEAR_CALLED(func) \
84 expect_ ## func = called_ ## func = FALSE
87 DEFINE_EXPECT(CreateInstance);
88 DEFINE_EXPECT(GetInterfaceSafetyOptions);
89 DEFINE_EXPECT(SetInterfaceSafetyOptions);
90 DEFINE_EXPECT(InitNew);
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);
103 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
105 static const GUID CLSID_TestScript =
106 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
108 static IHTMLDocument2 *notif_doc;
109 static IDispatchEx *window_dispex;
110 static BOOL doc_complete;
112 static const char *debugstr_w(LPCWSTR str)
114 static char buf[1024];
115 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
119 static const char *debugstr_guid(REFIID riid)
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]);
131 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
132 REFIID riid, void**ppv)
134 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
139 return E_NOINTERFACE;
142 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
147 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
152 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
154 if(dispID == DISPID_READYSTATE){
158 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
160 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
161 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
163 if(!lstrcmpW(state, completeW))
166 SysFreeString(state);
172 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
174 ok(0, "unexpected call\n");
178 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
179 PropertyNotifySink_QueryInterface,
180 PropertyNotifySink_AddRef,
181 PropertyNotifySink_Release,
182 PropertyNotifySink_OnChanged,
183 PropertyNotifySink_OnRequestEdit
186 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
188 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
192 if(IsEqualGUID(riid, &IID_IUnknown)
193 || IsEqualGUID(riid, &IID_IDispatch)
194 || IsEqualGUID(riid, &IID_IDispatchEx))
197 return E_NOINTERFACE;
202 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
207 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
212 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
214 ok(0, "unexpected call\n");
218 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
219 LCID lcid, ITypeInfo **ppTInfo)
221 ok(0, "unexpected call\n");
225 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
226 LPOLESTR *rgszNames, UINT cNames,
227 LCID lcid, DISPID *rgDispId)
229 ok(0, "unexpected call\n");
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)
237 ok(0, "unexpected call\n");
241 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
243 ok(0, "unexpected call %s %x\n", debugstr_w(bstrName), grfdex);
247 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
249 ok(0, "unexpected call\n");
253 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
255 ok(0, "unexpected call\n");
259 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
261 ok(0, "unexpected call\n");
265 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
267 ok(0, "unexpected call\n");
271 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
273 ok(0, "unexpected call\n");
277 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
279 ok(0, "unexpected call\n");
283 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
284 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
286 CHECK_EXPECT(funcDisp);
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");
302 V_VT(pvarRes) = VT_I4;
307 static IDispatchExVtbl testObjVtbl = {
308 DispatchEx_QueryInterface,
311 DispatchEx_GetTypeInfoCount,
312 DispatchEx_GetTypeInfo,
313 DispatchEx_GetIDsOfNames,
315 DispatchEx_GetDispID,
317 DispatchEx_DeleteMemberByName,
318 DispatchEx_DeleteMemberByDispID,
319 DispatchEx_GetMemberProperties,
320 DispatchEx_GetMemberName,
321 DispatchEx_GetNextDispID,
322 DispatchEx_GetNameSpaceParent
325 static IDispatchEx funcDisp = { &testObjVtbl };
327 static IHTMLDocument2 *create_document(void)
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);
339 static IHTMLDocument2 *create_doc_with_string(const char *str)
341 IPersistStreamInit *init;
347 notif_doc = doc = create_document();
351 doc_complete = FALSE;
353 mem = GlobalAlloc(0, len);
354 memcpy(mem, str, len);
355 CreateStreamOnHGlobal(mem, TRUE, &stream);
357 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
359 IPersistStreamInit_Load(init, stream);
360 IPersistStreamInit_Release(init);
361 IStream_Release(stream);
366 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
368 IConnectionPointContainer *container;
369 IConnectionPoint *cp;
373 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
374 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
376 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
377 IConnectionPointContainer_Release(container);
378 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
380 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
381 IConnectionPoint_Release(cp);
382 ok(hres == S_OK, "Advise failed: %08x\n", hres);
385 typedef void (*domtest_t)(IHTMLDocument2*);
387 static IHTMLDocument2 *create_and_load_doc(const char *str)
390 IHTMLElement *body = NULL;
394 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
399 doc = create_doc_with_string(str);
400 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
402 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
403 TranslateMessage(&msg);
404 DispatchMessage(&msg);
407 hres = IHTMLDocument2_get_body(doc, &body);
408 ok(hres == S_OK, "get_body failed: %08x\n", hres);
411 skip("Could not get document body. Assuming no Gecko installed.\n");
412 ref = IHTMLDocument2_Release(doc);
413 ok(!ref, "ref = %d\n", ref);
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);
423 IHTMLElement_Release(body);
427 static IActiveScriptSite *site;
428 static SCRIPTSTATE state;
430 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
433 ok(0, "unexpected call\n");
434 return E_NOINTERFACE;
437 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
442 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
447 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
448 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
450 CHECK_EXPECT(GetInterfaceSafetyOptions);
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");
456 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
457 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
462 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
463 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
465 CHECK_EXPECT(SetInterfaceSafetyOptions);
467 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
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);
477 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
478 ObjectSafety_QueryInterface,
480 ObjectSafety_Release,
481 ObjectSafety_GetInterfaceSafetyOptions,
482 ObjectSafety_SetInterfaceSafetyOptions
485 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
487 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
490 ok(0, "unexpected call\n");
491 return E_NOINTERFACE;
494 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
499 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
504 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
505 VARIANT *pvarIndex, VARIANT *pvarValue)
507 ok(0, "unexpected call\n");
511 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
512 VARIANT *pvarIndex, VARIANT *pvarValue)
514 CHECK_EXPECT(SetProperty);
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));
525 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
526 ActiveScriptProperty_QueryInterface,
527 ActiveScriptProperty_AddRef,
528 ActiveScriptProperty_Release,
529 ActiveScriptProperty_GetProperty,
530 ActiveScriptProperty_SetProperty
533 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
535 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
538 ok(0, "unexpected call\n");
539 return E_NOINTERFACE;
542 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
547 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
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)
557 ok(0, "unexpected call\n");
561 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
562 ActiveScriptParseProcedure_QueryInterface,
563 ActiveScriptParseProcedure_AddRef,
564 ActiveScriptParseProcedure_Release,
565 ActiveScriptParseProcedure_ParseProcedureText
568 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
570 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
573 ok(0, "unexpected call\n");
574 return E_NOINTERFACE;
577 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
582 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
587 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
589 CHECK_EXPECT(InitNew);
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)
599 ok(0, "unexpected call\n");
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)
608 IDispatchEx *document;
613 DISPID id, named_arg = DISPID_PROPERTYPUT;
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};
621 CHECK_EXPECT(ParseScriptText);
623 SET_EXPECT(GetScriptDispatch);
625 tmp = SysAllocString(documentW);
626 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
628 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
629 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
631 todo_wine CHECK_CALLED(GetScriptDispatch);
634 memset(&dp, 0, sizeof(dp));
635 memset(&ei, 0, sizeof(ei));
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");
642 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
644 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
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);
654 tmp = SysAllocString(testW);
655 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
657 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
663 dp.rgdispidNamedArgs = &named_arg;
667 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
668 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
670 tmp = SysAllocString(testW);
671 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
673 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
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");
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);
689 tmp = SysAllocString(funcW);
690 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
692 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
698 dp.rgdispidNamedArgs = NULL;
699 V_VT(&var) = VT_DISPATCH;
700 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
702 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
703 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
706 memset(&dp, 0, sizeof(dp));
707 memset(&ei, 0, sizeof(ei));
708 V_VT(&arg) = VT_BOOL;
709 V_BOOL(&arg) = VARIANT_TRUE;
713 SET_EXPECT(funcDisp);
714 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
715 CHECK_CALLED(funcDisp);
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");
721 IDispatchEx_Release(document);
726 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
727 ActiveScriptParse_QueryInterface,
728 ActiveScriptParse_AddRef,
729 ActiveScriptParse_Release,
730 ActiveScriptParse_InitNew,
731 ActiveScriptParse_AddScriptlet,
732 ActiveScriptParse_ParseScriptText
735 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
737 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
741 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
746 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
747 *ppv = &ActiveScriptParse;
751 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
752 *ppv = &ActiveScriptParseProcedure;
756 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
757 *ppv = &ActiveScriptProperty;
761 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
762 *ppv = &ObjectSafety;
766 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
767 return E_NOINTERFACE;
770 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
775 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
780 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
782 IActiveScriptSiteInterruptPoll *poll;
783 IActiveScriptSiteDebug *debug;
784 IServiceProvider *service;
785 ICanHandleException *canexpection;
789 CHECK_EXPECT(SetScriptSite);
791 ok(pass != NULL, "pass == NULL\n");
793 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
794 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
796 IActiveScriptSiteInterruptPoll_Release(poll);
798 hres = IActiveScriptSite_GetLCID(pass, &lcid);
799 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
801 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
802 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
804 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
805 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
807 IActiveScriptSiteDebug32_Release(debug);
809 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
810 ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
812 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
813 todo_wine ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
815 IServiceProvider_Release(service);
818 IActiveScriptSite_AddRef(site);
822 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
825 ok(0, "unexpected call\n");
829 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
834 case SCRIPTSTATE_STARTED:
835 CHECK_EXPECT(SetScriptState_STARTED);
837 case SCRIPTSTATE_CONNECTED:
838 CHECK_EXPECT(SetScriptState_CONNECTED);
840 case SCRIPTSTATE_DISCONNECTED:
841 CHECK_EXPECT(SetScriptState_DISCONNECTED);
844 ok(0, "unexpected state %d\n", ss);
848 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
852 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
854 CHECK_EXPECT(GetScriptState);
860 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
866 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
867 LPCOLESTR pstrName, DWORD dwFlags)
870 IUnknown *unk = NULL, *unk2;
873 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
875 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
877 CHECK_EXPECT(AddNamedItem);
879 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", debugstr_w(pstrName));
880 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
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");
886 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
887 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
889 IDispatch_Release(disp);
891 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
892 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
894 IUnknown_Release(unk2);
896 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
897 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
899 IUnknown_Release(unk);
903 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
904 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
906 ok(0, "unexpected call\n");
910 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
913 CHECK_EXPECT(GetScriptDispatch);
917 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
918 SCRIPTTHREADID *pstridThread)
920 ok(0, "unexpected call\n");
924 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
925 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
927 ok(0, "unexpected call\n");
931 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
932 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
934 ok(0, "unexpected call\n");
938 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
939 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
941 ok(0, "unexpected call\n");
945 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
947 ok(0, "unexpected call\n");
951 static const IActiveScriptVtbl ActiveScriptVtbl = {
952 ActiveScript_QueryInterface,
954 ActiveScript_Release,
955 ActiveScript_SetScriptSite,
956 ActiveScript_GetScriptSite,
957 ActiveScript_SetScriptState,
958 ActiveScript_GetScriptState,
960 ActiveScript_AddNamedItem,
961 ActiveScript_AddTypeLib,
962 ActiveScript_GetScriptDispatch,
963 ActiveScript_GetCurrentScriptThreadID,
964 ActiveScript_GetScriptThreadID,
965 ActiveScript_GetScriptThreadState,
966 ActiveScript_InterruptScriptThread,
970 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
972 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
976 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
981 if(IsEqualGUID(&IID_IMarshal, riid))
982 return E_NOINTERFACE;
983 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
984 return E_NOINTERFACE;
986 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
990 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
995 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1000 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1002 CHECK_EXPECT(CreateInstance);
1004 ok(!outer, "outer = %p\n", outer);
1005 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
1006 *ppv = &ActiveScript;
1010 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1012 ok(0, "unexpected call\n");
1016 static const IClassFactoryVtbl ClassFactoryVtbl = {
1017 ClassFactory_QueryInterface,
1018 ClassFactory_AddRef,
1019 ClassFactory_Release,
1020 ClassFactory_CreateInstance,
1021 ClassFactory_LockServer
1024 static IClassFactory script_cf = { &ClassFactoryVtbl };
1026 static const char simple_script_str[] =
1027 "<html><head></head><body>"
1028 "<script language=\"TestScript\">simple script</script>"
1031 static void test_simple_script(void)
1033 IHTMLDocument2 *doc;
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);
1047 doc = create_and_load_doc(simple_script_str);
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);
1063 IActiveScriptSite_Release(site);
1065 IDispatchEx_Release(window_dispex);
1067 SET_EXPECT(SetScriptState_DISCONNECTED);
1070 IHTMLDocument2_Release(doc);
1072 CHECK_CALLED(SetScriptState_DISCONNECTED);
1073 CHECK_CALLED(Close);
1076 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1082 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1086 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1087 if(res != ERROR_SUCCESS)
1091 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1095 return res == ERROR_SUCCESS;
1098 static BOOL init_registry(BOOL init)
1100 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1101 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1103 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1107 static BOOL register_script_engine(void)
1112 if(!init_registry(TRUE)) {
1113 init_registry(FALSE);
1117 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1118 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1119 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1124 static void gecko_installer_workaround(BOOL disable)
1129 static BOOL has_url = FALSE;
1130 static char url[2048];
1132 if(!disable && !has_url)
1135 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1136 if(res != ERROR_SUCCESS)
1140 DWORD type, size = sizeof(url);
1142 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1143 if(res == ERROR_SUCCESS && type == REG_SZ)
1146 RegDeleteValue(hkey, "GeckoUrl");
1148 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
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)
1159 DWORD ie_harden, type, size;
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) {
1169 RegCloseKey(zone_map);
1172 return ie_harden != 0;
1177 gecko_installer_workaround(TRUE);
1180 if(winetest_interactive || ! is_ie_hardened()) {
1181 if(register_script_engine()) {
1182 test_simple_script();
1183 init_registry(FALSE);
1185 skip("Could not register TestScript engine\n");
1188 skip("IE running in Enhanced Security Configuration\n");
1192 gecko_installer_workaround(FALSE);