wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / mshtml / tests / script.c
blob749ec21607b60a3f080bc5b77ec2b9a1198b5db2
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
53 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug64_Release
55 #else
57 #define CTXARG_T DWORD
58 #define IActiveScriptParseVtbl IActiveScriptParse32Vtbl
59 #define IActiveScriptParseProcedure2Vtbl IActiveScriptParseProcedure2_32Vtbl
60 #define IActiveScriptSiteDebug_Release IActiveScriptSiteDebug32_Release
62 #endif
64 #define DEFINE_EXPECT(func) \
65 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
67 #define SET_EXPECT(func) \
68 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
70 #define CHECK_EXPECT2(func) \
71 do { \
72 ok(expect_ ##func, "unexpected call " #func "\n"); \
73 called_ ## func = TRUE; \
74 }while(0)
76 #define CHECK_EXPECT(func) \
77 do { \
78 CHECK_EXPECT2(func); \
79 expect_ ## func = FALSE; \
80 }while(0)
82 #define CHECK_CALLED(func) \
83 do { \
84 ok(called_ ## func, "expected " #func "\n"); \
85 expect_ ## func = called_ ## func = FALSE; \
86 }while(0)
88 #define CHECK_CALLED_BROKEN(func) \
89 do { \
90 ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
91 expect_ ## func = called_ ## func = FALSE; \
92 }while(0)
94 #define CHECK_NOT_CALLED(func) \
95 do { \
96 ok(!called_ ## func, "unexpected " #func "\n"); \
97 expect_ ## func = called_ ## func = FALSE; \
98 }while(0)
100 #define CLEAR_CALLED(func) \
101 expect_ ## func = called_ ## func = FALSE
104 DEFINE_EXPECT(CreateInstance);
105 DEFINE_EXPECT(GetInterfaceSafetyOptions);
106 DEFINE_EXPECT(SetInterfaceSafetyOptions);
107 DEFINE_EXPECT(InitNew);
108 DEFINE_EXPECT(Close);
109 DEFINE_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
110 DEFINE_EXPECT(SetProperty_INVOKEVERSIONING);
111 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_FALSE);
112 DEFINE_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_TRUE);
113 DEFINE_EXPECT(SetScriptSite);
114 DEFINE_EXPECT(GetScriptState);
115 DEFINE_EXPECT(SetScriptState_STARTED);
116 DEFINE_EXPECT(SetScriptState_CONNECTED);
117 DEFINE_EXPECT(SetScriptState_DISCONNECTED);
118 DEFINE_EXPECT(AddNamedItem);
119 DEFINE_EXPECT(ParseScriptText_script);
120 DEFINE_EXPECT(ParseScriptText_execScript);
121 DEFINE_EXPECT(GetScriptDispatch);
122 DEFINE_EXPECT(funcDisp);
123 DEFINE_EXPECT(script_divid_d);
124 DEFINE_EXPECT(script_testprop_d);
125 DEFINE_EXPECT(script_testprop_i);
126 DEFINE_EXPECT(script_testprop2_d);
127 DEFINE_EXPECT(AXQueryInterface_IActiveScript);
128 DEFINE_EXPECT(AXQueryInterface_IObjectSafety);
129 DEFINE_EXPECT(AXGetInterfaceSafetyOptions);
130 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
131 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
132 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
133 DEFINE_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
134 DEFINE_EXPECT(external_success);
135 DEFINE_EXPECT(QS_VariantConversion);
136 DEFINE_EXPECT(QS_IActiveScriptSite);
137 DEFINE_EXPECT(QS_GetCaller);
138 DEFINE_EXPECT(ChangeType);
139 DEFINE_EXPECT(GetTypeInfo);
141 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
142 #define TESTACTIVEX_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80646}"
144 #define DISPID_SCRIPT_TESTPROP 0x100000
145 #define DISPID_SCRIPT_TESTPROP2 0x100001
147 #define DISPID_EXTERNAL_OK 0x300000
148 #define DISPID_EXTERNAL_TRACE 0x300001
149 #define DISPID_EXTERNAL_REPORTSUCCESS 0x300002
150 #define DISPID_EXTERNAL_TODO_WINE_OK 0x300003
151 #define DISPID_EXTERNAL_BROKEN 0x300004
152 #define DISPID_EXTERNAL_WIN_SKIP 0x300005
153 #define DISPID_EXTERNAL_WRITESTREAM 0x300006
155 static const GUID CLSID_TestScript =
156 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
157 static const GUID CLSID_TestActiveX =
158 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
160 static BOOL is_ie9plus;
161 static IHTMLDocument2 *notif_doc;
162 static IOleDocumentView *view;
163 static IDispatchEx *window_dispex;
164 static BOOL doc_complete;
165 static IDispatch *script_disp;
166 static BOOL ax_objsafe;
167 static HWND container_hwnd;
168 static HRESULT ax_getopt_hres = S_OK, ax_setopt_dispex_hres = S_OK;
169 static HRESULT ax_setopt_disp_caller_hres = S_OK, ax_setopt_disp_data_hres = S_OK;
170 static BOOL skip_loadobject_tests;
172 static IActiveScriptSite *site;
173 static SCRIPTSTATE state;
175 static BOOL init_key(const char *key_name, const char *def_value, BOOL init)
177 HKEY hkey;
178 DWORD res;
180 if(!init) {
181 RegDeleteKeyA(HKEY_CLASSES_ROOT, key_name);
182 return TRUE;
185 res = RegCreateKeyA(HKEY_CLASSES_ROOT, key_name, &hkey);
186 if(res != ERROR_SUCCESS)
187 return FALSE;
189 if(def_value)
190 res = RegSetValueA(hkey, NULL, REG_SZ, def_value, strlen(def_value));
192 RegCloseKey(hkey);
194 return res == ERROR_SUCCESS;
197 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
198 REFIID riid, void**ppv)
200 if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
201 *ppv = iface;
202 return S_OK;
205 return E_NOINTERFACE;
208 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
210 return 2;
213 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
215 return 1;
218 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
220 if(dispID == DISPID_READYSTATE){
221 BSTR state;
222 HRESULT hres;
224 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
226 hres = IHTMLDocument2_get_readyState(notif_doc, &state);
227 ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
229 if(!lstrcmpW(state, completeW))
230 doc_complete = TRUE;
232 SysFreeString(state);
235 return S_OK;
238 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
240 ok(0, "unexpected call\n");
241 return E_NOTIMPL;
244 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
245 PropertyNotifySink_QueryInterface,
246 PropertyNotifySink_AddRef,
247 PropertyNotifySink_Release,
248 PropertyNotifySink_OnChanged,
249 PropertyNotifySink_OnRequestEdit
252 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
254 static HRESULT WINAPI VariantChangeType_QueryInterface(IVariantChangeType *iface, REFIID riid, void **ppv)
256 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
257 *ppv = NULL;
258 return E_NOINTERFACE;
261 static ULONG WINAPI VariantChangeType_AddRef(IVariantChangeType *iface)
263 return 2;
266 static ULONG WINAPI VariantChangeType_Release(IVariantChangeType *iface)
268 return 1;
271 static HRESULT WINAPI VariantChangeType_ChangeType(IVariantChangeType *iface, VARIANT *dst, VARIANT *src, LCID lcid, VARTYPE vt)
273 CHECK_EXPECT(ChangeType);
275 ok(dst != NULL, "dst = NULL\n");
276 ok(V_VT(dst) == VT_EMPTY, "V_VT(dst) = %d\n", V_VT(dst));
277 ok(src != NULL, "src = NULL\n");
278 ok(V_VT(src) == VT_I4, "V_VT(src) = %d\n", V_VT(src));
279 ok(V_I4(src) == 0xf0f0f0, "V_I4(src) = %x\n", V_I4(src));
280 ok(lcid == LOCALE_NEUTRAL, "lcid = %d\n", lcid);
281 ok(vt == VT_BSTR, "vt = %d\n", vt);
283 V_VT(dst) = VT_BSTR;
284 V_BSTR(dst) = SysAllocString(L"red");
285 return S_OK;
288 static const IVariantChangeTypeVtbl VariantChangeTypeVtbl = {
289 VariantChangeType_QueryInterface,
290 VariantChangeType_AddRef,
291 VariantChangeType_Release,
292 VariantChangeType_ChangeType
295 static IVariantChangeType VChangeType = { &VariantChangeTypeVtbl };
297 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
299 ok(0, "unexpected call\n");
300 return E_NOINTERFACE;
303 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
305 return 2;
308 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
310 return 1;
313 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
314 REFIID riid, void **ppv)
316 if(IsEqualGUID(guidService, &SID_VariantConversion)) {
317 CHECK_EXPECT(QS_VariantConversion);
318 ok(IsEqualGUID(riid, &IID_IVariantChangeType), "unexpected riid %s\n", wine_dbgstr_guid(riid));
319 *ppv = &VChangeType;
320 return S_OK;
323 if(IsEqualGUID(guidService, &IID_IActiveScriptSite)) {
324 CHECK_EXPECT(QS_IActiveScriptSite);
325 ok(IsEqualGUID(riid, &IID_IOleCommandTarget), "unexpected riid %s\n", wine_dbgstr_guid(riid));
326 return IActiveScriptSite_QueryInterface(site, riid, ppv);
329 if(IsEqualGUID(guidService, &SID_GetCaller)) {
330 CHECK_EXPECT(QS_GetCaller);
331 ok(IsEqualGUID(riid, &IID_IServiceProvider), "unexpected riid %s\n", wine_dbgstr_guid(riid));
332 *ppv = NULL;
333 return E_NOINTERFACE;
336 ok(0, "unexpected service %s\n", wine_dbgstr_guid(guidService));
337 return E_NOINTERFACE;
340 static const IServiceProviderVtbl ServiceProviderVtbl = {
341 ServiceProvider_QueryInterface,
342 ServiceProvider_AddRef,
343 ServiceProvider_Release,
344 ServiceProvider_QueryService
347 static IServiceProvider caller_sp = { &ServiceProviderVtbl };
349 static HRESULT WINAPI DispatchEx_QueryInterface(IDispatchEx *iface, REFIID riid, void **ppv)
351 *ppv = NULL;
353 if(IsEqualGUID(riid, &IID_IUnknown)
354 || IsEqualGUID(riid, &IID_IDispatch)
355 || IsEqualGUID(riid, &IID_IDispatchEx))
356 *ppv = iface;
357 else
358 return E_NOINTERFACE;
360 return S_OK;
363 static ULONG WINAPI DispatchEx_AddRef(IDispatchEx *iface)
365 return 2;
368 static ULONG WINAPI DispatchEx_Release(IDispatchEx *iface)
370 return 1;
373 static HRESULT WINAPI DispatchEx_GetTypeInfoCount(IDispatchEx *iface, UINT *pctinfo)
375 ok(0, "unexpected call\n");
376 return E_NOTIMPL;
379 static HRESULT WINAPI DispatchEx_GetTypeInfo(IDispatchEx *iface, UINT iTInfo,
380 LCID lcid, ITypeInfo **ppTInfo)
382 CHECK_EXPECT2(GetTypeInfo);
383 return E_NOTIMPL;
386 static HRESULT WINAPI DispatchEx_GetIDsOfNames(IDispatchEx *iface, REFIID riid,
387 LPOLESTR *rgszNames, UINT cNames,
388 LCID lcid, DISPID *rgDispId)
390 ok(0, "unexpected call\n");
391 return E_NOTIMPL;
394 static HRESULT WINAPI DispatchEx_Invoke(IDispatchEx *iface, DISPID dispIdMember,
395 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
396 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
398 ok(0, "unexpected call\n");
399 return E_NOTIMPL;
402 static HRESULT WINAPI DispatchEx_DeleteMemberByName(IDispatchEx *iface, BSTR bstrName, DWORD grfdex)
404 ok(0, "unexpected call %s %x\n", wine_dbgstr_w(bstrName), grfdex);
405 return E_NOTIMPL;
408 static HRESULT WINAPI DispatchEx_DeleteMemberByDispID(IDispatchEx *iface, DISPID id)
410 ok(0, "unexpected call\n");
411 return E_NOTIMPL;
414 static HRESULT WINAPI DispatchEx_GetMemberProperties(IDispatchEx *iface, DISPID id, DWORD grfdexFetch, DWORD *pgrfdex)
416 ok(0, "unexpected call\n");
417 return E_NOTIMPL;
420 static HRESULT WINAPI DispatchEx_GetMemberName(IDispatchEx *iface, DISPID id, BSTR *pbstrName)
422 ok(0, "unexpected call\n");
423 return E_NOTIMPL;
426 static HRESULT WINAPI DispatchEx_GetNextDispID(IDispatchEx *iface, DWORD grfdex, DISPID id, DISPID *pid)
428 ok(0, "unexpected call\n");
429 return E_NOTIMPL;
432 static HRESULT WINAPI DispatchEx_GetNameSpaceParent(IDispatchEx *iface, IUnknown **ppunk)
434 ok(0, "unexpected call\n");
435 return E_NOTIMPL;
438 static HRESULT WINAPI DispatchEx_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
440 ok(0, "unexpected call\n");
441 return E_NOTIMPL;
444 static HRESULT WINAPI funcDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
445 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
447 CHECK_EXPECT(funcDisp);
449 ok(id == DISPID_VALUE, "id = %d\n", id);
450 ok(lcid == 0, "lcid = %x\n", lcid);
451 ok(wFlags == DISPATCH_METHOD, "wFlags = %x\n", wFlags);
452 ok(pdp != NULL, "pdp == NULL\n");
453 ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
454 ok(pdp->cNamedArgs == 1, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
455 ok(pdp->rgdispidNamedArgs[0] == DISPID_THIS, "pdp->rgdispidNamedArgs[0] = %d\n", pdp->rgdispidNamedArgs[0]);
456 ok(V_VT(pdp->rgvarg) == VT_DISPATCH, "V_VT(rgvarg) = %d\n", V_VT(pdp->rgvarg));
457 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp->rgvarg));
458 ok(V_BOOL(pdp->rgvarg+1) == VARIANT_TRUE, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp->rgvarg));
459 ok(pvarRes != NULL, "pvarRes == NULL\n");
460 ok(pei != NULL, "pei == NULL\n");
461 ok(!pspCaller, "pspCaller != NULL\n");
463 V_VT(pvarRes) = VT_I4;
464 V_I4(pvarRes) = 100;
465 return S_OK;
468 static IDispatchExVtbl testObjVtbl = {
469 DispatchEx_QueryInterface,
470 DispatchEx_AddRef,
471 DispatchEx_Release,
472 DispatchEx_GetTypeInfoCount,
473 DispatchEx_GetTypeInfo,
474 DispatchEx_GetIDsOfNames,
475 DispatchEx_Invoke,
476 DispatchEx_GetDispID,
477 funcDisp_InvokeEx,
478 DispatchEx_DeleteMemberByName,
479 DispatchEx_DeleteMemberByDispID,
480 DispatchEx_GetMemberProperties,
481 DispatchEx_GetMemberName,
482 DispatchEx_GetNextDispID,
483 DispatchEx_GetNameSpaceParent
486 static IDispatchEx funcDisp = { &testObjVtbl };
488 static HRESULT WINAPI scriptDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
490 if(!lstrcmpW(bstrName, L"testProp")) {
491 CHECK_EXPECT(script_testprop_d);
492 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
493 *pid = DISPID_SCRIPT_TESTPROP;
494 return S_OK;
497 if(!lstrcmpW(bstrName, L"testProp2")) {
498 CHECK_EXPECT(script_testprop2_d);
499 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
500 *pid = DISPID_SCRIPT_TESTPROP2;
501 return S_OK;
504 if(!lstrcmpW(bstrName, L"divid")) {
505 CHECK_EXPECT(script_divid_d);
506 ok(grfdex == fdexNameCaseSensitive, "grfdex = %x\n", grfdex);
507 return E_FAIL;
510 ok(0, "unexpected call %s\n", wine_dbgstr_w(bstrName));
511 return E_NOTIMPL;
514 static HRESULT WINAPI scriptDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
515 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
517 switch(id) {
518 case DISPID_SCRIPT_TESTPROP:
519 CHECK_EXPECT(script_testprop_i);
521 ok(lcid == 0, "lcid = %x\n", lcid);
522 ok(wFlags == DISPATCH_PROPERTYGET, "wFlags = %x\n", wFlags);
523 ok(pdp != NULL, "pdp == NULL\n");
524 ok(pdp->cArgs == 0, "pdp->cArgs = %d\n", pdp->cArgs);
525 ok(pdp->cNamedArgs == 0, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
526 ok(!pdp->rgdispidNamedArgs, "pdp->rgdispidNamedArgs != NULL\n");
527 ok(!pdp->rgvarg, "rgvarg != NULL\n");
528 ok(pvarRes != NULL, "pvarRes == NULL\n");
529 ok(pei != NULL, "pei == NULL\n");
530 ok(!pspCaller, "pspCaller != NULL\n");
532 V_VT(pvarRes) = VT_NULL;
533 break;
534 default:
535 ok(0, "unexpected call\n");
536 return E_NOTIMPL;
539 return S_OK;
542 static IDispatchExVtbl scriptDispVtbl = {
543 DispatchEx_QueryInterface,
544 DispatchEx_AddRef,
545 DispatchEx_Release,
546 DispatchEx_GetTypeInfoCount,
547 DispatchEx_GetTypeInfo,
548 DispatchEx_GetIDsOfNames,
549 DispatchEx_Invoke,
550 scriptDisp_GetDispID,
551 scriptDisp_InvokeEx,
552 DispatchEx_DeleteMemberByName,
553 DispatchEx_DeleteMemberByDispID,
554 DispatchEx_GetMemberProperties,
555 DispatchEx_GetMemberName,
556 DispatchEx_GetNextDispID,
557 DispatchEx_GetNameSpaceParent
560 static IDispatchEx scriptDisp = { &scriptDispVtbl };
562 static HRESULT WINAPI externalDisp_GetDispID(IDispatchEx *iface, BSTR bstrName, DWORD grfdex, DISPID *pid)
564 if(!lstrcmpW(bstrName, L"ok")) {
565 *pid = DISPID_EXTERNAL_OK;
566 return S_OK;
568 if(!lstrcmpW(bstrName, L"trace")) {
569 *pid = DISPID_EXTERNAL_TRACE;
570 return S_OK;
572 if(!lstrcmpW(bstrName, L"reportSuccess")) {
573 *pid = DISPID_EXTERNAL_REPORTSUCCESS;
574 return S_OK;
576 if(!lstrcmpW(bstrName, L"todo_wine_ok")) {
577 *pid = DISPID_EXTERNAL_TODO_WINE_OK;
578 return S_OK;
580 if(!lstrcmpW(bstrName, L"broken")) {
581 *pid = DISPID_EXTERNAL_BROKEN;
582 return S_OK;
584 if(!lstrcmpW(bstrName, L"win_skip")) {
585 *pid = DISPID_EXTERNAL_WIN_SKIP;
586 return S_OK;
588 if(!lstrcmpW(bstrName, L"writeStream")) {
589 *pid = DISPID_EXTERNAL_WRITESTREAM;
590 return S_OK;
593 ok(0, "unexpected name %s\n", wine_dbgstr_w(bstrName));
594 return DISP_E_UNKNOWNNAME;
597 static void stream_write(const WCHAR*,const WCHAR*);
599 static HRESULT WINAPI externalDisp_InvokeEx(IDispatchEx *iface, DISPID id, LCID lcid, WORD wFlags, DISPPARAMS *pdp,
600 VARIANT *pvarRes, EXCEPINFO *pei, IServiceProvider *pspCaller)
602 switch(id) {
603 case DISPID_EXTERNAL_OK: {
604 VARIANT *b, *m;
606 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
607 ok(pdp != NULL, "pdp == NULL\n");
608 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
609 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
610 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
611 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
612 ok(pei != NULL, "pei == NULL\n");
614 m = pdp->rgvarg;
615 if(V_VT(m) == (VT_BYREF|VT_VARIANT))
616 m = V_BYREF(m);
617 ok(V_VT(m) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
619 b = pdp->rgvarg+1;
620 if(V_VT(b) == (VT_BYREF|VT_VARIANT))
621 b = V_BYREF(b);
622 ok(V_VT(b) == VT_BOOL, "V_VT(b) = %d\n", V_VT(b));
624 ok(V_BOOL(b), "%s\n", wine_dbgstr_w(V_BSTR(m)));
625 return S_OK;
628 case DISPID_EXTERNAL_TRACE:
629 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
630 ok(pdp != NULL, "pdp == NULL\n");
631 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
632 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
633 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
634 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
635 ok(!pvarRes, "pvarRes != NULL\n");
636 ok(pei != NULL, "pei == NULL\n");
638 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
639 if(V_VT(pdp->rgvarg) == VT_BSTR)
640 trace("%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
642 return S_OK;
644 case DISPID_EXTERNAL_REPORTSUCCESS:
645 CHECK_EXPECT(external_success);
647 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
648 ok(pdp != NULL, "pdp == NULL\n");
649 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
650 ok(pdp->cArgs == 0, "cArgs = %d\n", pdp->cArgs);
651 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
652 ok(!pvarRes, "pvarRes != NULL\n");
653 ok(pei != NULL, "pei == NULL\n");
655 return S_OK;
657 case DISPID_EXTERNAL_TODO_WINE_OK:
658 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
659 ok(pdp != NULL, "pdp == NULL\n");
660 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
661 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
662 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
663 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
664 ok(pei != NULL, "pei == NULL\n");
666 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
667 ok(V_VT(pdp->rgvarg+1) == VT_BOOL, "V_VT(psp->rgvargs+1) = %d\n", V_VT(pdp->rgvarg));
668 todo_wine
669 ok(V_BOOL(pdp->rgvarg+1), "%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
671 return S_OK;
673 case DISPID_EXTERNAL_BROKEN:
674 ok(wFlags == INVOKE_FUNC || wFlags == (INVOKE_FUNC|INVOKE_PROPERTYGET), "wFlags = %x\n", wFlags);
675 ok(pdp != NULL, "pdp == NULL\n");
676 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
677 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
678 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
679 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
680 ok(pei != NULL, "pei == NULL\n");
682 ok(V_VT(pdp->rgvarg) == VT_BOOL, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
683 V_VT(pvarRes) = VT_BOOL;
684 V_BOOL(pvarRes) = broken(V_BOOL(pdp->rgvarg)) ? VARIANT_TRUE : VARIANT_FALSE;
685 return S_OK;
687 case DISPID_EXTERNAL_WIN_SKIP:
688 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
689 ok(pdp != NULL, "pdp == NULL\n");
690 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
691 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
692 ok(pdp->cArgs == 1, "cArgs = %d\n", pdp->cArgs);
693 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
694 ok(!pvarRes, "pvarRes != NULL\n");
695 ok(pei != NULL, "pei == NULL\n");
697 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
698 if(V_VT(pdp->rgvarg) == VT_BSTR)
699 win_skip("%s\n", wine_dbgstr_w(V_BSTR(pdp->rgvarg)));
701 return S_OK;
703 case DISPID_EXTERNAL_WRITESTREAM:
704 ok(wFlags == INVOKE_FUNC, "wFlags = %x\n", wFlags);
705 ok(pdp != NULL, "pdp == NULL\n");
706 ok(pdp->rgvarg != NULL, "rgvarg == NULL\n");
707 ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs != NULL\n");
708 ok(pdp->cArgs == 2, "cArgs = %d\n", pdp->cArgs);
709 ok(!pdp->cNamedArgs, "cNamedArgs = %d\n", pdp->cNamedArgs);
710 ok(!pvarRes, "pvarRes != NULL\n");
711 ok(pei != NULL, "pei == NULL\n");
713 ok(V_VT(pdp->rgvarg) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
714 ok(V_VT(pdp->rgvarg+1) == VT_BSTR, "V_VT(psp->rgvargs) = %d\n", V_VT(pdp->rgvarg));
716 stream_write(V_BSTR(pdp->rgvarg+1), V_BSTR(pdp->rgvarg));
717 return S_OK;
719 default:
720 ok(0, "unexpected call\n");
721 return E_NOTIMPL;
724 return S_OK;
727 static IDispatchExVtbl externalDispVtbl = {
728 DispatchEx_QueryInterface,
729 DispatchEx_AddRef,
730 DispatchEx_Release,
731 DispatchEx_GetTypeInfoCount,
732 DispatchEx_GetTypeInfo,
733 DispatchEx_GetIDsOfNames,
734 DispatchEx_Invoke,
735 externalDisp_GetDispID,
736 externalDisp_InvokeEx,
737 DispatchEx_DeleteMemberByName,
738 DispatchEx_DeleteMemberByDispID,
739 DispatchEx_GetMemberProperties,
740 DispatchEx_GetMemberName,
741 DispatchEx_GetNextDispID,
742 DispatchEx_GetNameSpaceParent
745 static IDispatchEx externalDisp = { &externalDispVtbl };
747 static HRESULT QueryInterface(REFIID,void**);
749 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
751 return QueryInterface(riid, ppv);
754 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
756 return 2;
759 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
761 return 1;
764 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
765 IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
767 return E_NOTIMPL;
770 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
772 return E_NOTIMPL;
775 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
776 IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
777 IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
779 return S_OK;
782 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
784 return S_OK;
787 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
789 return S_OK;
792 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
794 return E_NOTIMPL;
797 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
799 return E_NOTIMPL;
802 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
804 return S_OK;
807 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
808 IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
810 return E_NOTIMPL;
813 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
814 const GUID *pguidCmdGroup, DWORD nCmdID)
816 return E_NOTIMPL;
819 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
820 LPOLESTR *pchKey, DWORD dw)
822 return S_OK;
825 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
826 IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
828 return E_NOTIMPL;
831 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
833 *ppDispatch = (IDispatch*)&externalDisp;
834 return S_OK;
837 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
838 OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
840 return S_FALSE;
843 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
844 IDataObject **ppPORet)
846 return E_NOTIMPL;
849 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
850 LPOLESTR *pchKey, DWORD dw)
852 return E_NOTIMPL;
855 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
856 DocHostUIHandler_QueryInterface,
857 DocHostUIHandler_AddRef,
858 DocHostUIHandler_Release,
859 DocHostUIHandler_ShowContextMenu,
860 DocHostUIHandler_GetHostInfo,
861 DocHostUIHandler_ShowUI,
862 DocHostUIHandler_HideUI,
863 DocHostUIHandler_UpdateUI,
864 DocHostUIHandler_EnableModeless,
865 DocHostUIHandler_OnDocWindowActivate,
866 DocHostUIHandler_OnFrameWindowActivate,
867 DocHostUIHandler_ResizeBorder,
868 DocHostUIHandler_TranslateAccelerator,
869 DocHostUIHandler_GetOptionKeyPath,
870 DocHostUIHandler_GetDropTarget,
871 DocHostUIHandler_GetExternal,
872 DocHostUIHandler_TranslateUrl,
873 DocHostUIHandler_FilterDataObject,
874 DocHostUIHandler_GetOverrideKeyPath
877 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
879 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
881 return E_NOINTERFACE;
884 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
886 return 2;
889 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
891 return 1;
894 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
896 return E_NOTIMPL;
899 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
901 return E_NOTIMPL;
904 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
906 return E_NOTIMPL;
909 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
910 LPCBORDERWIDTHS pborderwidths)
912 return E_NOTIMPL;
915 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
916 LPCBORDERWIDTHS pborderwidths)
918 return S_OK;
921 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
922 IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
924 return S_OK;
927 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
928 LPOLEMENUGROUPWIDTHS lpMenuWidths)
930 return E_NOTIMPL;
933 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
934 HOLEMENU holemenu, HWND hwndActiveObject)
936 ok(0, "unexpected call\n");
937 return E_NOTIMPL;
940 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
942 ok(0, "unexpected call\n");
943 return E_NOTIMPL;
946 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
948 return S_OK;
951 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
953 return E_NOTIMPL;
956 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
958 ok(0, "unexpected call\n");
959 return E_NOTIMPL;
962 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
963 InPlaceFrame_QueryInterface,
964 InPlaceFrame_AddRef,
965 InPlaceFrame_Release,
966 InPlaceFrame_GetWindow,
967 InPlaceFrame_ContextSensitiveHelp,
968 InPlaceFrame_GetBorder,
969 InPlaceFrame_RequestBorderSpace,
970 InPlaceFrame_SetBorderSpace,
971 InPlaceFrame_SetActiveObject,
972 InPlaceFrame_InsertMenus,
973 InPlaceFrame_SetMenu,
974 InPlaceFrame_RemoveMenus,
975 InPlaceFrame_SetStatusText,
976 InPlaceFrame_EnableModeless,
977 InPlaceFrame_TranslateAccelerator
980 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
982 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
984 return QueryInterface(riid, ppv);
987 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
989 return 2;
992 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
994 return 1;
997 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
999 *phwnd = container_hwnd;
1000 return S_OK;
1003 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
1005 ok(0, "unexpected call\n");
1006 return E_NOTIMPL;
1009 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
1011 return S_OK;
1014 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
1016 return S_OK;
1019 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
1021 return S_OK;
1024 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
1025 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1026 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1028 static const RECT rect = {0,0,300,300};
1030 *ppFrame = &InPlaceFrame;
1031 *ppDoc = (IOleInPlaceUIWindow*)&InPlaceFrame;
1032 *lprcPosRect = rect;
1033 *lprcClipRect = rect;
1035 ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
1036 lpFrameInfo->fMDIApp = FALSE;
1037 lpFrameInfo->hwndFrame = container_hwnd;
1038 lpFrameInfo->haccel = NULL;
1039 lpFrameInfo->cAccelEntries = 0;
1041 return S_OK;
1044 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
1046 return E_NOTIMPL;
1049 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
1051 return S_OK;
1054 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
1056 return S_OK;
1059 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
1061 return E_NOTIMPL;
1064 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
1066 return E_NOTIMPL;
1069 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
1071 return E_NOTIMPL;
1074 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
1075 InPlaceSite_QueryInterface,
1076 InPlaceSite_AddRef,
1077 InPlaceSite_Release,
1078 InPlaceSite_GetWindow,
1079 InPlaceSite_ContextSensitiveHelp,
1080 InPlaceSite_CanInPlaceActivate,
1081 InPlaceSite_OnInPlaceActivate,
1082 InPlaceSite_OnUIActivate,
1083 InPlaceSite_GetWindowContext,
1084 InPlaceSite_Scroll,
1085 InPlaceSite_OnUIDeactivate,
1086 InPlaceSite_OnInPlaceDeactivate,
1087 InPlaceSite_DiscardUndoState,
1088 InPlaceSite_DeactivateAndUndo,
1089 InPlaceSite_OnPosRectChange,
1092 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
1094 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
1096 return QueryInterface(riid, ppv);
1099 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
1101 return 2;
1104 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1106 return 1;
1109 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1111 ok(0, "unexpected call\n");
1112 return E_NOTIMPL;
1115 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1116 IMoniker **ppmon)
1118 ok(0, "unexpected call\n");
1119 return E_NOTIMPL;
1122 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1124 return E_NOTIMPL;
1127 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1129 ok(0, "unexpected call\n");
1130 return E_NOTIMPL;
1133 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1135 ok(0, "unexpected call\n");
1136 return E_NOTIMPL;
1139 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1141 ok(0, "unexpected call\n");
1142 return E_NOTIMPL;
1145 static const IOleClientSiteVtbl ClientSiteVtbl = {
1146 ClientSite_QueryInterface,
1147 ClientSite_AddRef,
1148 ClientSite_Release,
1149 ClientSite_SaveObject,
1150 ClientSite_GetMoniker,
1151 ClientSite_GetContainer,
1152 ClientSite_ShowObject,
1153 ClientSite_OnShowWindow,
1154 ClientSite_RequestNewObjectLayout
1157 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1159 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
1161 return QueryInterface(riid, ppv);
1164 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
1166 return 2;
1169 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
1171 return 1;
1174 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
1176 RECT rect = {0,0,300,300};
1177 IOleDocument *document;
1178 HRESULT hres;
1180 hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
1181 ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
1183 hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
1184 IOleDocument_Release(document);
1185 ok(hres == S_OK, "CreateView failed: %08x\n", hres);
1187 hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
1188 ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
1190 hres = IOleDocumentView_UIActivate(view, TRUE);
1191 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
1193 hres = IOleDocumentView_SetRect(view, &rect);
1194 ok(hres == S_OK, "SetRect failed: %08x\n", hres);
1196 hres = IOleDocumentView_Show(view, TRUE);
1197 ok(hres == S_OK, "Show failed: %08x\n", hres);
1199 return S_OK;
1202 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
1203 DocumentSite_QueryInterface,
1204 DocumentSite_AddRef,
1205 DocumentSite_Release,
1206 DocumentSite_ActivateMe
1209 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
1211 static HRESULT QueryInterface(REFIID riid, void **ppv)
1213 *ppv = NULL;
1215 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
1216 *ppv = &ClientSite;
1217 else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
1218 *ppv = &DocumentSite;
1219 else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
1220 *ppv = &InPlaceSite;
1221 else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
1222 *ppv = &DocHostUIHandler;
1224 return *ppv ? S_OK : E_NOINTERFACE;
1227 static IHTMLDocument2 *create_document(void)
1229 IHTMLDocument2 *doc;
1230 HRESULT hres;
1232 hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1233 &IID_IHTMLDocument2, (void**)&doc);
1234 #if !defined(__i386__) && !defined(__x86_64__)
1235 todo_wine
1236 #endif
1237 ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
1238 return SUCCEEDED(hres) ? doc : NULL;
1241 static void load_string(IHTMLDocument2 *doc, const char *str)
1243 IPersistStreamInit *init;
1244 IStream *stream;
1245 HRESULT hres;
1246 HGLOBAL mem;
1247 SIZE_T len;
1249 doc_complete = FALSE;
1250 len = strlen(str);
1251 mem = GlobalAlloc(0, len);
1252 memcpy(mem, str, len);
1253 hres = CreateStreamOnHGlobal(mem, TRUE, &stream);
1254 ok(hres == S_OK, "Failed to create a stream, hr %#x.\n", hres);
1256 hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
1257 ok(hres == S_OK, "Failed to get IPersistStreamInit, hr %#x.\n", hres);
1259 IPersistStreamInit_Load(init, stream);
1260 IPersistStreamInit_Release(init);
1261 IStream_Release(stream);
1264 static void do_advise(IHTMLDocument2 *doc, REFIID riid, IUnknown *unk_advise)
1266 IConnectionPointContainer *container;
1267 IConnectionPoint *cp;
1268 DWORD cookie;
1269 HRESULT hres;
1271 hres = IHTMLDocument2_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&container);
1272 ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
1274 hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
1275 IConnectionPointContainer_Release(container);
1276 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
1278 notif_doc = doc;
1280 hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
1281 IConnectionPoint_Release(cp);
1282 ok(hres == S_OK, "Advise failed: %08x\n", hres);
1285 static void set_client_site(IHTMLDocument2 *doc, BOOL set)
1287 IOleObject *oleobj;
1288 HRESULT hres;
1290 if(!set && view) {
1291 IOleDocumentView_Show(view, FALSE);
1292 IOleDocumentView_CloseView(view, 0);
1293 IOleDocumentView_SetInPlaceSite(view, NULL);
1294 IOleDocumentView_Release(view);
1295 view = NULL;
1298 hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
1299 ok(hres == S_OK, "Could not et IOleObject: %08x\n", hres);
1301 hres = IOleObject_SetClientSite(oleobj, set ? &ClientSite : NULL);
1302 ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1304 if(set) {
1305 IHlinkTarget *hlink;
1307 hres = IOleObject_QueryInterface(oleobj, &IID_IHlinkTarget, (void**)&hlink);
1308 ok(hres == S_OK, "Could not get IHlinkTarget iface: %08x\n", hres);
1310 hres = IHlinkTarget_Navigate(hlink, 0, NULL);
1311 ok(hres == S_OK, "Navgate failed: %08x\n", hres);
1313 IHlinkTarget_Release(hlink);
1316 IOleObject_Release(oleobj);
1319 typedef void (*domtest_t)(IHTMLDocument2*);
1321 static void load_doc(IHTMLDocument2 *doc, const char *str)
1323 IHTMLElement *body = NULL;
1324 MSG msg;
1325 HRESULT hres;
1326 static const WCHAR ucPtr[] = {'b','a','c','k','g','r','o','u','n','d',0};
1327 DISPID dispID = -1;
1328 OLECHAR *name;
1330 load_string(doc, str);
1331 do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
1333 while(!doc_complete && GetMessageW(&msg, NULL, 0, 0)) {
1334 TranslateMessage(&msg);
1335 DispatchMessageW(&msg);
1338 hres = IHTMLDocument2_get_body(doc, &body);
1339 ok(hres == S_OK, "get_body failed: %08x\n", hres);
1341 /* Check we can query for function on the IHTMLElementBody interface */
1342 name = (WCHAR*)ucPtr;
1343 hres = IHTMLElement_GetIDsOfNames(body, &IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &dispID);
1344 ok(hres == S_OK, "GetIDsOfNames(background) failed %08x\n", hres);
1345 ok(dispID == DISPID_IHTMLBODYELEMENT_BACKGROUND, "Incorrect dispID got (%d)\n", dispID);
1347 IHTMLElement_Release(body);
1350 static HRESULT WINAPI ObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1352 *ppv = NULL;
1353 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
1354 return E_NOINTERFACE;
1357 static ULONG WINAPI ObjectSafety_AddRef(IObjectSafety *iface)
1359 return 2;
1362 static ULONG WINAPI ObjectSafety_Release(IObjectSafety *iface)
1364 return 1;
1367 static HRESULT WINAPI ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1368 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1370 CHECK_EXPECT(GetInterfaceSafetyOptions);
1372 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
1373 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1374 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1376 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1377 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1379 return S_OK;
1382 static HRESULT WINAPI ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1383 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1385 CHECK_EXPECT(SetInterfaceSafetyOptions);
1387 ok(IsEqualGUID(&IID_IActiveScriptParse, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
1389 ok(dwOptionSetMask == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1390 "dwOptionSetMask=%x\n", dwOptionSetMask);
1391 ok(dwEnabledOptions == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
1392 "dwEnabledOptions=%x\n", dwOptionSetMask);
1394 return S_OK;
1397 static const IObjectSafetyVtbl ObjectSafetyVtbl = {
1398 ObjectSafety_QueryInterface,
1399 ObjectSafety_AddRef,
1400 ObjectSafety_Release,
1401 ObjectSafety_GetInterfaceSafetyOptions,
1402 ObjectSafety_SetInterfaceSafetyOptions
1405 static IObjectSafety ObjectSafety = { &ObjectSafetyVtbl };
1407 static HRESULT WINAPI AXObjectSafety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1409 *ppv = NULL;
1411 if(IsEqualGUID(&IID_IActiveScript, riid)) {
1412 CHECK_EXPECT(AXQueryInterface_IActiveScript);
1413 return E_NOINTERFACE;
1416 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
1417 CHECK_EXPECT2(AXQueryInterface_IObjectSafety);
1418 if(!ax_objsafe)
1419 return E_NOINTERFACE;
1420 *ppv = iface;
1421 return S_OK;
1424 ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
1425 return E_NOINTERFACE;
1428 static HRESULT WINAPI AXObjectSafety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1429 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1431 CHECK_EXPECT(AXGetInterfaceSafetyOptions);
1433 ok(IsEqualGUID(&IID_IDispatchEx, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
1434 ok(pdwSupportedOptions != NULL, "pdwSupportedOptions == NULL\n");
1435 ok(pdwEnabledOptions != NULL, "pdwEnabledOptions == NULL\n");
1437 if(SUCCEEDED(ax_getopt_hres)) {
1438 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER;
1439 *pdwEnabledOptions = INTERFACE_USES_DISPEX;
1442 return ax_getopt_hres;
1445 static HRESULT WINAPI AXObjectSafety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1446 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1448 if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1449 switch(dwEnabledOptions) {
1450 case INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACE_USES_SECURITY_MANAGER:
1451 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1452 break;
1453 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1454 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1455 break;
1456 default:
1457 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1460 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1461 return ax_setopt_dispex_hres;
1464 if(IsEqualGUID(&IID_IDispatch, riid)) {
1465 HRESULT hres;
1467 switch(dwEnabledOptions) {
1468 case INTERFACESAFE_FOR_UNTRUSTED_CALLER:
1469 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1470 hres = ax_setopt_disp_caller_hres;
1471 break;
1472 case INTERFACESAFE_FOR_UNTRUSTED_DATA:
1473 CHECK_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1474 hres = ax_setopt_disp_data_hres;
1475 break;
1476 default:
1477 ok(0, "unexpected dwEnabledOptions %x\n", dwEnabledOptions);
1478 hres = E_FAIL;
1480 ok(dwOptionSetMask == dwEnabledOptions, "dwOptionSetMask=%x, expected %x\n", dwOptionSetMask, dwEnabledOptions);
1481 return hres;
1484 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
1485 return E_NOINTERFACE;
1488 static const IObjectSafetyVtbl AXObjectSafetyVtbl = {
1489 AXObjectSafety_QueryInterface,
1490 ObjectSafety_AddRef,
1491 ObjectSafety_Release,
1492 AXObjectSafety_GetInterfaceSafetyOptions,
1493 AXObjectSafety_SetInterfaceSafetyOptions
1496 static IObjectSafety AXObjectSafety = { &AXObjectSafetyVtbl };
1498 static BOOL set_safe_reg(BOOL safe_call, BOOL safe_data)
1500 return init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95801-9882-11cf-9fa9-00aa006c42c4}",
1501 NULL, safe_call)
1502 && init_key("CLSID\\"TESTACTIVEX_CLSID"\\Implemented Categories\\{7dd95802-9882-11cf-9fa9-00aa006c42c4}",
1503 NULL, safe_data);
1506 #define check_custom_policy(a,b,c,d) _check_custom_policy(__LINE__,a,b,c,d)
1507 static void _check_custom_policy(unsigned line, HRESULT hres, BYTE *ppolicy, DWORD policy_size, DWORD expolicy)
1509 ok_(__FILE__,line)(hres == S_OK, "QueryCusromPolicy failed: %08x\n", hres);
1510 ok_(__FILE__,line)(policy_size == sizeof(DWORD), "policy_size = %d\n", policy_size);
1511 ok_(__FILE__,line)(*(DWORD*)ppolicy == expolicy, "policy = %x, expected %x\n", *(DWORD*)ppolicy, expolicy);
1512 CoTaskMemFree(ppolicy);
1515 static void test_security_reg(IInternetHostSecurityManager *sec_mgr, DWORD policy_caller, DWORD policy_load)
1517 struct CONFIRMSAFETY cs;
1518 DWORD policy_size;
1519 BYTE *ppolicy;
1520 HRESULT hres;
1522 cs.clsid = CLSID_TestActiveX;
1523 cs.pUnk = (IUnknown*)&AXObjectSafety;
1525 cs.dwFlags = 0;
1526 ax_objsafe = FALSE;
1527 SET_EXPECT(AXQueryInterface_IActiveScript);
1528 SET_EXPECT(AXQueryInterface_IObjectSafety);
1529 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1530 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1531 CHECK_CALLED(AXQueryInterface_IActiveScript);
1532 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1533 check_custom_policy(hres, ppolicy, policy_size, policy_caller);
1535 ax_objsafe = TRUE;
1536 SET_EXPECT(AXQueryInterface_IActiveScript);
1537 SET_EXPECT(AXQueryInterface_IObjectSafety);
1538 SET_EXPECT(AXGetInterfaceSafetyOptions);
1539 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1540 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1541 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1542 CHECK_CALLED(AXQueryInterface_IActiveScript);
1543 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1544 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1545 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1546 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1548 if(skip_loadobject_tests)
1549 return;
1551 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1552 ax_objsafe = FALSE;
1553 SET_EXPECT(AXQueryInterface_IActiveScript);
1554 SET_EXPECT(AXQueryInterface_IObjectSafety);
1555 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1556 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1557 CHECK_CALLED(AXQueryInterface_IActiveScript);
1558 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1559 check_custom_policy(hres, ppolicy, policy_size, policy_load);
1561 ax_objsafe = TRUE;
1562 SET_EXPECT(AXQueryInterface_IActiveScript);
1563 SET_EXPECT(AXQueryInterface_IObjectSafety);
1564 SET_EXPECT(AXGetInterfaceSafetyOptions);
1565 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1566 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1567 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1568 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1569 CHECK_CALLED(AXQueryInterface_IActiveScript);
1570 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1571 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1572 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1573 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1574 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1577 static void test_security(void)
1579 IInternetHostSecurityManager *sec_mgr;
1580 IServiceProvider *sp;
1581 DWORD policy, policy_size;
1582 struct CONFIRMSAFETY cs;
1583 BYTE *ppolicy;
1584 HRESULT hres;
1586 hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
1587 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
1589 hres = IServiceProvider_QueryService(sp, &SID_SInternetHostSecurityManager,
1590 &IID_IInternetHostSecurityManager, (void**)&sec_mgr);
1591 IServiceProvider_Release(sp);
1592 ok(hres == S_OK, "QueryService failed: %08x\n", hres);
1594 hres = IInternetHostSecurityManager_ProcessUrlAction(sec_mgr, URLACTION_ACTIVEX_RUN, (BYTE*)&policy, sizeof(policy),
1595 (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
1596 ok(hres == S_OK, "ProcessUrlAction failed: %08x\n", hres);
1597 ok(policy == URLPOLICY_ALLOW, "policy = %x\n", policy);
1599 cs.clsid = CLSID_TestActiveX;
1600 cs.pUnk = (IUnknown*)&AXObjectSafety;
1601 cs.dwFlags = 0;
1603 ax_objsafe = TRUE;
1604 SET_EXPECT(AXQueryInterface_IActiveScript);
1605 SET_EXPECT(AXQueryInterface_IObjectSafety);
1606 SET_EXPECT(AXGetInterfaceSafetyOptions);
1607 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1608 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1609 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1610 CHECK_CALLED(AXQueryInterface_IActiveScript);
1611 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1612 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1613 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1614 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1616 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1617 SET_EXPECT(AXQueryInterface_IActiveScript);
1618 SET_EXPECT(AXQueryInterface_IObjectSafety);
1619 SET_EXPECT(AXGetInterfaceSafetyOptions);
1620 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1621 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1622 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1623 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1624 CHECK_CALLED(AXQueryInterface_IActiveScript);
1625 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1626 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1627 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1628 if(called_AXSetInterfaceSafetyOptions_IDispatch_data) {
1629 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1630 }else {
1631 win_skip("CONFIRMSAFETYACTION_LOADOBJECT flag not supported\n");
1632 skip_loadobject_tests = TRUE;
1633 CLEAR_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1635 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1637 cs.dwFlags = 0;
1638 ax_objsafe = FALSE;
1639 SET_EXPECT(AXQueryInterface_IActiveScript);
1640 SET_EXPECT(AXQueryInterface_IObjectSafety);
1641 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1642 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1643 CHECK_CALLED(AXQueryInterface_IActiveScript);
1644 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1645 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1647 if(!skip_loadobject_tests) {
1648 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1649 ax_objsafe = FALSE;
1650 SET_EXPECT(AXQueryInterface_IActiveScript);
1651 SET_EXPECT(AXQueryInterface_IObjectSafety);
1652 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1653 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1654 CHECK_CALLED(AXQueryInterface_IActiveScript);
1655 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1656 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1659 if(set_safe_reg(TRUE, FALSE)) {
1660 test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_DISALLOW);
1662 set_safe_reg(FALSE, TRUE);
1663 test_security_reg(sec_mgr, URLPOLICY_DISALLOW, URLPOLICY_DISALLOW);
1665 set_safe_reg(TRUE, TRUE);
1666 test_security_reg(sec_mgr, URLPOLICY_ALLOW, URLPOLICY_ALLOW);
1668 set_safe_reg(FALSE, FALSE);
1669 }else {
1670 skip("Could not set safety registry\n");
1673 ax_objsafe = TRUE;
1675 cs.dwFlags = 0;
1676 ax_setopt_dispex_hres = E_NOINTERFACE;
1677 SET_EXPECT(AXQueryInterface_IActiveScript);
1678 SET_EXPECT(AXQueryInterface_IObjectSafety);
1679 SET_EXPECT(AXGetInterfaceSafetyOptions);
1680 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1681 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1682 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1683 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1684 CHECK_CALLED(AXQueryInterface_IActiveScript);
1685 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1686 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1687 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1688 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1689 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1691 ax_setopt_dispex_hres = E_FAIL;
1692 ax_setopt_disp_caller_hres = E_NOINTERFACE;
1693 SET_EXPECT(AXQueryInterface_IActiveScript);
1694 SET_EXPECT(AXQueryInterface_IObjectSafety);
1695 SET_EXPECT(AXGetInterfaceSafetyOptions);
1696 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1697 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1698 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1699 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1700 CHECK_CALLED(AXQueryInterface_IActiveScript);
1701 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1702 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1703 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1704 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1705 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1707 if(!skip_loadobject_tests) {
1708 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1709 ax_setopt_dispex_hres = E_FAIL;
1710 ax_setopt_disp_caller_hres = E_NOINTERFACE;
1711 SET_EXPECT(AXQueryInterface_IActiveScript);
1712 SET_EXPECT(AXQueryInterface_IObjectSafety);
1713 SET_EXPECT(AXGetInterfaceSafetyOptions);
1714 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1715 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1716 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1717 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1718 CHECK_CALLED(AXQueryInterface_IActiveScript);
1719 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1720 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1721 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller_secmgr);
1722 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1723 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1726 cs.dwFlags = 0;
1727 ax_setopt_dispex_hres = E_FAIL;
1728 ax_setopt_disp_caller_hres = S_OK;
1729 ax_getopt_hres = E_NOINTERFACE;
1730 SET_EXPECT(AXQueryInterface_IActiveScript);
1731 SET_EXPECT(AXQueryInterface_IObjectSafety);
1732 SET_EXPECT(AXGetInterfaceSafetyOptions);
1733 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1734 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1735 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1736 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1737 CHECK_CALLED(AXQueryInterface_IActiveScript);
1738 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1739 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1740 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1741 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1742 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_ALLOW);
1744 if(!skip_loadobject_tests) {
1745 cs.dwFlags = CONFIRMSAFETYACTION_LOADOBJECT;
1746 ax_setopt_dispex_hres = E_FAIL;
1747 ax_setopt_disp_caller_hres = S_OK;
1748 ax_setopt_disp_data_hres = E_FAIL;
1749 ax_getopt_hres = E_NOINTERFACE;
1750 SET_EXPECT(AXQueryInterface_IActiveScript);
1751 SET_EXPECT(AXQueryInterface_IObjectSafety);
1752 SET_EXPECT(AXGetInterfaceSafetyOptions);
1753 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1754 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_caller);
1755 SET_EXPECT(AXSetInterfaceSafetyOptions_IDispatch_data);
1756 hres = IInternetHostSecurityManager_QueryCustomPolicy(sec_mgr, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
1757 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
1758 CHECK_CALLED(AXQueryInterface_IActiveScript);
1759 CHECK_CALLED(AXQueryInterface_IObjectSafety);
1760 CHECK_CALLED(AXGetInterfaceSafetyOptions);
1761 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatchEx_caller);
1762 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_caller);
1763 CHECK_CALLED(AXSetInterfaceSafetyOptions_IDispatch_data);
1764 check_custom_policy(hres, ppolicy, policy_size, URLPOLICY_DISALLOW);
1767 IInternetHostSecurityManager_Release(sec_mgr);
1770 static HRESULT WINAPI ActiveScriptProperty_QueryInterface(IActiveScriptProperty *iface, REFIID riid, void **ppv)
1772 *ppv = NULL;
1773 ok(0, "unexpected call\n");
1774 return E_NOINTERFACE;
1777 static ULONG WINAPI ActiveScriptProperty_AddRef(IActiveScriptProperty *iface)
1779 return 2;
1782 static ULONG WINAPI ActiveScriptProperty_Release(IActiveScriptProperty *iface)
1784 return 1;
1787 static HRESULT WINAPI ActiveScriptProperty_GetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1788 VARIANT *pvarIndex, VARIANT *pvarValue)
1790 ok(0, "unexpected call\n");
1791 return E_NOTIMPL;
1794 static HRESULT WINAPI ActiveScriptProperty_SetProperty(IActiveScriptProperty *iface, DWORD dwProperty,
1795 VARIANT *pvarIndex, VARIANT *pvarValue)
1797 switch(dwProperty) {
1798 case SCRIPTPROP_HACK_TRIDENTEVENTSINK:
1799 CHECK_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
1800 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1801 ok(V_BOOL(pvarValue) == VARIANT_TRUE, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue));
1802 break;
1803 case SCRIPTPROP_INVOKEVERSIONING:
1804 CHECK_EXPECT(SetProperty_INVOKEVERSIONING);
1805 ok(V_VT(pvarValue) == VT_I4, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1806 ok(V_I4(pvarValue) == 1, "V_I4(pvarValue)=%d\n", V_I4(pvarValue));
1807 break;
1808 case SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION:
1809 if(V_BOOL(pvarValue))
1810 CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_TRUE);
1811 else
1812 CHECK_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_FALSE);
1813 ok(V_VT(pvarValue) == VT_BOOL, "V_VT(pvarValue)=%d\n", V_VT(pvarValue));
1814 break;
1815 case 0x70000003: /* Undocumented property set by IE10 */
1816 return E_NOTIMPL;
1817 default:
1818 ok(0, "unexpected property %x\n", dwProperty);
1819 return E_NOTIMPL;
1822 ok(!pvarIndex, "pvarIndex != NULL\n");
1823 ok(pvarValue != NULL, "pvarValue == NULL\n");
1825 return S_OK;
1828 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl = {
1829 ActiveScriptProperty_QueryInterface,
1830 ActiveScriptProperty_AddRef,
1831 ActiveScriptProperty_Release,
1832 ActiveScriptProperty_GetProperty,
1833 ActiveScriptProperty_SetProperty
1836 static IActiveScriptProperty ActiveScriptProperty = { &ActiveScriptPropertyVtbl };
1838 static HRESULT WINAPI ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2 *iface, REFIID riid, void **ppv)
1840 *ppv = NULL;
1841 ok(0, "unexpected call\n");
1842 return E_NOINTERFACE;
1845 static ULONG WINAPI ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2 *iface)
1847 return 2;
1850 static ULONG WINAPI ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2 *iface)
1852 return 1;
1855 static HRESULT WINAPI ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2 *iface,
1856 LPCOLESTR pstrCode, LPCOLESTR pstrFormalParams, LPCOLESTR pstrProcedureName,
1857 LPCOLESTR pstrItemName, IUnknown *punkContext, LPCOLESTR pstrDelimiter,
1858 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags, IDispatch **ppdisp)
1860 ok(0, "unexpected call\n");
1861 return E_NOTIMPL;
1864 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl = {
1865 ActiveScriptParseProcedure_QueryInterface,
1866 ActiveScriptParseProcedure_AddRef,
1867 ActiveScriptParseProcedure_Release,
1868 ActiveScriptParseProcedure_ParseProcedureText
1871 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure = { &ActiveScriptParseProcedureVtbl };
1873 static HRESULT WINAPI ActiveScriptParse_QueryInterface(IActiveScriptParse *iface, REFIID riid, void **ppv)
1875 *ppv = NULL;
1876 ok(0, "unexpected call\n");
1877 return E_NOINTERFACE;
1880 static ULONG WINAPI ActiveScriptParse_AddRef(IActiveScriptParse *iface)
1882 return 2;
1885 static ULONG WINAPI ActiveScriptParse_Release(IActiveScriptParse *iface)
1887 return 1;
1890 static HRESULT WINAPI ActiveScriptParse_InitNew(IActiveScriptParse *iface)
1892 CHECK_EXPECT(InitNew);
1893 return S_OK;
1896 static HRESULT WINAPI ActiveScriptParse_AddScriptlet(IActiveScriptParse *iface,
1897 LPCOLESTR pstrDefaultName, LPCOLESTR pstrCode, LPCOLESTR pstrItemName,
1898 LPCOLESTR pstrSubItemName, LPCOLESTR pstrEventName, LPCOLESTR pstrDelimiter,
1899 CTXARG_T dwSourceContextCookie, ULONG ulStartingLineNumber, DWORD dwFlags,
1900 BSTR *pbstrName, EXCEPINFO *pexcepinfo)
1902 ok(0, "unexpected call\n");
1903 return E_NOTIMPL;
1906 static HRESULT dispex_propput(IDispatchEx *obj, DISPID id, DWORD flags, VARIANT *var, IServiceProvider *caller_sp)
1908 DISPID propput_arg = DISPID_PROPERTYPUT;
1909 DISPPARAMS dp = {var, &propput_arg, 1, 1};
1910 EXCEPINFO ei = {0};
1912 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYPUT|flags, &dp, NULL, &ei, caller_sp);
1915 static HRESULT dispex_propget(IDispatchEx *obj, DISPID id, VARIANT *res, IServiceProvider *caller_sp)
1917 DISPPARAMS dp = {NULL};
1918 EXCEPINFO ei = {0};
1920 return IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, res, &ei, caller_sp);
1923 static void test_func(IDispatchEx *obj)
1925 DISPID id;
1926 IDispatchEx *dispex;
1927 IDispatch *disp;
1928 EXCEPINFO ei;
1929 DISPPARAMS dp;
1930 BSTR str;
1931 VARIANT var;
1932 HRESULT hres;
1934 str = SysAllocString(L"toString");
1935 hres = IDispatchEx_GetDispID(obj, str, fdexNameCaseSensitive, &id);
1936 SysFreeString(str);
1937 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
1938 ok(id == DISPID_IOMNAVIGATOR_TOSTRING, "id = %x\n", id);
1940 memset(&dp, 0, sizeof(dp));
1941 memset(&ei, 0, sizeof(ei));
1942 VariantInit(&var);
1943 hres = IDispatchEx_InvokeEx(obj, id, LOCALE_NEUTRAL, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
1944 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1945 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
1946 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(var) == NULL\n");
1947 disp = V_DISPATCH(&var);
1949 hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
1950 IDispatch_Release(disp);
1951 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
1953 /* FIXME: Test InvokeEx(DISPATCH_METHOD) */
1955 memset(&dp, 0, sizeof(dp));
1956 memset(&ei, 0, sizeof(ei));
1957 VariantInit(&var);
1958 hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
1959 ok(hres == S_OK || broken(hres == E_ACCESSDENIED), "InvokeEx failed: %08x\n", hres);
1960 if(SUCCEEDED(hres)) {
1961 DISPID named_args[2] = { DISPID_THIS, 0xdeadbeef };
1962 VARIANT args[2];
1964 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1965 ok(!lstrcmpW(V_BSTR(&var), L"[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
1966 VariantClear(&var);
1968 dp.rgdispidNamedArgs = named_args;
1969 dp.cNamedArgs = 2;
1970 dp.cArgs = 2;
1971 dp.rgvarg = &var;
1972 V_VT(args) = VT_DISPATCH;
1973 V_DISPATCH(args) = (IDispatch*)obj;
1974 V_VT(args+1) = VT_I4;
1975 V_I4(args+1) = 3;
1976 hres = IDispatchEx_Invoke(dispex, DISPID_VALUE, &IID_NULL, LOCALE_NEUTRAL, DISPATCH_METHOD, &dp, &var, &ei, NULL);
1977 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
1978 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
1979 ok(!lstrcmpW(V_BSTR(&var), L"[object]"), "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
1980 VariantClear(&var);
1983 V_VT(&var) = VT_I4;
1984 V_I4(&var) = 100;
1985 hres = dispex_propput(obj, id, 0, &var, NULL);
1986 todo_wine ok(hres == E_NOTIMPL, "InvokeEx failed: %08x\n", hres);
1988 hres = dispex_propget(dispex, DISPID_VALUE, &var, NULL);
1989 ok(hres == E_ACCESSDENIED, "InvokeEx returned: %08x, expected E_ACCESSDENIED\n", hres);
1990 if(SUCCEEDED(hres))
1991 VariantClear(&var);
1993 SET_EXPECT(QS_IActiveScriptSite);
1994 SET_EXPECT(QS_GetCaller);
1995 hres = dispex_propget(dispex, DISPID_VALUE, &var, &caller_sp);
1996 ok(hres == S_OK, "InvokeEx returned: %08x, expected S_OK\n", hres);
1997 ok(V_VT(&var) == VT_BSTR, "V_VT(var) = %d\n", V_VT(&var));
1998 ok(!lstrcmpW(V_BSTR(&var), L"\nfunction toString() {\n [native code]\n}\n"),
1999 "V_BSTR(var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
2000 VariantClear(&var);
2001 todo_wine CHECK_CALLED(QS_IActiveScriptSite);
2002 todo_wine CHECK_CALLED(QS_GetCaller);
2004 IDispatchEx_Release(dispex);
2007 static void test_nextdispid(IDispatchEx *dispex)
2009 DISPID last_id = DISPID_STARTENUM, id, dyn_id;
2010 BSTR name;
2011 VARIANT var;
2012 HRESULT hres;
2014 name = SysAllocString(L"dynVal");
2015 hres = IDispatchEx_GetDispID(dispex, name, fdexNameCaseSensitive|fdexNameEnsure, &dyn_id);
2016 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2017 SysFreeString(name);
2019 V_VT(&var) = VT_EMPTY;
2020 hres = dispex_propput(dispex, dyn_id, 0, &var, NULL);
2021 ok(hres == S_OK, "dispex_propput failed: %08x\n", hres);
2023 while(last_id != dyn_id) {
2024 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, last_id, &id);
2025 ok(hres == S_OK, "GetNextDispID returned: %08x\n", hres);
2026 ok(id != DISPID_STARTENUM, "id == DISPID_STARTENUM\n");
2027 ok(id != DISPID_IOMNAVIGATOR_TOSTRING, "id == DISPID_IOMNAVIGATOR_TOSTRING\n");
2029 hres = IDispatchEx_GetMemberName(dispex, id, &name);
2030 ok(hres == S_OK, "GetMemberName failed: %08x\n", hres);
2032 if(id == dyn_id)
2033 ok(!lstrcmpW(name, L"dynVal"), "name = %s\n", wine_dbgstr_w(name));
2034 else if(id == DISPID_IOMNAVIGATOR_PLATFORM)
2035 ok(!lstrcmpW(name, L"platform"), "name = %s\n", wine_dbgstr_w(name));
2037 SysFreeString(name);
2038 last_id = id;
2041 hres = IDispatchEx_GetNextDispID(dispex, 0, id, &id);
2042 ok(hres == S_FALSE, "GetNextDispID returned: %08x\n", hres);
2043 ok(id == DISPID_STARTENUM, "id != DISPID_STARTENUM\n");
2046 static void test_global_id(void)
2048 VARIANT var;
2049 DISPPARAMS dp;
2050 EXCEPINFO ei;
2051 BSTR tmp;
2052 DISPID id;
2053 HRESULT hres;
2055 SET_EXPECT(GetScriptDispatch);
2056 SET_EXPECT(script_divid_d);
2057 tmp = SysAllocString(L"divid");
2058 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2059 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2060 SysFreeString(tmp);
2061 CHECK_CALLED(GetScriptDispatch);
2062 CHECK_CALLED(script_divid_d);
2064 VariantInit(&var);
2065 memset(&ei, 0, sizeof(ei));
2066 memset(&dp, 0, sizeof(dp));
2067 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
2068 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2069 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var) = %d\n", V_VT(&var));
2070 VariantClear(&var);
2073 static void test_arg_conv(IHTMLWindow2 *window)
2075 IHTMLDocument2 *doc;
2076 IDispatchEx *dispex;
2077 IHTMLElement *elem;
2078 VARIANT v;
2079 HRESULT hres;
2081 hres = IHTMLWindow2_get_document(window, &doc);
2082 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2084 hres = IHTMLDocument2_get_body(doc, &elem);
2085 IHTMLDocument2_Release(doc);
2086 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2088 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2089 IHTMLElement_Release(elem);
2090 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2092 SET_EXPECT(QS_VariantConversion);
2093 SET_EXPECT(ChangeType);
2094 V_VT(&v) = VT_I4;
2095 V_I4(&v) = 0xf0f0f0;
2096 hres = dispex_propput(dispex, DISPID_IHTMLBODYELEMENT_BACKGROUND, 0, &v, &caller_sp);
2097 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2098 CHECK_CALLED(QS_VariantConversion);
2099 CHECK_CALLED(ChangeType);
2101 V_VT(&v) = VT_EMPTY;
2102 hres = dispex_propget(dispex, DISPID_IHTMLBODYELEMENT_BGCOLOR, &v, &caller_sp);
2103 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2104 ok(V_VT(&v) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&v));
2105 ok(!V_BSTR(&v), "V_BSTR(&var) = %s\n", wine_dbgstr_w(V_BSTR(&v)));
2107 IDispatchEx_Release(dispex);
2110 #define test_elem_disabled(a,b) _test_elem_disabled(__LINE__,a,b)
2111 static void _test_elem_disabled(unsigned line, IHTMLElement *elem, VARIANT_BOOL exb)
2113 IHTMLElement3 *elem3;
2114 VARIANT_BOOL b = 100;
2115 HRESULT hres;
2117 hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLElement3, (void**)&elem3);
2118 ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLElement3 iface: %08x\n", hres);
2120 hres = IHTMLElement3_get_disabled(elem3, &b);
2121 ok_(__FILE__,line)(hres == S_OK, "get_disabled failed: %08x\n", hres);
2122 ok_(__FILE__,line)(b == exb, "disabled = %x, expected %x\n", b, exb);
2124 IHTMLElement3_Release(elem3);
2127 static void test_default_arg_conv(IHTMLWindow2 *window)
2129 IHTMLDocument2 *doc;
2130 IDispatchEx *dispex;
2131 IHTMLElement *elem;
2132 VARIANT v;
2133 HRESULT hres;
2135 hres = IHTMLWindow2_get_document(window, &doc);
2136 ok(hres == S_OK, "get_document failed: %08x\n", hres);
2138 hres = IHTMLDocument2_get_body(doc, &elem);
2139 IHTMLDocument2_Release(doc);
2140 ok(hres == S_OK, "get_body failed: %08x\n", hres);
2142 hres = IHTMLElement_QueryInterface(elem, &IID_IDispatchEx, (void**)&dispex);
2143 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2145 test_elem_disabled(elem, VARIANT_FALSE);
2147 V_VT(&v) = VT_BSTR;
2148 V_BSTR(&v) = SysAllocString(L"test");
2149 hres = dispex_propput(dispex, DISPID_IHTMLELEMENT3_DISABLED, 0, &v, NULL);
2150 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2151 SysFreeString(V_BSTR(&v));
2153 test_elem_disabled(elem, VARIANT_TRUE);
2155 V_VT(&v) = VT_I4;
2156 V_I4(&v) = 0;
2157 hres = dispex_propput(dispex, DISPID_IHTMLELEMENT3_DISABLED, 0, &v, NULL);
2158 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2160 test_elem_disabled(elem, VARIANT_FALSE);
2162 V_VT(&v) = VT_I4;
2163 V_I4(&v) = 1;
2164 hres = dispex_propput(dispex, DISPID_IHTMLELEMENT3_DISABLED, DISPATCH_PROPERTYPUTREF, &v, NULL);
2165 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2167 test_elem_disabled(elem, VARIANT_TRUE);
2169 IHTMLElement_Release(elem);
2170 IDispatchEx_Release(dispex);
2173 static void test_ui(void)
2175 IActiveScriptSiteUIControl *ui_control;
2176 SCRIPTUICHANDLING uic_handling = 10;
2177 HRESULT hres;
2179 hres = IActiveScriptSite_QueryInterface(site, &IID_IActiveScriptSiteUIControl, (void**)&ui_control);
2180 if(hres == E_NOINTERFACE) {
2181 win_skip("IActiveScriptSiteUIControl not supported\n");
2182 return;
2184 ok(hres == S_OK, "Could not get IActiveScriptSiteUIControl: %08x\n", hres);
2186 hres = IActiveScriptSiteUIControl_GetUIBehavior(ui_control, SCRIPTUICITEM_MSGBOX, &uic_handling);
2187 ok(hres == S_OK, "GetUIBehavior failed: %08x\n", hres);
2188 ok(uic_handling == SCRIPTUICHANDLING_ALLOW, "uic_handling = %d\n", uic_handling);
2190 IActiveScriptSiteUIControl_Release(ui_control);
2193 static void test_sp(void)
2195 IServiceProvider *sp;
2196 IUnknown *unk;
2197 HRESULT hres;
2199 hres = IActiveScriptSite_QueryInterface(site, &IID_IServiceProvider, (void**)&sp);
2200 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
2202 hres = IServiceProvider_QueryService(sp, &SID_SContainerDispatch, &IID_IHTMLDocument, (void**)&unk);
2203 ok(hres == S_OK, "Could not get SID_SContainerDispatch service: %08x\n", hres);
2204 IUnknown_Release(unk);
2206 IServiceProvider_Release(sp);
2209 static void test_script_run(void)
2211 IDispatchEx *document, *dispex;
2212 IHTMLWindow2 *window;
2213 IOmNavigator *navigator;
2214 IUnknown *unk;
2215 VARIANT var, arg;
2216 DISPPARAMS dp;
2217 EXCEPINFO ei;
2218 DISPID id;
2219 BSTR tmp;
2220 HRESULT hres;
2222 static const WCHAR documentW[] = {'d','o','c','u','m','e','n','t',0};
2223 static const WCHAR testW[] = {'t','e','s','t',0};
2224 static const WCHAR funcW[] = {'f','u','n','c',0};
2226 SET_EXPECT(GetScriptDispatch);
2228 tmp = SysAllocString(documentW);
2229 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2230 SysFreeString(tmp);
2231 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2232 ok(id == DISPID_IHTMLWINDOW2_DOCUMENT, "id=%x\n", id);
2234 CHECK_CALLED(GetScriptDispatch);
2236 VariantInit(&var);
2237 memset(&dp, 0, sizeof(dp));
2238 memset(&ei, 0, sizeof(ei));
2240 hres = IDispatchEx_InvokeEx(window_dispex, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2241 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2242 ok(V_VT(&var) == VT_DISPATCH, "V_VT(var)=%d\n", V_VT(&var));
2243 ok(V_DISPATCH(&var) != NULL, "V_DISPATCH(&var) == NULL\n");
2245 hres = IDispatch_QueryInterface(V_DISPATCH(&var), &IID_IDispatchEx, (void**)&document);
2246 VariantClear(&var);
2247 ok(hres == S_OK, "Could not get DispatchEx: %08x\n", hres);
2249 tmp = SysAllocString(testW);
2250 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
2251 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2252 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive | fdexNameImplicit, &id);
2253 ok(hres == DISP_E_UNKNOWNNAME, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres);
2254 SysFreeString(tmp);
2256 id = 0;
2257 tmp = SysAllocString(testW);
2258 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2259 SysFreeString(tmp);
2260 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2261 ok(id, "id == 0\n");
2263 V_VT(&var) = VT_I4;
2264 V_I4(&var) = 100;
2265 hres = dispex_propput(document, id, 0, &var, NULL);
2266 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2268 tmp = SysAllocString(testW);
2269 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive, &id);
2270 SysFreeString(tmp);
2271 ok(hres == S_OK, "GetDispID(document) failed: %08x\n", hres);
2273 hres = IDispatchEx_DeleteMemberByDispID(document, id);
2274 ok(hres == E_NOTIMPL, "DeleteMemberByDispID failed = %08x\n", hres);
2276 VariantInit(&var);
2277 memset(&dp, 0, sizeof(dp));
2278 memset(&ei, 0, sizeof(ei));
2279 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2280 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2281 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2282 ok(V_I4(&var) == 100, "V_I4(&var) = %d\n", V_I4(&var));
2284 V_VT(&var) = VT_I4;
2285 V_I4(&var) = 200;
2286 hres = dispex_propput(document, id, DISPATCH_PROPERTYPUTREF, &var, NULL);
2287 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2289 VariantInit(&var);
2290 memset(&dp, 0, sizeof(dp));
2291 memset(&ei, 0, sizeof(ei));
2292 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2293 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2294 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2295 ok(V_I4(&var) == 200, "V_I4(&var) = %d\n", V_I4(&var));
2297 memset(&dp, 0, sizeof(dp));
2298 memset(&ei, 0, sizeof(ei));
2299 V_VT(&var) = VT_I4;
2300 V_I4(&var) = 300;
2301 dp.cArgs = 1;
2302 dp.rgvarg = &var;
2303 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2304 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2306 VariantInit(&var);
2307 memset(&dp, 0, sizeof(dp));
2308 memset(&ei, 0, sizeof(ei));
2309 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2310 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2311 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2312 ok(V_I4(&var) == 300, "V_I4(&var) = %d\n", V_I4(&var));
2314 V_VT(&var) = VT_BSTR;
2315 V_BSTR(&var) = NULL;
2316 hres = dispex_propput(document, id, 0, &var, NULL);
2317 ok(hres == S_OK, "dispex_propput failed: %08x\n", hres);
2319 VariantInit(&var);
2320 memset(&dp, 0, sizeof(dp));
2321 memset(&ei, 0, sizeof(ei));
2322 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYGET, &dp, &var, &ei, NULL);
2323 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2324 ok(V_VT(&var) == VT_BSTR, "V_VT(var)=%d\n", V_VT(&var));
2325 ok(!V_BSTR(&var), "V_BSTR(&var) = %s\n", wine_dbgstr_w(V_BSTR(&var)));
2327 unk = (void*)0xdeadbeef;
2328 hres = IDispatchEx_GetNameSpaceParent(window_dispex, &unk);
2329 ok(hres == S_OK, "GetNameSpaceParent failed: %08x\n", hres);
2330 ok(!unk, "unk=%p, expected NULL\n", unk);
2332 id = 0;
2333 tmp = SysAllocString(funcW);
2334 hres = IDispatchEx_GetDispID(document, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2335 SysFreeString(tmp);
2336 ok(hres == S_OK, "GetDispID(func) failed: %08x\n", hres);
2337 ok(id, "id == 0\n");
2339 dp.cArgs = 1;
2340 dp.rgvarg = &var;
2341 dp.cNamedArgs = 0;
2342 dp.rgdispidNamedArgs = NULL;
2343 V_VT(&var) = VT_DISPATCH;
2344 V_DISPATCH(&var) = (IDispatch*)&funcDisp;
2345 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_PROPERTYPUT, &dp, NULL, &ei, NULL);
2346 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2348 VariantInit(&var);
2349 memset(&dp, 0, sizeof(dp));
2350 memset(&ei, 0, sizeof(ei));
2351 V_VT(&arg) = VT_BOOL;
2352 V_BOOL(&arg) = VARIANT_TRUE;
2353 dp.cArgs = 1;
2354 dp.rgvarg = &arg;
2356 SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_FALSE); /* IE11 */
2357 SET_EXPECT(funcDisp);
2358 hres = IDispatchEx_InvokeEx(document, id, LOCALE_NEUTRAL, INVOKE_FUNC, &dp, &var, &ei, NULL);
2359 todo_wine
2360 CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_FALSE); /* IE11 */
2361 CHECK_CALLED(funcDisp);
2363 ok(hres == S_OK, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres);
2364 ok(V_VT(&var) == VT_I4, "V_VT(var)=%d\n", V_VT(&var));
2365 ok(V_I4(&var) == 100, "V_I4(&var) == NULL\n");
2367 IDispatchEx_Release(document);
2369 hres = IDispatchEx_QueryInterface(window_dispex, &IID_IHTMLWindow2, (void**)&window);
2370 ok(hres == S_OK, "Could not get IHTMLWindow2 iface: %08x\n", hres);
2372 hres = IHTMLWindow2_get_navigator(window, &navigator);
2373 ok(hres == S_OK, "get_navigator failed: %08x\n", hres);
2375 hres = IOmNavigator_QueryInterface(navigator, &IID_IDispatchEx, (void**)&dispex);
2376 IOmNavigator_Release(navigator);
2377 ok(hres == S_OK, "Could not get IDispatchEx iface: %08x\n", hres);
2379 test_func(dispex);
2380 test_nextdispid(dispex);
2382 test_arg_conv(window);
2383 test_default_arg_conv(window);
2384 IHTMLWindow2_Release(window);
2386 tmp = SysAllocString(L"test");
2387 hres = IDispatchEx_DeleteMemberByName(dispex, tmp, fdexNameCaseSensitive);
2388 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2390 IDispatchEx_Release(dispex);
2392 script_disp = (IDispatch*)&scriptDisp;
2394 SET_EXPECT(GetScriptDispatch);
2395 SET_EXPECT(script_testprop_d);
2396 tmp = SysAllocString(L"testProp");
2397 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2398 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2399 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2400 CHECK_CALLED(GetScriptDispatch);
2401 CHECK_CALLED(script_testprop_d);
2402 SysFreeString(tmp);
2404 tmp = SysAllocString(L"testProp");
2405 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive, &id);
2406 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2407 ok(id != DISPID_SCRIPT_TESTPROP, "id == DISPID_SCRIPT_TESTPROP\n");
2408 SysFreeString(tmp);
2410 SET_EXPECT(GetScriptDispatch);
2411 SET_EXPECT(script_testprop_i);
2412 memset(&ei, 0, sizeof(ei));
2413 memset(&dp, 0, sizeof(dp));
2414 hres = IDispatchEx_InvokeEx(window_dispex, id, 0, DISPATCH_PROPERTYGET, &dp, &var, &ei, NULL);
2415 ok(hres == S_OK, "InvokeEx failed: %08x\n", hres);
2416 ok(V_VT(&var) == VT_NULL, "V_VT(var) = %d\n", V_VT(&var));
2417 CHECK_CALLED(GetScriptDispatch);
2418 CHECK_CALLED(script_testprop_i);
2420 SET_EXPECT(GetScriptDispatch);
2421 SET_EXPECT(script_testprop2_d);
2422 tmp = SysAllocString(L"testProp2");
2423 hres = IDispatchEx_GetDispID(window_dispex, tmp, fdexNameCaseSensitive|fdexNameEnsure, &id);
2424 ok(hres == S_OK, "GetDispID failed: %08x\n", hres);
2425 ok(id != DISPID_SCRIPT_TESTPROP2, "id == DISPID_SCRIPT_TESTPROP2\n");
2426 CHECK_CALLED(GetScriptDispatch);
2427 CHECK_CALLED(script_testprop2_d);
2428 SysFreeString(tmp);
2430 tmp = SysAllocString(L"test");
2431 hres = IDispatchEx_DeleteMemberByName(window_dispex, tmp, fdexNameCaseSensitive);
2432 ok(hres == E_NOTIMPL, "DeleteMemberByName failed: %08x\n", hres);
2434 test_global_id();
2436 test_security();
2437 test_ui();
2438 test_sp();
2441 static HRESULT WINAPI ActiveScriptParse_ParseScriptText(IActiveScriptParse *iface,
2442 LPCOLESTR pstrCode, LPCOLESTR pstrItemName, IUnknown *punkContext,
2443 LPCOLESTR pstrDelimiter, CTXARG_T dwSourceContextCookie, ULONG ulStartingLine,
2444 DWORD dwFlags, VARIANT *pvarResult, EXCEPINFO *pexcepinfo)
2446 ok(pvarResult != NULL, "pvarResult == NULL\n");
2447 ok(pexcepinfo != NULL, "pexcepinfo == NULL\n");
2449 if(!lstrcmpW(pstrCode, L"execScript call")) {
2450 CHECK_EXPECT(ParseScriptText_execScript);
2451 ok(!pstrItemName, "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2452 ok(!lstrcmpW(pstrDelimiter, L"\""), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2453 ok(dwFlags == SCRIPTTEXT_ISVISIBLE, "dwFlags = %x\n", dwFlags);
2455 V_VT(pvarResult) = VT_I4;
2456 V_I4(pvarResult) = 10;
2457 return S_OK;
2458 }else if(!lstrcmpW(pstrCode, L"simple script")) {
2459 CHECK_EXPECT(ParseScriptText_script);
2460 ok(!lstrcmpW(pstrItemName, L"window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2461 ok(!lstrcmpW(pstrDelimiter, L"</SCRIPT>"), "pstrDelimiter = %s\n", wine_dbgstr_w(pstrDelimiter));
2462 ok(dwFlags == (SCRIPTTEXT_ISVISIBLE|SCRIPTTEXT_HOSTMANAGESSOURCE), "dwFlags = %x\n", dwFlags);
2464 test_script_run();
2465 return S_OK;
2468 ok(0, "unexpected script %s\n", wine_dbgstr_w(pstrCode));
2469 return E_FAIL;
2472 static const IActiveScriptParseVtbl ActiveScriptParseVtbl = {
2473 ActiveScriptParse_QueryInterface,
2474 ActiveScriptParse_AddRef,
2475 ActiveScriptParse_Release,
2476 ActiveScriptParse_InitNew,
2477 ActiveScriptParse_AddScriptlet,
2478 ActiveScriptParse_ParseScriptText
2481 static IActiveScriptParse ActiveScriptParse = { &ActiveScriptParseVtbl };
2483 static HRESULT WINAPI ActiveScript_QueryInterface(IActiveScript *iface, REFIID riid, void **ppv)
2485 *ppv = NULL;
2487 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IActiveScript, riid)) {
2488 *ppv = iface;
2489 return S_OK;
2492 if(IsEqualGUID(&IID_IActiveScriptParse, riid)) {
2493 *ppv = &ActiveScriptParse;
2494 return S_OK;
2497 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2, riid)) {
2498 *ppv = &ActiveScriptParseProcedure;
2499 return S_OK;
2502 if(IsEqualGUID(&IID_IActiveScriptProperty, riid)) {
2503 *ppv = &ActiveScriptProperty;
2504 return S_OK;
2507 if(IsEqualGUID(&IID_IObjectSafety, riid)) {
2508 *ppv = &ObjectSafety;
2509 return S_OK;
2512 if(IsEqualGUID(&IID_IActiveScriptDebug, riid))
2513 return E_NOINTERFACE;
2515 trace("QI(%s)\n", wine_dbgstr_guid(riid));
2516 return E_NOINTERFACE;
2519 static ULONG WINAPI ActiveScript_AddRef(IActiveScript *iface)
2521 return 2;
2524 static ULONG WINAPI ActiveScript_Release(IActiveScript *iface)
2526 return 1;
2529 static HRESULT WINAPI ActiveScript_SetScriptSite(IActiveScript *iface, IActiveScriptSite *pass)
2531 IActiveScriptSiteInterruptPoll *poll;
2532 IActiveScriptSiteDebug *debug;
2533 IServiceProvider *service;
2534 ICanHandleException *canexception;
2535 LCID lcid;
2536 HRESULT hres;
2538 CHECK_EXPECT(SetScriptSite);
2540 ok(pass != NULL, "pass == NULL\n");
2542 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteInterruptPoll, (void**)&poll);
2543 ok(hres == S_OK, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres);
2544 if(SUCCEEDED(hres))
2545 IActiveScriptSiteInterruptPoll_Release(poll);
2547 hres = IActiveScriptSite_GetLCID(pass, &lcid);
2548 ok(hres == S_OK, "GetLCID failed: %08x\n", hres);
2550 hres = IActiveScriptSite_OnStateChange(pass, (state = SCRIPTSTATE_INITIALIZED));
2551 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2553 hres = IActiveScriptSite_QueryInterface(pass, &IID_IActiveScriptSiteDebug, (void**)&debug);
2554 ok(hres == S_OK, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres);
2555 if(SUCCEEDED(hres))
2556 IActiveScriptSiteDebug_Release(debug);
2558 hres = IActiveScriptSite_QueryInterface(pass, &IID_ICanHandleException, (void**)&canexception);
2559 ok(hres == E_NOINTERFACE, "Could not get IID_ICanHandleException interface: %08x\n", hres);
2561 hres = IActiveScriptSite_QueryInterface(pass, &IID_IServiceProvider, (void**)&service);
2562 ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);
2563 if(SUCCEEDED(hres))
2564 IServiceProvider_Release(service);
2566 site = pass;
2567 IActiveScriptSite_AddRef(site);
2568 return S_OK;
2571 static HRESULT WINAPI ActiveScript_GetScriptSite(IActiveScript *iface, REFIID riid,
2572 void **ppvObject)
2574 ok(0, "unexpected call\n");
2575 return E_NOTIMPL;
2578 static HRESULT WINAPI ActiveScript_SetScriptState(IActiveScript *iface, SCRIPTSTATE ss)
2580 HRESULT hres;
2582 switch(ss) {
2583 case SCRIPTSTATE_STARTED:
2584 CHECK_EXPECT(SetScriptState_STARTED);
2585 break;
2586 case SCRIPTSTATE_CONNECTED:
2587 CHECK_EXPECT(SetScriptState_CONNECTED);
2588 break;
2589 case SCRIPTSTATE_DISCONNECTED:
2590 CHECK_EXPECT(SetScriptState_DISCONNECTED);
2591 break;
2592 default:
2593 ok(0, "unexpected state %d\n", ss);
2594 return E_NOTIMPL;
2597 hres = IActiveScriptSite_OnStateChange(site, (state = ss));
2598 ok(hres == S_OK, "OnStateChange failed: %08x\n", hres);
2600 return S_OK;
2603 static HRESULT WINAPI ActiveScript_GetScriptState(IActiveScript *iface, SCRIPTSTATE *pssState)
2605 CHECK_EXPECT(GetScriptState);
2607 *pssState = state;
2608 return S_OK;
2611 static HRESULT WINAPI ActiveScript_Close(IActiveScript *iface)
2613 CHECK_EXPECT(Close);
2614 return E_NOTIMPL;
2617 static HRESULT WINAPI ActiveScript_AddNamedItem(IActiveScript *iface,
2618 LPCOLESTR pstrName, DWORD dwFlags)
2620 IDispatch *disp;
2621 IUnknown *unk = NULL, *unk2;
2622 HRESULT hres;
2624 static const WCHAR windowW[] = {'w','i','n','d','o','w',0};
2626 static const IID unknown_iid = {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
2628 CHECK_EXPECT(AddNamedItem);
2630 ok(!lstrcmpW(pstrName, windowW), "pstrName=%s\n", wine_dbgstr_w(pstrName));
2631 ok(dwFlags == (SCRIPTITEM_ISVISIBLE|SCRIPTITEM_ISSOURCE|SCRIPTITEM_GLOBALMEMBERS), "dwFlags=%x\n", dwFlags);
2633 hres = IActiveScriptSite_GetItemInfo(site, windowW, SCRIPTINFO_IUNKNOWN, &unk, NULL);
2634 ok(hres == S_OK, "GetItemInfo failed: %08x\n", hres);
2635 ok(unk != NULL, "unk == NULL\n");
2637 hres = IUnknown_QueryInterface(unk, &IID_IDispatch, (void**)&disp);
2638 ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
2639 if(SUCCEEDED(hres))
2640 IDispatch_Release(disp);
2642 hres = IUnknown_QueryInterface(unk, &unknown_iid, (void**)&unk2);
2643 ok(hres == E_NOINTERFACE, "Got ?? interface: %p\n", unk2);
2644 if(SUCCEEDED(hres))
2645 IUnknown_Release(unk2);
2647 hres = IUnknown_QueryInterface(unk, &IID_IDispatchEx, (void**)&window_dispex);
2648 ok(hres == S_OK, "Could not get IDispatchEx interface: %08x\n", hres);
2650 IUnknown_Release(unk);
2651 return S_OK;
2654 static HRESULT WINAPI ActiveScript_AddTypeLib(IActiveScript *iface, REFGUID rguidTypeLib,
2655 DWORD dwMajor, DWORD dwMinor, DWORD dwFlags)
2657 ok(0, "unexpected call\n");
2658 return E_NOTIMPL;
2661 static HRESULT WINAPI ActiveScript_GetScriptDispatch(IActiveScript *iface, LPCOLESTR pstrItemName,
2662 IDispatch **ppdisp)
2664 CHECK_EXPECT(GetScriptDispatch);
2666 ok(!lstrcmpW(pstrItemName, L"window"), "pstrItemName = %s\n", wine_dbgstr_w(pstrItemName));
2668 if(!script_disp)
2669 return E_NOTIMPL;
2671 *ppdisp = script_disp;
2672 return S_OK;
2675 static HRESULT WINAPI ActiveScript_GetCurrentScriptThreadID(IActiveScript *iface,
2676 SCRIPTTHREADID *pstridThread)
2678 ok(0, "unexpected call\n");
2679 return E_NOTIMPL;
2682 static HRESULT WINAPI ActiveScript_GetScriptThreadID(IActiveScript *iface,
2683 DWORD dwWin32ThreadId, SCRIPTTHREADID *pstidThread)
2685 ok(0, "unexpected call\n");
2686 return E_NOTIMPL;
2689 static HRESULT WINAPI ActiveScript_GetScriptThreadState(IActiveScript *iface,
2690 SCRIPTTHREADID stidThread, SCRIPTTHREADSTATE *pstsState)
2692 ok(0, "unexpected call\n");
2693 return E_NOTIMPL;
2696 static HRESULT WINAPI ActiveScript_InterruptScriptThread(IActiveScript *iface,
2697 SCRIPTTHREADID stidThread, const EXCEPINFO *pexcepinfo, DWORD dwFlags)
2699 ok(0, "unexpected call\n");
2700 return E_NOTIMPL;
2703 static HRESULT WINAPI ActiveScript_Clone(IActiveScript *iface, IActiveScript **ppscript)
2705 ok(0, "unexpected call\n");
2706 return E_NOTIMPL;
2709 static const IActiveScriptVtbl ActiveScriptVtbl = {
2710 ActiveScript_QueryInterface,
2711 ActiveScript_AddRef,
2712 ActiveScript_Release,
2713 ActiveScript_SetScriptSite,
2714 ActiveScript_GetScriptSite,
2715 ActiveScript_SetScriptState,
2716 ActiveScript_GetScriptState,
2717 ActiveScript_Close,
2718 ActiveScript_AddNamedItem,
2719 ActiveScript_AddTypeLib,
2720 ActiveScript_GetScriptDispatch,
2721 ActiveScript_GetCurrentScriptThreadID,
2722 ActiveScript_GetScriptThreadID,
2723 ActiveScript_GetScriptThreadState,
2724 ActiveScript_InterruptScriptThread,
2725 ActiveScript_Clone
2728 static IActiveScript ActiveScript = { &ActiveScriptVtbl };
2730 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
2732 *ppv = NULL;
2734 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
2735 *ppv = iface;
2736 return S_OK;
2739 if(IsEqualGUID(&IID_IMarshal, riid))
2740 return E_NOINTERFACE;
2741 if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
2742 return E_NOINTERFACE;
2744 ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
2745 return E_NOTIMPL;
2748 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
2750 return 2;
2753 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
2755 return 1;
2758 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
2760 CHECK_EXPECT(CreateInstance);
2762 ok(!outer, "outer = %p\n", outer);
2763 ok(IsEqualGUID(&IID_IActiveScript, riid), "unexpected riid %s\n", wine_dbgstr_guid(riid));
2764 *ppv = &ActiveScript;
2765 return S_OK;
2768 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
2770 ok(0, "unexpected call\n");
2771 return S_OK;
2774 static const IClassFactoryVtbl ClassFactoryVtbl = {
2775 ClassFactory_QueryInterface,
2776 ClassFactory_AddRef,
2777 ClassFactory_Release,
2778 ClassFactory_CreateInstance,
2779 ClassFactory_LockServer
2782 static IClassFactory script_cf = { &ClassFactoryVtbl };
2784 typedef struct {
2785 IInternetProtocolEx IInternetProtocolEx_iface;
2786 IWinInetHttpInfo IWinInetHttpInfo_iface;
2788 LONG ref;
2790 IInternetProtocolSink *sink;
2791 BINDINFO bind_info;
2793 IStream *stream;
2794 char *data;
2795 size_t size;
2796 char *ptr;
2798 IUri *uri;
2799 } ProtocolHandler;
2801 static void report_data(ProtocolHandler *This)
2803 IServiceProvider *service_provider;
2804 IHttpNegotiate *http_negotiate;
2805 WCHAR *addl_headers = NULL;
2806 BSTR headers, url;
2807 HRESULT hres;
2809 static const WCHAR emptyW[] = {0};
2811 hres = IInternetProtocolSink_QueryInterface(This->sink, &IID_IServiceProvider, (void**)&service_provider);
2812 ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
2814 hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate, &IID_IHttpNegotiate, (void**)&http_negotiate);
2815 IServiceProvider_Release(service_provider);
2816 ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);
2818 hres = IUri_GetDisplayUri(This->uri, &url);
2819 ok(hres == S_OK, "Failed to get display uri: %08x\n", hres);
2820 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, url, emptyW, 0, &addl_headers);
2821 ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
2822 SysFreeString(url);
2824 CoTaskMemFree(addl_headers);
2826 headers = SysAllocString(L"HTTP/1.1 200 OK\r\n\r\n");
2827 hres = IHttpNegotiate_OnResponse(http_negotiate, 200, headers, NULL, NULL);
2828 ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2829 SysFreeString(headers);
2831 IHttpNegotiate_Release(http_negotiate);
2833 hres = IInternetProtocolSink_ReportData(This->sink, BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION,
2834 This->size, This->size);
2835 ok(hres == S_OK, "ReportData failed: %08x\n", hres);
2837 hres = IInternetProtocolSink_ReportResult(This->sink, S_OK, 0, NULL);
2838 ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
2841 typedef struct js_stream_t {
2842 struct js_stream_t *next;
2843 ProtocolHandler *protocol_handler;
2844 WCHAR name[1];
2845 } js_stream_t;
2847 static js_stream_t *registered_stream_list;
2849 static void register_stream(ProtocolHandler *protocol_handler, const WCHAR *name)
2851 js_stream_t *stream;
2852 size_t len;
2854 len = lstrlenW(name)+1;
2855 stream = HeapAlloc(GetProcessHeap(), 0, offsetof(js_stream_t, name[len+1]));
2857 IInternetProtocolEx_AddRef(&protocol_handler->IInternetProtocolEx_iface);
2858 stream->protocol_handler = protocol_handler;
2859 memcpy(stream->name, name, len*sizeof(WCHAR));
2861 stream->next = registered_stream_list;
2862 registered_stream_list = stream;
2865 static void free_registered_streams(void)
2867 js_stream_t *iter;
2869 while((iter = registered_stream_list)) {
2870 ok(!iter->protocol_handler, "protocol handler still pending for %s\n", wine_dbgstr_w(iter->name));
2871 if(iter->protocol_handler)
2872 IInternetProtocolEx_Release(&iter->protocol_handler->IInternetProtocolEx_iface);
2874 registered_stream_list = iter->next;
2875 HeapFree(GetProcessHeap(), 0, iter);
2879 static DWORD WINAPI async_switch_proc(void *arg)
2881 PROTOCOLDATA protocol_data = {PI_FORCE_ASYNC};
2882 ProtocolHandler *protocol_handler = arg;
2884 IInternetProtocolSink_Switch(protocol_handler->sink, &protocol_data);
2885 return 0;
2888 static void async_switch(ProtocolHandler *protocol_handler)
2890 IInternetProtocolEx_AddRef(&protocol_handler->IInternetProtocolEx_iface);
2891 QueueUserWorkItem(async_switch_proc, protocol_handler, 0);
2894 static void stream_write(const WCHAR *name, const WCHAR *data)
2896 ProtocolHandler *protocol_handler;
2897 LARGE_INTEGER large_zero;
2898 js_stream_t *stream;
2899 HRESULT hres;
2901 static const BYTE bom_utf16[] = {0xff,0xfe};
2903 for(stream = registered_stream_list; stream; stream = stream->next) {
2904 if(!lstrcmpW(stream->name, name))
2905 break;
2907 ok(stream != NULL, "stream %s not found\n", wine_dbgstr_w(name));
2908 if(!stream)
2909 return;
2911 protocol_handler = stream->protocol_handler;
2912 ok(protocol_handler != NULL, "protocol_handler is NULL\n");
2913 if(!protocol_handler)
2914 return;
2915 stream->protocol_handler = NULL;
2917 hres = CreateStreamOnHGlobal(NULL, TRUE, &protocol_handler->stream);
2918 ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
2920 hres = IStream_Write(protocol_handler->stream, bom_utf16, sizeof(bom_utf16), NULL);
2921 ok(hres == S_OK, "Write failed: %08x\n", hres);
2923 hres = IStream_Write(protocol_handler->stream, data, lstrlenW(data)*sizeof(WCHAR), NULL);
2924 ok(hres == S_OK, "Write failed: %08x\n", hres);
2926 U(large_zero).QuadPart = 0;
2927 hres = IStream_Seek(protocol_handler->stream, large_zero, STREAM_SEEK_SET, NULL);
2928 ok(hres == S_OK, "Seek failed: %08x\n", hres);
2930 async_switch(protocol_handler);
2931 IInternetProtocolEx_Release(&protocol_handler->IInternetProtocolEx_iface);
2934 static char index_html_data[4096];
2936 static inline ProtocolHandler *impl_from_IInternetProtocolEx(IInternetProtocolEx *iface)
2938 return CONTAINING_RECORD(iface, ProtocolHandler, IInternetProtocolEx_iface);
2941 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv)
2943 ProtocolHandler *This = impl_from_IInternetProtocolEx(iface);
2945 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid) || IsEqualGUID(&IID_IInternetProtocolEx, riid)) {
2946 *ppv = &This->IInternetProtocolEx_iface;
2947 }else if(IsEqualGUID(&IID_IWinInetInfo, riid) || IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
2948 *ppv = &This->IWinInetHttpInfo_iface;
2949 }else {
2950 *ppv = NULL;
2951 return E_NOINTERFACE;
2954 IUnknown_AddRef((IUnknown*)*ppv);
2955 return S_OK;
2958 static ULONG WINAPI Protocol_AddRef(IInternetProtocolEx *iface)
2960 ProtocolHandler *This = impl_from_IInternetProtocolEx(iface);
2961 return InterlockedIncrement(&This->ref);
2964 static ULONG WINAPI Protocol_Release(IInternetProtocolEx *iface)
2966 ProtocolHandler *This = impl_from_IInternetProtocolEx(iface);
2967 LONG ref = InterlockedDecrement(&This->ref);
2969 if(!ref) {
2970 if(This->sink)
2971 IInternetProtocolSink_Release(This->sink);
2972 if(This->stream)
2973 IStream_Release(This->stream);
2974 if(This->uri)
2975 IUri_Release(This->uri);
2976 ReleaseBindInfo(&This->bind_info);
2977 HeapFree(GetProcessHeap(), 0, This);
2980 return ref;
2983 static HRESULT WINAPI Protocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink,
2984 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved)
2986 ok(0, "unexpected call\n");
2987 return E_NOTIMPL;
2990 static HRESULT WINAPI Protocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData)
2992 ProtocolHandler *This = impl_from_IInternetProtocolEx(iface);
2993 report_data(This);
2994 IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
2995 return S_OK;
2998 static HRESULT WINAPI Protocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason, DWORD dwOptions)
3000 trace("Abort(%08x %x)\n", hrReason, dwOptions);
3001 return E_NOTIMPL;
3004 static HRESULT WINAPI Protocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions)
3006 return S_OK;
3009 static HRESULT WINAPI Protocol_Suspend(IInternetProtocolEx *iface)
3011 ok(0, "unexpected call\n");
3012 return E_NOTIMPL;
3015 static HRESULT WINAPI Protocol_Resume(IInternetProtocolEx *iface)
3017 ok(0, "unexpected call\n");
3018 return E_NOTIMPL;
3021 static HRESULT WINAPI Protocol_Read(IInternetProtocolEx *iface, void *pv, ULONG cb, ULONG *pcbRead)
3023 ProtocolHandler *This = impl_from_IInternetProtocolEx(iface);
3024 ULONG read;
3025 HRESULT hres;
3027 if(This->stream) {
3028 hres = IStream_Read(This->stream, pv, cb, &read);
3029 ok(SUCCEEDED(hres), "Read failed: %08x\n", hres);
3030 if(FAILED(hres))
3031 return hres;
3032 if(pcbRead)
3033 *pcbRead = read;
3034 return read ? S_OK : S_FALSE;
3037 read = This->size - (This->ptr - This->data);
3038 if(read > cb)
3039 read = cb;
3041 if(read) {
3042 memcpy(pv, This->ptr, read);
3043 This->ptr += read;
3046 *pcbRead = read;
3047 return This->ptr == This->data+This->size ? S_FALSE : S_OK;
3050 static HRESULT WINAPI Protocol_Seek(IInternetProtocolEx *iface,
3051 LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
3053 ok(0, "unexpected call\n");
3054 return E_NOTIMPL;
3057 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions)
3059 return S_OK;
3062 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocolEx *iface)
3064 return S_OK;
3067 static HRESULT WINAPI ProtocolEx_StartEx(IInternetProtocolEx *iface, IUri *uri, IInternetProtocolSink *pOIProtSink,
3068 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE *dwReserved)
3070 ProtocolHandler *This = impl_from_IInternetProtocolEx(iface);
3071 BOOL block = FALSE;
3072 DWORD bindf;
3073 BSTR path;
3074 HRSRC src;
3075 HRESULT hres;
3077 static const WCHAR empty_prefixW[] = {'/','e','m','p','t','y'};
3079 hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &This->bind_info);
3080 ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
3082 hres = IUri_GetPath(uri, &path);
3083 if(FAILED(hres))
3084 return hres;
3086 if(!lstrcmpW(path, L"/index.html")) {
3087 This->data = index_html_data;
3088 This->size = strlen(This->data);
3089 }else if(!lstrcmpW(path, L"/echo.php")) {
3090 ok(This->bind_info.dwBindVerb == BINDVERB_POST, "unexpected bind verb %d\n", This->bind_info.dwBindVerb == BINDVERB_POST);
3091 todo_wine ok(This->bind_info.stgmedData.tymed == TYMED_ISTREAM, "tymed = %x\n", This->bind_info.stgmedData.tymed);
3092 switch(This->bind_info.stgmedData.tymed) {
3093 case TYMED_HGLOBAL:
3094 This->size = This->bind_info.cbstgmedData;
3095 This->data = U(This->bind_info.stgmedData).hGlobal;
3096 break;
3097 case TYMED_ISTREAM:
3098 This->stream = U(This->bind_info.stgmedData).pstm;
3099 IStream_AddRef(This->stream);
3100 break;
3101 default:
3102 ok(0, "unexpected tymed %d\n", This->bind_info.stgmedData.tymed);
3104 }else if(!lstrcmpW(path, L"/jsstream.php")) {
3105 BSTR query;
3107 hres = IUri_GetQuery(uri, &query);
3108 ok(hres == S_OK, "GetQuery failed: %08x\n", hres);
3109 ok(SysStringLen(query) > 1 && *query == '?', "unexpected query %s\n", wine_dbgstr_w(query));
3110 register_stream(This, query+1);
3111 SysFreeString(query);
3112 block = TRUE;
3113 }else if(SysStringLen(path) >= ARRAY_SIZE(empty_prefixW) && !memcmp(path, empty_prefixW, sizeof(empty_prefixW))) {
3114 static char empty_data[] = " ";
3115 This->data = empty_data;
3116 This->size = strlen(This->data);
3117 }else {
3118 src = FindResourceW(NULL, *path == '/' ? path+1 : path, (const WCHAR*)RT_HTML);
3119 ok(src != NULL, "Could not find resource for path %s\n", wine_dbgstr_w(path));
3120 if(src) {
3121 This->size = SizeofResource(NULL, src);
3122 This->data = LoadResource(NULL, src);
3123 }else {
3124 hres = E_FAIL;
3128 SysFreeString(path);
3129 if(FAILED(hres))
3130 return hres;
3132 IInternetProtocolSink_AddRef(This->sink = pOIProtSink);
3133 IUri_AddRef(This->uri = uri);
3135 This->ptr = This->data;
3136 if(!block)
3137 async_switch(This);
3138 return E_PENDING;
3141 static const IInternetProtocolExVtbl ProtocolExVtbl = {
3142 Protocol_QueryInterface,
3143 Protocol_AddRef,
3144 Protocol_Release,
3145 Protocol_Start,
3146 Protocol_Continue,
3147 Protocol_Abort,
3148 Protocol_Terminate,
3149 Protocol_Suspend,
3150 Protocol_Resume,
3151 Protocol_Read,
3152 Protocol_Seek,
3153 Protocol_LockRequest,
3154 Protocol_UnlockRequest,
3155 ProtocolEx_StartEx
3158 static inline ProtocolHandler *impl_from_IWinInetHttpInfo(IWinInetHttpInfo *iface)
3160 return CONTAINING_RECORD(iface, ProtocolHandler, IWinInetHttpInfo_iface);
3163 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
3165 ProtocolHandler *This = impl_from_IWinInetHttpInfo(iface);
3166 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv);
3169 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
3171 ProtocolHandler *This = impl_from_IWinInetHttpInfo(iface);
3172 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface);
3175 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
3177 ProtocolHandler *This = impl_from_IWinInetHttpInfo(iface);
3178 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface);
3181 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
3182 void *pBuffer, DWORD *pcbBuffer)
3184 return E_NOTIMPL;
3187 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
3188 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
3190 return E_NOTIMPL;
3193 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
3194 HttpInfo_QueryInterface,
3195 HttpInfo_AddRef,
3196 HttpInfo_Release,
3197 HttpInfo_QueryOption,
3198 HttpInfo_QueryInfo
3201 static HRESULT WINAPI ProtocolCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
3203 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
3204 *ppv = iface;
3205 return S_OK;
3208 *ppv = NULL;
3209 return E_NOINTERFACE;
3212 static HRESULT WINAPI ProtocolCF_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
3214 ProtocolHandler *protocol;
3215 HRESULT hres;
3217 protocol = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*protocol));
3218 protocol->IInternetProtocolEx_iface.lpVtbl = &ProtocolExVtbl;
3219 protocol->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
3220 protocol->ref = 1;
3221 protocol->bind_info.cbSize = sizeof(protocol->bind_info);
3223 hres = IInternetProtocolEx_QueryInterface(&protocol->IInternetProtocolEx_iface, riid, ppv);
3224 IInternetProtocolEx_Release(&protocol->IInternetProtocolEx_iface);
3225 return hres;
3228 static const IClassFactoryVtbl ProtocolCFVtbl = {
3229 ProtocolCF_QueryInterface,
3230 ClassFactory_AddRef,
3231 ClassFactory_Release,
3232 ProtocolCF_CreateInstance,
3233 ClassFactory_LockServer
3236 static IClassFactory protocol_cf = { &ProtocolCFVtbl };
3238 static const char simple_script_str[] =
3239 "<html><head></head><body>"
3240 "<div id=\"divid\"></div>"
3241 "<script language=\"TestScript\">simple script</script>"
3242 "</body></html>";
3244 static void test_exec_script(IHTMLDocument2 *doc, const WCHAR *codew, const WCHAR *langw)
3246 IHTMLWindow2 *window;
3247 BSTR code, lang;
3248 VARIANT v;
3249 HRESULT hres;
3251 hres = IHTMLDocument2_get_parentWindow(doc, &window);
3252 ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3254 code = SysAllocString(codew);
3255 lang = SysAllocString(langw);
3257 SET_EXPECT(ParseScriptText_execScript);
3258 hres = IHTMLWindow2_execScript(window, code, lang, &v);
3259 ok(hres == S_OK, "execScript failed: %08x\n", hres);
3260 ok(V_VT(&v) == VT_I4, "V_VT(v) = %d\n", V_VT(&v));
3261 ok(V_I4(&v) == 10, "V_I4(v) = %d\n", V_I4(&v));
3262 CHECK_CALLED(ParseScriptText_execScript);
3263 SysFreeString(lang);
3265 lang = SysAllocString(L"invalid");
3266 V_VT(&v) = 100;
3267 hres = IHTMLWindow2_execScript(window, code, lang, &v);
3268 ok(hres == CO_E_CLASSSTRING, "execScript failed: %08x, expected CO_E_CLASSSTRING\n", hres);
3269 ok(V_VT(&v) == 100, "V_VT(v) = %d\n", V_VT(&v));
3270 SysFreeString(lang);
3271 SysFreeString(code);
3273 IHTMLWindow2_Release(window);
3276 static void test_simple_script(void)
3278 IHTMLDocument2 *doc;
3280 doc = create_document();
3281 if(!doc)
3282 return;
3284 SET_EXPECT(CreateInstance);
3285 SET_EXPECT(GetInterfaceSafetyOptions);
3286 SET_EXPECT(SetInterfaceSafetyOptions);
3287 SET_EXPECT(SetProperty_INVOKEVERSIONING); /* IE8 */
3288 SET_EXPECT(SetProperty_HACK_TRIDENTEVENTSINK);
3289 SET_EXPECT(InitNew);
3290 SET_EXPECT(SetScriptSite);
3291 SET_EXPECT(GetScriptState);
3292 SET_EXPECT(SetScriptState_STARTED);
3293 SET_EXPECT(AddNamedItem);
3294 SET_EXPECT(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_TRUE); /* IE8 */
3295 SET_EXPECT(ParseScriptText_script);
3296 SET_EXPECT(SetScriptState_CONNECTED);
3298 load_doc(doc, simple_script_str);
3300 CHECK_CALLED(CreateInstance);
3301 CHECK_CALLED(GetInterfaceSafetyOptions);
3302 CHECK_CALLED(SetInterfaceSafetyOptions);
3303 CHECK_CALLED_BROKEN(SetProperty_INVOKEVERSIONING); /* IE8 */
3304 CHECK_CALLED(SetProperty_HACK_TRIDENTEVENTSINK);
3305 CHECK_CALLED(InitNew);
3306 CHECK_CALLED(SetScriptSite);
3307 CHECK_CALLED(GetScriptState);
3308 CHECK_CALLED(SetScriptState_STARTED);
3309 CHECK_CALLED(AddNamedItem);
3310 CHECK_CALLED_BROKEN(SetProperty_ABBREVIATE_GLOBALNAME_RESOLUTION_TRUE); /* IE8 */
3311 CHECK_CALLED(ParseScriptText_script);
3312 CHECK_CALLED(SetScriptState_CONNECTED);
3314 test_exec_script(doc, L"execScript call", L"TestScript");
3316 if(site)
3317 IActiveScriptSite_Release(site);
3318 if(window_dispex)
3319 IDispatchEx_Release(window_dispex);
3321 SET_EXPECT(SetScriptState_DISCONNECTED);
3322 SET_EXPECT(Close);
3324 IHTMLDocument2_Release(doc);
3326 CHECK_CALLED(SetScriptState_DISCONNECTED);
3327 CHECK_CALLED(Close);
3330 static void run_from_moniker(IMoniker *mon)
3332 IPersistMoniker *persist;
3333 IHTMLDocument2 *doc;
3334 MSG msg;
3335 HRESULT hres;
3337 doc = create_document();
3338 if(!doc)
3339 return;
3341 set_client_site(doc, TRUE);
3342 do_advise(doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
3344 hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker, (void**)&persist);
3345 ok(hres == S_OK, "Could not get IPersistMoniker iface: %08x\n", hres);
3347 hres = IPersistMoniker_Load(persist, FALSE, mon, NULL, 0);
3348 ok(hres == S_OK, "Load failed: %08x\n", hres);
3350 IPersistMoniker_Release(persist);
3352 SET_EXPECT(external_success);
3354 while(!called_external_success && GetMessageW(&msg, NULL, 0, 0)) {
3355 TranslateMessage(&msg);
3356 DispatchMessageW(&msg);
3359 CHECK_CALLED(external_success);
3361 free_registered_streams();
3362 set_client_site(doc, FALSE);
3363 IHTMLDocument2_Release(doc);
3366 static void run_js_script(const char *test_name)
3368 WCHAR url[INTERNET_MAX_URL_LENGTH] = {'r','e','s',':','/','/'}, *ptr;
3369 IMoniker *mon;
3370 HRESULT hres;
3372 trace("running %s...\n", test_name);
3374 ptr = url + lstrlenW(url);
3375 ptr += GetModuleFileNameW(NULL, ptr, url + ARRAY_SIZE(url) - ptr);
3376 *ptr++ = '/';
3377 MultiByteToWideChar(CP_ACP, 0, test_name, -1, ptr, url + ARRAY_SIZE(url) - ptr);
3379 hres = CreateURLMoniker(NULL, url, &mon);
3380 ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
3381 run_from_moniker(mon);
3383 IMoniker_Release(mon);
3386 static void run_from_path(const WCHAR *path, const char *opt)
3388 WCHAR buf[255] = L"http://winetest.example.org";
3389 IMoniker *mon;
3390 BSTR url;
3391 HRESULT hres;
3393 lstrcatW(buf, path);
3394 if(opt)
3395 wsprintfW(buf + lstrlenW(buf), L"?%S", opt);
3396 url = SysAllocString(buf);
3397 hres = CreateURLMoniker(NULL, url, &mon);
3398 SysFreeString(url);
3399 ok(hres == S_OK, "CreateUrlMoniker failed: %08x\n", hres);
3401 run_from_moniker(mon);
3403 IMoniker_Release(mon);
3406 static void run_script_as_http_with_mode(const char *script, const char *opt, const char *document_mode)
3408 trace("Running %s script in %s mode...\n", script, document_mode ? document_mode : "quirks");
3410 sprintf(index_html_data,
3411 "%s"
3412 "<html>\n"
3413 " <head>\n"
3414 " %s%s%s\n"
3415 " <script src=\"winetest.js\" type=\"text/javascript\"></script>\n"
3416 " <script src=\"%s\" type=\"text/javascript\"></script>\n"
3417 " </head>\n"
3418 " <body onload=\"run_tests();\">\n"
3419 " </body>\n"
3420 "</html>\n",
3421 document_mode ? "<!DOCTYPE html>\n" : "",
3422 document_mode ? "<meta http-equiv=\"x-ua-compatible\" content=\"Ie=" : "",
3423 document_mode ? document_mode : "",
3424 document_mode ? "\">" : "",
3425 script);
3427 run_from_path(L"/index.html", opt ? opt : script);
3430 static void init_protocol_handler(void)
3432 IInternetSession *internet_session;
3433 HRESULT hres;
3435 static const WCHAR httpW[] = {'h','t','t','p',0};
3437 hres = CoInternetGetSession(0, &internet_session, 0);
3438 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
3440 hres = IInternetSession_RegisterNameSpace(internet_session, &protocol_cf, &CLSID_HttpProtocol, httpW, 0, NULL, 0);
3441 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
3443 IInternetSession_Release(internet_session);
3446 static void run_js_tests(void)
3448 run_js_script("jstest.html");
3449 run_js_script("exectest.html");
3450 run_js_script("events.html");
3452 SET_EXPECT(GetTypeInfo);
3453 run_js_script("vbtest.html");
3454 CLEAR_CALLED(GetTypeInfo);
3456 if(!is_ie9plus) {
3457 win_skip("Skipping some script tests on IE older than 9.\n");
3458 return;
3461 init_protocol_handler();
3463 run_script_as_http_with_mode("xhr.js", NULL, "9");
3464 run_script_as_http_with_mode("xhr.js", NULL, "11");
3465 run_script_as_http_with_mode("dom.js", NULL, "11");
3466 run_script_as_http_with_mode("es5.js", NULL, "11");
3467 run_script_as_http_with_mode("events.js", NULL, "9");
3468 run_script_as_http_with_mode("navigation.js", NULL, NULL);
3469 run_script_as_http_with_mode("navigation.js", NULL, "11");
3471 run_script_as_http_with_mode("documentmode.js", "0", NULL);
3472 run_script_as_http_with_mode("documentmode.js", "5", "5");
3473 run_script_as_http_with_mode("documentmode.js", "5", "6");
3474 run_script_as_http_with_mode("documentmode.js", "7", "7");
3475 run_script_as_http_with_mode("documentmode.js", "8", "8");
3476 run_script_as_http_with_mode("documentmode.js", "9", "9");
3477 run_script_as_http_with_mode("documentmode.js", "10", "10;abc");
3478 run_script_as_http_with_mode("documentmode.js", "11", "11");
3479 run_script_as_http_with_mode("documentmode.js", "11", "edge;123");
3481 run_script_as_http_with_mode("asyncscriptload.js", NULL, "9");
3484 static BOOL init_registry(BOOL init)
3486 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID, init)
3487 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
3488 NULL, init)
3489 && init_key("CLSID\\"TESTSCRIPT_CLSID"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
3490 NULL, init);
3493 static BOOL register_script_engine(void)
3495 DWORD regid;
3496 HRESULT hres;
3498 if(!init_registry(TRUE)) {
3499 init_registry(FALSE);
3500 return FALSE;
3503 hres = CoRegisterClassObject(&CLSID_TestScript, (IUnknown *)&script_cf,
3504 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
3505 ok(hres == S_OK, "Could not register script engine: %08x\n", hres);
3507 return TRUE;
3510 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
3512 return DefWindowProcA(hwnd, msg, wParam, lParam);
3515 static HWND create_container_window(void)
3517 static const CHAR szHTMLDocumentTest[] = "HTMLDocumentTest";
3518 static WNDCLASSEXA wndclass = {
3519 sizeof(WNDCLASSEXA),
3521 wnd_proc,
3522 0, 0, NULL, NULL, NULL, NULL, NULL,
3523 szHTMLDocumentTest,
3524 NULL
3527 RegisterClassExA(&wndclass);
3528 return CreateWindowA(szHTMLDocumentTest, szHTMLDocumentTest,
3529 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
3530 300, 300, NULL, NULL, NULL, NULL);
3533 static BOOL check_ie(void)
3535 IHTMLDocument2 *doc;
3536 IHTMLDocument5 *doc5;
3537 IHTMLDocument7 *doc7;
3538 HRESULT hres;
3540 doc = create_document();
3541 if(!doc)
3542 return FALSE;
3544 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument7, (void**)&doc7);
3545 if(SUCCEEDED(hres)) {
3546 is_ie9plus = TRUE;
3547 IHTMLDocument7_Release(doc7);
3550 trace("is_ie9plus %x\n", is_ie9plus);
3552 hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
3553 if(SUCCEEDED(hres))
3554 IHTMLDocument5_Release(doc5);
3556 IHTMLDocument2_Release(doc);
3557 return SUCCEEDED(hres);
3560 START_TEST(script)
3562 CoInitialize(NULL);
3563 container_hwnd = create_container_window();
3565 if(check_ie()) {
3566 if(winetest_interactive || ! is_ie_hardened()) {
3567 if(register_script_engine()) {
3568 test_simple_script();
3569 init_registry(FALSE);
3570 }else {
3571 skip("Could not register TestScript engine\n");
3573 run_js_tests();
3574 }else {
3575 skip("IE running in Enhanced Security Configuration\n");
3577 }else {
3578 #if !defined(__i386__) && !defined(__x86_64__)
3579 todo_wine
3580 #endif
3581 win_skip("Too old IE.\n");
3584 DestroyWindow(container_hwnd);
3585 CoUninitialize();