Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / mshtml / tests / script.c
blob0457029bc9bf06d4a9e70f0617f1681b6a576de7
1 /*
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
19 #define COBJMACROS
20 #define CONST_VTABLE
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "wininet.h"
30 #include "docobj.h"
31 #include "dispex.h"
32 #include "hlink.h"
33 #include "mshtml.h"
34 #include "mshtmhst.h"
35 #include "initguid.h"
36 #include "activscp.h"
37 #include "activdbg.h"
38 #include "objsafe.h"
39 #include "mshtmdid.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}};
48 #ifdef _WIN64
50 #define CTXARG_T DWORDLONG
51 #define IActiveScriptParseVtbl IActiveScriptParse64Vtbl
52 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_64Vtbl
54 #else
56 #define CTXARG_T DWORD
57 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
58 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
60 #endif
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) \
69 do { \
70 ok(expect_ ##func, "unexpected call " #func "\n"); \
71 called_ ## func = TRUE; \
72 }while(0)
74 #define CHECK_EXPECT(func) \
75 do { \
76 CHECK_EXPECT2(func); \
77 expect_ ## func = FALSE; \
78 }while(0)
80 #define CHECK_CALLED(func) \
81 do { \
82 ok(called_ ## func, "expected " #func "\n"); \
83 expect_ ## func = called_ ## func = FALSE; \
84 }while(0)
86 #define CHECK_CALLED_BROKEN(func) \
87 do { \
88 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
89 expect_ ## func = called_ ## func = FALSE; \
90 }while(0)
92 #define CHECK_NOT_CALLED(func) \
93 do { \
94 ok(!called_ ## func, "unexpected " #func "\n"); \
95 expect_ ## func = called_ ## func = FALSE; \
96 }while(0)
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)
164 static char buf[50];
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]);
171 return buf;
174 static int strcmp_wa(LPCWSTR strw, const char *stra)
176 CHAR buf[512];
177 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
178 return lstrcmpA(stra, buf);
181 static BSTR a2bstr(const char *str)
183 BSTR ret;
184 int len;
186 if(!str)
187 return NULL;
189 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
190 ret = SysAllocStringLen(NULL, len);
191 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
193 return ret;
196 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
198 HKEY hkey;
199 DWORD res;
201 if(!init) {
202 RegDeleteKey(HKEY_CLASSES_ROOT, key_name);
203 return TRUE;
206 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
207 if(res != ERROR_SUCCESS)
208 return FALSE;
210 if(def_value)
211 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
213 RegCloseKey(hkey);
215 return res == ERROR_SUCCESS;
218 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
219 REFIID riid, void**ppv)
221 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
222 *ppv = iface;
223 return S_OK;
226 return E_NOINTERFACE;
229 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
231 return 2;
234 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
236 return 1;
239 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
241 if(dispID == DISPID_READYSTATE){
242 BSTR state;
243 HRESULT hres;
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))
251 doc_complete = TRUE;
253 SysFreeString(state);
256 return S_OK;
259 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
261 ok(0, "unexpected call\n");
262 return E_NOTIMPL;
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));
278 *ppv = NULL;
279 return E_NOINTERFACE;
282 static ULONG WINAPI VariantChangeType_AddRef(IVariantChangeType *iface)
284 return 2;
287 static ULONG WINAPI VariantChangeType_Release(IVariantChangeType *iface)
289 return 1;
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);
304 V_VT(dst) = VT_BSTR;
305 V_BSTR(dst) = a2bstr("red");
306 return S_OK;
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)
326 return 2;
329 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
331 return 1;
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));
340 *ppv = &VChangeType;
341 return S_OK;
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)
359 *ppv = NULL;
361 if(IsEqualGUID(riid, &IID_IUnknown)
362 || IsEqualGUID(riid, &IID_IDispatch)
363 || IsEqualGUID(riid, &IID_IDispatchEx))
364 *ppv = iface;
365 else
366 return E_NOINTERFACE;
368 return S_OK;
371 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
373 return 2;
376 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
378 return 1;
381 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
383 ok(0, "unexpected call\n");
384 return E_NOTIMPL;
387 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
388 LCID lcid, ITypeInfo **ppTInfo)
390 ok(0, "unexpected call\n");
391 return E_NOTIMPL;
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");
399 return E_NOTIMPL;
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");
407 return E_NOTIMPL;
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);
413 return E_NOTIMPL;
416 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
418 ok(0, "unexpected call\n");
419 return E_NOTIMPL;
422 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
424 ok(0, "unexpected call\n");
425 return E_NOTIMPL;
428 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
430 ok(0, "unexpected call\n");
431 return E_NOTIMPL;
434 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
436 ok(0, "unexpected call\n");
437 return E_NOTIMPL;
440 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
442 ok(0, "unexpected call\n");
443 return E_NOTIMPL;
446 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
448 ok(0, "unexpected call\n");
449 return E_NOTIMPL;
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;
472 V_I4(pvarRes) = 100;
473 return S_OK;
476 static IDispatchExVtbl testObjVtbl = {
477 DispatchEx_QueryInterface,
478 DispatchEx_AddRef,
479 DispatchEx_Release,
480 DispatchEx_GetTypeInfoCount,
481 DispatchEx_GetTypeInfo,
482 DispatchEx_GetIDsOfNames,
483 DispatchEx_Invoke,
484 DispatchEx_GetDispID,
485 funcDisp_InvokeEx,
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;
502 return S_OK;
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;
509 return S_OK;
512 if(!strcmp_wa(bstrName, "divid")) {
513 CHECK_EXPECT(script_divid_d);
514 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
515 return E_FAIL;
518 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
519 return E_NOTIMPL;
522 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
523 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
525 switch(id) {
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;
541 break;
542 default:
543 ok(0, "unexpected call\n");
544 return E_NOTIMPL;
547 return S_OK;
550 static IDispatchExVtbl scriptDispVtbl = {
551 DispatchEx_QueryInterface,
552 DispatchEx_AddRef,
553 DispatchEx_Release,
554 DispatchEx_GetTypeInfoCount,
555 DispatchEx_GetTypeInfo,
556 DispatchEx_GetIDsOfNames,
557 DispatchEx_Invoke,
558 scriptDisp_GetDispID,
559 scriptDisp_InvokeEx,
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;
574 return S_OK;
576 if(!strcmp_wa(bstrName, "trace")) {
577 *pid = DISPID_EXTERNAL_TRACE;
578 return S_OK;
580 if(!strcmp_wa(bstrName, "reportSuccess")) {
581 *pid = DISPID_EXTERNAL_REPORTSUCCESS;
582 return S_OK;
584 if(!strcmp_wa(bstrName, "todo_wine_ok")) {
585 *pid = DISPID_EXTERNAL_TODO_WINE_OK;
586 return S_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)
596 switch(id) {
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)));
610 return S_OK;
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)));
626 return S_OK;
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");
639 return S_OK;
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));
652 todo_wine
653 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
655 return S_OK;
657 default:
658 ok(0, "unexpected call\n");
659 return E_NOTIMPL;
662 return S_OK;
665 static IDispatchExVtbl externalDispVtbl = {
666 DispatchEx_QueryInterface,
667 DispatchEx_AddRef,
668 DispatchEx_Release,
669 DispatchEx_GetTypeInfoCount,
670 DispatchEx_GetTypeInfo,
671 DispatchEx_GetIDsOfNames,
672 DispatchEx_Invoke,
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)
694 return 2;
697 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
699 return 1;
702 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
703 IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
705 return E_NOTIMPL;
708 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
710 return E_NOTIMPL;
713 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
714 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
715 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
717 return S_OK;
720 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
722 return S_OK;
725 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
727 return S_OK;
730 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
732 return E_NOTIMPL;
735 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
737 return E_NOTIMPL;
740 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
742 return S_OK;
745 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
746 IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
748 return E_NOTIMPL;
751 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
752 const GUID *pguidCmdGroup, DWORD nCmdID)
754 return E_NOTIMPL;
757 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
758 LPOLESTR *pchKey, DWORD dw)
760 return S_OK;
763 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
764 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
766 return E_NOTIMPL;
769 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
771 *ppDispatch = (IDispatch*)&externalDisp;
772 return S_OK;
775 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
776 OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
778 return S_FALSE;
781 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
782 IDataObject **ppPORet)
784 return E_NOTIMPL;
787 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
788 LPOLESTR *pchKey, DWORD dw)
790 return E_NOTIMPL;
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)
824 return 2;
827 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
829 return 1;
832 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
834 return E_NOTIMPL;
837 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
839 return E_NOTIMPL;
842 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
844 return E_NOTIMPL;
847 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
848 LPCBORDERWIDTHS pborderwidths)
850 return E_NOTIMPL;
853 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
854 LPCBORDERWIDTHS pborderwidths)
856 return S_OK;
859 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
860 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
862 return S_OK;
865 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
866 LPOLEMENUGROUPWIDTHS lpMenuWidths)
868 return E_NOTIMPL;
871 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
872 HOLEMENU holemenu, HWND hwndActiveObject)
874 ok(0, "unexpected call\n");
875 return E_NOTIMPL;
878 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
880 ok(0, "unexpected call\n");
881 return E_NOTIMPL;
884 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
886 return S_OK;
889 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
891 return E_NOTIMPL;
894 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
896 ok(0, "unexpected call\n");
897 return E_NOTIMPL;
900 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
901 InPlaceFrame_QueryInterface,
902 InPlaceFrame_AddRef,
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)
927 return 2;
930 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
932 return 1;
935 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
937 *phwnd = container_hwnd;
938 return S_OK;
941 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
943 ok(0, "unexpected call\n");
944 return E_NOTIMPL;
947 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
949 return S_OK;
952 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
954 return S_OK;
957 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
959 return S_OK;
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;
970 *lprcPosRect = rect;
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;
979 return S_OK;
982 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
984 return E_NOTIMPL;
987 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
989 return S_OK;
992 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
994 return S_OK;
997 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
999 return E_NOTIMPL;
1002 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
1004 return E_NOTIMPL;
1007 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1009 return E_NOTIMPL;
1012 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
1013 InPlaceSite_QueryInterface,
1014 InPlaceSite_AddRef,
1015 InPlaceSite_Release,
1016 InPlaceSite_GetWindow,
1017 InPlaceSite_ContextSensitiveHelp,
1018 InPlaceSite_CanInPlaceActivate,
1019 InPlaceSite_OnInPlaceActivate,
1020 InPlaceSite_OnUIActivate,
1021 InPlaceSite_GetWindowContext,
1022 InPlaceSite_Scroll,
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)
1039 return 2;
1042 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1044 return 1;
1047 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1049 ok(0, "unexpected call\n");
1050 return E_NOTIMPL;
1053 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1054 IMoniker **ppmon)
1056 ok(0, "unexpected call\n");
1057 return E_NOTIMPL;
1060 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1062 return E_NOTIMPL;
1065 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1067 ok(0, "unexpected call\n");
1068 return E_NOTIMPL;
1071 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1073 ok(0, "unexpected call\n");
1074 return E_NOTIMPL;
1077 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1079 ok(0, "unexpected call\n");
1080 return E_NOTIMPL;
1083 static const IOleClientSiteVtbl ClientSiteVtbl = {
1084 ClientSite_QueryInterface,
1085 ClientSite_AddRef,
1086 ClientSite_Release,
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)
1104 return 2;
1107 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1109 return 1;
1112 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1114 RECT rect = {0,0,300,300};
1115 IOleDocument *document;
1116 HRESULT hres;
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);
1137 return S_OK;
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)
1151 *ppv = NULL;
1153 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1154 *ppv = &ClientSite;
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;
1169 HRESULT hres;
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);
1177 if(FAILED(hres)) {
1178 win_skip("Could not get IHTMLDocument5, probably too old IE\n");
1179 IHTMLDocument2_Release(doc);
1180 return NULL;
1183 IHTMLDocument5_Release(doc5);
1184 return doc;
1187 static void load_string(IHTMLDocument2 *doc, const char *str)
1189 IPersistStreamInit *init;
1190 IStream *stream;
1191 HGLOBAL mem;
1192 SIZE_T len;
1194 doc_complete = FALSE;
1195 len = strlen(str);
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;
1211 DWORD cookie;
1212 HRESULT hres;
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);
1221 notif_doc = doc;
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)
1230 IOleObject *oleobj;
1231 HRESULT hres;
1233 if(!set && view) {
1234 IOleDocumentView_Show(view, FALSE);
1235 IOleDocumentView_CloseView(view, 0);
1236 IOleDocumentView_SetInPlaceSite(view, NULL);
1237 IOleDocumentView_Release(view);
1238 view = NULL;
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);
1247 if(set) {
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;
1267 MSG msg;
1268 HRESULT hres;
1269 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
1270 DISPID dispID = -1;
1271 OLECHAR *name;
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)
1298 *ppv = NULL;
1299 ok(0, "unexpected call %s\n", debugstr_guid(riid));
1300 return E_NOINTERFACE;
1303 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
1305 return 2;
1308 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
1310 return 1;
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;
1325 return S_OK;
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);
1340 return S_OK;
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)
1355 *ppv = NULL;
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);
1364 if(!ax_objsafe)
1365 return E_NOINTERFACE;
1366 *ppv = iface;
1367 return S_OK;
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);
1398 break;
1399 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1400 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1401 break;
1402 default:
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)) {
1411 HRESULT hres;
1413 switch(dwEnabledOptions) {
1414 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1415 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1416 hres = ax_setopt_disp_caller_hres;
1417 break;
1418 case INTERFACESAFE_FOR_UNTRUSTED_DATA:
1419 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1420 hres = ax_setopt_disp_data_hres;
1421 break;
1422 default:
1423 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1424 hres = E_FAIL;
1426 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1427 return hres;
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}",
1447 NULL, safe_call)
1448 && init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95802-9882-11cf-9fa9-00aa006c42c4}",
1449 NULL, safe_data);
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;
1464 DWORD policy_size;
1465 BYTE *ppolicy;
1466 HRESULT hres;
1468 cs.clsid = CLSID_TestActiveX;
1469 cs.pUnk = (IUnknown*)&AXObjectSafety;
1471 cs.dwFlags = 0;
1472 ax_objsafe = FALSE;
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);
1481 ax_objsafe = TRUE;
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)
1495 return;
1497 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1498 ax_objsafe = FALSE;
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);
1507 ax_objsafe = TRUE;
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;
1529 BYTE *ppolicy;
1530 HRESULT hres;
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;
1547 cs.dwFlags = 0;
1549 ax_objsafe = TRUE;
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);
1576 }else {
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);
1583 cs.dwFlags = 0;
1584 ax_objsafe = FALSE;
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;
1595 ax_objsafe = FALSE;
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);
1615 }else {
1616 skip("Could not set safety registry\n");
1619 ax_objsafe = TRUE;
1621 cs.dwFlags = 0;
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);
1672 cs.dwFlags = 0;
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)
1718 *ppv = NULL;
1719 ok(0, "unexpected call\n");
1720 return E_NOINTERFACE;
1723 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
1725 return 2;
1728 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
1730 return 1;
1733 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1734 VARIANT *pvarIndex, VARIANT *pvarValue)
1736 ok(0, "unexpected call\n");
1737 return E_NOTIMPL;
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));
1748 break;
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));
1753 break;
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));
1758 break;
1759 default:
1760 ok(0, "unexpected property %x\n", dwProperty);
1761 return E_NOTIMPL;
1764 ok(!pvarIndex, "pvarIndex != NULL\n");
1765 ok(pvarValue != NULL, "pvarValue == NULL\n");
1767 return S_OK;
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)
1782 *ppv = NULL;
1783 ok(0, "unexpected call\n");
1784 return E_NOINTERFACE;
1787 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
1789 return 2;
1792 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
1794 return 1;
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");
1803 return E_NOTIMPL;
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)
1817 *ppv = NULL;
1818 ok(0, "unexpected call\n");
1819 return E_NOINTERFACE;
1822 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
1824 return 2;
1827 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
1829 return 1;
1832 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
1834 CHECK_EXPECT(InitNew);
1835 return S_OK;
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");
1845 return E_NOTIMPL;
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};
1852 EXCEPINFO ei = {0};
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};
1860 EXCEPINFO ei = {0};
1862 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, res, &ei, caller_sp);
1865 static void test_func(IDispatchEx *obj)
1867 DISPID id;
1868 IDispatchEx *dispex;
1869 IDispatch *disp;
1870 EXCEPINFO ei;
1871 DISPPARAMS dp;
1872 BSTR str;
1873 VARIANT var;
1874 HRESULT hres;
1876 str = a2bstr("toString");
1877 hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
1878 SysFreeString(str);
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));
1884 VariantInit(&var);
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));
1899 VariantInit(&var);
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)));
1905 VariantClear(&var);
1908 V_VT(&var) = VT_I4;
1909 V_I4(&var) = 100;
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;
1919 BSTR name;
1920 VARIANT var;
1921 HRESULT hres;
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);
1941 if(id == dyn_id)
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);
1947 last_id = id;
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)
1957 VARIANT var;
1958 DISPPARAMS dp;
1959 EXCEPINFO ei;
1960 BSTR tmp;
1961 DISPID id;
1962 HRESULT hres;
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);
1969 SysFreeString(tmp);
1970 CHECK_CALLED(GetScriptDispatch);
1971 CHECK_CALLED(script_divid_d);
1973 VariantInit(&var);
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));
1979 VariantClear(&var);
1982 static void test_arg_conv(IHTMLWindow2 *window)
1984 IHTMLDocument2 *doc;
1985 IDispatchEx *dispex;
1986 IHTMLElement *elem;
1987 VARIANT v;
1988 HRESULT hres;
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);
2003 V_VT(&v) = VT_I4;
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;
2024 IUnknown *unk;
2025 VARIANT var, arg;
2026 DISPPARAMS dp;
2027 EXCEPINFO ei;
2028 DISPID id;
2029 BSTR tmp;
2030 HRESULT hres;
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);
2040 SysFreeString(tmp);
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);
2046 VariantInit(&var);
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);
2056 VariantClear(&var);
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);
2064 SysFreeString(tmp);
2066 id = 0;
2067 tmp = SysAllocString(testW);
2068 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2069 SysFreeString(tmp);
2070 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2071 ok(id, "id == 0\n");
2073 V_VT(&var) = VT_I4;
2074 V_I4(&var) = 100;
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);
2080 SysFreeString(tmp);
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);
2086 VariantInit(&var);
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));
2094 V_VT(&var) = VT_I4;
2095 V_I4(&var) = 200;
2096 hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var, NULL);
2097 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2099 VariantInit(&var);
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));
2109 V_VT(&var) = VT_I4;
2110 V_I4(&var) = 300;
2111 dp.cArgs = 1;
2112 dp.rgvarg = &var;
2113 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2114 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2116 VariantInit(&var);
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);
2128 VariantInit(&var);
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);
2141 id = 0;
2142 tmp = SysAllocString(funcW);
2143 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2144 SysFreeString(tmp);
2145 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
2146 ok(id, "id == 0\n");
2148 dp.cArgs = 1;
2149 dp.rgvarg = &var;
2150 dp.cNamedArgs = 0;
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);
2157 VariantInit(&var);
2158 memset(&dp, 0, sizeof(dp));
2159 memset(&ei, 0, sizeof(ei));
2160 V_VT(&arg) = VT_BOOL;
2161 V_BOOL(&arg) = VARIANT_TRUE;
2162 dp.cArgs = 1;
2163 dp.rgvarg = &arg;
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);
2185 test_func(dispex);
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);
2207 SysFreeString(tmp);
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");
2213 SysFreeString(tmp);
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);
2233 SysFreeString(tmp);
2235 tmp = a2bstr("test");
2236 hres = IDispatchEx_DeleteMemberByName(window_dispex, tmp, fdexNameCaseSensitive);
2237 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2239 test_global_id();
2241 test_security();
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;
2260 return S_OK;
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);
2267 test_script_run();
2268 return S_OK;
2271 ok(0, "unexpected script %s\n", wine_dbgstr_w(pstrCode));
2272 return E_FAIL;
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)
2288 *ppv = NULL;
2290 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
2291 *ppv = iface;
2292 return S_OK;
2295 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
2296 *ppv = &ActiveScriptParse;
2297 return S_OK;
2300 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
2301 *ppv = &ActiveScriptParseProcedure;
2302 return S_OK;
2305 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
2306 *ppv = &ActiveScriptProperty;
2307 return S_OK;
2310 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2311 *ppv = &ObjectSafety;
2312 return S_OK;
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)
2324 return 2;
2327 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
2329 return 1;
2332 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
2334 IActiveScriptSiteInterruptPoll *poll;
2335 IActiveScriptSiteDebug *debug;
2336 IServiceProvider *service;
2337 ICanHandleException *canexpection;
2338 LCID lcid;
2339 HRESULT hres;
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);
2347 if(FAILED(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);
2358 if(SUCCEEDED(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);
2366 if(SUCCEEDED(hres))
2367 IServiceProvider_Release(service);
2369 site = pass;
2370 IActiveScriptSite_AddRef(site);
2371 return S_OK;
2374 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
2375 void **ppvObject)
2377 ok(0, "unexpected call\n");
2378 return E_NOTIMPL;
2381 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
2383 HRESULT hres;
2385 switch(ss) {
2386 case SCRIPTSTATE_STARTED:
2387 CHECK_EXPECT(SetScriptState_STARTED);
2388 break;
2389 case SCRIPTSTATE_CONNECTED:
2390 CHECK_EXPECT(SetScriptState_CONNECTED);
2391 break;
2392 case SCRIPTSTATE_DISCONNECTED:
2393 CHECK_EXPECT(SetScriptState_DISCONNECTED);
2394 break;
2395 default:
2396 ok(0, "unexpected state %d\n", ss);
2397 return E_NOTIMPL;
2400 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
2401 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2403 return S_OK;
2406 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
2408 CHECK_EXPECT(GetScriptState);
2410 *pssState = state;
2411 return S_OK;
2414 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
2416 CHECK_EXPECT(Close);
2417 return E_NOTIMPL;
2420 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
2421 LPCOLESTR pstrName, DWORD dwFlags)
2423 IDispatch *disp;
2424 IUnknown *unk = NULL, *unk2;
2425 HRESULT hres;
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);
2442 if(SUCCEEDED(hres))
2443 IDispatch_Release(disp);
2445 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
2446 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
2447 if(SUCCEEDED(hres))
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);
2454 return S_OK;
2457 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
2458 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
2460 ok(0, "unexpected call\n");
2461 return E_NOTIMPL;
2464 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
2465 IDispatch **ppdisp)
2467 CHECK_EXPECT(GetScriptDispatch);
2469 ok(!strcmp_wa(pstrItemName, "window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2471 if(!script_disp)
2472 return E_NOTIMPL;
2474 *ppdisp = script_disp;
2475 return S_OK;
2478 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
2479 SCRIPTTHREADID *pstridThread)
2481 ok(0, "unexpected call\n");
2482 return E_NOTIMPL;
2485 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
2486 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
2488 ok(0, "unexpected call\n");
2489 return E_NOTIMPL;
2492 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
2493 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
2495 ok(0, "unexpected call\n");
2496 return E_NOTIMPL;
2499 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
2500 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
2502 ok(0, "unexpected call\n");
2503 return E_NOTIMPL;
2506 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
2508 ok(0, "unexpected call\n");
2509 return E_NOTIMPL;
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,
2520 ActiveScript_Close,
2521 ActiveScript_AddNamedItem,
2522 ActiveScript_AddTypeLib,
2523 ActiveScript_GetScriptDispatch,
2524 ActiveScript_GetCurrentScriptThreadID,
2525 ActiveScript_GetScriptThreadID,
2526 ActiveScript_GetScriptThreadState,
2527 ActiveScript_InterruptScriptThread,
2528 ActiveScript_Clone
2531 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
2533 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2535 *ppv = NULL;
2537 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2538 *ppv = iface;
2539 return S_OK;
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));
2548 return E_NOTIMPL;
2551 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2553 return 2;
2556 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2558 return 1;
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;
2568 return S_OK;
2571 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2573 ok(0, "unexpected call\n");
2574 return S_OK;
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>"
2591 "</body></html>";
2593 static void test_exec_script(IHTMLDocument2 *doc, const char *codea, const char *langa)
2595 IHTMLWindow2 *window;
2596 BSTR code, lang;
2597 VARIANT v;
2598 HRESULT hres;
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");
2615 V_VT(&v) = 100;
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();
2630 if(!doc)
2631 return;
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");
2665 if(site)
2666 IActiveScriptSite_Release(site);
2667 if(window_dispex)
2668 IDispatchEx_Release(window_dispex);
2670 SET_EXPECT(SetScriptState_DISCONNECTED);
2671 SET_EXPECT(Close);
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;
2685 IMoniker *mon;
2686 MSG msg;
2687 HRESULT hres;
2689 static const char res[] = "res://";
2691 trace("running %s...\n", test_name);
2693 doc = create_document();
2694 if(!doc)
2695 return;
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}",
2741 NULL, init)
2742 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
2743 NULL, init);
2746 static BOOL register_script_engine(void)
2748 DWORD regid;
2749 HRESULT hres;
2751 if(!init_registry(TRUE)) {
2752 init_registry(FALSE);
2753 return FALSE;
2756 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
2757 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2758 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
2760 return TRUE;
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),
2774 wnd_proc,
2775 0, 0, NULL, NULL, NULL, NULL, NULL,
2776 szHTMLDocumentTest,
2777 NULL
2780 RegisterClassExA(&wndclass);
2781 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
2782 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
2783 300, 300, NULL, NULL, NULL, NULL);
2786 START_TEST(script)
2788 CoInitialize(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);
2795 }else {
2796 skip("Could not register TestScript engine\n");
2798 run_js_tests();
2799 }else {
2800 skip("IE running in Enhanced Security Configuration\n");
2803 DestroyWindow(container_hwnd);
2804 CoUninitialize();