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>
40 #include "mshtml_test.h"
42 DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
44 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
45 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
46 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
50 #define CTXARG_T DWORDLONG
51 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
52 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
56 #define CTXARG_T DWORD
57 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
58 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
62 #define DEFINE_EXPECT(func) \
63 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
65 #define SET_EXPECT(func) \
66 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
68 #define CHECK_EXPECT2(func) \
70 ok(expect_ ##func, "unexpected call " #func "\n"); \
71 called_ ## func = TRUE; \
74 #define CHECK_EXPECT(func) \
76 CHECK_EXPECT2(func); \
77 expect_ ## func = FALSE; \
80 #define CHECK_CALLED(func) \
82 ok(called_ ## func, "expected " #func "\n"); \
83 expect_ ## func = called_ ## func = FALSE; \
86 #define CHECK_CALLED_BROKEN(func) \
88 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
89 expect_ ## func = called_ ## func = FALSE; \
92 #define CHECK_NOT_CALLED(func) \
94 ok(!called_ ## func, "unexpected " #func "\n"); \
95 expect_ ## func = called_ ## func = FALSE; \
98 #define CLEAR_CALLED(func) \
99 expect_ ## func = called_ ## func = FALSE
102 DEFINE_EXPECT(CreateInstance);
103 DEFINE_EXPECT(GetInterfaceSafetyOptions);
104 DEFINE_EXPECT(SetInterfaceSafetyOptions);
105 DEFINE_EXPECT(InitNew);
106 DEFINE_EXPECT(Close);
107 DEFINE_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
108 DEFINE_EXPECT(SetProperty_INVOKEVERSIONING);
109 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
110 DEFINE_EXPECT(SetScriptSite);
111 DEFINE_EXPECT(GetScriptState);
112 DEFINE_EXPECT(SetScriptState_STARTED);
113 DEFINE_EXPECT(SetScriptState_CONNECTED);
114 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
115 DEFINE_EXPECT(AddNamedItem);
116 DEFINE_EXPECT(ParseScriptText_script);
117 DEFINE_EXPECT(ParseScriptText_execScript);
118 DEFINE_EXPECT(GetScriptDispatch);
119 DEFINE_EXPECT(funcDisp);
120 DEFINE_EXPECT(script_divid_d);
121 DEFINE_EXPECT(script_testprop_d);
122 DEFINE_EXPECT(script_testprop_i);
123 DEFINE_EXPECT(script_testprop2_d);
124 DEFINE_EXPECT(AXQueryInterface_IActiveScript);
125 DEFINE_EXPECT(AXQueryInterface_IObjectSafety);
126 DEFINE_EXPECT(AXGetInterfaceSafetyOptions);
127 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
128 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
129 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
130 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
131 DEFINE_EXPECT(external_success);
132 DEFINE_EXPECT(QS_VariantConversion);
133 DEFINE_EXPECT(ChangeType);
135 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
136 #define TESTACTIVEX_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
138 #define DISPID_SCRIPT_TESTPROP 0x100000
139 #define DISPID_SCRIPT_TESTPROP2 0x100001
141 #define DISPID_EXTERNAL_OK 0x300000
142 #define DISPID_EXTERNAL_TRACE 0x300001
143 #define DISPID_EXTERNAL_REPORTSUCCESS 0x300002
144 #define DISPID_EXTERNAL_TODO_WINE_OK 0x300003
146 static const GUID CLSID_TestScript =
147 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
148 static const GUID CLSID_TestActiveX =
149 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
151 static IHTMLDocument2 *notif_doc;
152 static IOleDocumentView *view;
153 static IDispatchEx *window_dispex;
154 static BOOL doc_complete;
155 static IDispatch *script_disp;
156 static BOOL ax_objsafe;
157 static HWND container_hwnd;
158 static HRESULT ax_getopt_hres = S_OK, ax_setopt_dispex_hres = S_OK;
159 static HRESULT ax_setopt_disp_caller_hres = S_OK, ax_setopt_disp_data_hres = S_OK;
160 static BOOL skip_loadobject_tests;
162 static const char *debugstr_guid(REFIID riid)
166 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
167 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
168 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
169 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
174 static int strcmp_wa(LPCWSTR strw, const char *stra)
177 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
178 return lstrcmpA(stra, buf);
181 static BSTR a2bstr(const char *str)
189 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
190 ret = SysAllocStringLen(NULL, len);
191 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
196 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
202 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
206 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
207 if(res != ERROR_SUCCESS)
211 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
215 return res == ERROR_SUCCESS;
218 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
219 REFIID riid, void**ppv)
221 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
226 return E_NOINTERFACE;
229 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
234 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
239 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
241 if(dispID == DISPID_READYSTATE){
245 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
247 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
248 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
250 if(!lstrcmpW(state, completeW))
253 SysFreeString(state);
259 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
261 ok(0, "unexpected call\n");
265 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
266 PropertyNotifySink_QueryInterface,
267 PropertyNotifySink_AddRef,
268 PropertyNotifySink_Release,
269 PropertyNotifySink_OnChanged,
270 PropertyNotifySink_OnRequestEdit
273 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
275 static HRESULT WINAPI VariantChangeType_QueryInterface(IVariantChangeType *iface, REFIID riid, void **ppv)
277 ok(0, "unexpected call %s\n", debugstr_guid(riid));
279 return E_NOINTERFACE;
282 static ULONG WINAPI VariantChangeType_AddRef(IVariantChangeType *iface)
287 static ULONG WINAPI VariantChangeType_Release(IVariantChangeType *iface)
292 static HRESULT WINAPI VariantChangeType_ChangeType(IVariantChangeType *iface, VARIANT *dst, VARIANT *src, LCID lcid, VARTYPE vt)
294 CHECK_EXPECT(ChangeType);
296 ok(dst != NULL, "dst = NULL\n");
297 ok(V_VT(dst) == VT_EMPTY, "V_VT(dst) = %d\n", V_VT(dst));
298 ok(src != NULL, "src = NULL\n");
299 ok(V_VT(src) == VT_I4, "V_VT(src) = %d\n", V_VT(src));
300 ok(V_I4(src) == 0xf0f0f0, "V_I4(src) = %x\n", V_I4(src));
301 ok(lcid == LOCALE_NEUTRAL, "lcid = %d\n", lcid);
302 ok(vt == VT_BSTR, "vt = %d\n", vt);
305 V_BSTR(dst) = a2bstr("red");
309 static const IVariantChangeTypeVtbl VariantChangeTypeVtbl = {
310 VariantChangeType_QueryInterface,
311 VariantChangeType_AddRef,
312 VariantChangeType_Release,
313 VariantChangeType_ChangeType
316 static IVariantChangeType VChangeType = { &VariantChangeTypeVtbl };
318 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
320 ok(0, "unexpected call\n");
321 return E_NOINTERFACE;
324 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
329 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
334 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
335 REFIID riid, void **ppv)
337 if(IsEqualGUID(guidService, &SID_VariantConversion)) {
338 CHECK_EXPECT(QS_VariantConversion);
339 ok(IsEqualGUID(riid, &IID_IVariantChangeType), "uenxpected riid %s\n", debugstr_guid(riid));
344 ok(0, "unexpected service %s\n", debugstr_guid(guidService));
345 return E_NOINTERFACE;
348 static const IServiceProviderVtbl ServiceProviderVtbl = {
349 ServiceProvider_QueryInterface,
350 ServiceProvider_AddRef,
351 ServiceProvider_Release,
352 ServiceProvider_QueryService
355 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
357 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
361 if(IsEqualGUID(riid, &IID_IUnknown)
362 || IsEqualGUID(riid, &IID_IDispatch)
363 || IsEqualGUID(riid, &IID_IDispatchEx))
366 return E_NOINTERFACE;
371 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
376 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
381 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
383 ok(0, "unexpected call\n");
387 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
388 LCID lcid, ITypeInfo **ppTInfo)
390 ok(0, "unexpected call\n");
394 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
395 LPOLESTR *rgszNames, UINT cNames,
396 LCID lcid, DISPID *rgDispId)
398 ok(0, "unexpected call\n");
402 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
403 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
404 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
406 ok(0, "unexpected call\n");
410 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
412 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
416 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
418 ok(0, "unexpected call\n");
422 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
424 ok(0, "unexpected call\n");
428 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
430 ok(0, "unexpected call\n");
434 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
436 ok(0, "unexpected call\n");
440 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
442 ok(0, "unexpected call\n");
446 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
448 ok(0, "unexpected call\n");
452 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
453 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
455 CHECK_EXPECT(funcDisp);
457 ok(id == DISPID_VALUE, "id = %d\n", id);
458 ok(lcid == 0, "lcid = %x\n", lcid);
459 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
460 ok(pdp != NULL, "pdp == NULL\n");
461 ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
462 ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
463 ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
464 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
465 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
466 ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
467 ok(pvarRes != NULL, "pvarRes == NULL\n");
468 ok(pei != NULL, "pei == NULL\n");
469 ok(!pspCaller, "pspCaller != NULL\n");
471 V_VT(pvarRes) = VT_I4;
476 static IDispatchExVtbl testObjVtbl = {
477 DispatchEx_QueryInterface,
480 DispatchEx_GetTypeInfoCount,
481 DispatchEx_GetTypeInfo,
482 DispatchEx_GetIDsOfNames,
484 DispatchEx_GetDispID,
486 DispatchEx_DeleteMemberByName,
487 DispatchEx_DeleteMemberByDispID,
488 DispatchEx_GetMemberProperties,
489 DispatchEx_GetMemberName,
490 DispatchEx_GetNextDispID,
491 DispatchEx_GetNameSpaceParent
494 static IDispatchEx funcDisp = { &testObjVtbl };
496 static HRESULT WINAPI scriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
498 if(!strcmp_wa(bstrName, "testProp")) {
499 CHECK_EXPECT(script_testprop_d);
500 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
501 *pid = DISPID_SCRIPT_TESTPROP;
505 if(!strcmp_wa(bstrName, "testProp2")) {
506 CHECK_EXPECT(script_testprop2_d);
507 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
508 *pid = DISPID_SCRIPT_TESTPROP2;
512 if(!strcmp_wa(bstrName, "divid")) {
513 CHECK_EXPECT(script_divid_d);
514 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
518 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
522 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
523 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
526 case DISPID_SCRIPT_TESTPROP:
527 CHECK_EXPECT(script_testprop_i);
529 ok(lcid == 0, "lcid = %x\n", lcid);
530 ok(wFlags == DISPATCH_PROPERTYGET, "wFlags = %x\n", wFlags);
531 ok(pdp != NULL, "pdp == NULL\n");
532 ok(pdp->cArgs == 0, "pdp->cArgs = %d\n", pdp->cArgs);
533 ok(pdp->cNamedArgs == 0, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
534 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs != NULL\n");
535 ok(!pdp->rgvarg, "rgvarg != NULL\n");
536 ok(pvarRes != NULL, "pvarRes == NULL\n");
537 ok(pei != NULL, "pei == NULL\n");
538 ok(!pspCaller, "pspCaller != NULL\n");
540 V_VT(pvarRes) = VT_NULL;
543 ok(0, "unexpected call\n");
550 static IDispatchExVtbl scriptDispVtbl = {
551 DispatchEx_QueryInterface,
554 DispatchEx_GetTypeInfoCount,
555 DispatchEx_GetTypeInfo,
556 DispatchEx_GetIDsOfNames,
558 scriptDisp_GetDispID,
560 DispatchEx_DeleteMemberByName,
561 DispatchEx_DeleteMemberByDispID,
562 DispatchEx_GetMemberProperties,
563 DispatchEx_GetMemberName,
564 DispatchEx_GetNextDispID,
565 DispatchEx_GetNameSpaceParent
568 static IDispatchEx scriptDisp = { &scriptDispVtbl };
570 static HRESULT WINAPI externalDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
572 if(!strcmp_wa(bstrName, "ok")) {
573 *pid = DISPID_EXTERNAL_OK;
576 if(!strcmp_wa(bstrName, "trace")) {
577 *pid = DISPID_EXTERNAL_TRACE;
580 if(!strcmp_wa(bstrName, "reportSuccess")) {
581 *pid = DISPID_EXTERNAL_REPORTSUCCESS;
584 if(!strcmp_wa(bstrName, "todo_wine_ok")) {
585 *pid = DISPID_EXTERNAL_TODO_WINE_OK;
589 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
590 return DISP_E_UNKNOWNNAME;
593 static HRESULT WINAPI externalDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
594 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
597 case DISPID_EXTERNAL_OK:
598 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
599 ok(pdp != NULL, "pdp == NULL\n");
600 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
601 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
602 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
603 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
604 ok(pei != NULL, "pei == NULL\n");
606 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
607 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
608 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
612 case DISPID_EXTERNAL_TRACE:
613 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
614 ok(pdp != NULL, "pdp == NULL\n");
615 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
616 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
617 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
618 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
619 ok(!pvarRes, "pvarRes != NULL\n");
620 ok(pei != NULL, "pei == NULL\n");
622 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
623 if(V_VT(pdp->rgvarg) == VT_BSTR)
624 trace("%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
628 case DISPID_EXTERNAL_REPORTSUCCESS:
629 CHECK_EXPECT(external_success);
631 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
632 ok(pdp != NULL, "pdp == NULL\n");
633 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
634 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
635 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
636 ok(!pvarRes, "pvarRes != NULL\n");
637 ok(pei != NULL, "pei == NULL\n");
641 case DISPID_EXTERNAL_TODO_WINE_OK:
642 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
643 ok(pdp != NULL, "pdp == NULL\n");
644 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
645 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
646 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
647 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
648 ok(pei != NULL, "pei == NULL\n");
650 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
651 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
653 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
658 ok(0, "unexpected call\n");
665 static IDispatchExVtbl externalDispVtbl = {
666 DispatchEx_QueryInterface,
669 DispatchEx_GetTypeInfoCount,
670 DispatchEx_GetTypeInfo,
671 DispatchEx_GetIDsOfNames,
673 externalDisp_GetDispID,
674 externalDisp_InvokeEx,
675 DispatchEx_DeleteMemberByName,
676 DispatchEx_DeleteMemberByDispID,
677 DispatchEx_GetMemberProperties,
678 DispatchEx_GetMemberName,
679 DispatchEx_GetNextDispID,
680 DispatchEx_GetNameSpaceParent
683 static IDispatchEx externalDisp = { &externalDispVtbl };
685 static HRESULT QueryInterface(REFIID,void**);
687 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
689 return QueryInterface(riid, ppv);
692 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
697 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
702 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
703 IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
708 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
713 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
714 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
715 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
720 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
725 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
730 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
735 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
740 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
745 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
746 IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
751 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
752 const GUID *pguidCmdGroup, DWORD nCmdID)
757 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
758 LPOLESTR *pchKey, DWORD dw)
763 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
764 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
769 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
771 *ppDispatch = (IDispatch*)&externalDisp;
775 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
776 OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
781 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
782 IDataObject **ppPORet)
787 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
788 LPOLESTR *pchKey, DWORD dw)
793 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
794 DocHostUIHandler_QueryInterface,
795 DocHostUIHandler_AddRef,
796 DocHostUIHandler_Release,
797 DocHostUIHandler_ShowContextMenu,
798 DocHostUIHandler_GetHostInfo,
799 DocHostUIHandler_ShowUI,
800 DocHostUIHandler_HideUI,
801 DocHostUIHandler_UpdateUI,
802 DocHostUIHandler_EnableModeless,
803 DocHostUIHandler_OnDocWindowActivate,
804 DocHostUIHandler_OnFrameWindowActivate,
805 DocHostUIHandler_ResizeBorder,
806 DocHostUIHandler_TranslateAccelerator,
807 DocHostUIHandler_GetOptionKeyPath,
808 DocHostUIHandler_GetDropTarget,
809 DocHostUIHandler_GetExternal,
810 DocHostUIHandler_TranslateUrl,
811 DocHostUIHandler_FilterDataObject,
812 DocHostUIHandler_GetOverrideKeyPath
815 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
817 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
819 return E_NOINTERFACE;
822 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
827 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
832 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
837 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
842 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
847 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
848 LPCBORDERWIDTHS pborderwidths)
853 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
854 LPCBORDERWIDTHS pborderwidths)
859 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
860 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
865 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
866 LPOLEMENUGROUPWIDTHS lpMenuWidths)
871 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
872 HOLEMENU holemenu, HWND hwndActiveObject)
874 ok(0, "unexpected call\n");
878 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
880 ok(0, "unexpected call\n");
884 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
889 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
894 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
896 ok(0, "unexpected call\n");
900 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
901 InPlaceFrame_QueryInterface,
903 InPlaceFrame_Release,
904 InPlaceFrame_GetWindow,
905 InPlaceFrame_ContextSensitiveHelp,
906 InPlaceFrame_GetBorder,
907 InPlaceFrame_RequestBorderSpace,
908 InPlaceFrame_SetBorderSpace,
909 InPlaceFrame_SetActiveObject,
910 InPlaceFrame_InsertMenus,
911 InPlaceFrame_SetMenu,
912 InPlaceFrame_RemoveMenus,
913 InPlaceFrame_SetStatusText,
914 InPlaceFrame_EnableModeless,
915 InPlaceFrame_TranslateAccelerator
918 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
920 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
922 return QueryInterface(riid, ppv);
925 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
930 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
935 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
937 *phwnd = container_hwnd;
941 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
943 ok(0, "unexpected call\n");
947 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
952 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
957 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
962 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
963 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
964 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
966 static const RECT rect = {0,0,300,300};
968 *ppFrame = &InPlaceFrame;
969 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceFrame;
971 *lprcClipRect = rect;
973 ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
974 lpFrameInfo->fMDIApp = FALSE;
975 lpFrameInfo->hwndFrame = container_hwnd;
976 lpFrameInfo->haccel = NULL;
977 lpFrameInfo->cAccelEntries = 0;
982 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
987 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
992 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
997 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
1002 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
1007 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1012 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
1013 InPlaceSite_QueryInterface,
1015 InPlaceSite_Release,
1016 InPlaceSite_GetWindow,
1017 InPlaceSite_ContextSensitiveHelp,
1018 InPlaceSite_CanInPlaceActivate,
1019 InPlaceSite_OnInPlaceActivate,
1020 InPlaceSite_OnUIActivate,
1021 InPlaceSite_GetWindowContext,
1023 InPlaceSite_OnUIDeactivate,
1024 InPlaceSite_OnInPlaceDeactivate,
1025 InPlaceSite_DiscardUndoState,
1026 InPlaceSite_DeactivateAndUndo,
1027 InPlaceSite_OnPosRectChange,
1030 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
1032 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
1034 return QueryInterface(riid, ppv);
1037 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
1042 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1047 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1049 ok(0, "unexpected call\n");
1053 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1056 ok(0, "unexpected call\n");
1060 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1065 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1067 ok(0, "unexpected call\n");
1071 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1073 ok(0, "unexpected call\n");
1077 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1079 ok(0, "unexpected call\n");
1083 static const IOleClientSiteVtbl ClientSiteVtbl = {
1084 ClientSite_QueryInterface,
1087 ClientSite_SaveObject,
1088 ClientSite_GetMoniker,
1089 ClientSite_GetContainer,
1090 ClientSite_ShowObject,
1091 ClientSite_OnShowWindow,
1092 ClientSite_RequestNewObjectLayout
1095 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1097 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1099 return QueryInterface(riid, ppv);
1102 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1107 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1112 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1114 RECT rect = {0,0,300,300};
1115 IOleDocument *document;
1118 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1119 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1121 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1122 IOleDocument_Release(document);
1123 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1125 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1126 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1128 hres = IOleDocumentView_UIActivate(view, TRUE);
1129 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1131 hres = IOleDocumentView_SetRect(view, &rect);
1132 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1134 hres = IOleDocumentView_Show(view, TRUE);
1135 ok(hres == S_OK, "Show failed: %08x\n", hres);
1140 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1141 DocumentSite_QueryInterface,
1142 DocumentSite_AddRef,
1143 DocumentSite_Release,
1144 DocumentSite_ActivateMe
1147 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1149 static HRESULT QueryInterface(REFIID riid, void **ppv)
1153 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1155 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1156 *ppv = &DocumentSite;
1157 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1158 *ppv = &InPlaceSite;
1159 else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
1160 *ppv = &DocHostUIHandler;
1162 return *ppv ? S_OK : E_NOINTERFACE;
1165 static IHTMLDocument2 *create_document(void)
1167 IHTMLDocument2 *doc;
1168 IHTMLDocument5 *doc5;
1171 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1172 &IID_IHTMLDocument2, (void**)&doc);
1173 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1174 if (hres != S_OK) return NULL;
1176 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1178 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
1179 IHTMLDocument2_Release(doc);
1183 IHTMLDocument5_Release(doc5);
1187 static void load_string(IHTMLDocument2 *doc, const char *str)
1189 IPersistStreamInit *init;
1194 doc_complete = FALSE;
1196 mem = GlobalAlloc(0, len);
1197 memcpy(mem, str, len);
1198 CreateStreamOnHGlobal(mem, TRUE, &stream);
1200 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1202 IPersistStreamInit_Load(init, stream);
1203 IPersistStreamInit_Release(init);
1204 IStream_Release(stream);
1207 static void do_advise(IHTMLDocument2 *doc, REFIID riid, IUnknown *unk_advise)
1209 IConnectionPointContainer *container;
1210 IConnectionPoint *cp;
1214 hres = IHTMLDocument2_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&container);
1215 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1217 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1218 IConnectionPointContainer_Release(container);
1219 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1223 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1224 IConnectionPoint_Release(cp);
1225 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1228 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1234 IOleDocumentView_Show(view, FALSE);
1235 IOleDocumentView_CloseView(view, 0);
1236 IOleDocumentView_SetInPlaceSite(view, NULL);
1237 IOleDocumentView_Release(view);
1241 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1242 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1244 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1245 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1248 IHlinkTarget *hlink;
1250 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1251 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1253 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1254 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1256 IHlinkTarget_Release(hlink);
1259 IOleObject_Release(oleobj);
1262 typedef void (*domtest_t)(IHTMLDocument2*);
1264 static void load_doc(IHTMLDocument2 *doc, const char *str)
1266 IHTMLElement *body = NULL;
1269 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
1273 load_string(doc, str);
1274 do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1276 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1277 TranslateMessage(&msg);
1278 DispatchMessage(&msg);
1281 hres = IHTMLDocument2_get_body(doc, &body);
1282 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1284 /* Check we can query for function on the IHTMLElementBody interface */
1285 name = (WCHAR*)ucPtr;
1286 hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
1287 ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
1288 ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
1290 IHTMLElement_Release(body);
1293 static IActiveScriptSite *site;
1294 static SCRIPTSTATE state;
1296 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1299 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1300 return E_NOINTERFACE;
1303 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
1308 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
1313 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1314 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1316 CHECK_EXPECT(GetInterfaceSafetyOptions);
1318 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
1319 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1320 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1322 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1323 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1328 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1329 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1331 CHECK_EXPECT(SetInterfaceSafetyOptions);
1333 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
1335 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1336 "dwOptionSetMask=%x\n", dwOptionSetMask);
1337 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1338 "dwEnabledOptions=%x\n", dwOptionSetMask);
1343 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1344 ObjectSafety_QueryInterface,
1345 ObjectSafety_AddRef,
1346 ObjectSafety_Release,
1347 ObjectSafety_GetInterfaceSafetyOptions,
1348 ObjectSafety_SetInterfaceSafetyOptions
1351 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
1353 static HRESULT WINAPI AXObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1357 if(IsEqualGUID(&IID_IActiveScript, riid)) {
1358 CHECK_EXPECT(AXQueryInterface_IActiveScript);
1359 return E_NOINTERFACE;
1362 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1363 CHECK_EXPECT2(AXQueryInterface_IObjectSafety);
1365 return E_NOINTERFACE;
1370 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1371 return E_NOINTERFACE;
1374 static HRESULT WINAPI AXObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1375 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1377 CHECK_EXPECT(AXGetInterfaceSafetyOptions);
1379 ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
1380 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1381 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1383 if(SUCCEEDED(ax_getopt_hres)) {
1384 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1385 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1388 return ax_getopt_hres;
1391 static HRESULT WINAPI AXObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1392 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1394 if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1395 switch(dwEnabledOptions) {
1396 case INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER:
1397 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1399 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1400 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1403 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1406 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1407 return ax_setopt_dispex_hres;
1410 if(IsEqualGUID(&IID_IDispatch, riid)) {
1413 switch(dwEnabledOptions) {
1414 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1415 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1416 hres = ax_setopt_disp_caller_hres;
1418 case INTERFACESAFE_FOR_UNTRUSTED_DATA:
1419 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1420 hres = ax_setopt_disp_data_hres;
1423 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1426 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1430 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1431 return E_NOINTERFACE;
1434 static const IObjectSafetyVtbl AXObjectSafetyVtbl = {
1435 AXObjectSafety_QueryInterface,
1436 ObjectSafety_AddRef,
1437 ObjectSafety_Release,
1438 AXObjectSafety_GetInterfaceSafetyOptions,
1439 AXObjectSafety_SetInterfaceSafetyOptions
1442 static IObjectSafety AXObjectSafety = { &AXObjectSafetyVtbl };
1444 static BOOL set_safe_reg(BOOL safe_call, BOOL safe_data)
1446 return init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95801-9882-11cf-9fa9-00aa006c42c4}",
1448 && init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95802-9882-11cf-9fa9-00aa006c42c4}",
1452 #define check_custom_policy(a,b,c,d) _check_custom_policy(__LINE__,a,b,c,d)
1453 static void _check_custom_policy(unsigned line, HRESULT hres, BYTE *ppolicy, DWORD policy_size, DWORD expolicy)
1455 ok_(__FILE__,line)(hres == S_OK, "QueryCusromPolicy failed: %08x\n", hres);
1456 ok_(__FILE__,line)(policy_size == sizeof(DWORD), "policy_size = %d\n", policy_size);
1457 ok_(__FILE__,line)(*(DWORD*)ppolicy == expolicy, "policy = %x, expected %x\n", *(DWORD*)ppolicy, expolicy);
1458 CoTaskMemFree(ppolicy);
1461 static void test_security_reg(IInternetHostSecurityManager *sec_mgr, DWORD policy_caller, DWORD policy_load)
1463 struct CONFIRMSAFETY cs;
1468 cs.clsid = CLSID_TestActiveX;
1469 cs.pUnk = (IUnknown*)&AXObjectSafety;
1473 SET_EXPECT(AXQueryInterface_IActiveScript);
1474 SET_EXPECT(AXQueryInterface_IObjectSafety);
1475 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1476 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1477 CHECK_CALLED(AXQueryInterface_IActiveScript);
1478 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1479 check_custom_policy(hres, ppolicy, policy_size, policy_caller);
1482 SET_EXPECT(AXQueryInterface_IActiveScript);
1483 SET_EXPECT(AXQueryInterface_IObjectSafety);
1484 SET_EXPECT(AXGetInterfaceSafetyOptions);
1485 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1486 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1487 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1488 CHECK_CALLED(AXQueryInterface_IActiveScript);
1489 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1490 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1491 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1492 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1494 if(skip_loadobject_tests)
1497 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1499 SET_EXPECT(AXQueryInterface_IActiveScript);
1500 SET_EXPECT(AXQueryInterface_IObjectSafety);
1501 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1502 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1503 CHECK_CALLED(AXQueryInterface_IActiveScript);
1504 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1505 check_custom_policy(hres, ppolicy, policy_size, policy_load);
1508 SET_EXPECT(AXQueryInterface_IActiveScript);
1509 SET_EXPECT(AXQueryInterface_IObjectSafety);
1510 SET_EXPECT(AXGetInterfaceSafetyOptions);
1511 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1512 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1513 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1514 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1515 CHECK_CALLED(AXQueryInterface_IActiveScript);
1516 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1517 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1518 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1519 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1520 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1523 static void test_security(void)
1525 IInternetHostSecurityManager *sec_mgr;
1526 IServiceProvider *sp;
1527 DWORD policy, policy_size;
1528 struct CONFIRMSAFETY cs;
1532 hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
1533 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
1535 hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager,
1536 &IID_IInternetHostSecurityManager, (void**)&sec_mgr);
1537 IServiceProvider_Release(sp);
1538 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1540 hres = IInternetHostSecurityManager_ProcessUrlAction(sec_mgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
1541 (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
1542 ok(hres == S_OK, "ProcessUrlAction failed: %08x\n", hres);
1543 ok(policy == URLPOLICY_ALLOW, "policy = %x\n", policy);
1545 cs.clsid = CLSID_TestActiveX;
1546 cs.pUnk = (IUnknown*)&AXObjectSafety;
1550 SET_EXPECT(AXQueryInterface_IActiveScript);
1551 SET_EXPECT(AXQueryInterface_IObjectSafety);
1552 SET_EXPECT(AXGetInterfaceSafetyOptions);
1553 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1554 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1555 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1556 CHECK_CALLED(AXQueryInterface_IActiveScript);
1557 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1558 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1559 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1560 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1562 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1563 SET_EXPECT(AXQueryInterface_IActiveScript);
1564 SET_EXPECT(AXQueryInterface_IObjectSafety);
1565 SET_EXPECT(AXGetInterfaceSafetyOptions);
1566 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1567 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1568 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1569 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1570 CHECK_CALLED(AXQueryInterface_IActiveScript);
1571 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1572 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1573 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1574 if(called_AXSetInterfaceSafetyOptions_IDispatch_data) {
1575 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1577 win_skip("CONFIRMSAFETYACTION_LOADOBJECT flag not supported\n");
1578 skip_loadobject_tests = TRUE;
1579 CLEAR_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1581 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1585 SET_EXPECT(AXQueryInterface_IActiveScript);
1586 SET_EXPECT(AXQueryInterface_IObjectSafety);
1587 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1588 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1589 CHECK_CALLED(AXQueryInterface_IActiveScript);
1590 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1591 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1593 if(!skip_loadobject_tests) {
1594 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1596 SET_EXPECT(AXQueryInterface_IActiveScript);
1597 SET_EXPECT(AXQueryInterface_IObjectSafety);
1598 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1599 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1600 CHECK_CALLED(AXQueryInterface_IActiveScript);
1601 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1602 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1605 if(set_safe_reg(TRUE, FALSE)) {
1606 test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_DISALLOW);
1608 set_safe_reg(FALSE, TRUE);
1609 test_security_reg(sec_mgr, URLPOLICY_DISALLOW, URLPOLICY_DISALLOW);
1611 set_safe_reg(TRUE, TRUE);
1612 test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_ALLOW);
1614 set_safe_reg(FALSE, FALSE);
1616 skip("Could not set safety registry\n");
1622 ax_setopt_dispex_hres = E_NOINTERFACE;
1623 SET_EXPECT(AXQueryInterface_IActiveScript);
1624 SET_EXPECT(AXQueryInterface_IObjectSafety);
1625 SET_EXPECT(AXGetInterfaceSafetyOptions);
1626 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1627 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1628 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1629 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1630 CHECK_CALLED(AXQueryInterface_IActiveScript);
1631 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1632 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1633 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1634 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1635 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1637 ax_setopt_dispex_hres = E_FAIL;
1638 ax_setopt_disp_caller_hres = E_NOINTERFACE;
1639 SET_EXPECT(AXQueryInterface_IActiveScript);
1640 SET_EXPECT(AXQueryInterface_IObjectSafety);
1641 SET_EXPECT(AXGetInterfaceSafetyOptions);
1642 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1643 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1644 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1645 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1646 CHECK_CALLED(AXQueryInterface_IActiveScript);
1647 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1648 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1649 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1650 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1651 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1653 if(!skip_loadobject_tests) {
1654 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1655 ax_setopt_dispex_hres = E_FAIL;
1656 ax_setopt_disp_caller_hres = E_NOINTERFACE;
1657 SET_EXPECT(AXQueryInterface_IActiveScript);
1658 SET_EXPECT(AXQueryInterface_IObjectSafety);
1659 SET_EXPECT(AXGetInterfaceSafetyOptions);
1660 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1661 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1662 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1663 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1664 CHECK_CALLED(AXQueryInterface_IActiveScript);
1665 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1666 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1667 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1668 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1669 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1673 ax_setopt_dispex_hres = E_FAIL;
1674 ax_setopt_disp_caller_hres = S_OK;
1675 ax_getopt_hres = E_NOINTERFACE;
1676 SET_EXPECT(AXQueryInterface_IActiveScript);
1677 SET_EXPECT(AXQueryInterface_IObjectSafety);
1678 SET_EXPECT(AXGetInterfaceSafetyOptions);
1679 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1680 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1681 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1682 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1683 CHECK_CALLED(AXQueryInterface_IActiveScript);
1684 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1685 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1686 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1687 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1688 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1690 if(!skip_loadobject_tests) {
1691 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1692 ax_setopt_dispex_hres = E_FAIL;
1693 ax_setopt_disp_caller_hres = S_OK;
1694 ax_setopt_disp_data_hres = E_FAIL;
1695 ax_getopt_hres = E_NOINTERFACE;
1696 SET_EXPECT(AXQueryInterface_IActiveScript);
1697 SET_EXPECT(AXQueryInterface_IObjectSafety);
1698 SET_EXPECT(AXGetInterfaceSafetyOptions);
1699 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1700 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1701 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1702 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1703 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1704 CHECK_CALLED(AXQueryInterface_IActiveScript);
1705 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1706 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1707 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1708 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1709 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1710 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1713 IInternetHostSecurityManager_Release(sec_mgr);
1716 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
1719 ok(0, "unexpected call\n");
1720 return E_NOINTERFACE;
1723 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
1728 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
1733 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1734 VARIANT *pvarIndex, VARIANT *pvarValue)
1736 ok(0, "unexpected call\n");
1740 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1741 VARIANT *pvarIndex, VARIANT *pvarValue)
1743 switch(dwProperty) {
1744 case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
1745 CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1746 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1747 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1749 case SCRIPTPROP_INVOKEVERSIONING:
1750 CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
1751 ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1752 ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
1754 case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
1755 CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
1756 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1757 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1760 ok(0, "unexpected property %x\n", dwProperty);
1764 ok(!pvarIndex, "pvarIndex != NULL\n");
1765 ok(pvarValue != NULL, "pvarValue == NULL\n");
1770 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
1771 ActiveScriptProperty_QueryInterface,
1772 ActiveScriptProperty_AddRef,
1773 ActiveScriptProperty_Release,
1774 ActiveScriptProperty_GetProperty,
1775 ActiveScriptProperty_SetProperty
1778 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
1780 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
1783 ok(0, "unexpected call\n");
1784 return E_NOINTERFACE;
1787 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
1792 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
1797 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
1798 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
1799 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
1800 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
1802 ok(0, "unexpected call\n");
1806 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
1807 ActiveScriptParseProcedure_QueryInterface,
1808 ActiveScriptParseProcedure_AddRef,
1809 ActiveScriptParseProcedure_Release,
1810 ActiveScriptParseProcedure_ParseProcedureText
1813 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
1815 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
1818 ok(0, "unexpected call\n");
1819 return E_NOINTERFACE;
1822 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
1827 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
1832 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
1834 CHECK_EXPECT(InitNew);
1838 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
1839 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
1840 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
1841 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
1842 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
1844 ok(0, "unexpected call\n");
1848 static HRESULT dispex_propput(IDispatchEx *obj, DISPID id, DWORD flags, VARIANT *var, IServiceProvider *caller_sp)
1850 DISPID propput_arg = DISPID_PROPERTYPUT;
1851 DISPPARAMS dp = {var, &propput_arg, 1, 1};
1854 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT|flags, &dp, NULL, &ei, caller_sp);
1857 static HRESULT dispex_propget(IDispatchEx *obj, DISPID id, VARIANT *res, IServiceProvider *caller_sp)
1859 DISPPARAMS dp = {NULL};
1862 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, res, &ei, caller_sp);
1865 static void test_func(IDispatchEx *obj)
1868 IDispatchEx *dispex;
1876 str = a2bstr("toString");
1877 hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
1879 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1880 ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
1882 memset(&dp, 0, sizeof(dp));
1883 memset(&ei, 0, sizeof(ei));
1885 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1886 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1887 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
1888 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
1889 disp = V_DISPATCH(&var);
1891 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1892 IDispatch_Release(disp);
1893 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1895 /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
1897 memset(&dp, 0, sizeof(dp));
1898 memset(&ei, 0, sizeof(ei));
1900 hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
1901 ok(hres == S_OK || broken(E_ACCESSDENIED), "InvokeEx failed: %08x\n", hres);
1902 if(SUCCEEDED(hres)) {
1903 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1904 ok(!strcmp_wa(V_BSTR(&var), "[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
1910 hres = dispex_propput(obj, id, 0, &var, NULL);
1911 ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
1913 IDispatchEx_Release(dispex);
1916 static void test_nextdispid(IDispatchEx *dispex)
1918 DISPID last_id = DISPID_STARTENUM, id, dyn_id;
1923 name = a2bstr("dynVal");
1924 hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive|fdexNameEnsure, &dyn_id);
1925 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1926 SysFreeString(name);
1928 V_VT(&var) = VT_EMPTY;
1929 hres = dispex_propput(dispex, dyn_id, 0, &var, NULL);
1930 ok(hres == S_OK, "dispex_propput failed: %08x\n", hres);
1932 while(last_id != dyn_id) {
1933 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, last_id, &id);
1934 ok(hres == S_OK, "GetNextDispID returned: %08x\n", hres);
1935 ok(id != DISPID_STARTENUM, "id == DISPID_STARTENUM\n");
1936 ok(id != DISPID_IOMNAVIGATOR_TOSTRING, "id == DISPID_IOMNAVIGATOR_TOSTRING\n");
1938 hres = IDispatchEx_GetMemberName(dispex, id, &name);
1939 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
1942 ok(!strcmp_wa(name, "dynVal"), "name = %s\n", wine_dbgstr_w(name));
1943 else if(id == DISPID_IOMNAVIGATOR_PLATFORM)
1944 ok(!strcmp_wa(name, "platform"), "name = %s\n", wine_dbgstr_w(name));
1946 SysFreeString(name);
1950 hres = IDispatchEx_GetNextDispID(dispex, 0, id, &id);
1951 ok(hres == S_FALSE, "GetNextDispID returned: %08x\n", hres);
1952 ok(id == DISPID_STARTENUM, "id != DISPID_STARTENUM\n");
1955 static void test_global_id(void)
1964 SET_EXPECT(GetScriptDispatch);
1965 SET_EXPECT(script_divid_d);
1966 tmp = a2bstr("divid");
1967 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1968 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1970 CHECK_CALLED(GetScriptDispatch);
1971 CHECK_CALLED(script_divid_d);
1974 memset(&ei, 0, sizeof(ei));
1975 memset(&dp, 0, sizeof(dp));
1976 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1977 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1978 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d\n", V_VT(&var));
1982 static void test_arg_conv(IHTMLWindow2 *window)
1984 IHTMLDocument2 *doc;
1985 IDispatchEx *dispex;
1990 hres = IHTMLWindow2_get_document(window, &doc);
1991 ok(hres == S_OK, "get_document failed: %08x\n", hres);
1993 hres = IHTMLDocument2_get_body(doc, &elem);
1994 IHTMLDocument2_Release(doc);
1995 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1997 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
1998 IHTMLElement_Release(elem);
1999 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2001 SET_EXPECT(QS_VariantConversion);
2002 SET_EXPECT(ChangeType);
2004 V_I4(&v) = 0xf0f0f0;
2005 hres = dispex_propput(dispex, DISPID_IHTMLBODYELEMENT_BACKGROUND, 0, &v, &caller_sp);
2006 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2007 CHECK_CALLED(QS_VariantConversion);
2008 CHECK_CALLED(ChangeType);
2010 V_VT(&v) = VT_EMPTY;
2011 hres = dispex_propget(dispex, DISPID_IHTMLBODYELEMENT_BGCOLOR, &v, &caller_sp);
2012 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2013 ok(V_VT(&v) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&v));
2014 ok(!V_BSTR(&v), "V_BSTR(&var) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
2016 IDispatchEx_Release(dispex);
2019 static void test_script_run(void)
2021 IDispatchEx *document, *dispex;
2022 IHTMLWindow2 *window;
2023 IOmNavigator *navigator;
2032 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
2033 static const WCHAR testW[] = {'t','e','s','t',0};
2034 static const WCHAR funcW[] = {'f','u','n','c',0};
2036 SET_EXPECT(GetScriptDispatch);
2038 tmp = SysAllocString(documentW);
2039 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2041 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2042 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
2044 CHECK_CALLED(GetScriptDispatch);
2047 memset(&dp, 0, sizeof(dp));
2048 memset(&ei, 0, sizeof(ei));
2050 hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2051 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2052 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2053 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
2055 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
2057 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
2059 tmp = SysAllocString(testW);
2060 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
2061 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2062 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
2063 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2067 tmp = SysAllocString(testW);
2068 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2070 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2071 ok(id, "id == 0\n");
2075 hres = dispex_propput(document, id, 0, &var, NULL);
2076 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2078 tmp = SysAllocString(testW);
2079 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
2081 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2083 hres = IDispatchEx_DeleteMemberByDispID(document, id);
2084 ok(hres == E_NOTIMPL, "DeleteMemberByDispID failed = %08x\n", hres);
2087 memset(&dp, 0, sizeof(dp));
2088 memset(&ei, 0, sizeof(ei));
2089 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2090 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2091 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2092 ok(V_I4(&var) == 100, "V_I4(&var) = %d\n", V_I4(&var));
2096 hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var, NULL);
2097 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2100 memset(&dp, 0, sizeof(dp));
2101 memset(&ei, 0, sizeof(ei));
2102 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2103 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2104 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2105 ok(V_I4(&var) == 200, "V_I4(&var) = %d\n", V_I4(&var));
2107 memset(&dp, 0, sizeof(dp));
2108 memset(&ei, 0, sizeof(ei));
2113 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2114 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2117 memset(&dp, 0, sizeof(dp));
2118 memset(&ei, 0, sizeof(ei));
2119 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2120 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2121 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2122 ok(V_I4(&var) == 300, "V_I4(&var) = %d\n", V_I4(&var));
2124 V_VT(&var) = VT_BSTR;
2125 V_BSTR(&var) = NULL;
2126 dispex_propput(document, id, 0, &var, NULL);
2129 memset(&dp, 0, sizeof(dp));
2130 memset(&ei, 0, sizeof(ei));
2131 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2132 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2133 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
2134 ok(!V_BSTR(&var), "V_BSTR(&var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
2136 unk = (void*)0xdeadbeef;
2137 hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
2138 ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
2139 ok(!unk, "unk=%p, expected NULL\n", unk);
2142 tmp = SysAllocString(funcW);
2143 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2145 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
2146 ok(id, "id == 0\n");
2151 dp.rgdispidNamedArgs = NULL;
2152 V_VT(&var) = VT_DISPATCH;
2153 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
2154 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2155 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2158 memset(&dp, 0, sizeof(dp));
2159 memset(&ei, 0, sizeof(ei));
2160 V_VT(&arg) = VT_BOOL;
2161 V_BOOL(&arg) = VARIANT_TRUE;
2165 SET_EXPECT(funcDisp);
2166 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
2167 CHECK_CALLED(funcDisp);
2169 ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
2170 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2171 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
2173 IDispatchEx_Release(document);
2175 hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
2176 ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
2178 hres = IHTMLWindow2_get_navigator(window, &navigator);
2179 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2181 hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
2182 IOmNavigator_Release(navigator);
2183 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2186 test_nextdispid(dispex);
2188 test_arg_conv(window);
2189 IHTMLWindow2_Release(window);
2191 tmp = a2bstr("test");
2192 hres = IDispatchEx_DeleteMemberByName(dispex, tmp, fdexNameCaseSensitive);
2193 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2195 IDispatchEx_Release(dispex);
2197 script_disp = (IDispatch*)&scriptDisp;
2199 SET_EXPECT(GetScriptDispatch);
2200 SET_EXPECT(script_testprop_d);
2201 tmp = a2bstr("testProp");
2202 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2203 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2204 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2205 CHECK_CALLED(GetScriptDispatch);
2206 CHECK_CALLED(script_testprop_d);
2209 tmp = a2bstr("testProp");
2210 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2211 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2212 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2215 SET_EXPECT(GetScriptDispatch);
2216 SET_EXPECT(script_testprop_i);
2217 memset(&ei, 0, sizeof(ei));
2218 memset(&dp, 0, sizeof(dp));
2219 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
2220 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2221 ok(V_VT(&var) == VT_NULL, "V_VT(var) = %d\n", V_VT(&var));
2222 CHECK_CALLED(GetScriptDispatch);
2223 CHECK_CALLED(script_testprop_i);
2225 SET_EXPECT(GetScriptDispatch);
2226 SET_EXPECT(script_testprop2_d);
2227 tmp = a2bstr("testProp2");
2228 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2229 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2230 ok(id != DISPID_SCRIPT_TESTPROP2, "id == DISPID_SCRIPT_TESTPROP2\n");
2231 CHECK_CALLED(GetScriptDispatch);
2232 CHECK_CALLED(script_testprop2_d);
2235 tmp = a2bstr("test");
2236 hres = IDispatchEx_DeleteMemberByName(window_dispex, tmp, fdexNameCaseSensitive);
2237 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2244 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
2245 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
2246 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
2247 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
2249 ok(pvarResult != NULL, "pvarResult == NULL\n");
2250 ok(pexcepinfo != NULL, "pexcepinfo == NULL\n");
2252 if(!strcmp_wa(pstrCode, "execScript call")) {
2253 CHECK_EXPECT(ParseScriptText_execScript);
2254 ok(!pstrItemName, "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2255 ok(!strcmp_wa(pstrDelimiter, "\""), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2256 ok(dwFlags == SCRIPTTEXT_ISVISIBLE, "dwFlags = %x\n", dwFlags);
2258 V_VT(pvarResult) = VT_I4;
2259 V_I4(pvarResult) = 10;
2261 }else if(!strcmp_wa(pstrCode, "simple script")) {
2262 CHECK_EXPECT(ParseScriptText_script);
2263 ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2264 ok(!strcmp_wa(pstrDelimiter, "</SCRIPT>"), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2265 ok(dwFlags == (SCRIPTTEXT_ISVISIBLE|SCRIPTTEXT_HOSTMANAGESSOURCE), "dwFlags = %x\n", dwFlags);
2271 ok(0, "unexpected script %s\n", wine_dbgstr_w(pstrCode));
2275 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
2276 ActiveScriptParse_QueryInterface,
2277 ActiveScriptParse_AddRef,
2278 ActiveScriptParse_Release,
2279 ActiveScriptParse_InitNew,
2280 ActiveScriptParse_AddScriptlet,
2281 ActiveScriptParse_ParseScriptText
2284 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
2286 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
2290 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
2295 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
2296 *ppv = &ActiveScriptParse;
2300 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
2301 *ppv = &ActiveScriptParseProcedure;
2305 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
2306 *ppv = &ActiveScriptProperty;
2310 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2311 *ppv = &ObjectSafety;
2315 if(IsEqualGUID(&IID_IActiveScriptDebug, riid))
2316 return E_NOINTERFACE;
2318 trace("QI(%s)\n", debugstr_guid(riid));
2319 return E_NOINTERFACE;
2322 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
2327 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
2332 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
2334 IActiveScriptSiteInterruptPoll *poll;
2335 IActiveScriptSiteDebug *debug;
2336 IServiceProvider *service;
2337 ICanHandleException *canexpection;
2341 CHECK_EXPECT(SetScriptSite);
2343 ok(pass != NULL, "pass == NULL\n");
2345 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
2346 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
2348 IActiveScriptSiteInterruptPoll_Release(poll);
2350 hres = IActiveScriptSite_GetLCID(pass, &lcid);
2351 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
2353 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
2354 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2356 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
2357 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
2359 IActiveScriptSiteDebug32_Release(debug);
2361 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
2362 ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
2364 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
2365 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2367 IServiceProvider_Release(service);
2370 IActiveScriptSite_AddRef(site);
2374 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
2377 ok(0, "unexpected call\n");
2381 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
2386 case SCRIPTSTATE_STARTED:
2387 CHECK_EXPECT(SetScriptState_STARTED);
2389 case SCRIPTSTATE_CONNECTED:
2390 CHECK_EXPECT(SetScriptState_CONNECTED);
2392 case SCRIPTSTATE_DISCONNECTED:
2393 CHECK_EXPECT(SetScriptState_DISCONNECTED);
2396 ok(0, "unexpected state %d\n", ss);
2400 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
2401 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2406 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
2408 CHECK_EXPECT(GetScriptState);
2414 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
2416 CHECK_EXPECT(Close);
2420 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
2421 LPCOLESTR pstrName, DWORD dwFlags)
2424 IUnknown *unk = NULL, *unk2;
2427 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
2429 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
2431 CHECK_EXPECT(AddNamedItem);
2433 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
2434 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
2436 hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
2437 ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
2438 ok(unk != NULL, "unk == NULL\n");
2440 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
2441 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
2443 IDispatch_Release(disp);
2445 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
2446 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
2448 IUnknown_Release(unk2);
2450 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
2451 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
2453 IUnknown_Release(unk);
2457 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
2458 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
2460 ok(0, "unexpected call\n");
2464 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
2467 CHECK_EXPECT(GetScriptDispatch);
2469 ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2474 *ppdisp = script_disp;
2478 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
2479 SCRIPTTHREADID *pstridThread)
2481 ok(0, "unexpected call\n");
2485 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
2486 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
2488 ok(0, "unexpected call\n");
2492 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
2493 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
2495 ok(0, "unexpected call\n");
2499 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
2500 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
2502 ok(0, "unexpected call\n");
2506 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
2508 ok(0, "unexpected call\n");
2512 static const IActiveScriptVtbl ActiveScriptVtbl = {
2513 ActiveScript_QueryInterface,
2514 ActiveScript_AddRef,
2515 ActiveScript_Release,
2516 ActiveScript_SetScriptSite,
2517 ActiveScript_GetScriptSite,
2518 ActiveScript_SetScriptState,
2519 ActiveScript_GetScriptState,
2521 ActiveScript_AddNamedItem,
2522 ActiveScript_AddTypeLib,
2523 ActiveScript_GetScriptDispatch,
2524 ActiveScript_GetCurrentScriptThreadID,
2525 ActiveScript_GetScriptThreadID,
2526 ActiveScript_GetScriptThreadState,
2527 ActiveScript_InterruptScriptThread,
2531 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
2533 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2537 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2542 if(IsEqualGUID(&IID_IMarshal, riid))
2543 return E_NOINTERFACE;
2544 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
2545 return E_NOINTERFACE;
2547 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2551 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2556 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2561 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2563 CHECK_EXPECT(CreateInstance);
2565 ok(!outer, "outer = %p\n", outer);
2566 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
2567 *ppv = &ActiveScript;
2571 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2573 ok(0, "unexpected call\n");
2577 static const IClassFactoryVtbl ClassFactoryVtbl = {
2578 ClassFactory_QueryInterface,
2579 ClassFactory_AddRef,
2580 ClassFactory_Release,
2581 ClassFactory_CreateInstance,
2582 ClassFactory_LockServer
2585 static IClassFactory script_cf = { &ClassFactoryVtbl };
2587 static const char simple_script_str[] =
2588 "<html><head></head><body>"
2589 "<div id=\"divid\"></div>"
2590 "<script language=\"TestScript\">simple script</script>"
2593 static void test_exec_script(IHTMLDocument2 *doc, const char *codea, const char *langa)
2595 IHTMLWindow2 *window;
2600 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2601 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2603 code = a2bstr(codea);
2604 lang = a2bstr(langa);
2606 SET_EXPECT(ParseScriptText_execScript);
2607 hres = IHTMLWindow2_execScript(window, code, lang, &v);
2608 ok(hres == S_OK, "execScript failed: %08x\n", hres);
2609 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2610 ok(V_I4(&v) == 10, "V_I4(v) = %d\n", V_I4(&v));
2611 CHECK_CALLED(ParseScriptText_execScript);
2612 SysFreeString(lang);
2614 lang = a2bstr("invalid");
2616 hres = IHTMLWindow2_execScript(window, code, lang, &v);
2617 ok(hres == CO_E_CLASSSTRING, "execScript failed: %08x, expected CO_E_CLASSSTRING\n", hres);
2618 ok(V_VT(&v) == 100, "V_VT(v) = %d\n", V_VT(&v));
2619 SysFreeString(lang);
2620 SysFreeString(code);
2622 IHTMLWindow2_Release(window);
2625 static void test_simple_script(void)
2627 IHTMLDocument2 *doc;
2629 doc = create_document();
2633 SET_EXPECT(CreateInstance);
2634 SET_EXPECT(GetInterfaceSafetyOptions);
2635 SET_EXPECT(SetInterfaceSafetyOptions);
2636 SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
2637 SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
2638 SET_EXPECT(InitNew);
2639 SET_EXPECT(SetScriptSite);
2640 SET_EXPECT(GetScriptState);
2641 SET_EXPECT(SetScriptState_STARTED);
2642 SET_EXPECT(AddNamedItem);
2643 SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
2644 SET_EXPECT(ParseScriptText_script);
2645 SET_EXPECT(SetScriptState_CONNECTED);
2647 load_doc(doc, simple_script_str);
2649 CHECK_CALLED(CreateInstance);
2650 CHECK_CALLED(GetInterfaceSafetyOptions);
2651 CHECK_CALLED(SetInterfaceSafetyOptions);
2652 CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
2653 CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
2654 CHECK_CALLED(InitNew);
2655 CHECK_CALLED(SetScriptSite);
2656 CHECK_CALLED(GetScriptState);
2657 CHECK_CALLED(SetScriptState_STARTED);
2658 CHECK_CALLED(AddNamedItem);
2659 CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
2660 CHECK_CALLED(ParseScriptText_script);
2661 CHECK_CALLED(SetScriptState_CONNECTED);
2663 test_exec_script(doc, "execScript call", "TestScript");
2666 IActiveScriptSite_Release(site);
2668 IDispatchEx_Release(window_dispex);
2670 SET_EXPECT(SetScriptState_DISCONNECTED);
2673 IHTMLDocument2_Release(doc);
2675 CHECK_CALLED(SetScriptState_DISCONNECTED);
2676 CHECK_CALLED(Close);
2679 static void run_js_script(const char *test_name)
2681 WCHAR url[INTERNET_MAX_URL_LENGTH];
2682 char urlA[INTERNET_MAX_URL_LENGTH];
2683 IPersistMoniker *persist;
2684 IHTMLDocument2 *doc;
2689 static const char res[] = "res://";
2691 trace("running %s...\n", test_name);
2693 doc = create_document();
2697 set_client_site(doc, TRUE);
2698 do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2700 lstrcpyA(urlA, res);
2701 GetModuleFileNameA(NULL, urlA + lstrlenA(res), sizeof(urlA) - lstrlenA(res));
2702 lstrcatA(urlA, "/");
2703 lstrcatA(urlA, test_name);
2704 MultiByteToWideChar(CP_ACP, 0, urlA, -1, url, sizeof(url)/sizeof(WCHAR));
2706 hres = CreateURLMoniker(NULL, url, &mon);
2707 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2709 hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker, (void**)&persist);
2710 ok(hres == S_OK, "Could not get IPersistMoniker iface: %08x\n", hres);
2712 hres = IPersistMoniker_Load(persist, FALSE, mon, NULL, 0);
2713 ok(hres == S_OK, "Load failed: %08x\n", hres);
2715 IMoniker_Release(mon);
2716 IPersistMoniker_Release(persist);
2718 SET_EXPECT(external_success);
2720 while(!called_external_success && GetMessage(&msg, NULL, 0, 0)) {
2721 TranslateMessage(&msg);
2722 DispatchMessage(&msg);
2725 CHECK_CALLED(external_success);
2727 set_client_site(doc, FALSE);
2728 IHTMLDocument2_Release(doc);
2731 static void run_js_tests(void)
2733 run_js_script("jstest.html");
2734 run_js_script("exectest.html");
2737 static BOOL init_registry(BOOL init)
2739 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
2740 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
2742 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
2746 static BOOL register_script_engine(void)
2751 if(!init_registry(TRUE)) {
2752 init_registry(FALSE);
2756 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
2757 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
2758 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
2763 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2765 return DefWindowProc(hwnd, msg, wParam, lParam);
2768 static HWND create_container_window(void)
2770 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
2771 static WNDCLASSEXA wndclass = {
2772 sizeof(WNDCLASSEXA),
2775 0, 0, NULL, NULL, NULL, NULL, NULL,
2780 RegisterClassExA(&wndclass);
2781 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
2782 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
2783 300, 300, NULL, NULL, NULL, NULL);
2789 container_hwnd = create_container_window();
2791 if(winetest_interactive || ! is_ie_hardened()) {
2792 if(register_script_engine()) {
2793 test_simple_script();
2794 init_registry(FALSE);
2796 skip("Could not register TestScript engine\n");
2800 skip("IE running in Enhanced Security Configuration\n");
2803 DestroyWindow(container_hwnd);