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);
39 #define DEFINE_EXPECT(func) \
40 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
42 #define SET_EXPECT(func) \
43 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
45 #define CHECK_EXPECT2(func) \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
51 #define CHECK_EXPECT(func) \
53 CHECK_EXPECT2(func); \
54 expect_ ## func = FALSE; \
57 #define CHECK_CALLED(func) \
59 ok(called_ ## func, "expected " #func "\n"); \
60 expect_ ## func = called_ ## func = FALSE; \
63 #define CHECK_NOT_CALLED(func) \
65 ok(!called_ ## func, "unexpected " #func "\n"); \
66 expect_ ## func = called_ ## func = FALSE; \
69 #define CLEAR_CALLED(func) \
70 expect_ ## func = called_ ## func = FALSE
73 DEFINE_EXPECT(CreateInstance);
74 DEFINE_EXPECT(GetInterfaceSafetyOptions);
75 DEFINE_EXPECT(SetInterfaceSafetyOptions);
76 DEFINE_EXPECT(InitNew);
78 DEFINE_EXPECT(SetProperty);
79 DEFINE_EXPECT(SetScriptSite);
80 DEFINE_EXPECT(GetScriptState);
81 DEFINE_EXPECT(SetScriptState_STARTED);
82 DEFINE_EXPECT(SetScriptState_CONNECTED);
83 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
84 DEFINE_EXPECT(AddNamedItem);
85 DEFINE_EXPECT(ParseScriptText);
86 DEFINE_EXPECT(GetScriptDispatch);
87 DEFINE_EXPECT(funcDisp);
89 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
91 static const GUID CLSID_TestScript =
92 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
94 static IHTMLDocument2 *notif_doc;
95 static IDispatchEx *window_dispex;
96 static BOOL doc_complete;
98 static const char *debugstr_w(LPCWSTR str)
100 static char buf[1024];
101 WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
105 static const char *debugstr_guid(REFIID riid)
109 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
110 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
111 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
112 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
117 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
118 REFIID riid, void**ppv)
120 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
125 return E_NOINTERFACE;
128 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
133 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
138 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
140 if(dispID == DISPID_READYSTATE){
144 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
146 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
147 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
149 if(!lstrcmpW(state, completeW))
152 SysFreeString(state);
158 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
160 ok(0, "unexpected call\n");
164 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
165 PropertyNotifySink_QueryInterface,
166 PropertyNotifySink_AddRef,
167 PropertyNotifySink_Release,
168 PropertyNotifySink_OnChanged,
169 PropertyNotifySink_OnRequestEdit
172 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
174 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
178 if(IsEqualGUID(riid, &IID_IUnknown)
179 || IsEqualGUID(riid, &IID_IDispatch)
180 || IsEqualGUID(riid, &IID_IDispatchEx))
183 return E_NOINTERFACE;
188 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
193 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
198 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
200 ok(0, "unexpected call\n");
204 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
205 LCID lcid, ITypeInfo **ppTInfo)
207 ok(0, "unexpected call\n");
211 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
212 LPOLESTR *rgszNames, UINT cNames,
213 LCID lcid, DISPID *rgDispId)
215 ok(0, "unexpected call\n");
219 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
220 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
221 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
223 ok(0, "unexpected call\n");
227 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
229 ok(0, "unexpected call %s %x\n", debugstr_w(bstrName), grfdex);
233 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
235 ok(0, "unexpected call\n");
239 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
241 ok(0, "unexpected call\n");
245 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
247 ok(0, "unexpected call\n");
251 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
253 ok(0, "unexpected call\n");
257 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
259 ok(0, "unexpected call\n");
263 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
265 ok(0, "unexpected call\n");
269 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
270 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
272 CHECK_EXPECT(funcDisp);
274 ok(id == DISPID_VALUE, "id = %d\n", id);
275 ok(lcid == 0, "lcid = %x\n", lcid);
276 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
277 ok(pdp != NULL, "pdp == NULL\n");
278 ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
279 ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
280 ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
281 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
282 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
283 ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
284 ok(pvarRes != NULL, "pvarRes == NULL\n");
285 ok(pei != NULL, "pei == NULL");
286 ok(!pspCaller, "pspCaller != NULL\n");
288 V_VT(pvarRes) = VT_I4;
293 static IDispatchExVtbl testObjVtbl = {
294 DispatchEx_QueryInterface,
297 DispatchEx_GetTypeInfoCount,
298 DispatchEx_GetTypeInfo,
299 DispatchEx_GetIDsOfNames,
301 DispatchEx_GetDispID,
303 DispatchEx_DeleteMemberByName,
304 DispatchEx_DeleteMemberByDispID,
305 DispatchEx_GetMemberProperties,
306 DispatchEx_GetMemberName,
307 DispatchEx_GetNextDispID,
308 DispatchEx_GetNameSpaceParent
311 static IDispatchEx funcDisp = { &testObjVtbl };
313 static IHTMLDocument2 *create_document(void)
318 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
319 &IID_IHTMLDocument2, (void**)&doc);
320 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
325 static IHTMLDocument2 *create_doc_with_string(const char *str)
327 IPersistStreamInit *init;
333 notif_doc = doc = create_document();
337 doc_complete = FALSE;
339 mem = GlobalAlloc(0, len);
340 memcpy(mem, str, len);
341 CreateStreamOnHGlobal(mem, TRUE, &stream);
343 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
345 IPersistStreamInit_Load(init, stream);
346 IPersistStreamInit_Release(init);
347 IStream_Release(stream);
352 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
354 IConnectionPointContainer *container;
355 IConnectionPoint *cp;
359 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
360 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
362 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
363 IConnectionPointContainer_Release(container);
364 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
366 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
367 IConnectionPoint_Release(cp);
368 ok(hres == S_OK, "Advise failed: %08x\n", hres);
371 typedef void (*domtest_t)(IHTMLDocument2*);
373 static IHTMLDocument2 *create_and_load_doc(const char *str)
376 IHTMLElement *body = NULL;
380 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
385 doc = create_doc_with_string(str);
386 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
388 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
389 TranslateMessage(&msg);
390 DispatchMessage(&msg);
393 hres = IHTMLDocument2_get_body(doc, &body);
394 ok(hres == S_OK, "get_body failed: %08x\n", hres);
397 skip("Could not get document body. Assuming no Gecko installed.\n");
398 ref = IHTMLDocument2_Release(doc);
399 ok(!ref, "ref = %d\n", ref);
403 /* Check we can query for function on the IHTMLElementBody interface */
404 name = (WCHAR*)ucPtr;
405 hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
406 ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
407 ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
409 IHTMLElement_Release(body);
413 static IActiveScriptSite *site;
414 static SCRIPTSTATE state;
416 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
419 ok(0, "unexpected call\n");
420 return E_NOINTERFACE;
423 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
428 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
433 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
434 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
436 CHECK_EXPECT(GetInterfaceSafetyOptions);
438 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
439 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
440 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
442 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
443 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
448 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
449 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
451 CHECK_EXPECT(SetInterfaceSafetyOptions);
453 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
455 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
456 "dwOptionSetMask=%x\n", dwOptionSetMask);
457 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
458 "dwEnabledOptions=%x\n", dwOptionSetMask);
463 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
464 ObjectSafety_QueryInterface,
466 ObjectSafety_Release,
467 ObjectSafety_GetInterfaceSafetyOptions,
468 ObjectSafety_SetInterfaceSafetyOptions
471 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
473 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
476 ok(0, "unexpected call\n");
477 return E_NOINTERFACE;
480 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
485 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
490 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
491 VARIANT *pvarIndex, VARIANT *pvarValue)
493 ok(0, "unexpected call\n");
497 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
498 VARIANT *pvarIndex, VARIANT *pvarValue)
500 CHECK_EXPECT(SetProperty);
502 ok(dwProperty == SCRIPTPROP_HACK_TRIDENTEVENTSINK, "unexpected property %d\n", dwProperty);
503 ok(!pvarIndex, "pvarIndex != NULL\n");
504 ok(pvarValue != NULL, "pvarValue == NULL\n");
505 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
506 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
511 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
512 ActiveScriptProperty_QueryInterface,
513 ActiveScriptProperty_AddRef,
514 ActiveScriptProperty_Release,
515 ActiveScriptProperty_GetProperty,
516 ActiveScriptProperty_SetProperty
519 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
521 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
524 ok(0, "unexpected call\n");
525 return E_NOINTERFACE;
528 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
533 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
538 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
539 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
540 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
541 DWORD dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
543 ok(0, "unexpected call\n");
547 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
548 ActiveScriptParseProcedure_QueryInterface,
549 ActiveScriptParseProcedure_AddRef,
550 ActiveScriptParseProcedure_Release,
551 ActiveScriptParseProcedure_ParseProcedureText
554 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
556 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
559 ok(0, "unexpected call\n");
560 return E_NOINTERFACE;
563 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
568 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
573 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
575 CHECK_EXPECT(InitNew);
579 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
580 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
581 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
582 DWORD dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
583 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
585 ok(0, "unexpected call\n");
589 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
590 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
591 LPCOLESTR pstrDelimiter, DWORD dwSourceContextCookie, ULONG ulStartingLine,
592 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
594 IDispatchEx *document;
599 DISPID id, named_arg = DISPID_PROPERTYPUT;
603 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
604 static const WCHAR testW[] = {'t','e','s','t',0};
605 static const WCHAR funcW[] = {'f','u','n','c',0};
607 CHECK_EXPECT(ParseScriptText);
609 SET_EXPECT(GetScriptDispatch);
611 tmp = SysAllocString(documentW);
612 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
614 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
615 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
617 todo_wine CHECK_CALLED(GetScriptDispatch);
620 memset(&dp, 0, sizeof(dp));
621 memset(&ei, 0, sizeof(ei));
623 hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
624 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
625 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
626 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
628 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
630 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
632 tmp = SysAllocString(testW);
633 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
634 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
635 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
636 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
640 tmp = SysAllocString(testW);
641 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
643 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
649 dp.rgdispidNamedArgs = &named_arg;
653 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
654 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
656 tmp = SysAllocString(testW);
657 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
659 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
662 memset(&dp, 0, sizeof(dp));
663 memset(&ei, 0, sizeof(ei));
664 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
665 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
666 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
667 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
669 unk = (void*)0xdeadbeef;
670 hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
671 ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
672 ok(!unk, "unk=%p, expected NULL\n", unk);
675 tmp = SysAllocString(funcW);
676 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
678 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
684 dp.rgdispidNamedArgs = NULL;
685 V_VT(&var) = VT_DISPATCH;
686 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
688 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
689 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
692 memset(&dp, 0, sizeof(dp));
693 memset(&ei, 0, sizeof(ei));
694 V_VT(&arg) = VT_BOOL;
695 V_BOOL(&arg) = VARIANT_TRUE;
699 SET_EXPECT(funcDisp);
700 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
701 CHECK_CALLED(funcDisp);
703 ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
704 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
705 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
707 IDispatchEx_Release(document);
712 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
713 ActiveScriptParse_QueryInterface,
714 ActiveScriptParse_AddRef,
715 ActiveScriptParse_Release,
716 ActiveScriptParse_InitNew,
717 ActiveScriptParse_AddScriptlet,
718 ActiveScriptParse_ParseScriptText
721 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
723 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
727 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
732 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
733 *ppv = &ActiveScriptParse;
737 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
738 *ppv = &ActiveScriptParseProcedure;
742 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
743 *ppv = &ActiveScriptProperty;
747 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
748 *ppv = &ObjectSafety;
752 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
753 return E_NOINTERFACE;
756 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
761 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
766 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
768 IActiveScriptSiteInterruptPoll *poll;
769 IActiveScriptSiteDebug *debug;
773 CHECK_EXPECT(SetScriptSite);
775 ok(pass != NULL, "pass == NULL\n");
777 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
778 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
780 IActiveScriptSiteInterruptPoll_Release(poll);
782 hres = IActiveScriptSite_GetLCID(pass, &lcid);
783 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
785 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
786 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
788 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
789 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
791 IActiveScriptSiteDebug32_Release(debug);
794 IActiveScriptSite_AddRef(site);
798 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
801 ok(0, "unexpected call\n");
805 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
810 case SCRIPTSTATE_STARTED:
811 CHECK_EXPECT(SetScriptState_STARTED);
813 case SCRIPTSTATE_CONNECTED:
814 CHECK_EXPECT(SetScriptState_CONNECTED);
816 case SCRIPTSTATE_DISCONNECTED:
817 CHECK_EXPECT(SetScriptState_DISCONNECTED);
820 ok(0, "unexpected state %d\n", ss);
824 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
828 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
830 CHECK_EXPECT(GetScriptState);
836 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
842 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
843 LPCOLESTR pstrName, DWORD dwFlags)
846 IUnknown *unk = NULL, *unk2;
849 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
851 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
853 CHECK_EXPECT(AddNamedItem);
855 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", debugstr_w(pstrName));
856 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
858 hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
859 ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
860 ok(unk != NULL, "unk == NULL\n");
862 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
863 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
865 IDispatch_Release(disp);
867 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
868 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
870 IUnknown_Release(unk2);
872 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
873 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
875 IUnknown_Release(unk);
879 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
880 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
882 ok(0, "unexpected call\n");
886 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
889 CHECK_EXPECT(GetScriptDispatch);
893 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
894 SCRIPTTHREADID *pstridThread)
896 ok(0, "unexpected call\n");
900 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
901 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
903 ok(0, "unexpected call\n");
907 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
908 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
910 ok(0, "unexpected call\n");
914 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
915 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
917 ok(0, "unexpected call\n");
921 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
923 ok(0, "unexpected call\n");
927 static const IActiveScriptVtbl ActiveScriptVtbl = {
928 ActiveScript_QueryInterface,
930 ActiveScript_Release,
931 ActiveScript_SetScriptSite,
932 ActiveScript_GetScriptSite,
933 ActiveScript_SetScriptState,
934 ActiveScript_GetScriptState,
936 ActiveScript_AddNamedItem,
937 ActiveScript_AddTypeLib,
938 ActiveScript_GetScriptDispatch,
939 ActiveScript_GetCurrentScriptThreadID,
940 ActiveScript_GetScriptThreadID,
941 ActiveScript_GetScriptThreadState,
942 ActiveScript_InterruptScriptThread,
946 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
948 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
952 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
957 if(IsEqualGUID(&IID_IMarshal, riid))
958 return E_NOINTERFACE;
959 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
960 return E_NOINTERFACE;
962 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
966 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
971 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
976 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
978 CHECK_EXPECT(CreateInstance);
980 ok(!outer, "outer = %p\n", outer);
981 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
982 *ppv = &ActiveScript;
986 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
988 ok(0, "unexpected call\n");
992 static const IClassFactoryVtbl ClassFactoryVtbl = {
993 ClassFactory_QueryInterface,
995 ClassFactory_Release,
996 ClassFactory_CreateInstance,
997 ClassFactory_LockServer
1000 static IClassFactory script_cf = { &ClassFactoryVtbl };
1002 static const char simple_script_str[] =
1003 "<html><head></head><body>"
1004 "<script language=\"TestScript\">simple script</script>"
1007 static void test_simple_script(void)
1009 IHTMLDocument2 *doc;
1011 SET_EXPECT(CreateInstance);
1012 SET_EXPECT(GetInterfaceSafetyOptions);
1013 SET_EXPECT(SetInterfaceSafetyOptions);
1014 SET_EXPECT(SetProperty);
1015 SET_EXPECT(InitNew);
1016 SET_EXPECT(SetScriptSite);
1017 SET_EXPECT(GetScriptState);
1018 SET_EXPECT(SetScriptState_STARTED);
1019 SET_EXPECT(AddNamedItem);
1020 SET_EXPECT(ParseScriptText);
1021 SET_EXPECT(SetScriptState_CONNECTED);
1023 doc = create_and_load_doc(simple_script_str);
1026 CHECK_CALLED(CreateInstance);
1027 CHECK_CALLED(GetInterfaceSafetyOptions);
1028 CHECK_CALLED(SetInterfaceSafetyOptions);
1029 CHECK_CALLED(SetProperty);
1030 CHECK_CALLED(InitNew);
1031 CHECK_CALLED(SetScriptSite);
1032 CHECK_CALLED(GetScriptState);
1033 CHECK_CALLED(SetScriptState_STARTED);
1034 CHECK_CALLED(AddNamedItem);
1035 CHECK_CALLED(ParseScriptText);
1036 CHECK_CALLED(SetScriptState_CONNECTED);
1039 IActiveScriptSite_Release(site);
1041 IDispatchEx_Release(window_dispex);
1043 SET_EXPECT(SetScriptState_DISCONNECTED);
1046 IHTMLDocument2_Release(doc);
1048 CHECK_CALLED(SetScriptState_DISCONNECTED);
1049 CHECK_CALLED(Close);
1052 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1058 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1062 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1063 if(res != ERROR_SUCCESS)
1067 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1071 return res == ERROR_SUCCESS;
1074 static BOOL init_registry(BOOL init)
1076 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1077 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1079 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1083 static BOOL register_script_engine(void)
1088 if(!init_registry(TRUE)) {
1089 init_registry(FALSE);
1093 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1094 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1095 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1100 static void gecko_installer_workaround(BOOL disable)
1105 static BOOL has_url = FALSE;
1106 static char url[2048];
1108 if(!disable && !has_url)
1111 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1112 if(res != ERROR_SUCCESS)
1116 DWORD type, size = sizeof(url);
1118 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1119 if(res == ERROR_SUCCESS && type == REG_SZ)
1122 RegDeleteValue(hkey, "GeckoUrl");
1124 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1132 gecko_installer_workaround(TRUE);
1135 if(register_script_engine()) {
1136 test_simple_script();
1137 init_registry(FALSE);
1139 skip("Could not register TestScript engine\n");
1143 gecko_installer_workaround(FALSE);