2 * Copyright 2008-2009 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>
36 #include "mshtml_test.h"
38 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
40 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
41 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
42 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
46 #define CTXARG_T DWORDLONG
47 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
48 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
52 #define CTXARG_T DWORD
53 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
54 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
58 #define DEFINE_EXPECT(func) \
59 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
61 #define SET_EXPECT(func) \
62 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
64 #define CHECK_EXPECT2(func) \
66 ok(expect_ ##func, "unexpected call " #func "\n"); \
67 called_ ## func = TRUE; \
70 #define CHECK_EXPECT(func) \
72 CHECK_EXPECT2(func); \
73 expect_ ## func = FALSE; \
76 #define CHECK_CALLED(func) \
78 ok(called_ ## func, "expected " #func "\n"); \
79 expect_ ## func = called_ ## func = FALSE; \
82 #define CHECK_CALLED_BROKEN(func) \
84 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
85 expect_ ## func = called_ ## func = FALSE; \
88 #define CHECK_NOT_CALLED(func) \
90 ok(!called_ ## func, "unexpected " #func "\n"); \
91 expect_ ## func = called_ ## func = FALSE; \
94 #define CLEAR_CALLED(func) \
95 expect_ ## func = called_ ## func = FALSE
98 DEFINE_EXPECT(CreateInstance);
99 DEFINE_EXPECT(GetInterfaceSafetyOptions);
100 DEFINE_EXPECT(SetInterfaceSafetyOptions);
101 DEFINE_EXPECT(InitNew);
102 DEFINE_EXPECT(Close);
103 DEFINE_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
104 DEFINE_EXPECT(SetProperty_INVOKEVERSIONING);
105 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
106 DEFINE_EXPECT(SetScriptSite);
107 DEFINE_EXPECT(GetScriptState);
108 DEFINE_EXPECT(SetScriptState_STARTED);
109 DEFINE_EXPECT(SetScriptState_CONNECTED);
110 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
111 DEFINE_EXPECT(AddNamedItem);
112 DEFINE_EXPECT(ParseScriptText);
113 DEFINE_EXPECT(GetScriptDispatch);
114 DEFINE_EXPECT(funcDisp);
115 DEFINE_EXPECT(script_divid_d);
116 DEFINE_EXPECT(script_testprop_d);
117 DEFINE_EXPECT(script_testprop_i);
118 DEFINE_EXPECT(AXQueryInterface_IActiveScript);
119 DEFINE_EXPECT(AXQueryInterface_IObjectSafety);
120 DEFINE_EXPECT(AXGetInterfaceSafetyOptions);
121 DEFINE_EXPECT(AXSetInterfaceSafetyOptions);
123 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
125 #define DISPID_SCRIPT_TESTPROP 0x100000
127 static const GUID CLSID_TestScript =
128 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
129 static const GUID CLSID_TestActiveX =
130 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
132 static IHTMLDocument2 *notif_doc;
133 static IDispatchEx *window_dispex;
134 static BOOL doc_complete;
135 static IDispatch *script_disp;
137 static const char *debugstr_guid(REFIID riid)
141 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
142 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
143 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
144 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
149 static int strcmp_wa(LPCWSTR strw, const char *stra)
152 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
153 return lstrcmpA(stra, buf);
156 static BSTR a2bstr(const char *str)
161 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
162 ret = SysAllocStringLen(NULL, len);
163 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
168 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
169 REFIID riid, void**ppv)
171 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
176 return E_NOINTERFACE;
179 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
184 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
189 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
191 if(dispID == DISPID_READYSTATE){
195 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
197 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
198 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
200 if(!lstrcmpW(state, completeW))
203 SysFreeString(state);
209 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
211 ok(0, "unexpected call\n");
215 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
216 PropertyNotifySink_QueryInterface,
217 PropertyNotifySink_AddRef,
218 PropertyNotifySink_Release,
219 PropertyNotifySink_OnChanged,
220 PropertyNotifySink_OnRequestEdit
223 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
225 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
229 if(IsEqualGUID(riid, &IID_IUnknown)
230 || IsEqualGUID(riid, &IID_IDispatch)
231 || IsEqualGUID(riid, &IID_IDispatchEx))
234 return E_NOINTERFACE;
239 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
244 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
249 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
251 ok(0, "unexpected call\n");
255 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
256 LCID lcid, ITypeInfo **ppTInfo)
258 ok(0, "unexpected call\n");
262 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
263 LPOLESTR *rgszNames, UINT cNames,
264 LCID lcid, DISPID *rgDispId)
266 ok(0, "unexpected call\n");
270 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
271 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
272 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
274 ok(0, "unexpected call\n");
278 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
280 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
284 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
286 ok(0, "unexpected call\n");
290 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
292 ok(0, "unexpected call\n");
296 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
298 ok(0, "unexpected call\n");
302 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
304 ok(0, "unexpected call\n");
308 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
310 ok(0, "unexpected call\n");
314 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
316 ok(0, "unexpected call\n");
320 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
321 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
323 CHECK_EXPECT(funcDisp);
325 ok(id == DISPID_VALUE, "id = %d\n", id);
326 ok(lcid == 0, "lcid = %x\n", lcid);
327 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
328 ok(pdp != NULL, "pdp == NULL\n");
329 ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
330 ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
331 ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
332 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
333 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
334 ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
335 ok(pvarRes != NULL, "pvarRes == NULL\n");
336 ok(pei != NULL, "pei == NULL\n");
337 ok(!pspCaller, "pspCaller != NULL\n");
339 V_VT(pvarRes) = VT_I4;
344 static IDispatchExVtbl testObjVtbl = {
345 DispatchEx_QueryInterface,
348 DispatchEx_GetTypeInfoCount,
349 DispatchEx_GetTypeInfo,
350 DispatchEx_GetIDsOfNames,
352 DispatchEx_GetDispID,
354 DispatchEx_DeleteMemberByName,
355 DispatchEx_DeleteMemberByDispID,
356 DispatchEx_GetMemberProperties,
357 DispatchEx_GetMemberName,
358 DispatchEx_GetNextDispID,
359 DispatchEx_GetNameSpaceParent
362 static IDispatchEx funcDisp = { &testObjVtbl };
364 static HRESULT WINAPI scriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
366 if(!strcmp_wa(bstrName, "testProp")) {
367 CHECK_EXPECT(script_testprop_d);
368 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
369 *pid = DISPID_SCRIPT_TESTPROP;
373 if(!strcmp_wa(bstrName, "divid")) {
374 CHECK_EXPECT(script_divid_d);
375 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
379 ok(0, "unexpected call\b");
383 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
384 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
387 case DISPID_SCRIPT_TESTPROP:
388 CHECK_EXPECT(script_testprop_i);
390 ok(lcid == 0, "lcid = %x\n", lcid);
391 ok(wFlags == DISPATCH_PROPERTYGET, "wFlags = %x\n", wFlags);
392 ok(pdp != NULL, "pdp == NULL\n");
393 ok(pdp->cArgs == 0, "pdp->cArgs = %d\n", pdp->cArgs);
394 ok(pdp->cNamedArgs == 0, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
395 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs != NULL\n");
396 ok(!pdp->rgvarg, "rgvarg != NULL\n");
397 ok(pvarRes != NULL, "pvarRes == NULL\n");
398 ok(pei != NULL, "pei == NULL\n");
399 ok(!pspCaller, "pspCaller != NULL\n");
401 V_VT(pvarRes) = VT_NULL;
404 ok(0, "unexpected call\n");
411 static IDispatchExVtbl scriptDispVtbl = {
412 DispatchEx_QueryInterface,
415 DispatchEx_GetTypeInfoCount,
416 DispatchEx_GetTypeInfo,
417 DispatchEx_GetIDsOfNames,
419 scriptDisp_GetDispID,
421 DispatchEx_DeleteMemberByName,
422 DispatchEx_DeleteMemberByDispID,
423 DispatchEx_GetMemberProperties,
424 DispatchEx_GetMemberName,
425 DispatchEx_GetNextDispID,
426 DispatchEx_GetNameSpaceParent
429 static IDispatchEx scriptDisp = { &scriptDispVtbl };
431 static IHTMLDocument2 *create_document(void)
436 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
437 &IID_IHTMLDocument2, (void**)&doc);
438 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
443 static IHTMLDocument2 *create_doc_with_string(const char *str)
445 IPersistStreamInit *init;
451 notif_doc = doc = create_document();
455 doc_complete = FALSE;
457 mem = GlobalAlloc(0, len);
458 memcpy(mem, str, len);
459 CreateStreamOnHGlobal(mem, TRUE, &stream);
461 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
463 IPersistStreamInit_Load(init, stream);
464 IPersistStreamInit_Release(init);
465 IStream_Release(stream);
470 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
472 IConnectionPointContainer *container;
473 IConnectionPoint *cp;
477 hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
478 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
480 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
481 IConnectionPointContainer_Release(container);
482 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
484 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
485 IConnectionPoint_Release(cp);
486 ok(hres == S_OK, "Advise failed: %08x\n", hres);
489 typedef void (*domtest_t)(IHTMLDocument2*);
491 static IHTMLDocument2 *create_and_load_doc(const char *str)
494 IHTMLElement *body = NULL;
498 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
503 doc = create_doc_with_string(str);
504 do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
506 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
507 TranslateMessage(&msg);
508 DispatchMessage(&msg);
511 hres = IHTMLDocument2_get_body(doc, &body);
512 ok(hres == S_OK, "get_body failed: %08x\n", hres);
515 skip("Could not get document body. Assuming no Gecko installed.\n");
516 ref = IHTMLDocument2_Release(doc);
517 ok(!ref, "ref = %d\n", ref);
521 /* Check we can query for function on the IHTMLElementBody interface */
522 name = (WCHAR*)ucPtr;
523 hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
524 ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
525 ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
527 IHTMLElement_Release(body);
531 static IActiveScriptSite *site;
532 static SCRIPTSTATE state;
534 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
537 ok(0, "unexpected call %s\n", debugstr_guid(riid));
538 return E_NOINTERFACE;
541 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
546 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
551 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
552 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
554 CHECK_EXPECT(GetInterfaceSafetyOptions);
556 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
557 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
558 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
560 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
561 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
566 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
567 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
569 CHECK_EXPECT(SetInterfaceSafetyOptions);
571 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
573 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
574 "dwOptionSetMask=%x\n", dwOptionSetMask);
575 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
576 "dwEnabledOptions=%x\n", dwOptionSetMask);
581 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
582 ObjectSafety_QueryInterface,
584 ObjectSafety_Release,
585 ObjectSafety_GetInterfaceSafetyOptions,
586 ObjectSafety_SetInterfaceSafetyOptions
589 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
591 static HRESULT WINAPI AXObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
595 if(IsEqualGUID(&IID_IActiveScript, riid)) {
596 CHECK_EXPECT(AXQueryInterface_IActiveScript);
597 return E_NOINTERFACE;
600 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
601 CHECK_EXPECT(AXQueryInterface_IObjectSafety);
606 ok(0, "unexpected call %s\n", debugstr_guid(riid));
607 return E_NOINTERFACE;
610 static HRESULT WINAPI AXObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
611 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
613 CHECK_EXPECT(AXGetInterfaceSafetyOptions);
615 ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
616 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
617 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
619 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
620 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
625 static HRESULT WINAPI AXObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
626 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
628 CHECK_EXPECT(AXSetInterfaceSafetyOptions);
630 ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
632 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER),
633 "dwOptionSetMask=%x\n", dwOptionSetMask);
634 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER),
635 "dwEnabledOptions=%x\n", dwOptionSetMask);
640 static const IObjectSafetyVtbl AXObjectSafetyVtbl = {
641 AXObjectSafety_QueryInterface,
643 ObjectSafety_Release,
644 AXObjectSafety_GetInterfaceSafetyOptions,
645 AXObjectSafety_SetInterfaceSafetyOptions
648 static IObjectSafety AXObjectSafety = { &AXObjectSafetyVtbl };
650 static void test_security(void)
652 IInternetHostSecurityManager *sec_mgr;
653 IServiceProvider *sp;
654 DWORD policy, policy_size;
655 struct CONFIRMSAFETY cs;
659 hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
660 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
662 hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager,
663 &IID_IInternetHostSecurityManager, (void**)&sec_mgr);
664 IServiceProvider_Release(sp);
665 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
667 hres = IInternetHostSecurityManager_ProcessUrlAction(sec_mgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
668 (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
669 ok(hres == S_OK, "ProcessUrlAction failed: %08x\n", hres);
670 ok(policy == URLPOLICY_ALLOW, "policy = %x\n", policy);
672 cs.clsid = CLSID_TestActiveX;
673 cs.pUnk = (IUnknown*)&AXObjectSafety;
676 SET_EXPECT(AXQueryInterface_IActiveScript);
677 SET_EXPECT(AXQueryInterface_IObjectSafety);
678 SET_EXPECT(AXGetInterfaceSafetyOptions);
679 SET_EXPECT(AXSetInterfaceSafetyOptions);
680 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
681 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
682 CHECK_CALLED(AXQueryInterface_IActiveScript);
683 CHECK_CALLED(AXQueryInterface_IObjectSafety);
684 CHECK_CALLED(AXGetInterfaceSafetyOptions);
685 CHECK_CALLED(AXSetInterfaceSafetyOptions);
687 ok(hres == S_OK, "QueryCusromPolicy failed: %08x\n", hres);
688 ok(policy_size == sizeof(DWORD), "policy_size = %d\n", policy_size);
689 ok(*(DWORD*)ppolicy == URLPOLICY_ALLOW, "policy = %x\n", *(DWORD*)ppolicy);
690 CoTaskMemFree(ppolicy);
692 IInternetHostSecurityManager_Release(sec_mgr);
695 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
698 ok(0, "unexpected call\n");
699 return E_NOINTERFACE;
702 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
707 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
712 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
713 VARIANT *pvarIndex, VARIANT *pvarValue)
715 ok(0, "unexpected call\n");
719 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
720 VARIANT *pvarIndex, VARIANT *pvarValue)
723 case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
724 CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
725 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
726 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
728 case SCRIPTPROP_INVOKEVERSIONING:
729 CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
730 ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
731 ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
733 case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
734 CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
735 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
736 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
739 ok(0, "unexpected property %x\n", dwProperty);
743 ok(!pvarIndex, "pvarIndex != NULL\n");
744 ok(pvarValue != NULL, "pvarValue == NULL\n");
749 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
750 ActiveScriptProperty_QueryInterface,
751 ActiveScriptProperty_AddRef,
752 ActiveScriptProperty_Release,
753 ActiveScriptProperty_GetProperty,
754 ActiveScriptProperty_SetProperty
757 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
759 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
762 ok(0, "unexpected call\n");
763 return E_NOINTERFACE;
766 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
771 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
776 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
777 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
778 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
779 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
781 ok(0, "unexpected call\n");
785 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
786 ActiveScriptParseProcedure_QueryInterface,
787 ActiveScriptParseProcedure_AddRef,
788 ActiveScriptParseProcedure_Release,
789 ActiveScriptParseProcedure_ParseProcedureText
792 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
794 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
797 ok(0, "unexpected call\n");
798 return E_NOINTERFACE;
801 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
806 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
811 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
813 CHECK_EXPECT(InitNew);
817 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
818 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
819 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
820 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
821 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
823 ok(0, "unexpected call\n");
827 static HRESULT dispex_propput(IDispatchEx *obj, DISPID id, DWORD flags, VARIANT *var)
829 DISPID propput_arg = DISPID_PROPERTYPUT;
830 DISPPARAMS dp = {var, &propput_arg, 1, 1};
833 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT|flags, &dp, NULL, &ei, NULL);
836 static void test_func(IDispatchEx *obj)
847 str = a2bstr("toString");
848 hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
850 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
851 ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
853 memset(&dp, 0, sizeof(dp));
854 memset(&ei, 0, sizeof(ei));
856 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
857 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
858 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
859 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
860 disp = V_DISPATCH(&var);
862 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
863 IDispatch_Release(disp);
864 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
866 /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
868 memset(&dp, 0, sizeof(dp));
869 memset(&ei, 0, sizeof(ei));
871 hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
872 ok(hres == S_OK || broken(E_ACCESSDENIED), "InvokeEx failed: %08x\n", hres);
873 if(SUCCEEDED(hres)) {
874 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
875 ok(!strcmp_wa(V_BSTR(&var), "[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
881 hres = dispex_propput(obj, id, 0, &var);
882 ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
884 IDispatchEx_Release(dispex);
887 static void test_nextdispid(IDispatchEx *dispex)
889 DISPID last_id = DISPID_STARTENUM, id, dyn_id;
894 name = a2bstr("dynVal");
895 hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive|fdexNameEnsure, &dyn_id);
896 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
899 V_VT(&var) = VT_EMPTY;
900 hres = dispex_propput(dispex, dyn_id, 0, &var);
902 while(last_id != dyn_id) {
903 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, last_id, &id);
904 ok(hres == S_OK, "GetNextDispID returned: %08x\n", hres);
905 ok(id != DISPID_STARTENUM, "id == DISPID_STARTENUM\n");
906 ok(id != DISPID_IOMNAVIGATOR_TOSTRING, "id == DISPID_IOMNAVIGATOR_TOSTRING\n");
908 hres = IDispatchEx_GetMemberName(dispex, id, &name);
909 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
912 ok(!strcmp_wa(name, "dynVal"), "name = %s\n", wine_dbgstr_w(name));
913 else if(id == DISPID_IOMNAVIGATOR_PLATFORM)
914 ok(!strcmp_wa(name, "platform"), "name = %s\n", wine_dbgstr_w(name));
920 hres = IDispatchEx_GetNextDispID(dispex, 0, id, &id);
921 ok(hres == S_FALSE, "GetNextDispID returned: %08x\n", hres);
922 ok(id == DISPID_STARTENUM, "id != DISPID_STARTENUM\n");
925 static void test_global_id(void)
934 SET_EXPECT(GetScriptDispatch);
935 SET_EXPECT(script_divid_d);
936 tmp = a2bstr("divid");
937 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
938 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
940 CHECK_CALLED(GetScriptDispatch);
941 CHECK_CALLED(script_divid_d);
944 memset(&ei, 0, sizeof(ei));
945 memset(&dp, 0, sizeof(dp));
946 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
947 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
948 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d\n", V_VT(&var));
952 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
953 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
954 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
955 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
957 IDispatchEx *document, *dispex;
958 IHTMLWindow2 *window;
959 IOmNavigator *navigator;
968 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
969 static const WCHAR testW[] = {'t','e','s','t',0};
970 static const WCHAR funcW[] = {'f','u','n','c',0};
972 CHECK_EXPECT(ParseScriptText);
974 SET_EXPECT(GetScriptDispatch);
976 tmp = SysAllocString(documentW);
977 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
979 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
980 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
982 CHECK_CALLED(GetScriptDispatch);
985 memset(&dp, 0, sizeof(dp));
986 memset(&ei, 0, sizeof(ei));
988 hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
989 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
990 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
991 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
993 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
995 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
997 tmp = SysAllocString(testW);
998 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
999 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1000 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
1001 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1005 tmp = SysAllocString(testW);
1006 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
1008 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1009 ok(id, "id == 0\n");
1013 hres = dispex_propput(document, id, 0, &var);
1014 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1016 tmp = SysAllocString(testW);
1017 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
1019 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1022 memset(&dp, 0, sizeof(dp));
1023 memset(&ei, 0, sizeof(ei));
1024 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1025 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1026 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1027 ok(V_I4(&var) == 100, "V_I4(&var) = %d\n", V_I4(&var));
1031 hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var);
1032 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1035 memset(&dp, 0, sizeof(dp));
1036 memset(&ei, 0, sizeof(ei));
1037 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1038 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1039 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1040 ok(V_I4(&var) == 200, "V_I4(&var) = %d\n", V_I4(&var));
1042 memset(&dp, 0, sizeof(dp));
1043 memset(&ei, 0, sizeof(ei));
1048 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
1049 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1052 memset(&dp, 0, sizeof(dp));
1053 memset(&ei, 0, sizeof(ei));
1054 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1055 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1056 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1057 ok(V_I4(&var) == 300, "V_I4(&var) = %d\n", V_I4(&var));
1059 unk = (void*)0xdeadbeef;
1060 hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
1061 ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
1062 ok(!unk, "unk=%p, expected NULL\n", unk);
1065 tmp = SysAllocString(funcW);
1066 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
1068 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
1069 ok(id, "id == 0\n");
1074 dp.rgdispidNamedArgs = NULL;
1075 V_VT(&var) = VT_DISPATCH;
1076 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
1077 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
1078 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1081 memset(&dp, 0, sizeof(dp));
1082 memset(&ei, 0, sizeof(ei));
1083 V_VT(&arg) = VT_BOOL;
1084 V_BOOL(&arg) = VARIANT_TRUE;
1088 SET_EXPECT(funcDisp);
1089 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
1090 CHECK_CALLED(funcDisp);
1092 ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
1093 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1094 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
1096 IDispatchEx_Release(document);
1098 hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
1099 ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
1101 hres = IHTMLWindow2_get_navigator(window, &navigator);
1102 IHTMLWindow2_Release(window);
1103 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
1105 hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
1106 IOmNavigator_Release(navigator);
1107 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1110 test_nextdispid(dispex);
1111 IDispatchEx_Release(dispex);
1113 script_disp = (IDispatch*)&scriptDisp;
1115 SET_EXPECT(GetScriptDispatch);
1116 SET_EXPECT(script_testprop_d);
1117 tmp = a2bstr("testProp");
1118 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1119 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1120 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
1121 CHECK_CALLED(GetScriptDispatch);
1122 CHECK_CALLED(script_testprop_d);
1125 tmp = a2bstr("testProp");
1126 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1127 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1128 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
1131 SET_EXPECT(GetScriptDispatch);
1132 SET_EXPECT(script_testprop_i);
1133 memset(&ei, 0, sizeof(ei));
1134 memset(&dp, 0, sizeof(dp));
1135 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1136 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1137 ok(V_VT(&var) == VT_NULL, "V_VT(var) = %d\n", V_VT(&var));
1138 CHECK_CALLED(GetScriptDispatch);
1139 CHECK_CALLED(script_testprop_i);
1148 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
1149 ActiveScriptParse_QueryInterface,
1150 ActiveScriptParse_AddRef,
1151 ActiveScriptParse_Release,
1152 ActiveScriptParse_InitNew,
1153 ActiveScriptParse_AddScriptlet,
1154 ActiveScriptParse_ParseScriptText
1157 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
1159 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
1163 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
1168 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
1169 *ppv = &ActiveScriptParse;
1173 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
1174 *ppv = &ActiveScriptParseProcedure;
1178 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
1179 *ppv = &ActiveScriptProperty;
1183 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1184 *ppv = &ObjectSafety;
1188 if(IsEqualGUID(&IID_IActiveScriptDebug, riid))
1189 return E_NOINTERFACE;
1191 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1192 return E_NOINTERFACE;
1195 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
1200 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
1205 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
1207 IActiveScriptSiteInterruptPoll *poll;
1208 IActiveScriptSiteDebug *debug;
1209 IServiceProvider *service;
1210 ICanHandleException *canexpection;
1214 CHECK_EXPECT(SetScriptSite);
1216 ok(pass != NULL, "pass == NULL\n");
1218 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
1219 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
1221 IActiveScriptSiteInterruptPoll_Release(poll);
1223 hres = IActiveScriptSite_GetLCID(pass, &lcid);
1224 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
1226 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
1227 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
1229 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
1230 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
1232 IActiveScriptSiteDebug32_Release(debug);
1234 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
1235 ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
1237 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
1238 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
1240 IServiceProvider_Release(service);
1243 IActiveScriptSite_AddRef(site);
1247 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
1250 ok(0, "unexpected call\n");
1254 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
1259 case SCRIPTSTATE_STARTED:
1260 CHECK_EXPECT(SetScriptState_STARTED);
1262 case SCRIPTSTATE_CONNECTED:
1263 CHECK_EXPECT(SetScriptState_CONNECTED);
1265 case SCRIPTSTATE_DISCONNECTED:
1266 CHECK_EXPECT(SetScriptState_DISCONNECTED);
1269 ok(0, "unexpected state %d\n", ss);
1273 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
1277 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
1279 CHECK_EXPECT(GetScriptState);
1285 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
1287 CHECK_EXPECT(Close);
1291 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
1292 LPCOLESTR pstrName, DWORD dwFlags)
1295 IUnknown *unk = NULL, *unk2;
1298 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
1300 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
1302 CHECK_EXPECT(AddNamedItem);
1304 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
1305 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
1307 hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
1308 ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
1309 ok(unk != NULL, "unk == NULL\n");
1311 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
1312 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
1314 IDispatch_Release(disp);
1316 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
1317 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
1319 IUnknown_Release(unk2);
1321 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
1322 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
1324 IUnknown_Release(unk);
1328 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
1329 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
1331 ok(0, "unexpected call\n");
1335 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
1338 CHECK_EXPECT(GetScriptDispatch);
1340 ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
1345 *ppdisp = script_disp;
1349 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
1350 SCRIPTTHREADID *pstridThread)
1352 ok(0, "unexpected call\n");
1356 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
1357 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
1359 ok(0, "unexpected call\n");
1363 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
1364 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
1366 ok(0, "unexpected call\n");
1370 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
1371 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
1373 ok(0, "unexpected call\n");
1377 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
1379 ok(0, "unexpected call\n");
1383 static const IActiveScriptVtbl ActiveScriptVtbl = {
1384 ActiveScript_QueryInterface,
1385 ActiveScript_AddRef,
1386 ActiveScript_Release,
1387 ActiveScript_SetScriptSite,
1388 ActiveScript_GetScriptSite,
1389 ActiveScript_SetScriptState,
1390 ActiveScript_GetScriptState,
1392 ActiveScript_AddNamedItem,
1393 ActiveScript_AddTypeLib,
1394 ActiveScript_GetScriptDispatch,
1395 ActiveScript_GetCurrentScriptThreadID,
1396 ActiveScript_GetScriptThreadID,
1397 ActiveScript_GetScriptThreadState,
1398 ActiveScript_InterruptScriptThread,
1402 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
1404 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1408 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
1413 if(IsEqualGUID(&IID_IMarshal, riid))
1414 return E_NOINTERFACE;
1415 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
1416 return E_NOINTERFACE;
1418 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1422 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1427 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1432 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
1434 CHECK_EXPECT(CreateInstance);
1436 ok(!outer, "outer = %p\n", outer);
1437 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
1438 *ppv = &ActiveScript;
1442 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1444 ok(0, "unexpected call\n");
1448 static const IClassFactoryVtbl ClassFactoryVtbl = {
1449 ClassFactory_QueryInterface,
1450 ClassFactory_AddRef,
1451 ClassFactory_Release,
1452 ClassFactory_CreateInstance,
1453 ClassFactory_LockServer
1456 static IClassFactory script_cf = { &ClassFactoryVtbl };
1458 static const char simple_script_str[] =
1459 "<html><head></head><body>"
1460 "<div id=\"divid\"></div>"
1461 "<script language=\"TestScript\">simple script</script>"
1464 static void test_simple_script(void)
1466 IHTMLDocument2 *doc;
1468 SET_EXPECT(CreateInstance);
1469 SET_EXPECT(GetInterfaceSafetyOptions);
1470 SET_EXPECT(SetInterfaceSafetyOptions);
1471 SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
1472 SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1473 SET_EXPECT(InitNew);
1474 SET_EXPECT(SetScriptSite);
1475 SET_EXPECT(GetScriptState);
1476 SET_EXPECT(SetScriptState_STARTED);
1477 SET_EXPECT(AddNamedItem);
1478 SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
1479 SET_EXPECT(ParseScriptText);
1480 SET_EXPECT(SetScriptState_CONNECTED);
1482 doc = create_and_load_doc(simple_script_str);
1485 CHECK_CALLED(CreateInstance);
1486 CHECK_CALLED(GetInterfaceSafetyOptions);
1487 CHECK_CALLED(SetInterfaceSafetyOptions);
1488 CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
1489 CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
1490 CHECK_CALLED(InitNew);
1491 CHECK_CALLED(SetScriptSite);
1492 CHECK_CALLED(GetScriptState);
1493 CHECK_CALLED(SetScriptState_STARTED);
1494 CHECK_CALLED(AddNamedItem);
1495 CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
1496 CHECK_CALLED(ParseScriptText);
1497 CHECK_CALLED(SetScriptState_CONNECTED);
1500 IActiveScriptSite_Release(site);
1502 IDispatchEx_Release(window_dispex);
1504 SET_EXPECT(SetScriptState_DISCONNECTED);
1507 IHTMLDocument2_Release(doc);
1509 CHECK_CALLED(SetScriptState_DISCONNECTED);
1510 CHECK_CALLED(Close);
1513 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
1519 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
1523 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
1524 if(res != ERROR_SUCCESS)
1528 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
1532 return res == ERROR_SUCCESS;
1535 static BOOL init_registry(BOOL init)
1537 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
1538 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1540 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1544 static BOOL register_script_engine(void)
1549 if(!init_registry(TRUE)) {
1550 init_registry(FALSE);
1554 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
1555 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1556 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
1561 static void gecko_installer_workaround(BOOL disable)
1566 static BOOL has_url = FALSE;
1567 static char url[2048];
1569 if(!disable && !has_url)
1572 res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
1573 if(res != ERROR_SUCCESS)
1577 DWORD type, size = sizeof(url);
1579 res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
1580 if(res == ERROR_SUCCESS && type == REG_SZ)
1583 RegDeleteValue(hkey, "GeckoUrl");
1585 RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
1593 gecko_installer_workaround(TRUE);
1596 if(winetest_interactive || ! is_ie_hardened()) {
1597 if(register_script_engine()) {
1598 test_simple_script();
1599 init_registry(FALSE);
1601 skip("Could not register TestScript engine\n");
1604 skip("IE running in Enhanced Security Configuration\n");
1608 gecko_installer_workaround(FALSE);