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);
133 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
134 #define TESTACTIVEX_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
136 #define DISPID_SCRIPT_TESTPROP 0x100000
137 #define DISPID_SCRIPT_TESTPROP2 0x100001
139 #define DISPID_EXTERNAL_OK 0x300000
140 #define DISPID_EXTERNAL_TRACE 0x300001
141 #define DISPID_EXTERNAL_REPORTSUCCESS 0x300002
142 #define DISPID_EXTERNAL_TODO_WINE_OK 0x300003
144 static const GUID CLSID_TestScript =
145 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
146 static const GUID CLSID_TestActiveX =
147 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
149 static IHTMLDocument2 *notif_doc;
150 static IOleDocumentView *view;
151 static IDispatchEx *window_dispex;
152 static BOOL doc_complete;
153 static IDispatch *script_disp;
154 static BOOL ax_objsafe;
155 static HWND container_hwnd;
156 static HRESULT ax_getopt_hres = S_OK, ax_setopt_dispex_hres = S_OK;
157 static HRESULT ax_setopt_disp_caller_hres = S_OK, ax_setopt_disp_data_hres = S_OK;
158 static BOOL skip_loadobject_tests;
160 static const char *debugstr_guid(REFIID riid)
164 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
165 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
166 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
167 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
172 static int strcmp_wa(LPCWSTR strw, const char *stra)
175 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
176 return lstrcmpA(stra, buf);
179 static BSTR a2bstr(const char *str)
184 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
185 ret = SysAllocStringLen(NULL, len);
186 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
191 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
197 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
201 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
202 if(res != ERROR_SUCCESS)
206 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
210 return res == ERROR_SUCCESS;
213 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
214 REFIID riid, void**ppv)
216 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
221 return E_NOINTERFACE;
224 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
229 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
234 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
236 if(dispID == DISPID_READYSTATE){
240 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
242 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
243 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
245 if(!lstrcmpW(state, completeW))
248 SysFreeString(state);
254 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
256 ok(0, "unexpected call\n");
260 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
261 PropertyNotifySink_QueryInterface,
262 PropertyNotifySink_AddRef,
263 PropertyNotifySink_Release,
264 PropertyNotifySink_OnChanged,
265 PropertyNotifySink_OnRequestEdit
268 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
270 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
274 if(IsEqualGUID(riid, &IID_IUnknown)
275 || IsEqualGUID(riid, &IID_IDispatch)
276 || IsEqualGUID(riid, &IID_IDispatchEx))
279 return E_NOINTERFACE;
284 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
289 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
294 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
296 ok(0, "unexpected call\n");
300 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
301 LCID lcid, ITypeInfo **ppTInfo)
303 ok(0, "unexpected call\n");
307 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
308 LPOLESTR *rgszNames, UINT cNames,
309 LCID lcid, DISPID *rgDispId)
311 ok(0, "unexpected call\n");
315 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
316 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
317 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
319 ok(0, "unexpected call\n");
323 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
325 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
329 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
331 ok(0, "unexpected call\n");
335 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
337 ok(0, "unexpected call\n");
341 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
343 ok(0, "unexpected call\n");
347 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
349 ok(0, "unexpected call\n");
353 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
355 ok(0, "unexpected call\n");
359 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
361 ok(0, "unexpected call\n");
365 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
366 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
368 CHECK_EXPECT(funcDisp);
370 ok(id == DISPID_VALUE, "id = %d\n", id);
371 ok(lcid == 0, "lcid = %x\n", lcid);
372 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
373 ok(pdp != NULL, "pdp == NULL\n");
374 ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
375 ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
376 ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
377 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
378 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
379 ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
380 ok(pvarRes != NULL, "pvarRes == NULL\n");
381 ok(pei != NULL, "pei == NULL\n");
382 ok(!pspCaller, "pspCaller != NULL\n");
384 V_VT(pvarRes) = VT_I4;
389 static IDispatchExVtbl testObjVtbl = {
390 DispatchEx_QueryInterface,
393 DispatchEx_GetTypeInfoCount,
394 DispatchEx_GetTypeInfo,
395 DispatchEx_GetIDsOfNames,
397 DispatchEx_GetDispID,
399 DispatchEx_DeleteMemberByName,
400 DispatchEx_DeleteMemberByDispID,
401 DispatchEx_GetMemberProperties,
402 DispatchEx_GetMemberName,
403 DispatchEx_GetNextDispID,
404 DispatchEx_GetNameSpaceParent
407 static IDispatchEx funcDisp = { &testObjVtbl };
409 static HRESULT WINAPI scriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
411 if(!strcmp_wa(bstrName, "testProp")) {
412 CHECK_EXPECT(script_testprop_d);
413 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
414 *pid = DISPID_SCRIPT_TESTPROP;
418 if(!strcmp_wa(bstrName, "testProp2")) {
419 CHECK_EXPECT(script_testprop2_d);
420 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
421 *pid = DISPID_SCRIPT_TESTPROP2;
425 if(!strcmp_wa(bstrName, "divid")) {
426 CHECK_EXPECT(script_divid_d);
427 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
431 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
435 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
436 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
439 case DISPID_SCRIPT_TESTPROP:
440 CHECK_EXPECT(script_testprop_i);
442 ok(lcid == 0, "lcid = %x\n", lcid);
443 ok(wFlags == DISPATCH_PROPERTYGET, "wFlags = %x\n", wFlags);
444 ok(pdp != NULL, "pdp == NULL\n");
445 ok(pdp->cArgs == 0, "pdp->cArgs = %d\n", pdp->cArgs);
446 ok(pdp->cNamedArgs == 0, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
447 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs != NULL\n");
448 ok(!pdp->rgvarg, "rgvarg != NULL\n");
449 ok(pvarRes != NULL, "pvarRes == NULL\n");
450 ok(pei != NULL, "pei == NULL\n");
451 ok(!pspCaller, "pspCaller != NULL\n");
453 V_VT(pvarRes) = VT_NULL;
456 ok(0, "unexpected call\n");
463 static IDispatchExVtbl scriptDispVtbl = {
464 DispatchEx_QueryInterface,
467 DispatchEx_GetTypeInfoCount,
468 DispatchEx_GetTypeInfo,
469 DispatchEx_GetIDsOfNames,
471 scriptDisp_GetDispID,
473 DispatchEx_DeleteMemberByName,
474 DispatchEx_DeleteMemberByDispID,
475 DispatchEx_GetMemberProperties,
476 DispatchEx_GetMemberName,
477 DispatchEx_GetNextDispID,
478 DispatchEx_GetNameSpaceParent
481 static IDispatchEx scriptDisp = { &scriptDispVtbl };
483 static HRESULT WINAPI externalDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
485 if(!strcmp_wa(bstrName, "ok")) {
486 *pid = DISPID_EXTERNAL_OK;
489 if(!strcmp_wa(bstrName, "trace")) {
490 *pid = DISPID_EXTERNAL_TRACE;
493 if(!strcmp_wa(bstrName, "reportSuccess")) {
494 *pid = DISPID_EXTERNAL_REPORTSUCCESS;
497 if(!strcmp_wa(bstrName, "todo_wine_ok")) {
498 *pid = DISPID_EXTERNAL_TODO_WINE_OK;
502 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
503 return DISP_E_UNKNOWNNAME;
506 static HRESULT WINAPI externalDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
507 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
510 case DISPID_EXTERNAL_OK:
511 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
512 ok(pdp != NULL, "pdp == NULL\n");
513 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
514 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
515 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
516 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
517 ok(pei != NULL, "pei == NULL\n");
519 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
520 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
521 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
525 case DISPID_EXTERNAL_TRACE:
526 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
527 ok(pdp != NULL, "pdp == NULL\n");
528 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
529 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
530 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
531 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
532 ok(!pvarRes, "pvarRes != NULL\n");
533 ok(pei != NULL, "pei == NULL\n");
535 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
536 if(V_VT(pdp->rgvarg) == VT_BSTR)
537 trace("%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
541 case DISPID_EXTERNAL_REPORTSUCCESS:
542 CHECK_EXPECT(external_success);
544 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
545 ok(pdp != NULL, "pdp == NULL\n");
546 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
547 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
548 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
549 ok(!pvarRes, "pvarRes != NULL\n");
550 ok(pei != NULL, "pei == NULL\n");
554 case DISPID_EXTERNAL_TODO_WINE_OK:
555 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
556 ok(pdp != NULL, "pdp == NULL\n");
557 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
558 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
559 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
560 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
561 ok(pei != NULL, "pei == NULL\n");
563 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
564 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
566 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
571 ok(0, "unexpected call\n");
578 static IDispatchExVtbl externalDispVtbl = {
579 DispatchEx_QueryInterface,
582 DispatchEx_GetTypeInfoCount,
583 DispatchEx_GetTypeInfo,
584 DispatchEx_GetIDsOfNames,
586 externalDisp_GetDispID,
587 externalDisp_InvokeEx,
588 DispatchEx_DeleteMemberByName,
589 DispatchEx_DeleteMemberByDispID,
590 DispatchEx_GetMemberProperties,
591 DispatchEx_GetMemberName,
592 DispatchEx_GetNextDispID,
593 DispatchEx_GetNameSpaceParent
596 static IDispatchEx externalDisp = { &externalDispVtbl };
598 static HRESULT QueryInterface(REFIID,void**);
600 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
602 return QueryInterface(riid, ppv);
605 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
610 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
615 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
616 IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
621 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
626 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
627 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
628 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
633 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
638 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
643 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
648 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
653 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
658 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
659 IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
664 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
665 const GUID *pguidCmdGroup, DWORD nCmdID)
670 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
671 LPOLESTR *pchKey, DWORD dw)
676 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
677 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
682 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
684 *ppDispatch = (IDispatch*)&externalDisp;
688 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
689 OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
694 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
695 IDataObject **ppPORet)
700 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
701 LPOLESTR *pchKey, DWORD dw)
706 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
707 DocHostUIHandler_QueryInterface,
708 DocHostUIHandler_AddRef,
709 DocHostUIHandler_Release,
710 DocHostUIHandler_ShowContextMenu,
711 DocHostUIHandler_GetHostInfo,
712 DocHostUIHandler_ShowUI,
713 DocHostUIHandler_HideUI,
714 DocHostUIHandler_UpdateUI,
715 DocHostUIHandler_EnableModeless,
716 DocHostUIHandler_OnDocWindowActivate,
717 DocHostUIHandler_OnFrameWindowActivate,
718 DocHostUIHandler_ResizeBorder,
719 DocHostUIHandler_TranslateAccelerator,
720 DocHostUIHandler_GetOptionKeyPath,
721 DocHostUIHandler_GetDropTarget,
722 DocHostUIHandler_GetExternal,
723 DocHostUIHandler_TranslateUrl,
724 DocHostUIHandler_FilterDataObject,
725 DocHostUIHandler_GetOverrideKeyPath
728 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
730 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
732 return E_NOINTERFACE;
735 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
740 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
745 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
750 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
755 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
760 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
761 LPCBORDERWIDTHS pborderwidths)
766 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
767 LPCBORDERWIDTHS pborderwidths)
772 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
773 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
778 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
779 LPOLEMENUGROUPWIDTHS lpMenuWidths)
784 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
785 HOLEMENU holemenu, HWND hwndActiveObject)
787 ok(0, "unexpected call\n");
791 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
793 ok(0, "unexpected call\n");
797 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
802 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
807 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
809 ok(0, "unexpected call\n");
813 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
814 InPlaceFrame_QueryInterface,
816 InPlaceFrame_Release,
817 InPlaceFrame_GetWindow,
818 InPlaceFrame_ContextSensitiveHelp,
819 InPlaceFrame_GetBorder,
820 InPlaceFrame_RequestBorderSpace,
821 InPlaceFrame_SetBorderSpace,
822 InPlaceFrame_SetActiveObject,
823 InPlaceFrame_InsertMenus,
824 InPlaceFrame_SetMenu,
825 InPlaceFrame_RemoveMenus,
826 InPlaceFrame_SetStatusText,
827 InPlaceFrame_EnableModeless,
828 InPlaceFrame_TranslateAccelerator
831 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
833 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
835 return QueryInterface(riid, ppv);
838 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
843 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
848 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
850 *phwnd = container_hwnd;
854 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
856 ok(0, "unexpected call\n");
860 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
865 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
870 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
875 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
876 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
877 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
879 static const RECT rect = {0,0,300,300};
881 *ppFrame = &InPlaceFrame;
882 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceFrame;
884 *lprcClipRect = rect;
886 ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
887 lpFrameInfo->fMDIApp = FALSE;
888 lpFrameInfo->hwndFrame = container_hwnd;
889 lpFrameInfo->haccel = NULL;
890 lpFrameInfo->cAccelEntries = 0;
895 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
900 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
905 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
910 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
915 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
920 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
925 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
926 InPlaceSite_QueryInterface,
929 InPlaceSite_GetWindow,
930 InPlaceSite_ContextSensitiveHelp,
931 InPlaceSite_CanInPlaceActivate,
932 InPlaceSite_OnInPlaceActivate,
933 InPlaceSite_OnUIActivate,
934 InPlaceSite_GetWindowContext,
936 InPlaceSite_OnUIDeactivate,
937 InPlaceSite_OnInPlaceDeactivate,
938 InPlaceSite_DiscardUndoState,
939 InPlaceSite_DeactivateAndUndo,
940 InPlaceSite_OnPosRectChange,
943 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
945 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
947 return QueryInterface(riid, ppv);
950 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
955 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
960 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
962 ok(0, "unexpected call\n");
966 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
969 ok(0, "unexpected call\n");
973 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
978 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
980 ok(0, "unexpected call\n");
984 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
986 ok(0, "unexpected call\n");
990 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
992 ok(0, "unexpected call\n");
996 static const IOleClientSiteVtbl ClientSiteVtbl = {
997 ClientSite_QueryInterface,
1000 ClientSite_SaveObject,
1001 ClientSite_GetMoniker,
1002 ClientSite_GetContainer,
1003 ClientSite_ShowObject,
1004 ClientSite_OnShowWindow,
1005 ClientSite_RequestNewObjectLayout
1008 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1010 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1012 return QueryInterface(riid, ppv);
1015 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1020 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1025 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1027 RECT rect = {0,0,300,300};
1028 IOleDocument *document;
1031 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1032 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1034 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1035 IOleDocument_Release(document);
1036 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1038 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1039 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1041 hres = IOleDocumentView_UIActivate(view, TRUE);
1042 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1044 hres = IOleDocumentView_SetRect(view, &rect);
1045 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1047 hres = IOleDocumentView_Show(view, TRUE);
1048 ok(hres == S_OK, "Show failed: %08x\n", hres);
1053 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1054 DocumentSite_QueryInterface,
1055 DocumentSite_AddRef,
1056 DocumentSite_Release,
1057 DocumentSite_ActivateMe
1060 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1062 static HRESULT QueryInterface(REFIID riid, void **ppv)
1066 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1068 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1069 *ppv = &DocumentSite;
1070 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1071 *ppv = &InPlaceSite;
1072 else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
1073 *ppv = &DocHostUIHandler;
1075 return *ppv ? S_OK : E_NOINTERFACE;
1078 static IHTMLDocument2 *create_document(void)
1080 IHTMLDocument2 *doc;
1081 IHTMLDocument5 *doc5;
1084 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1085 &IID_IHTMLDocument2, (void**)&doc);
1086 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1087 if (hres != S_OK) return NULL;
1089 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
1091 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
1092 IHTMLDocument2_Release(doc);
1096 IHTMLDocument5_Release(doc5);
1100 static void load_string(IHTMLDocument2 *doc, const char *str)
1102 IPersistStreamInit *init;
1107 doc_complete = FALSE;
1109 mem = GlobalAlloc(0, len);
1110 memcpy(mem, str, len);
1111 CreateStreamOnHGlobal(mem, TRUE, &stream);
1113 IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1115 IPersistStreamInit_Load(init, stream);
1116 IPersistStreamInit_Release(init);
1117 IStream_Release(stream);
1120 static void do_advise(IHTMLDocument2 *doc, REFIID riid, IUnknown *unk_advise)
1122 IConnectionPointContainer *container;
1123 IConnectionPoint *cp;
1127 hres = IHTMLDocument2_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&container);
1128 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1130 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1131 IConnectionPointContainer_Release(container);
1132 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1136 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1137 IConnectionPoint_Release(cp);
1138 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1141 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1147 IOleDocumentView_Show(view, FALSE);
1148 IOleDocumentView_CloseView(view, 0);
1149 IOleDocumentView_SetInPlaceSite(view, NULL);
1150 IOleDocumentView_Release(view);
1154 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1155 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1157 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1158 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1161 IHlinkTarget *hlink;
1163 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1164 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1166 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1167 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1169 IHlinkTarget_Release(hlink);
1172 IOleObject_Release(oleobj);
1175 typedef void (*domtest_t)(IHTMLDocument2*);
1177 static void load_doc(IHTMLDocument2 *doc, const char *str)
1179 IHTMLElement *body = NULL;
1182 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
1186 load_string(doc, str);
1187 do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1189 while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
1190 TranslateMessage(&msg);
1191 DispatchMessage(&msg);
1194 hres = IHTMLDocument2_get_body(doc, &body);
1195 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1197 /* Check we can query for function on the IHTMLElementBody interface */
1198 name = (WCHAR*)ucPtr;
1199 hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
1200 ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
1201 ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
1203 IHTMLElement_Release(body);
1206 static IActiveScriptSite *site;
1207 static SCRIPTSTATE state;
1209 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1212 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1213 return E_NOINTERFACE;
1216 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
1221 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
1226 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1227 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1229 CHECK_EXPECT(GetInterfaceSafetyOptions);
1231 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
1232 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1233 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1235 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1236 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1241 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1242 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1244 CHECK_EXPECT(SetInterfaceSafetyOptions);
1246 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", debugstr_guid(riid));
1248 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1249 "dwOptionSetMask=%x\n", dwOptionSetMask);
1250 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1251 "dwEnabledOptions=%x\n", dwOptionSetMask);
1256 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1257 ObjectSafety_QueryInterface,
1258 ObjectSafety_AddRef,
1259 ObjectSafety_Release,
1260 ObjectSafety_GetInterfaceSafetyOptions,
1261 ObjectSafety_SetInterfaceSafetyOptions
1264 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
1266 static HRESULT WINAPI AXObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1270 if(IsEqualGUID(&IID_IActiveScript, riid)) {
1271 CHECK_EXPECT(AXQueryInterface_IActiveScript);
1272 return E_NOINTERFACE;
1275 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1276 CHECK_EXPECT2(AXQueryInterface_IObjectSafety);
1278 return E_NOINTERFACE;
1283 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1284 return E_NOINTERFACE;
1287 static HRESULT WINAPI AXObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1288 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1290 CHECK_EXPECT(AXGetInterfaceSafetyOptions);
1292 ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", debugstr_guid(riid));
1293 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1294 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1296 if(SUCCEEDED(ax_getopt_hres)) {
1297 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1298 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1301 return ax_getopt_hres;
1304 static HRESULT WINAPI AXObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1305 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1307 if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1308 switch(dwEnabledOptions) {
1309 case INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER:
1310 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1312 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1313 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1316 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1319 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1320 return ax_setopt_dispex_hres;
1323 if(IsEqualGUID(&IID_IDispatch, riid)) {
1326 switch(dwEnabledOptions) {
1327 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1328 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1329 hres = ax_setopt_disp_caller_hres;
1331 case INTERFACESAFE_FOR_UNTRUSTED_DATA:
1332 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1333 hres = ax_setopt_disp_data_hres;
1336 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1339 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1343 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
1344 return E_NOINTERFACE;
1347 static const IObjectSafetyVtbl AXObjectSafetyVtbl = {
1348 AXObjectSafety_QueryInterface,
1349 ObjectSafety_AddRef,
1350 ObjectSafety_Release,
1351 AXObjectSafety_GetInterfaceSafetyOptions,
1352 AXObjectSafety_SetInterfaceSafetyOptions
1355 static IObjectSafety AXObjectSafety = { &AXObjectSafetyVtbl };
1357 static BOOL set_safe_reg(BOOL safe_call, BOOL safe_data)
1359 return init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95801-9882-11cf-9fa9-00aa006c42c4}",
1361 && init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95802-9882-11cf-9fa9-00aa006c42c4}",
1365 #define check_custom_policy(a,b,c,d) _check_custom_policy(__LINE__,a,b,c,d)
1366 static void _check_custom_policy(unsigned line, HRESULT hres, BYTE *ppolicy, DWORD policy_size, DWORD expolicy)
1368 ok_(__FILE__,line)(hres == S_OK, "QueryCusromPolicy failed: %08x\n", hres);
1369 ok_(__FILE__,line)(policy_size == sizeof(DWORD), "policy_size = %d\n", policy_size);
1370 ok_(__FILE__,line)(*(DWORD*)ppolicy == expolicy, "policy = %x, expected %x\n", *(DWORD*)ppolicy, expolicy);
1371 CoTaskMemFree(ppolicy);
1374 static void test_security_reg(IInternetHostSecurityManager *sec_mgr, DWORD policy_caller, DWORD policy_load)
1376 struct CONFIRMSAFETY cs;
1381 cs.clsid = CLSID_TestActiveX;
1382 cs.pUnk = (IUnknown*)&AXObjectSafety;
1386 SET_EXPECT(AXQueryInterface_IActiveScript);
1387 SET_EXPECT(AXQueryInterface_IObjectSafety);
1388 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1389 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1390 CHECK_CALLED(AXQueryInterface_IActiveScript);
1391 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1392 check_custom_policy(hres, ppolicy, policy_size, policy_caller);
1395 SET_EXPECT(AXQueryInterface_IActiveScript);
1396 SET_EXPECT(AXQueryInterface_IObjectSafety);
1397 SET_EXPECT(AXGetInterfaceSafetyOptions);
1398 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1399 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1400 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1401 CHECK_CALLED(AXQueryInterface_IActiveScript);
1402 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1403 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1404 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1405 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1407 if(skip_loadobject_tests)
1410 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1412 SET_EXPECT(AXQueryInterface_IActiveScript);
1413 SET_EXPECT(AXQueryInterface_IObjectSafety);
1414 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1415 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1416 CHECK_CALLED(AXQueryInterface_IActiveScript);
1417 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1418 check_custom_policy(hres, ppolicy, policy_size, policy_load);
1421 SET_EXPECT(AXQueryInterface_IActiveScript);
1422 SET_EXPECT(AXQueryInterface_IObjectSafety);
1423 SET_EXPECT(AXGetInterfaceSafetyOptions);
1424 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1425 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1426 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1427 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1428 CHECK_CALLED(AXQueryInterface_IActiveScript);
1429 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1430 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1431 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1432 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1433 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1436 static void test_security(void)
1438 IInternetHostSecurityManager *sec_mgr;
1439 IServiceProvider *sp;
1440 DWORD policy, policy_size;
1441 struct CONFIRMSAFETY cs;
1445 hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
1446 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
1448 hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager,
1449 &IID_IInternetHostSecurityManager, (void**)&sec_mgr);
1450 IServiceProvider_Release(sp);
1451 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1453 hres = IInternetHostSecurityManager_ProcessUrlAction(sec_mgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
1454 (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
1455 ok(hres == S_OK, "ProcessUrlAction failed: %08x\n", hres);
1456 ok(policy == URLPOLICY_ALLOW, "policy = %x\n", policy);
1458 cs.clsid = CLSID_TestActiveX;
1459 cs.pUnk = (IUnknown*)&AXObjectSafety;
1463 SET_EXPECT(AXQueryInterface_IActiveScript);
1464 SET_EXPECT(AXQueryInterface_IObjectSafety);
1465 SET_EXPECT(AXGetInterfaceSafetyOptions);
1466 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1467 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1468 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1469 CHECK_CALLED(AXQueryInterface_IActiveScript);
1470 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1471 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1472 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1473 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1475 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1476 SET_EXPECT(AXQueryInterface_IActiveScript);
1477 SET_EXPECT(AXQueryInterface_IObjectSafety);
1478 SET_EXPECT(AXGetInterfaceSafetyOptions);
1479 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1480 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1481 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1482 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1483 CHECK_CALLED(AXQueryInterface_IActiveScript);
1484 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1485 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1486 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1487 if(called_AXSetInterfaceSafetyOptions_IDispatch_data) {
1488 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1490 win_skip("CONFIRMSAFETYACTION_LOADOBJECT flag not supported\n");
1491 skip_loadobject_tests = TRUE;
1492 CLEAR_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1494 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1498 SET_EXPECT(AXQueryInterface_IActiveScript);
1499 SET_EXPECT(AXQueryInterface_IObjectSafety);
1500 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1501 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1502 CHECK_CALLED(AXQueryInterface_IActiveScript);
1503 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1504 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1506 if(!skip_loadobject_tests) {
1507 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1509 SET_EXPECT(AXQueryInterface_IActiveScript);
1510 SET_EXPECT(AXQueryInterface_IObjectSafety);
1511 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1512 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1513 CHECK_CALLED(AXQueryInterface_IActiveScript);
1514 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1515 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1518 if(set_safe_reg(TRUE, FALSE)) {
1519 test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_DISALLOW);
1521 set_safe_reg(FALSE, TRUE);
1522 test_security_reg(sec_mgr, URLPOLICY_DISALLOW, URLPOLICY_DISALLOW);
1524 set_safe_reg(TRUE, TRUE);
1525 test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_ALLOW);
1527 set_safe_reg(FALSE, FALSE);
1529 skip("Could not set safety registry\n");
1535 ax_setopt_dispex_hres = E_NOINTERFACE;
1536 SET_EXPECT(AXQueryInterface_IActiveScript);
1537 SET_EXPECT(AXQueryInterface_IObjectSafety);
1538 SET_EXPECT(AXGetInterfaceSafetyOptions);
1539 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1540 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1541 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1542 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1543 CHECK_CALLED(AXQueryInterface_IActiveScript);
1544 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1545 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1546 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1547 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1548 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1550 ax_setopt_dispex_hres = E_FAIL;
1551 ax_setopt_disp_caller_hres = E_NOINTERFACE;
1552 SET_EXPECT(AXQueryInterface_IActiveScript);
1553 SET_EXPECT(AXQueryInterface_IObjectSafety);
1554 SET_EXPECT(AXGetInterfaceSafetyOptions);
1555 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1556 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1557 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1558 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1559 CHECK_CALLED(AXQueryInterface_IActiveScript);
1560 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1561 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1562 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1563 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1564 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1566 if(!skip_loadobject_tests) {
1567 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1568 ax_setopt_dispex_hres = E_FAIL;
1569 ax_setopt_disp_caller_hres = E_NOINTERFACE;
1570 SET_EXPECT(AXQueryInterface_IActiveScript);
1571 SET_EXPECT(AXQueryInterface_IObjectSafety);
1572 SET_EXPECT(AXGetInterfaceSafetyOptions);
1573 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1574 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1575 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1576 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1577 CHECK_CALLED(AXQueryInterface_IActiveScript);
1578 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1579 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1580 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1581 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1582 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1586 ax_setopt_dispex_hres = E_FAIL;
1587 ax_setopt_disp_caller_hres = S_OK;
1588 ax_getopt_hres = E_NOINTERFACE;
1589 SET_EXPECT(AXQueryInterface_IActiveScript);
1590 SET_EXPECT(AXQueryInterface_IObjectSafety);
1591 SET_EXPECT(AXGetInterfaceSafetyOptions);
1592 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1593 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1594 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1595 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1596 CHECK_CALLED(AXQueryInterface_IActiveScript);
1597 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1598 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1599 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1600 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1601 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1603 if(!skip_loadobject_tests) {
1604 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1605 ax_setopt_dispex_hres = E_FAIL;
1606 ax_setopt_disp_caller_hres = S_OK;
1607 ax_setopt_disp_data_hres = E_FAIL;
1608 ax_getopt_hres = E_NOINTERFACE;
1609 SET_EXPECT(AXQueryInterface_IActiveScript);
1610 SET_EXPECT(AXQueryInterface_IObjectSafety);
1611 SET_EXPECT(AXGetInterfaceSafetyOptions);
1612 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1613 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1614 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1615 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1616 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1617 CHECK_CALLED(AXQueryInterface_IActiveScript);
1618 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1619 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1620 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1621 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1622 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1623 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1626 IInternetHostSecurityManager_Release(sec_mgr);
1629 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
1632 ok(0, "unexpected call\n");
1633 return E_NOINTERFACE;
1636 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
1641 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
1646 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1647 VARIANT *pvarIndex, VARIANT *pvarValue)
1649 ok(0, "unexpected call\n");
1653 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1654 VARIANT *pvarIndex, VARIANT *pvarValue)
1656 switch(dwProperty) {
1657 case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
1658 CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1659 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1660 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1662 case SCRIPTPROP_INVOKEVERSIONING:
1663 CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
1664 ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1665 ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
1667 case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
1668 CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION);
1669 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1670 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1673 ok(0, "unexpected property %x\n", dwProperty);
1677 ok(!pvarIndex, "pvarIndex != NULL\n");
1678 ok(pvarValue != NULL, "pvarValue == NULL\n");
1683 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
1684 ActiveScriptProperty_QueryInterface,
1685 ActiveScriptProperty_AddRef,
1686 ActiveScriptProperty_Release,
1687 ActiveScriptProperty_GetProperty,
1688 ActiveScriptProperty_SetProperty
1691 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
1693 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
1696 ok(0, "unexpected call\n");
1697 return E_NOINTERFACE;
1700 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
1705 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
1710 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
1711 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
1712 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
1713 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
1715 ok(0, "unexpected call\n");
1719 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
1720 ActiveScriptParseProcedure_QueryInterface,
1721 ActiveScriptParseProcedure_AddRef,
1722 ActiveScriptParseProcedure_Release,
1723 ActiveScriptParseProcedure_ParseProcedureText
1726 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
1728 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
1731 ok(0, "unexpected call\n");
1732 return E_NOINTERFACE;
1735 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
1740 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
1745 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
1747 CHECK_EXPECT(InitNew);
1751 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
1752 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
1753 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
1754 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
1755 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
1757 ok(0, "unexpected call\n");
1761 static HRESULT dispex_propput(IDispatchEx *obj, DISPID id, DWORD flags, VARIANT *var)
1763 DISPID propput_arg = DISPID_PROPERTYPUT;
1764 DISPPARAMS dp = {var, &propput_arg, 1, 1};
1767 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT|flags, &dp, NULL, &ei, NULL);
1770 static void test_func(IDispatchEx *obj)
1773 IDispatchEx *dispex;
1781 str = a2bstr("toString");
1782 hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
1784 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1785 ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
1787 memset(&dp, 0, sizeof(dp));
1788 memset(&ei, 0, sizeof(ei));
1790 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1791 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1792 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
1793 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
1794 disp = V_DISPATCH(&var);
1796 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1797 IDispatch_Release(disp);
1798 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1800 /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
1802 memset(&dp, 0, sizeof(dp));
1803 memset(&ei, 0, sizeof(ei));
1805 hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
1806 ok(hres == S_OK || broken(E_ACCESSDENIED), "InvokeEx failed: %08x\n", hres);
1807 if(SUCCEEDED(hres)) {
1808 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1809 ok(!strcmp_wa(V_BSTR(&var), "[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
1815 hres = dispex_propput(obj, id, 0, &var);
1816 ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
1818 IDispatchEx_Release(dispex);
1821 static void test_nextdispid(IDispatchEx *dispex)
1823 DISPID last_id = DISPID_STARTENUM, id, dyn_id;
1828 name = a2bstr("dynVal");
1829 hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive|fdexNameEnsure, &dyn_id);
1830 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1831 SysFreeString(name);
1833 V_VT(&var) = VT_EMPTY;
1834 hres = dispex_propput(dispex, dyn_id, 0, &var);
1835 ok(hres == S_OK, "dispex_propput failed: %08x\n", hres);
1837 while(last_id != dyn_id) {
1838 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, last_id, &id);
1839 ok(hres == S_OK, "GetNextDispID returned: %08x\n", hres);
1840 ok(id != DISPID_STARTENUM, "id == DISPID_STARTENUM\n");
1841 ok(id != DISPID_IOMNAVIGATOR_TOSTRING, "id == DISPID_IOMNAVIGATOR_TOSTRING\n");
1843 hres = IDispatchEx_GetMemberName(dispex, id, &name);
1844 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
1847 ok(!strcmp_wa(name, "dynVal"), "name = %s\n", wine_dbgstr_w(name));
1848 else if(id == DISPID_IOMNAVIGATOR_PLATFORM)
1849 ok(!strcmp_wa(name, "platform"), "name = %s\n", wine_dbgstr_w(name));
1851 SysFreeString(name);
1855 hres = IDispatchEx_GetNextDispID(dispex, 0, id, &id);
1856 ok(hres == S_FALSE, "GetNextDispID returned: %08x\n", hres);
1857 ok(id == DISPID_STARTENUM, "id != DISPID_STARTENUM\n");
1860 static void test_global_id(void)
1869 SET_EXPECT(GetScriptDispatch);
1870 SET_EXPECT(script_divid_d);
1871 tmp = a2bstr("divid");
1872 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1873 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1875 CHECK_CALLED(GetScriptDispatch);
1876 CHECK_CALLED(script_divid_d);
1879 memset(&ei, 0, sizeof(ei));
1880 memset(&dp, 0, sizeof(dp));
1881 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1882 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1883 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d\n", V_VT(&var));
1887 static void test_script_run(void)
1889 IDispatchEx *document, *dispex;
1890 IHTMLWindow2 *window;
1891 IOmNavigator *navigator;
1900 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
1901 static const WCHAR testW[] = {'t','e','s','t',0};
1902 static const WCHAR funcW[] = {'f','u','n','c',0};
1904 SET_EXPECT(GetScriptDispatch);
1906 tmp = SysAllocString(documentW);
1907 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
1909 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1910 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
1912 CHECK_CALLED(GetScriptDispatch);
1915 memset(&dp, 0, sizeof(dp));
1916 memset(&ei, 0, sizeof(ei));
1918 hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1919 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1920 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
1921 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
1923 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
1925 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
1927 tmp = SysAllocString(testW);
1928 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
1929 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1930 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
1931 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
1935 tmp = SysAllocString(testW);
1936 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
1938 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1939 ok(id, "id == 0\n");
1943 hres = dispex_propput(document, id, 0, &var);
1944 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1946 tmp = SysAllocString(testW);
1947 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
1949 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
1952 memset(&dp, 0, sizeof(dp));
1953 memset(&ei, 0, sizeof(ei));
1954 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1955 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1956 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1957 ok(V_I4(&var) == 100, "V_I4(&var) = %d\n", V_I4(&var));
1961 hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var);
1962 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1965 memset(&dp, 0, sizeof(dp));
1966 memset(&ei, 0, sizeof(ei));
1967 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1968 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1969 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1970 ok(V_I4(&var) == 200, "V_I4(&var) = %d\n", V_I4(&var));
1972 memset(&dp, 0, sizeof(dp));
1973 memset(&ei, 0, sizeof(ei));
1978 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
1979 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1982 memset(&dp, 0, sizeof(dp));
1983 memset(&ei, 0, sizeof(ei));
1984 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1985 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1986 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
1987 ok(V_I4(&var) == 300, "V_I4(&var) = %d\n", V_I4(&var));
1989 V_VT(&var) = VT_BSTR;
1990 V_BSTR(&var) = NULL;
1991 dispex_propput(document, id, 0,&var);
1994 memset(&dp, 0, sizeof(dp));
1995 memset(&ei, 0, sizeof(ei));
1996 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
1997 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1998 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1999 ok(!V_BSTR(&var), "V_BSTR(&var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
2001 unk = (void*)0xdeadbeef;
2002 hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
2003 ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
2004 ok(!unk, "unk=%p, expected NULL\n", unk);
2007 tmp = SysAllocString(funcW);
2008 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2010 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
2011 ok(id, "id == 0\n");
2016 dp.rgdispidNamedArgs = NULL;
2017 V_VT(&var) = VT_DISPATCH;
2018 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
2019 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2020 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2023 memset(&dp, 0, sizeof(dp));
2024 memset(&ei, 0, sizeof(ei));
2025 V_VT(&arg) = VT_BOOL;
2026 V_BOOL(&arg) = VARIANT_TRUE;
2030 SET_EXPECT(funcDisp);
2031 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
2032 CHECK_CALLED(funcDisp);
2034 ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
2035 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2036 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
2038 IDispatchEx_Release(document);
2040 hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
2041 ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
2043 hres = IHTMLWindow2_get_navigator(window, &navigator);
2044 IHTMLWindow2_Release(window);
2045 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2047 hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
2048 IOmNavigator_Release(navigator);
2049 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2052 test_nextdispid(dispex);
2054 tmp = a2bstr("test");
2055 hres = IDispatchEx_DeleteMemberByName(dispex, tmp, fdexNameCaseSensitive);
2056 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2058 IDispatchEx_Release(dispex);
2060 script_disp = (IDispatch*)&scriptDisp;
2062 SET_EXPECT(GetScriptDispatch);
2063 SET_EXPECT(script_testprop_d);
2064 tmp = a2bstr("testProp");
2065 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2066 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2067 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2068 CHECK_CALLED(GetScriptDispatch);
2069 CHECK_CALLED(script_testprop_d);
2072 tmp = a2bstr("testProp");
2073 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2074 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2075 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2078 SET_EXPECT(GetScriptDispatch);
2079 SET_EXPECT(script_testprop_i);
2080 memset(&ei, 0, sizeof(ei));
2081 memset(&dp, 0, sizeof(dp));
2082 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
2083 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2084 ok(V_VT(&var) == VT_NULL, "V_VT(var) = %d\n", V_VT(&var));
2085 CHECK_CALLED(GetScriptDispatch);
2086 CHECK_CALLED(script_testprop_i);
2088 SET_EXPECT(GetScriptDispatch);
2089 SET_EXPECT(script_testprop2_d);
2090 tmp = a2bstr("testProp2");
2091 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2092 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2093 ok(id != DISPID_SCRIPT_TESTPROP2, "id == DISPID_SCRIPT_TESTPROP2\n");
2094 CHECK_CALLED(GetScriptDispatch);
2095 CHECK_CALLED(script_testprop2_d);
2098 tmp = a2bstr("test");
2099 hres = IDispatchEx_DeleteMemberByName(window_dispex, tmp, fdexNameCaseSensitive);
2100 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2107 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
2108 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
2109 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
2110 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
2112 ok(!punkContext, "punkContext = %p\n", punkContext);
2113 ok(pvarResult != NULL, "pvarResult == NULL\n");
2114 ok(pexcepinfo != NULL, "pexcepinfo == NULL\n");
2116 if(!strcmp_wa(pstrCode, "execScript call")) {
2117 CHECK_EXPECT(ParseScriptText_execScript);
2118 ok(!pstrItemName, "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2119 ok(!strcmp_wa(pstrDelimiter, "\""), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2120 ok(dwFlags == SCRIPTTEXT_ISVISIBLE, "dwFlags = %x\n", dwFlags);
2122 V_VT(pvarResult) = VT_I4;
2123 V_I4(pvarResult) = 10;
2125 }else if(!strcmp_wa(pstrCode, "simple script")) {
2126 CHECK_EXPECT(ParseScriptText_script);
2127 ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2128 ok(!strcmp_wa(pstrDelimiter, "</SCRIPT>"), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2129 ok(dwFlags == (SCRIPTTEXT_ISVISIBLE|SCRIPTTEXT_HOSTMANAGESSOURCE), "dwFlags = %x\n", dwFlags);
2135 ok(0, "unexpected script %s\n", wine_dbgstr_w(pstrCode));
2139 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
2140 ActiveScriptParse_QueryInterface,
2141 ActiveScriptParse_AddRef,
2142 ActiveScriptParse_Release,
2143 ActiveScriptParse_InitNew,
2144 ActiveScriptParse_AddScriptlet,
2145 ActiveScriptParse_ParseScriptText
2148 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
2150 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
2154 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
2159 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
2160 *ppv = &ActiveScriptParse;
2164 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
2165 *ppv = &ActiveScriptParseProcedure;
2169 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
2170 *ppv = &ActiveScriptProperty;
2174 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2175 *ppv = &ObjectSafety;
2179 if(IsEqualGUID(&IID_IActiveScriptDebug, riid))
2180 return E_NOINTERFACE;
2182 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2183 return E_NOINTERFACE;
2186 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
2191 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
2196 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
2198 IActiveScriptSiteInterruptPoll *poll;
2199 IActiveScriptSiteDebug *debug;
2200 IServiceProvider *service;
2201 ICanHandleException *canexpection;
2205 CHECK_EXPECT(SetScriptSite);
2207 ok(pass != NULL, "pass == NULL\n");
2209 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
2210 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
2212 IActiveScriptSiteInterruptPoll_Release(poll);
2214 hres = IActiveScriptSite_GetLCID(pass, &lcid);
2215 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
2217 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
2218 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2220 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
2221 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
2223 IActiveScriptSiteDebug32_Release(debug);
2225 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexpection);
2226 ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
2228 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
2229 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2231 IServiceProvider_Release(service);
2234 IActiveScriptSite_AddRef(site);
2238 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
2241 ok(0, "unexpected call\n");
2245 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
2250 case SCRIPTSTATE_STARTED:
2251 CHECK_EXPECT(SetScriptState_STARTED);
2253 case SCRIPTSTATE_CONNECTED:
2254 CHECK_EXPECT(SetScriptState_CONNECTED);
2256 case SCRIPTSTATE_DISCONNECTED:
2257 CHECK_EXPECT(SetScriptState_DISCONNECTED);
2260 ok(0, "unexpected state %d\n", ss);
2264 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
2265 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2270 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
2272 CHECK_EXPECT(GetScriptState);
2278 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
2280 CHECK_EXPECT(Close);
2284 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
2285 LPCOLESTR pstrName, DWORD dwFlags)
2288 IUnknown *unk = NULL, *unk2;
2291 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
2293 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
2295 CHECK_EXPECT(AddNamedItem);
2297 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
2298 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
2300 hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
2301 ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
2302 ok(unk != NULL, "unk == NULL\n");
2304 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
2305 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
2307 IDispatch_Release(disp);
2309 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
2310 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
2312 IUnknown_Release(unk2);
2314 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
2315 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
2317 IUnknown_Release(unk);
2321 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
2322 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
2324 ok(0, "unexpected call\n");
2328 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
2331 CHECK_EXPECT(GetScriptDispatch);
2333 ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2338 *ppdisp = script_disp;
2342 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
2343 SCRIPTTHREADID *pstridThread)
2345 ok(0, "unexpected call\n");
2349 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
2350 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
2352 ok(0, "unexpected call\n");
2356 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
2357 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
2359 ok(0, "unexpected call\n");
2363 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
2364 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
2366 ok(0, "unexpected call\n");
2370 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
2372 ok(0, "unexpected call\n");
2376 static const IActiveScriptVtbl ActiveScriptVtbl = {
2377 ActiveScript_QueryInterface,
2378 ActiveScript_AddRef,
2379 ActiveScript_Release,
2380 ActiveScript_SetScriptSite,
2381 ActiveScript_GetScriptSite,
2382 ActiveScript_SetScriptState,
2383 ActiveScript_GetScriptState,
2385 ActiveScript_AddNamedItem,
2386 ActiveScript_AddTypeLib,
2387 ActiveScript_GetScriptDispatch,
2388 ActiveScript_GetCurrentScriptThreadID,
2389 ActiveScript_GetScriptThreadID,
2390 ActiveScript_GetScriptThreadState,
2391 ActiveScript_InterruptScriptThread,
2395 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
2397 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2401 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2406 if(IsEqualGUID(&IID_IMarshal, riid))
2407 return E_NOINTERFACE;
2408 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
2409 return E_NOINTERFACE;
2411 ok(0, "unexpected riid %s\n", debugstr_guid(riid));
2415 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2420 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2425 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2427 CHECK_EXPECT(CreateInstance);
2429 ok(!outer, "outer = %p\n", outer);
2430 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", debugstr_guid(riid));
2431 *ppv = &ActiveScript;
2435 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2437 ok(0, "unexpected call\n");
2441 static const IClassFactoryVtbl ClassFactoryVtbl = {
2442 ClassFactory_QueryInterface,
2443 ClassFactory_AddRef,
2444 ClassFactory_Release,
2445 ClassFactory_CreateInstance,
2446 ClassFactory_LockServer
2449 static IClassFactory script_cf = { &ClassFactoryVtbl };
2451 static const char simple_script_str[] =
2452 "<html><head></head><body>"
2453 "<div id=\"divid\"></div>"
2454 "<script language=\"TestScript\">simple script</script>"
2457 static void test_exec_script(IHTMLDocument2 *doc)
2459 IHTMLWindow2 *window;
2464 hres = IHTMLDocument2_get_parentWindow(doc, &window);
2465 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
2467 code = a2bstr("execScript call");
2468 lang = a2bstr("TestScript");
2470 SET_EXPECT(ParseScriptText_execScript);
2471 hres = IHTMLWindow2_execScript(window, code, lang, &v);
2472 ok(hres == S_OK, "execScript failed: %08x\n", hres);
2473 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
2474 ok(V_I4(&v) == 10, "V_I4(v) = %d\n", V_I4(&v));
2475 CHECK_CALLED(ParseScriptText_execScript);
2476 SysFreeString(lang);
2478 lang = a2bstr("invalid");
2480 hres = IHTMLWindow2_execScript(window, code, lang, &v);
2481 ok(hres == CO_E_CLASSSTRING, "execScript failed: %08x, expected CO_E_CLASSSTRING\n", hres);
2482 ok(V_VT(&v) == 100, "V_VT(v) = %d\n", V_VT(&v));
2483 SysFreeString(lang);
2484 SysFreeString(code);
2486 IHTMLWindow2_Release(window);
2489 static void test_simple_script(void)
2491 IHTMLDocument2 *doc;
2493 doc = create_document();
2497 SET_EXPECT(CreateInstance);
2498 SET_EXPECT(GetInterfaceSafetyOptions);
2499 SET_EXPECT(SetInterfaceSafetyOptions);
2500 SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
2501 SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
2502 SET_EXPECT(InitNew);
2503 SET_EXPECT(SetScriptSite);
2504 SET_EXPECT(GetScriptState);
2505 SET_EXPECT(SetScriptState_STARTED);
2506 SET_EXPECT(AddNamedItem);
2507 SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
2508 SET_EXPECT(ParseScriptText_script);
2509 SET_EXPECT(SetScriptState_CONNECTED);
2511 load_doc(doc, simple_script_str);
2513 CHECK_CALLED(CreateInstance);
2514 CHECK_CALLED(GetInterfaceSafetyOptions);
2515 CHECK_CALLED(SetInterfaceSafetyOptions);
2516 CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
2517 CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
2518 CHECK_CALLED(InitNew);
2519 CHECK_CALLED(SetScriptSite);
2520 CHECK_CALLED(GetScriptState);
2521 CHECK_CALLED(SetScriptState_STARTED);
2522 CHECK_CALLED(AddNamedItem);
2523 CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION); /* IE8 */
2524 CHECK_CALLED(ParseScriptText_script);
2525 CHECK_CALLED(SetScriptState_CONNECTED);
2527 test_exec_script(doc);
2530 IActiveScriptSite_Release(site);
2532 IDispatchEx_Release(window_dispex);
2534 SET_EXPECT(SetScriptState_DISCONNECTED);
2537 IHTMLDocument2_Release(doc);
2539 CHECK_CALLED(SetScriptState_DISCONNECTED);
2540 CHECK_CALLED(Close);
2543 static void run_js_script(const char *test_name)
2545 WCHAR url[INTERNET_MAX_URL_LENGTH];
2546 char urlA[INTERNET_MAX_URL_LENGTH];
2547 IPersistMoniker *persist;
2548 IHTMLDocument2 *doc;
2553 static const char res[] = "res://";
2555 trace("running %s...\n", test_name);
2557 doc = create_document();
2561 set_client_site(doc, TRUE);
2562 do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
2564 lstrcpyA(urlA, res);
2565 GetModuleFileNameA(NULL, urlA + lstrlenA(res), sizeof(urlA) - lstrlenA(res));
2566 lstrcatA(urlA, "/");
2567 lstrcatA(urlA, test_name);
2568 MultiByteToWideChar(CP_ACP, 0, urlA, -1, url, sizeof(url)/sizeof(WCHAR));
2570 hres = CreateURLMoniker(NULL, url, &mon);
2571 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2573 hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker, (void**)&persist);
2574 ok(hres == S_OK, "Could not get IPersistMoniker iface: %08x\n", hres);
2576 hres = IPersistMoniker_Load(persist, FALSE, mon, NULL, 0);
2577 ok(hres == S_OK, "Load failed: %08x\n", hres);
2579 IMoniker_Release(mon);
2580 IPersistMoniker_Release(persist);
2582 SET_EXPECT(external_success);
2584 while(!called_external_success && GetMessage(&msg, NULL, 0, 0)) {
2585 TranslateMessage(&msg);
2586 DispatchMessage(&msg);
2589 CHECK_CALLED(external_success);
2591 set_client_site(doc, FALSE);
2592 IHTMLDocument2_Release(doc);
2595 static void run_js_tests(void)
2597 run_js_script("jstest.html");
2598 run_js_script("exectest.html");
2601 static BOOL init_registry(BOOL init)
2603 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
2604 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
2606 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
2610 static BOOL register_script_engine(void)
2615 if(!init_registry(TRUE)) {
2616 init_registry(FALSE);
2620 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
2621 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
2622 ok(hres == S_OK, "Could not register screipt engine: %08x\n", hres);
2627 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2629 return DefWindowProc(hwnd, msg, wParam, lParam);
2632 static HWND create_container_window(void)
2634 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
2635 static WNDCLASSEXA wndclass = {
2636 sizeof(WNDCLASSEXA),
2639 0, 0, NULL, NULL, NULL, NULL, NULL,
2644 RegisterClassExA(&wndclass);
2645 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
2646 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
2647 300, 300, NULL, NULL, NULL, NULL);
2653 container_hwnd = create_container_window();
2655 if(winetest_interactive || ! is_ie_hardened()) {
2656 if(register_script_engine()) {
2657 test_simple_script();
2659 init_registry(FALSE);
2661 skip("Could not register TestScript engine\n");
2664 skip("IE running in Enhanced Security Configuration\n");
2667 DestroyWindow(container_hwnd);