2 * Copyright 2011 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
21 #include <wine/test.h>
32 #include "ieautomation.h"
34 #define DEFINE_EXPECT(func) \
35 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
37 #define SET_EXPECT(func) \
38 expect_ ## func = TRUE
40 #define CHECK_EXPECT2(func) \
42 ok(expect_ ##func, "unexpected call " #func "\n"); \
43 called_ ## func = TRUE; \
46 #define CHECK_EXPECT(func) \
48 CHECK_EXPECT2(func); \
49 expect_ ## func = FALSE; \
52 #define CHECK_CALLED(func) \
54 ok(called_ ## func, "expected " #func "\n"); \
55 expect_ ## func = called_ ## func = FALSE; \
58 DEFINE_EXPECT(Invoke_NAVIGATECOMPLETE2
);
60 static BOOL navigate_complete
;
62 static BSTR
a2bstr(const char *str
)
67 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
68 ret
= SysAllocStringLen(NULL
, len
);
69 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
74 static HRESULT WINAPI
Dispatch_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
76 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
85 static ULONG WINAPI
Dispatch_AddRef(IDispatch
*iface
)
90 static ULONG WINAPI
Dispatch_Release(IDispatch
*iface
)
95 static HRESULT WINAPI
Dispatch_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
97 ok(0, "unexpected call\n");
101 static HRESULT WINAPI
Dispatch_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
104 ok(0, "unexpected call\n");
108 static HRESULT WINAPI
Dispatch_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
109 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
111 ok(0, "unexpected call\n");
115 static HRESULT WINAPI
Dispatch_Invoke(IDispatch
*iface
, DISPID dispIdMember
, REFIID riid
,
116 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
117 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
119 switch(dispIdMember
) {
120 case DISPID_NAVIGATECOMPLETE2
:
121 CHECK_EXPECT(Invoke_NAVIGATECOMPLETE2
);
122 navigate_complete
= TRUE
;
129 static IDispatchVtbl DispatchVtbl
= {
130 Dispatch_QueryInterface
,
133 Dispatch_GetTypeInfoCount
,
134 Dispatch_GetTypeInfo
,
135 Dispatch_GetIDsOfNames
,
139 static IDispatch Dispatch
= { &DispatchVtbl
};
141 static void advise_cp(IUnknown
*unk
, BOOL init
)
143 IConnectionPointContainer
*container
;
144 IConnectionPoint
*point
;
147 static DWORD cookie
= 100;
149 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
150 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
154 hres
= IConnectionPointContainer_FindConnectionPoint(container
, &DIID_DWebBrowserEvents2
, &point
);
155 IConnectionPointContainer_Release(container
);
156 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
161 hres
= IConnectionPoint_Advise(point
, (IUnknown
*)&Dispatch
, &cookie
);
162 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
164 hres
= IConnectionPoint_Unadvise(point
, cookie
);
165 ok(hres
== S_OK
, "Unadvise failed: %08x\n", hres
);
168 IConnectionPoint_Release(point
);
172 static void test_visible(IWebBrowser2
*wb
)
178 hres
= IWebBrowser2_get_Visible(wb
, &b
);
179 ok(hres
== S_OK
, "get_Visible failed: %08x\n", hres
);
180 ok(b
== VARIANT_FALSE
, "Visible = %x\n", hres
);
182 hres
= IWebBrowser2_put_Visible(wb
, VARIANT_TRUE
);
183 ok(hres
== S_OK
, "put_Visible failed: %08x\n", hres
);
186 hres
= IWebBrowser2_get_Visible(wb
, &b
);
187 ok(hres
== S_OK
, "get_Visible failed: %08x\n", hres
);
188 ok(b
== VARIANT_TRUE
, "Visible = %x\n", hres
);
190 hres
= IWebBrowser2_put_Visible(wb
, VARIANT_FALSE
);
191 ok(hres
== S_OK
, "put_Visible failed: %08x\n", hres
);
194 static void test_html_window(IWebBrowser2
*wb
)
196 IHTMLWindow2
*html_window
;
197 IServiceProvider
*sp
;
200 hres
= IWebBrowser2_QueryInterface(wb
, &IID_IServiceProvider
, (void**)&sp
);
201 ok(hres
== S_OK
, "Could not get IServiceProvider iface: %08x\n", hres
);
203 hres
= IServiceProvider_QueryService(sp
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&html_window
);
204 IServiceProvider_Release(sp
);
205 ok(hres
== S_OK
, "Could not get SHTMLWindow service: %08x\n", hres
);
207 IHTMLWindow2_Release(html_window
);
210 static void test_window(IWebBrowser2
*wb
)
212 SHANDLE_PTR handle
= 0;
217 hres
= IWebBrowser2_get_HWND(wb
, &handle
);
218 ok(hres
== S_OK
, "get_HWND faile: %08x\n", hres
);
219 ok(handle
, "handle == 0\n");
222 GetClassNameA(hwnd
, buf
, sizeof(buf
));
223 ok(!strcmp(buf
, "IEFrame"), "Unexpected class name %s\n", buf
);
226 static void test_navigate(IWebBrowser2
*wb
, const char *url
)
228 VARIANT urlv
, emptyv
;
232 SET_EXPECT(Invoke_NAVIGATECOMPLETE2
);
234 V_VT(&urlv
) = VT_BSTR
;
235 V_BSTR(&urlv
) = a2bstr(url
);
236 V_VT(&emptyv
) = VT_EMPTY
;
237 hres
= IWebBrowser2_Navigate2(wb
, &urlv
, &emptyv
, &emptyv
, &emptyv
, &emptyv
);
238 ok(hres
== S_OK
, "Navigate2 failed: %08x\n", hres
);
239 SysFreeString(V_BSTR(&urlv
));
241 while(!navigate_complete
&& GetMessageW(&msg
, NULL
, 0, 0)) {
242 TranslateMessage(&msg
);
243 DispatchMessageW(&msg
);
246 CHECK_CALLED(Invoke_NAVIGATECOMPLETE2
);
249 static void test_InternetExplorer(void)
256 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_SERVER
,
257 &IID_IUnknown
, (void**)&unk
);
258 ok(hres
== S_OK
, "Could not create InternetExplorer instance: %08x\n", hres
);
263 hres
= IUnknown_QueryInterface(unk
, &IID_IWebBrowser2
, (void**)&wb
);
264 ok(hres
== S_OK
, "Could not get IWebBrowser2 interface: %08x\n", hres
);
266 IUnknown_Release(unk
);
270 advise_cp(unk
, TRUE
);
273 test_html_window(wb
);
275 test_navigate(wb
, "http://test.winehq.org/tests/hello.html");
277 advise_cp(unk
, FALSE
);
279 IWebBrowser2_Release(wb
);
280 ref
= IUnknown_Release(unk
);
281 ok(!ref
, "object not destroyed, ref=%u\n", ref
);
284 static void test_InternetExplorerManager(void)
290 hres
= CoCreateInstance(&CLSID_InternetExplorerManager
, NULL
, CLSCTX_LOCAL_SERVER
,
291 &IID_IInternetExplorerManager
, (void**)&unk
);
292 ok(hres
== S_OK
|| broken(hres
== REGDB_E_CLASSNOTREG
), "Could not create InternetExplorerManager instance: %08x\n", hres
);
296 win_skip("InternetExplorerManager not available\n");
300 ref
= IUnknown_Release(unk
);
301 ok(!ref
, "object not destroyed, ref=%u\n", ref
);
308 test_InternetExplorerManager();
310 test_InternetExplorer();