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 HRESULT WINAPI
Dispatch_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
64 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
73 static ULONG WINAPI
Dispatch_AddRef(IDispatch
*iface
)
78 static ULONG WINAPI
Dispatch_Release(IDispatch
*iface
)
83 static HRESULT WINAPI
Dispatch_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
85 ok(0, "unexpected call\n");
89 static HRESULT WINAPI
Dispatch_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
92 ok(0, "unexpected call\n");
96 static HRESULT WINAPI
Dispatch_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
97 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
99 ok(0, "unexpected call\n");
103 static HRESULT WINAPI
Dispatch_Invoke(IDispatch
*iface
, DISPID dispIdMember
, REFIID riid
,
104 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
105 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
107 switch(dispIdMember
) {
108 case DISPID_NAVIGATECOMPLETE2
:
109 CHECK_EXPECT(Invoke_NAVIGATECOMPLETE2
);
110 navigate_complete
= TRUE
;
117 static IDispatchVtbl DispatchVtbl
= {
118 Dispatch_QueryInterface
,
121 Dispatch_GetTypeInfoCount
,
122 Dispatch_GetTypeInfo
,
123 Dispatch_GetIDsOfNames
,
127 static IDispatch Dispatch
= { &DispatchVtbl
};
129 static void advise_cp(IUnknown
*unk
, BOOL init
)
131 IConnectionPointContainer
*container
;
132 IConnectionPoint
*point
;
135 static DWORD cookie
= 100;
137 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
138 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
142 hres
= IConnectionPointContainer_FindConnectionPoint(container
, &DIID_DWebBrowserEvents2
, &point
);
143 IConnectionPointContainer_Release(container
);
144 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
149 hres
= IConnectionPoint_Advise(point
, (IUnknown
*)&Dispatch
, &cookie
);
150 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
152 hres
= IConnectionPoint_Unadvise(point
, cookie
);
153 ok(hres
== S_OK
, "Unadvise failed: %08x\n", hres
);
156 IConnectionPoint_Release(point
);
160 static void test_visible(IWebBrowser2
*wb
)
166 hres
= IWebBrowser2_get_Visible(wb
, &b
);
167 ok(hres
== S_OK
, "get_Visible failed: %08x\n", hres
);
168 ok(b
== VARIANT_FALSE
, "Visible = %x\n", b
);
170 hres
= IWebBrowser2_put_Visible(wb
, VARIANT_TRUE
);
171 ok(hres
== S_OK
, "put_Visible failed: %08x\n", hres
);
174 hres
= IWebBrowser2_get_Visible(wb
, &b
);
175 ok(hres
== S_OK
, "get_Visible failed: %08x\n", hres
);
176 ok(b
== VARIANT_TRUE
, "Visible = %x\n", b
);
178 hres
= IWebBrowser2_put_Visible(wb
, VARIANT_FALSE
);
179 ok(hres
== S_OK
, "put_Visible failed: %08x\n", hres
);
182 static void test_html_window(IWebBrowser2
*wb
)
184 IHTMLWindow2
*html_window
;
185 IServiceProvider
*sp
;
188 hres
= IWebBrowser2_QueryInterface(wb
, &IID_IServiceProvider
, (void**)&sp
);
189 ok(hres
== S_OK
, "Could not get IServiceProvider iface: %08x\n", hres
);
191 hres
= IServiceProvider_QueryService(sp
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&html_window
);
192 IServiceProvider_Release(sp
);
193 ok(hres
== S_OK
, "Could not get SHTMLWindow service: %08x\n", hres
);
195 IHTMLWindow2_Release(html_window
);
198 static void test_window(IWebBrowser2
*wb
)
200 SHANDLE_PTR handle
= 0;
205 hres
= IWebBrowser2_get_HWND(wb
, &handle
);
206 ok(hres
== S_OK
, "get_HWND failed: %08x\n", hres
);
207 ok(handle
, "handle == 0\n");
210 GetClassNameA(hwnd
, buf
, sizeof(buf
));
211 ok(!strcmp(buf
, "IEFrame"), "Unexpected class name %s\n", buf
);
214 static void test_navigate(IWebBrowser2
*wb
, const WCHAR
*url
)
216 VARIANT urlv
, emptyv
;
220 SET_EXPECT(Invoke_NAVIGATECOMPLETE2
);
222 V_VT(&urlv
) = VT_BSTR
;
223 V_BSTR(&urlv
) = SysAllocString(url
);
224 V_VT(&emptyv
) = VT_EMPTY
;
225 hres
= IWebBrowser2_Navigate2(wb
, &urlv
, &emptyv
, &emptyv
, &emptyv
, &emptyv
);
226 ok(hres
== S_OK
, "Navigate2 failed: %08x\n", hres
);
227 SysFreeString(V_BSTR(&urlv
));
229 while(!navigate_complete
&& GetMessageW(&msg
, NULL
, 0, 0)) {
230 TranslateMessage(&msg
);
231 DispatchMessageW(&msg
);
234 CHECK_CALLED(Invoke_NAVIGATECOMPLETE2
);
237 static void test_busy(IWebBrowser2
*wb
)
243 hres
= IWebBrowser2_get_Busy(wb
, &b
);
244 ok(hres
== S_OK
, "get_Busy failed: %08x\n", hres
);
245 ok(b
== VARIANT_FALSE
, "Busy = %x\n", b
);
248 static void test_InternetExplorer(void)
255 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_SERVER
,
256 &IID_IUnknown
, (void**)&unk
);
257 ok(hres
== S_OK
, "Could not create InternetExplorer instance: %08x\n", hres
);
262 hres
= IUnknown_QueryInterface(unk
, &IID_IWebBrowser2
, (void**)&wb
);
263 ok(hres
== S_OK
, "Could not get IWebBrowser2 interface: %08x\n", hres
);
265 IUnknown_Release(unk
);
269 advise_cp(unk
, TRUE
);
273 test_html_window(wb
);
275 test_navigate(wb
, L
"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();