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 #define DEFINE_EXPECT(func) \
33 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
35 #define SET_EXPECT(func) \
36 expect_ ## func = TRUE
38 #define CHECK_EXPECT2(func) \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
44 #define CHECK_EXPECT(func) \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
50 #define CHECK_CALLED(func) \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
56 DEFINE_EXPECT(Invoke_NAVIGATECOMPLETE2
);
58 static BOOL navigate_complete
;
60 static BSTR
a2bstr(const char *str
)
65 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
66 ret
= SysAllocStringLen(NULL
, len
);
67 MultiByteToWideChar(CP_ACP
, 0, str
, -1, ret
, len
);
72 static HRESULT WINAPI
Dispatch_QueryInterface(IDispatch
*iface
, REFIID riid
, void **ppv
)
74 if(IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IDispatch
, riid
)) {
83 static ULONG WINAPI
Dispatch_AddRef(IDispatch
*iface
)
88 static ULONG WINAPI
Dispatch_Release(IDispatch
*iface
)
93 static HRESULT WINAPI
Dispatch_GetTypeInfoCount(IDispatch
*iface
, UINT
*pctinfo
)
95 ok(0, "unexpected call\n");
99 static HRESULT WINAPI
Dispatch_GetTypeInfo(IDispatch
*iface
, UINT iTInfo
, LCID lcid
,
102 ok(0, "unexpected call\n");
106 static HRESULT WINAPI
Dispatch_GetIDsOfNames(IDispatch
*iface
, REFIID riid
, LPOLESTR
*rgszNames
,
107 UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
109 ok(0, "unexpected call\n");
113 static HRESULT WINAPI
Dispatch_Invoke(IDispatch
*iface
, DISPID dispIdMember
, REFIID riid
,
114 LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
115 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
117 switch(dispIdMember
) {
118 case DISPID_NAVIGATECOMPLETE2
:
119 CHECK_EXPECT(Invoke_NAVIGATECOMPLETE2
);
120 navigate_complete
= TRUE
;
127 static IDispatchVtbl DispatchVtbl
= {
128 Dispatch_QueryInterface
,
131 Dispatch_GetTypeInfoCount
,
132 Dispatch_GetTypeInfo
,
133 Dispatch_GetIDsOfNames
,
137 static IDispatch Dispatch
= { &DispatchVtbl
};
139 static void advise_cp(IUnknown
*unk
, BOOL init
)
141 IConnectionPointContainer
*container
;
142 IConnectionPoint
*point
;
145 static DWORD cookie
= 100;
147 hres
= IUnknown_QueryInterface(unk
, &IID_IConnectionPointContainer
, (void**)&container
);
148 ok(hres
== S_OK
, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres
);
152 hres
= IConnectionPointContainer_FindConnectionPoint(container
, &DIID_DWebBrowserEvents2
, &point
);
153 IConnectionPointContainer_Release(container
);
154 ok(hres
== S_OK
, "FindConnectionPoint failed: %08x\n", hres
);
159 hres
= IConnectionPoint_Advise(point
, (IUnknown
*)&Dispatch
, &cookie
);
160 ok(hres
== S_OK
, "Advise failed: %08x\n", hres
);
162 hres
= IConnectionPoint_Unadvise(point
, cookie
);
163 ok(hres
== S_OK
, "Unadvise failed: %08x\n", hres
);
166 IConnectionPoint_Release(point
);
170 static void test_visible(IWebBrowser2
*wb
)
176 hres
= IWebBrowser2_get_Visible(wb
, &b
);
177 ok(hres
== S_OK
, "get_Visible failed: %08x\n", hres
);
178 ok(b
== VARIANT_FALSE
, "Visible = %x\n", hres
);
180 hres
= IWebBrowser2_put_Visible(wb
, VARIANT_TRUE
);
181 ok(hres
== S_OK
, "put_Visible failed: %08x\n", hres
);
184 hres
= IWebBrowser2_get_Visible(wb
, &b
);
185 ok(hres
== S_OK
, "get_Visible failed: %08x\n", hres
);
186 ok(b
== VARIANT_TRUE
, "Visible = %x\n", hres
);
188 hres
= IWebBrowser2_put_Visible(wb
, VARIANT_FALSE
);
189 ok(hres
== S_OK
, "put_Visible failed: %08x\n", hres
);
192 static void test_html_window(IWebBrowser2
*wb
)
194 IHTMLWindow2
*html_window
;
195 IServiceProvider
*sp
;
198 hres
= IWebBrowser2_QueryInterface(wb
, &IID_IServiceProvider
, (void**)&sp
);
199 ok(hres
== S_OK
, "Could not get IServiceProvider iface: %08x\n", hres
);
201 hres
= IServiceProvider_QueryService(sp
, &SID_SHTMLWindow
, &IID_IHTMLWindow2
, (void**)&html_window
);
202 IServiceProvider_Release(sp
);
203 ok(hres
== S_OK
, "Could not get SHTMLWindow service: %08x\n", hres
);
205 IHTMLWindow2_Release(html_window
);
208 static void test_navigate(IWebBrowser2
*wb
, const char *url
)
210 VARIANT urlv
, emptyv
;
214 SET_EXPECT(Invoke_NAVIGATECOMPLETE2
);
216 V_VT(&urlv
) = VT_BSTR
;
217 V_BSTR(&urlv
) = a2bstr(url
);
218 V_VT(&emptyv
) = VT_EMPTY
;
219 hres
= IWebBrowser2_Navigate2(wb
, &urlv
, &emptyv
, &emptyv
, &emptyv
, &emptyv
);
220 ok(hres
== S_OK
, "Navigate2 failed: %08x\n", hres
);
221 SysFreeString(V_BSTR(&urlv
));
223 while(!navigate_complete
&& GetMessageW(&msg
, NULL
, 0, 0)) {
224 TranslateMessage(&msg
);
225 DispatchMessage(&msg
);
228 CHECK_CALLED(Invoke_NAVIGATECOMPLETE2
);
231 static void test_InternetExplorer(void)
238 hres
= CoCreateInstance(&CLSID_InternetExplorer
, NULL
, CLSCTX_SERVER
,
239 &IID_IUnknown
, (void**)&unk
);
240 ok(hres
== S_OK
, "Could not create InternetExplorer instance: %08x\n", hres
);
245 advise_cp(unk
, TRUE
);
247 hres
= IUnknown_QueryInterface(unk
, &IID_IWebBrowser2
, (void**)&wb
);
248 ok(hres
== S_OK
, "Could not get IWebBrowser2 interface: %08x\n", hres
);
251 test_html_window(wb
);
252 test_navigate(wb
, "http://test.winehq.org/tests/hello.html");
254 advise_cp(unk
, FALSE
);
256 IWebBrowser2_Release(wb
);
257 ref
= IUnknown_Release(unk
);
258 ok(!ref
, "object not destroyed, ref=%u\n", ref
);
265 test_InternetExplorer();