2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <wine/test.h>
37 DEFINE_GUID(CLSID_IdentityUnmarshal
,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
39 #define DEFINE_EXPECT(func) \
40 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
42 #define SET_EXPECT(func) \
43 do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
45 #define CHECK_EXPECT2(func) \
47 ok(expect_ ##func, "unexpected call " #func "\n"); \
48 called_ ## func = TRUE; \
51 #define CHECK_EXPECT(func) \
53 CHECK_EXPECT2(func); \
54 expect_ ## func = FALSE; \
57 #define CHECK_CALLED(func) \
59 ok(called_ ## func, "expected " #func "\n"); \
60 expect_ ## func = called_ ## func = FALSE; \
63 #define CHECK_NOT_CALLED(func) \
65 ok(!called_ ## func, "unexpected " #func "\n"); \
66 expect_ ## func = called_ ## func = FALSE; \
69 #define CLEAR_CALLED(func) \
70 expect_ ## func = called_ ## func = FALSE
73 DEFINE_EXPECT(CreateInstance
);
74 DEFINE_EXPECT(GetInterfaceSafetyOptions
);
75 DEFINE_EXPECT(SetInterfaceSafetyOptions
);
76 DEFINE_EXPECT(InitNew
);
78 DEFINE_EXPECT(SetProperty
);
79 DEFINE_EXPECT(SetScriptSite
);
80 DEFINE_EXPECT(GetScriptState
);
81 DEFINE_EXPECT(SetScriptState_STARTED
);
82 DEFINE_EXPECT(SetScriptState_CONNECTED
);
83 DEFINE_EXPECT(SetScriptState_DISCONNECTED
);
84 DEFINE_EXPECT(AddNamedItem
);
85 DEFINE_EXPECT(ParseScriptText
);
86 DEFINE_EXPECT(GetScriptDispatch
);
87 DEFINE_EXPECT(funcDisp
);
89 #define TESTSCRIPT_CLSID "{178fc163-f585-4e24-9c13-4bb7faf80746}"
91 static const GUID CLSID_TestScript
=
92 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x07,0x46}};
94 static IHTMLDocument2
*notif_doc
;
95 static IDispatchEx
*window_dispex
;
96 static BOOL doc_complete
;
98 static const char *debugstr_w(LPCWSTR str
)
100 static char buf
[1024];
101 WideCharToMultiByte(CP_ACP
, 0, str
, -1, buf
, sizeof(buf
), NULL
, NULL
);
105 static const char *debugstr_guid(REFIID riid
)
109 sprintf(buf
, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
110 riid
->Data1
, riid
->Data2
, riid
->Data3
, riid
->Data4
[0],
111 riid
->Data4
[1], riid
->Data4
[2], riid
->Data4
[3], riid
->Data4
[4],
112 riid
->Data4
[5], riid
->Data4
[6], riid
->Data4
[7]);
117 static HRESULT WINAPI
PropertyNotifySink_QueryInterface(IPropertyNotifySink
*iface
,
118 REFIID riid
, void**ppv
)
120 if(IsEqualGUID(&IID_IPropertyNotifySink
, riid
)) {
125 return E_NOINTERFACE
;
128 static ULONG WINAPI
PropertyNotifySink_AddRef(IPropertyNotifySink
*iface
)
133 static ULONG WINAPI
PropertyNotifySink_Release(IPropertyNotifySink
*iface
)
138 static HRESULT WINAPI
PropertyNotifySink_OnChanged(IPropertyNotifySink
*iface
, DISPID dispID
)
140 if(dispID
== DISPID_READYSTATE
){
144 static const WCHAR completeW
[] = {'c','o','m','p','l','e','t','e',0};
146 hres
= IHTMLDocument2_get_readyState(notif_doc
, &state
);
147 ok(hres
== S_OK
, "get_readyState failed: %08x\n", hres
);
149 if(!lstrcmpW(state
, completeW
))
152 SysFreeString(state
);
158 static HRESULT WINAPI
PropertyNotifySink_OnRequestEdit(IPropertyNotifySink
*iface
, DISPID dispID
)
160 ok(0, "unexpected call\n");
164 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl
= {
165 PropertyNotifySink_QueryInterface
,
166 PropertyNotifySink_AddRef
,
167 PropertyNotifySink_Release
,
168 PropertyNotifySink_OnChanged
,
169 PropertyNotifySink_OnRequestEdit
172 static IPropertyNotifySink PropertyNotifySink
= { &PropertyNotifySinkVtbl
};
174 static HRESULT WINAPI
DispatchEx_QueryInterface(IDispatchEx
*iface
, REFIID riid
, void **ppv
)
178 if(IsEqualGUID(riid
, &IID_IUnknown
)
179 || IsEqualGUID(riid
, &IID_IDispatch
)
180 || IsEqualGUID(riid
, &IID_IDispatchEx
))
183 return E_NOINTERFACE
;
188 static ULONG WINAPI
DispatchEx_AddRef(IDispatchEx
*iface
)
193 static ULONG WINAPI
DispatchEx_Release(IDispatchEx
*iface
)
198 static HRESULT WINAPI
DispatchEx_GetTypeInfoCount(IDispatchEx
*iface
, UINT
*pctinfo
)
200 ok(0, "unexpected call\n");
204 static HRESULT WINAPI
DispatchEx_GetTypeInfo(IDispatchEx
*iface
, UINT iTInfo
,
205 LCID lcid
, ITypeInfo
**ppTInfo
)
207 ok(0, "unexpected call\n");
211 static HRESULT WINAPI
DispatchEx_GetIDsOfNames(IDispatchEx
*iface
, REFIID riid
,
212 LPOLESTR
*rgszNames
, UINT cNames
,
213 LCID lcid
, DISPID
*rgDispId
)
215 ok(0, "unexpected call\n");
219 static HRESULT WINAPI
DispatchEx_Invoke(IDispatchEx
*iface
, DISPID dispIdMember
,
220 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
221 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
223 ok(0, "unexpected call\n");
227 static HRESULT WINAPI
DispatchEx_DeleteMemberByName(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
)
229 ok(0, "unexpected call %s %x\n", debugstr_w(bstrName
), grfdex
);
233 static HRESULT WINAPI
DispatchEx_DeleteMemberByDispID(IDispatchEx
*iface
, DISPID id
)
235 ok(0, "unexpected call\n");
239 static HRESULT WINAPI
DispatchEx_GetMemberProperties(IDispatchEx
*iface
, DISPID id
, DWORD grfdexFetch
, DWORD
*pgrfdex
)
241 ok(0, "unexpected call\n");
245 static HRESULT WINAPI
DispatchEx_GetMemberName(IDispatchEx
*iface
, DISPID id
, BSTR
*pbstrName
)
247 ok(0, "unexpected call\n");
251 static HRESULT WINAPI
DispatchEx_GetNextDispID(IDispatchEx
*iface
, DWORD grfdex
, DISPID id
, DISPID
*pid
)
253 ok(0, "unexpected call\n");
257 static HRESULT WINAPI
DispatchEx_GetNameSpaceParent(IDispatchEx
*iface
, IUnknown
**ppunk
)
259 ok(0, "unexpected call\n");
263 static HRESULT WINAPI
DispatchEx_GetDispID(IDispatchEx
*iface
, BSTR bstrName
, DWORD grfdex
, DISPID
*pid
)
265 ok(0, "unexpected call\n");
269 static HRESULT WINAPI
funcDisp_InvokeEx(IDispatchEx
*iface
, DISPID id
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pdp
,
270 VARIANT
*pvarRes
, EXCEPINFO
*pei
, IServiceProvider
*pspCaller
)
272 CHECK_EXPECT(funcDisp
);
274 ok(id
== DISPID_VALUE
, "id = %d\n", id
);
275 ok(lcid
== 0, "lcid = %x\n", lcid
);
276 ok(wFlags
== DISPATCH_METHOD
, "wFlags = %x\n", wFlags
);
277 ok(pdp
!= NULL
, "pdp == NULL\n");
278 ok(pdp
->cArgs
== 2, "pdp->cArgs = %d\n", pdp
->cArgs
);
279 ok(pdp
->cNamedArgs
== 1, "pdp->cNamedArgs = %d\n", pdp
->cNamedArgs
);
280 ok(pdp
->rgdispidNamedArgs
[0] == DISPID_THIS
, "pdp->rgdispidNamedArgs[0] = %d\n", pdp
->rgdispidNamedArgs
[0]);
281 ok(V_VT(pdp
->rgvarg
) == VT_DISPATCH
, "V_VT(rgvarg) = %d\n", V_VT(pdp
->rgvarg
));
282 ok(V_VT(pdp
->rgvarg
+1) == VT_BOOL
, "V_VT(rgvarg[1]) = %d\n", V_VT(pdp
->rgvarg
));
283 ok(V_BOOL(pdp
->rgvarg
+1) == VARIANT_TRUE
, "V_BOOL(rgvarg[1]) = %x\n", V_BOOL(pdp
->rgvarg
));
284 ok(pvarRes
!= NULL
, "pvarRes == NULL\n");
285 ok(pei
!= NULL
, "pei == NULL\n");
286 ok(!pspCaller
, "pspCaller != NULL\n");
288 V_VT(pvarRes
) = VT_I4
;
293 static IDispatchExVtbl testObjVtbl
= {
294 DispatchEx_QueryInterface
,
297 DispatchEx_GetTypeInfoCount
,
298 DispatchEx_GetTypeInfo
,
299 DispatchEx_GetIDsOfNames
,
301 DispatchEx_GetDispID
,
303 DispatchEx_DeleteMemberByName
,
304 DispatchEx_DeleteMemberByDispID
,
305 DispatchEx_GetMemberProperties
,
306 DispatchEx_GetMemberName
,
307 DispatchEx_GetNextDispID
,
308 DispatchEx_GetNameSpaceParent
311 static IDispatchEx funcDisp
= { &testObjVtbl
};
313 static IHTMLDocument2
*create_document(void)
318 hres
= CoCreateInstance(&CLSID_HTMLDocument
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
319 &IID_IHTMLDocument2
, (void**)&doc
);
320 ok(hres
== S_OK
, "CoCreateInstance failed: %08x\n", hres
);
325 static IHTMLDocument2
*create_doc_with_string(const char *str
)
327 IPersistStreamInit
*init
;
333 notif_doc
= doc
= create_document();
337 doc_complete
= FALSE
;
339 mem
= GlobalAlloc(0, len
);
340 memcpy(mem
, str
, len
);
341 CreateStreamOnHGlobal(mem
, TRUE
, &stream
);
343 IHTMLDocument2_QueryInterface(doc
, &IID_IPersistStreamInit
, (void**)&init
);
345 IPersistStreamInit_Load(init
, stream
);
346 IPersistStreamInit_Release(init
);
347 IStream_Release(stream
);
352 static void do_advise(IUnknown
*unk
, REFIID riid
, IUnknown
*unk_advise
)
354 IConnectionPointContainer
*container
;
355 IConnectionPoint
*cp
;
359 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
360 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
362 hres
= IConnectionPointContainer_FindConnectionPoint(container
, riid
, &cp
);
363 IConnectionPointContainer_Release(container
);
364 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
366 hres
= IConnectionPoint_Advise(cp
, unk_advise
, &cookie
);
367 IConnectionPoint_Release(cp
);
368 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
371 typedef void (*domtest_t
)(IHTMLDocument2
*);
373 static IHTMLDocument2
*create_and_load_doc(const char *str
)
376 IHTMLElement
*body
= NULL
;
380 static const WCHAR ucPtr
[] = {'b','a','c','k','g','r','o','u','n','d',0};
385 doc
= create_doc_with_string(str
);
386 do_advise((IUnknown
*)doc
, &IID_IPropertyNotifySink
, (IUnknown
*)&PropertyNotifySink
);
388 while(!doc_complete
&& GetMessage(&msg
, NULL
, 0, 0)) {
389 TranslateMessage(&msg
);
390 DispatchMessage(&msg
);
393 hres
= IHTMLDocument2_get_body(doc
, &body
);
394 ok(hres
== S_OK
, "get_body failed: %08x\n", hres
);
397 skip("Could not get document body. Assuming no Gecko installed.\n");
398 ref
= IHTMLDocument2_Release(doc
);
399 ok(!ref
, "ref = %d\n", ref
);
403 /* Check we can query for function on the IHTMLElementBody interface */
404 name
= (WCHAR
*)ucPtr
;
405 hres
= IHTMLElement_GetIDsOfNames(body
, &IID_NULL
, &name
, 1, LOCALE_USER_DEFAULT
, &dispID
);
406 ok(hres
== S_OK
, "GetIDsOfNames(background) failed %08x\n", hres
);
407 ok(dispID
== DISPID_IHTMLBODYELEMENT_BACKGROUND
, "Incorrect dispID got (%d)\n", dispID
);
409 IHTMLElement_Release(body
);
413 static IActiveScriptSite
*site
;
414 static SCRIPTSTATE state
;
416 static HRESULT WINAPI
ObjectSafety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
419 ok(0, "unexpected call\n");
420 return E_NOINTERFACE
;
423 static ULONG WINAPI
ObjectSafety_AddRef(IObjectSafety
*iface
)
428 static ULONG WINAPI
ObjectSafety_Release(IObjectSafety
*iface
)
433 static HRESULT WINAPI
ObjectSafety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
434 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
436 CHECK_EXPECT(GetInterfaceSafetyOptions
);
438 ok(IsEqualGUID(&IID_IActiveScriptParse
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
439 ok(pdwSupportedOptions
!= NULL
, "pdwSupportedOptions == NULL\n");
440 ok(pdwEnabledOptions
!= NULL
, "pdwEnabledOptions == NULL\n");
442 *pdwSupportedOptions
= INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
;
443 *pdwEnabledOptions
= INTERFACE_USES_DISPEX
;
448 static HRESULT WINAPI
ObjectSafety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
449 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
451 CHECK_EXPECT(SetInterfaceSafetyOptions
);
453 ok(IsEqualGUID(&IID_IActiveScriptParse
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
455 ok(dwOptionSetMask
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
456 "dwOptionSetMask=%x\n", dwOptionSetMask
);
457 ok(dwEnabledOptions
== (INTERFACESAFE_FOR_UNTRUSTED_DATA
|INTERFACE_USES_DISPEX
|INTERFACE_USES_SECURITY_MANAGER
),
458 "dwEnabledOptions=%x\n", dwOptionSetMask
);
463 static const IObjectSafetyVtbl ObjectSafetyVtbl
= {
464 ObjectSafety_QueryInterface
,
466 ObjectSafety_Release
,
467 ObjectSafety_GetInterfaceSafetyOptions
,
468 ObjectSafety_SetInterfaceSafetyOptions
471 static IObjectSafety ObjectSafety
= { &ObjectSafetyVtbl
};
473 static HRESULT WINAPI
ActiveScriptProperty_QueryInterface(IActiveScriptProperty
*iface
, REFIID riid
, void **ppv
)
476 ok(0, "unexpected call\n");
477 return E_NOINTERFACE
;
480 static ULONG WINAPI
ActiveScriptProperty_AddRef(IActiveScriptProperty
*iface
)
485 static ULONG WINAPI
ActiveScriptProperty_Release(IActiveScriptProperty
*iface
)
490 static HRESULT WINAPI
ActiveScriptProperty_GetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
491 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
493 ok(0, "unexpected call\n");
497 static HRESULT WINAPI
ActiveScriptProperty_SetProperty(IActiveScriptProperty
*iface
, DWORD dwProperty
,
498 VARIANT
*pvarIndex
, VARIANT
*pvarValue
)
500 CHECK_EXPECT(SetProperty
);
502 ok(dwProperty
== SCRIPTPROP_HACK_TRIDENTEVENTSINK
, "unexpected property %d\n", dwProperty
);
503 ok(!pvarIndex
, "pvarIndex != NULL\n");
504 ok(pvarValue
!= NULL
, "pvarValue == NULL\n");
505 ok(V_VT(pvarValue
) == VT_BOOL
, "V_VT(pvarValue)=%d\n", V_VT(pvarValue
));
506 ok(V_BOOL(pvarValue
) == VARIANT_TRUE
, "V_BOOL(pvarValue)=%x\n", V_BOOL(pvarValue
));
511 static const IActiveScriptPropertyVtbl ActiveScriptPropertyVtbl
= {
512 ActiveScriptProperty_QueryInterface
,
513 ActiveScriptProperty_AddRef
,
514 ActiveScriptProperty_Release
,
515 ActiveScriptProperty_GetProperty
,
516 ActiveScriptProperty_SetProperty
519 static IActiveScriptProperty ActiveScriptProperty
= { &ActiveScriptPropertyVtbl
};
521 static HRESULT WINAPI
ActiveScriptParseProcedure_QueryInterface(IActiveScriptParseProcedure2
*iface
, REFIID riid
, void **ppv
)
524 ok(0, "unexpected call\n");
525 return E_NOINTERFACE
;
528 static ULONG WINAPI
ActiveScriptParseProcedure_AddRef(IActiveScriptParseProcedure2
*iface
)
533 static ULONG WINAPI
ActiveScriptParseProcedure_Release(IActiveScriptParseProcedure2
*iface
)
538 static HRESULT WINAPI
ActiveScriptParseProcedure_ParseProcedureText(IActiveScriptParseProcedure2
*iface
,
539 LPCOLESTR pstrCode
, LPCOLESTR pstrFormalParams
, LPCOLESTR pstrProcedureName
,
540 LPCOLESTR pstrItemName
, IUnknown
*punkContext
, LPCOLESTR pstrDelimiter
,
541 DWORD dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
, IDispatch
**ppdisp
)
543 ok(0, "unexpected call\n");
547 static const IActiveScriptParseProcedure2Vtbl ActiveScriptParseProcedureVtbl
= {
548 ActiveScriptParseProcedure_QueryInterface
,
549 ActiveScriptParseProcedure_AddRef
,
550 ActiveScriptParseProcedure_Release
,
551 ActiveScriptParseProcedure_ParseProcedureText
554 static IActiveScriptParseProcedure2 ActiveScriptParseProcedure
= { &ActiveScriptParseProcedureVtbl
};
556 static HRESULT WINAPI
ActiveScriptParse_QueryInterface(IActiveScriptParse
*iface
, REFIID riid
, void **ppv
)
559 ok(0, "unexpected call\n");
560 return E_NOINTERFACE
;
563 static ULONG WINAPI
ActiveScriptParse_AddRef(IActiveScriptParse
*iface
)
568 static ULONG WINAPI
ActiveScriptParse_Release(IActiveScriptParse
*iface
)
573 static HRESULT WINAPI
ActiveScriptParse_InitNew(IActiveScriptParse
*iface
)
575 CHECK_EXPECT(InitNew
);
579 static HRESULT WINAPI
ActiveScriptParse_AddScriptlet(IActiveScriptParse
*iface
,
580 LPCOLESTR pstrDefaultName
, LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
,
581 LPCOLESTR pstrSubItemName
, LPCOLESTR pstrEventName
, LPCOLESTR pstrDelimiter
,
582 DWORD dwSourceContextCookie
, ULONG ulStartingLineNumber
, DWORD dwFlags
,
583 BSTR
*pbstrName
, EXCEPINFO
*pexcepinfo
)
585 ok(0, "unexpected call\n");
589 static HRESULT WINAPI
ActiveScriptParse_ParseScriptText(IActiveScriptParse
*iface
,
590 LPCOLESTR pstrCode
, LPCOLESTR pstrItemName
, IUnknown
*punkContext
,
591 LPCOLESTR pstrDelimiter
, DWORD dwSourceContextCookie
, ULONG ulStartingLine
,
592 DWORD dwFlags
, VARIANT
*pvarResult
, EXCEPINFO
*pexcepinfo
)
594 IDispatchEx
*document
;
599 DISPID id
, named_arg
= DISPID_PROPERTYPUT
;
603 static const WCHAR documentW
[] = {'d','o','c','u','m','e','n','t',0};
604 static const WCHAR testW
[] = {'t','e','s','t',0};
605 static const WCHAR funcW
[] = {'f','u','n','c',0};
607 CHECK_EXPECT(ParseScriptText
);
609 SET_EXPECT(GetScriptDispatch
);
611 tmp
= SysAllocString(documentW
);
612 hres
= IDispatchEx_GetDispID(window_dispex
, tmp
, fdexNameCaseSensitive
, &id
);
614 ok(hres
== S_OK
, "GetDispID(document) failed: %08x\n", hres
);
615 ok(id
== DISPID_IHTMLWINDOW2_DOCUMENT
, "id=%x\n", id
);
617 todo_wine
CHECK_CALLED(GetScriptDispatch
);
620 memset(&dp
, 0, sizeof(dp
));
621 memset(&ei
, 0, sizeof(ei
));
623 hres
= IDispatchEx_InvokeEx(window_dispex
, id
, LOCALE_NEUTRAL
, INVOKE_PROPERTYGET
, &dp
, &var
, &ei
, NULL
);
624 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
625 ok(V_VT(&var
) == VT_DISPATCH
, "V_VT(var)=%d\n", V_VT(&var
));
626 ok(V_DISPATCH(&var
) != NULL
, "V_DISPATCH(&var) == NULL\n");
628 hres
= IDispatch_QueryInterface(V_DISPATCH(&var
), &IID_IDispatchEx
, (void**)&document
);
630 ok(hres
== S_OK
, "Could not get DispatchEx: %08x\n", hres
);
632 tmp
= SysAllocString(testW
);
633 hres
= IDispatchEx_GetDispID(document
, tmp
, fdexNameCaseSensitive
, &id
);
634 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
635 hres
= IDispatchEx_GetDispID(document
, tmp
, fdexNameCaseSensitive
| fdexNameImplicit
, &id
);
636 ok(hres
== DISP_E_UNKNOWNNAME
, "GetDispID(document) failed: %08x, expected DISP_E_UNKNOWNNAME\n", hres
);
640 tmp
= SysAllocString(testW
);
641 hres
= IDispatchEx_GetDispID(document
, tmp
, fdexNameCaseSensitive
|fdexNameEnsure
, &id
);
643 ok(hres
== S_OK
, "GetDispID(document) failed: %08x\n", hres
);
649 dp
.rgdispidNamedArgs
= &named_arg
;
653 hres
= IDispatchEx_InvokeEx(document
, id
, LOCALE_NEUTRAL
, INVOKE_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
654 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
656 tmp
= SysAllocString(testW
);
657 hres
= IDispatchEx_GetDispID(document
, tmp
, fdexNameCaseSensitive
, &id
);
659 ok(hres
== S_OK
, "GetDispID(document) failed: %08x\n", hres
);
662 memset(&dp
, 0, sizeof(dp
));
663 memset(&ei
, 0, sizeof(ei
));
664 hres
= IDispatchEx_InvokeEx(document
, id
, LOCALE_NEUTRAL
, INVOKE_PROPERTYGET
, &dp
, &var
, &ei
, NULL
);
665 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
666 ok(V_VT(&var
) == VT_I4
, "V_VT(var)=%d\n", V_VT(&var
));
667 ok(V_I4(&var
) == 100, "V_I4(&var) == NULL\n");
669 unk
= (void*)0xdeadbeef;
670 hres
= IDispatchEx_GetNameSpaceParent(window_dispex
, &unk
);
671 ok(hres
== S_OK
, "GetNameSpaceParent failed: %08x\n", hres
);
672 ok(!unk
, "unk=%p, expected NULL\n", unk
);
675 tmp
= SysAllocString(funcW
);
676 hres
= IDispatchEx_GetDispID(document
, tmp
, fdexNameCaseSensitive
|fdexNameEnsure
, &id
);
678 ok(hres
== S_OK
, "GetDispID(func) failed: %08x\n", hres
);
684 dp
.rgdispidNamedArgs
= NULL
;
685 V_VT(&var
) = VT_DISPATCH
;
686 V_DISPATCH(&var
) = (IDispatch
*)&funcDisp
;
688 hres
= IDispatchEx_InvokeEx(document
, id
, LOCALE_NEUTRAL
, INVOKE_PROPERTYPUT
, &dp
, NULL
, &ei
, NULL
);
689 ok(hres
== S_OK
, "InvokeEx failed: %08x\n", hres
);
692 memset(&dp
, 0, sizeof(dp
));
693 memset(&ei
, 0, sizeof(ei
));
694 V_VT(&arg
) = VT_BOOL
;
695 V_BOOL(&arg
) = VARIANT_TRUE
;
699 SET_EXPECT(funcDisp
);
700 hres
= IDispatchEx_InvokeEx(document
, id
, LOCALE_NEUTRAL
, INVOKE_FUNC
, &dp
, &var
, &ei
, NULL
);
701 CHECK_CALLED(funcDisp
);
703 ok(hres
== S_OK
, "InvokeEx(INVOKE_FUNC) failed: %08x\n", hres
);
704 ok(V_VT(&var
) == VT_I4
, "V_VT(var)=%d\n", V_VT(&var
));
705 ok(V_I4(&var
) == 100, "V_I4(&var) == NULL\n");
707 IDispatchEx_Release(document
);
712 static const IActiveScriptParseVtbl ActiveScriptParseVtbl
= {
713 ActiveScriptParse_QueryInterface
,
714 ActiveScriptParse_AddRef
,
715 ActiveScriptParse_Release
,
716 ActiveScriptParse_InitNew
,
717 ActiveScriptParse_AddScriptlet
,
718 ActiveScriptParse_ParseScriptText
721 static IActiveScriptParse ActiveScriptParse
= { &ActiveScriptParseVtbl
};
723 static HRESULT WINAPI
ActiveScript_QueryInterface(IActiveScript
*iface
, REFIID riid
, void **ppv
)
727 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IActiveScript
, riid
)) {
732 if(IsEqualGUID(&IID_IActiveScriptParse
, riid
)) {
733 *ppv
= &ActiveScriptParse
;
737 if(IsEqualGUID(&IID_IActiveScriptParseProcedure2
, riid
)) {
738 *ppv
= &ActiveScriptParseProcedure
;
742 if(IsEqualGUID(&IID_IActiveScriptProperty
, riid
)) {
743 *ppv
= &ActiveScriptProperty
;
747 if(IsEqualGUID(&IID_IObjectSafety
, riid
)) {
748 *ppv
= &ObjectSafety
;
752 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
753 return E_NOINTERFACE
;
756 static ULONG WINAPI
ActiveScript_AddRef(IActiveScript
*iface
)
761 static ULONG WINAPI
ActiveScript_Release(IActiveScript
*iface
)
766 static HRESULT WINAPI
ActiveScript_SetScriptSite(IActiveScript
*iface
, IActiveScriptSite
*pass
)
768 IActiveScriptSiteInterruptPoll
*poll
;
769 IActiveScriptSiteDebug
*debug
;
770 IServiceProvider
*service
;
771 ICanHandleException
*canexpection
;
775 CHECK_EXPECT(SetScriptSite
);
777 ok(pass
!= NULL
, "pass == NULL\n");
779 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteInterruptPoll
, (void**)&poll
);
780 ok(hres
== S_OK
, "Could not get IActiveScriptSiteInterruptPoll interface: %08x\n", hres
);
782 IActiveScriptSiteInterruptPoll_Release(poll
);
784 hres
= IActiveScriptSite_GetLCID(pass
, &lcid
);
785 ok(hres
== S_OK
, "GetLCID failed: %08x\n", hres
);
787 hres
= IActiveScriptSite_OnStateChange(pass
, (state
= SCRIPTSTATE_INITIALIZED
));
788 ok(hres
== S_OK
, "OnStateChange failed: %08x\n", hres
);
790 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IActiveScriptSiteDebug
, (void**)&debug
);
791 ok(hres
== S_OK
, "Could not get IActiveScriptSiteDebug interface: %08x\n", hres
);
793 IActiveScriptSiteDebug32_Release(debug
);
795 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_ICanHandleException
, (void**)&canexpection
);
796 ok(hres
== E_NOINTERFACE
, "Could not get IID_ICanHandleException interface: %08x\n", hres
);
798 hres
= IActiveScriptSite_QueryInterface(pass
, &IID_IServiceProvider
, (void**)&service
);
799 todo_wine
ok(hres
== S_OK
, "Could not get IServiceProvider interface: %08x\n", hres
);
801 IServiceProvider_Release(service
);
804 IActiveScriptSite_AddRef(site
);
808 static HRESULT WINAPI
ActiveScript_GetScriptSite(IActiveScript
*iface
, REFIID riid
,
811 ok(0, "unexpected call\n");
815 static HRESULT WINAPI
ActiveScript_SetScriptState(IActiveScript
*iface
, SCRIPTSTATE ss
)
820 case SCRIPTSTATE_STARTED
:
821 CHECK_EXPECT(SetScriptState_STARTED
);
823 case SCRIPTSTATE_CONNECTED
:
824 CHECK_EXPECT(SetScriptState_CONNECTED
);
826 case SCRIPTSTATE_DISCONNECTED
:
827 CHECK_EXPECT(SetScriptState_DISCONNECTED
);
830 ok(0, "unexpected state %d\n", ss
);
834 hres
= IActiveScriptSite_OnStateChange(site
, (state
= ss
));
838 static HRESULT WINAPI
ActiveScript_GetScriptState(IActiveScript
*iface
, SCRIPTSTATE
*pssState
)
840 CHECK_EXPECT(GetScriptState
);
846 static HRESULT WINAPI
ActiveScript_Close(IActiveScript
*iface
)
852 static HRESULT WINAPI
ActiveScript_AddNamedItem(IActiveScript
*iface
,
853 LPCOLESTR pstrName
, DWORD dwFlags
)
856 IUnknown
*unk
= NULL
, *unk2
;
859 static const WCHAR windowW
[] = {'w','i','n','d','o','w',0};
861 static const IID unknown_iid
= {0x719C3050,0xF9D3,0x11CF,{0xA4,0x93,0x00,0x40,0x05,0x23,0xA8,0xA0}};
863 CHECK_EXPECT(AddNamedItem
);
865 ok(!lstrcmpW(pstrName
, windowW
), "pstrName=%s\n", debugstr_w(pstrName
));
866 ok(dwFlags
== (SCRIPTITEM_ISVISIBLE
|SCRIPTITEM_ISSOURCE
|SCRIPTITEM_GLOBALMEMBERS
), "dwFlags=%x\n", dwFlags
);
868 hres
= IActiveScriptSite_GetItemInfo(site
, windowW
, SCRIPTINFO_IUNKNOWN
, &unk
, NULL
);
869 ok(hres
== S_OK
, "GetItemInfo failed: %08x\n", hres
);
870 ok(unk
!= NULL
, "unk == NULL\n");
872 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
873 ok(hres
== S_OK
, "Could not get IDispatch interface: %08x\n", hres
);
875 IDispatch_Release(disp
);
877 hres
= IUnknown_QueryInterface(unk
, &unknown_iid
, (void**)&unk2
);
878 ok(hres
== E_NOINTERFACE
, "Got ?? interface: %p\n", unk2
);
880 IUnknown_Release(unk2
);
882 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatchEx
, (void**)&window_dispex
);
883 ok(hres
== S_OK
, "Could not get IDispatchEx interface: %08x\n", hres
);
885 IUnknown_Release(unk
);
889 static HRESULT WINAPI
ActiveScript_AddTypeLib(IActiveScript
*iface
, REFGUID rguidTypeLib
,
890 DWORD dwMajor
, DWORD dwMinor
, DWORD dwFlags
)
892 ok(0, "unexpected call\n");
896 static HRESULT WINAPI
ActiveScript_GetScriptDispatch(IActiveScript
*iface
, LPCOLESTR pstrItemName
,
899 CHECK_EXPECT(GetScriptDispatch
);
903 static HRESULT WINAPI
ActiveScript_GetCurrentScriptThreadID(IActiveScript
*iface
,
904 SCRIPTTHREADID
*pstridThread
)
906 ok(0, "unexpected call\n");
910 static HRESULT WINAPI
ActiveScript_GetScriptThreadID(IActiveScript
*iface
,
911 DWORD dwWin32ThreadId
, SCRIPTTHREADID
*pstidThread
)
913 ok(0, "unexpected call\n");
917 static HRESULT WINAPI
ActiveScript_GetScriptThreadState(IActiveScript
*iface
,
918 SCRIPTTHREADID stidThread
, SCRIPTTHREADSTATE
*pstsState
)
920 ok(0, "unexpected call\n");
924 static HRESULT WINAPI
ActiveScript_InterruptScriptThread(IActiveScript
*iface
,
925 SCRIPTTHREADID stidThread
, const EXCEPINFO
*pexcepinfo
, DWORD dwFlags
)
927 ok(0, "unexpected call\n");
931 static HRESULT WINAPI
ActiveScript_Clone(IActiveScript
*iface
, IActiveScript
**ppscript
)
933 ok(0, "unexpected call\n");
937 static const IActiveScriptVtbl ActiveScriptVtbl
= {
938 ActiveScript_QueryInterface
,
940 ActiveScript_Release
,
941 ActiveScript_SetScriptSite
,
942 ActiveScript_GetScriptSite
,
943 ActiveScript_SetScriptState
,
944 ActiveScript_GetScriptState
,
946 ActiveScript_AddNamedItem
,
947 ActiveScript_AddTypeLib
,
948 ActiveScript_GetScriptDispatch
,
949 ActiveScript_GetCurrentScriptThreadID
,
950 ActiveScript_GetScriptThreadID
,
951 ActiveScript_GetScriptThreadState
,
952 ActiveScript_InterruptScriptThread
,
956 static IActiveScript ActiveScript
= { &ActiveScriptVtbl
};
958 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
962 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IClassFactory
, riid
)) {
967 if(IsEqualGUID(&IID_IMarshal
, riid
))
968 return E_NOINTERFACE
;
969 if(IsEqualGUID(&CLSID_IdentityUnmarshal
, riid
))
970 return E_NOINTERFACE
;
972 ok(0, "unexpected riid %s\n", debugstr_guid(riid
));
976 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
981 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
986 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
, REFIID riid
, void **ppv
)
988 CHECK_EXPECT(CreateInstance
);
990 ok(!outer
, "outer = %p\n", outer
);
991 ok(IsEqualGUID(&IID_IActiveScript
, riid
), "unexpected riid %s\n", debugstr_guid(riid
));
992 *ppv
= &ActiveScript
;
996 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL dolock
)
998 ok(0, "unexpected call\n");
1002 static const IClassFactoryVtbl ClassFactoryVtbl
= {
1003 ClassFactory_QueryInterface
,
1004 ClassFactory_AddRef
,
1005 ClassFactory_Release
,
1006 ClassFactory_CreateInstance
,
1007 ClassFactory_LockServer
1010 static IClassFactory script_cf
= { &ClassFactoryVtbl
};
1012 static const char simple_script_str
[] =
1013 "<html><head></head><body>"
1014 "<script language=\"TestScript\">simple script</script>"
1017 static void test_simple_script(void)
1019 IHTMLDocument2
*doc
;
1021 SET_EXPECT(CreateInstance
);
1022 SET_EXPECT(GetInterfaceSafetyOptions
);
1023 SET_EXPECT(SetInterfaceSafetyOptions
);
1024 SET_EXPECT(SetProperty
);
1025 SET_EXPECT(InitNew
);
1026 SET_EXPECT(SetScriptSite
);
1027 SET_EXPECT(GetScriptState
);
1028 SET_EXPECT(SetScriptState_STARTED
);
1029 SET_EXPECT(AddNamedItem
);
1030 SET_EXPECT(ParseScriptText
);
1031 SET_EXPECT(SetScriptState_CONNECTED
);
1033 doc
= create_and_load_doc(simple_script_str
);
1036 CHECK_CALLED(CreateInstance
);
1037 CHECK_CALLED(GetInterfaceSafetyOptions
);
1038 CHECK_CALLED(SetInterfaceSafetyOptions
);
1039 CHECK_CALLED(SetProperty
);
1040 CHECK_CALLED(InitNew
);
1041 CHECK_CALLED(SetScriptSite
);
1042 CHECK_CALLED(GetScriptState
);
1043 CHECK_CALLED(SetScriptState_STARTED
);
1044 CHECK_CALLED(AddNamedItem
);
1045 CHECK_CALLED(ParseScriptText
);
1046 CHECK_CALLED(SetScriptState_CONNECTED
);
1049 IActiveScriptSite_Release(site
);
1051 IDispatchEx_Release(window_dispex
);
1053 SET_EXPECT(SetScriptState_DISCONNECTED
);
1056 IHTMLDocument2_Release(doc
);
1058 CHECK_CALLED(SetScriptState_DISCONNECTED
);
1059 CHECK_CALLED(Close
);
1062 static BOOL
init_key(const char *key_name
, const char *def_value
, BOOL init
)
1068 RegDeleteKey(HKEY_CLASSES_ROOT
, key_name
);
1072 res
= RegCreateKeyA(HKEY_CLASSES_ROOT
, key_name
, &hkey
);
1073 if(res
!= ERROR_SUCCESS
)
1077 res
= RegSetValueA(hkey
, NULL
, REG_SZ
, def_value
, strlen(def_value
));
1081 return res
== ERROR_SUCCESS
;
1084 static BOOL
init_registry(BOOL init
)
1086 return init_key("TestScript\\CLSID", TESTSCRIPT_CLSID
, init
)
1087 && init_key("CLSID\\"TESTSCRIPT_CLSID
"\\Implemented Categories\\{F0B7A1A1-9847-11CF-8F20-00805F2CD064}",
1089 && init_key("CLSID\\"TESTSCRIPT_CLSID
"\\Implemented Categories\\{F0B7A1A2-9847-11CF-8F20-00805F2CD064}",
1093 static BOOL
register_script_engine(void)
1098 if(!init_registry(TRUE
)) {
1099 init_registry(FALSE
);
1103 hres
= CoRegisterClassObject(&CLSID_TestScript
, (IUnknown
*)&script_cf
,
1104 CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
1105 ok(hres
== S_OK
, "Could not register screipt engine: %08x\n", hres
);
1110 static void gecko_installer_workaround(BOOL disable
)
1115 static BOOL has_url
= FALSE
;
1116 static char url
[2048];
1118 if(!disable
&& !has_url
)
1121 res
= RegOpenKey(HKEY_CURRENT_USER
, "Software\\Wine\\MSHTML", &hkey
);
1122 if(res
!= ERROR_SUCCESS
)
1126 DWORD type
, size
= sizeof(url
);
1128 res
= RegQueryValueEx(hkey
, "GeckoUrl", NULL
, &type
, (PVOID
)url
, &size
);
1129 if(res
== ERROR_SUCCESS
&& type
== REG_SZ
)
1132 RegDeleteValue(hkey
, "GeckoUrl");
1134 RegSetValueEx(hkey
, "GeckoUrl", 0, REG_SZ
, (PVOID
)url
, lstrlenA(url
)+1);
1140 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
1141 /* Note: this code is duplicated in dlls/mshtml/tests/dom.c, dlls/mshtml/tests/script.c and dlls/urlmon/tests/misc.c */
1142 static BOOL
is_ie_hardened(void)
1145 DWORD ie_harden
, type
, size
;
1148 if(RegOpenKeyEx(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
1149 0, KEY_QUERY_VALUE
, &zone_map
) == ERROR_SUCCESS
) {
1150 size
= sizeof(DWORD
);
1151 if (RegQueryValueEx(zone_map
, "IEHarden", NULL
, &type
, (LPBYTE
) &ie_harden
, &size
) != ERROR_SUCCESS
||
1152 type
!= REG_DWORD
) {
1155 RegCloseKey(zone_map
);
1158 return ie_harden
!= 0;
1163 gecko_installer_workaround(TRUE
);
1166 if(winetest_interactive
|| ! is_ie_hardened()) {
1167 if(register_script_engine()) {
1168 test_simple_script();
1169 init_registry(FALSE
);
1171 skip("Could not register TestScript engine\n");
1174 skip("IE running in Enhanced Security Configuration\n");
1178 gecko_installer_workaround(FALSE
);