ieframe: Added InternetExplore::get_HWND implementation.
[wine/multimedia.git] / dlls / ieframe / tests / ie.c
blob9ddd25c35a11689d17e3fbae160a10e9983a6a1c
1 /*
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
19 #define COBJMACROS
21 #include <wine/test.h>
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "ole2.h"
28 #include "exdisp.h"
29 #include "exdispid.h"
30 #include "mshtml.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) \
39 do { \
40 ok(expect_ ##func, "unexpected call " #func "\n"); \
41 called_ ## func = TRUE; \
42 }while(0)
44 #define CHECK_EXPECT(func) \
45 do { \
46 CHECK_EXPECT2(func); \
47 expect_ ## func = FALSE; \
48 }while(0)
50 #define CHECK_CALLED(func) \
51 do { \
52 ok(called_ ## func, "expected " #func "\n"); \
53 expect_ ## func = called_ ## func = FALSE; \
54 }while(0)
56 DEFINE_EXPECT(Invoke_NAVIGATECOMPLETE2);
58 static BOOL navigate_complete;
60 static BSTR a2bstr(const char *str)
62 BSTR ret;
63 int len;
65 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
66 ret = SysAllocStringLen(NULL, len);
67 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
69 return ret;
72 static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
74 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
75 *ppv = iface;
76 return S_OK;
79 *ppv = NULL;
80 return E_NOINTERFACE;
83 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
85 return 2;
88 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
90 return 1;
93 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
95 ok(0, "unexpected call\n");
96 return E_NOTIMPL;
99 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
100 ITypeInfo **ppTInfo)
102 ok(0, "unexpected call\n");
103 return E_NOTIMPL;
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");
110 return E_NOTIMPL;
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;
121 return S_OK;
124 return E_NOTIMPL;
127 static IDispatchVtbl DispatchVtbl = {
128 Dispatch_QueryInterface,
129 Dispatch_AddRef,
130 Dispatch_Release,
131 Dispatch_GetTypeInfoCount,
132 Dispatch_GetTypeInfo,
133 Dispatch_GetIDsOfNames,
134 Dispatch_Invoke
137 static IDispatch Dispatch = { &DispatchVtbl };
139 static void advise_cp(IUnknown *unk, BOOL init)
141 IConnectionPointContainer *container;
142 IConnectionPoint *point;
143 HRESULT hres;
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);
149 if(FAILED(hres))
150 return;
152 hres = IConnectionPointContainer_FindConnectionPoint(container, &DIID_DWebBrowserEvents2, &point);
153 IConnectionPointContainer_Release(container);
154 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
155 if(FAILED(hres))
156 return;
158 if(init) {
159 hres = IConnectionPoint_Advise(point, (IUnknown*)&Dispatch, &cookie);
160 ok(hres == S_OK, "Advise failed: %08x\n", hres);
161 }else {
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)
172 VARIANT_BOOL b;
173 HRESULT hres;
175 b = 0x100;
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);
183 b = 0x100;
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;
196 HRESULT hres;
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_window(IWebBrowser2 *wb)
210 SHANDLE_PTR handle = 0;
211 HWND hwnd = NULL;
212 char buf[100];
213 HRESULT hres;
215 hres = IWebBrowser2_get_HWND(wb, &handle);
216 ok(hres == S_OK, "get_HWND faile: %08x\n", hres);
217 ok(handle, "handle == 0\n");
219 hwnd = (HWND)handle;
220 GetClassNameA(hwnd, buf, sizeof(buf));
221 ok(!strcmp(buf, "IEFrame"), "Unexpected class name %s\n", buf);
224 static void test_navigate(IWebBrowser2 *wb, const char *url)
226 VARIANT urlv, emptyv;
227 MSG msg;
228 HRESULT hres;
230 SET_EXPECT(Invoke_NAVIGATECOMPLETE2);
232 V_VT(&urlv) = VT_BSTR;
233 V_BSTR(&urlv) = a2bstr(url);
234 V_VT(&emptyv) = VT_EMPTY;
235 hres = IWebBrowser2_Navigate2(wb, &urlv, &emptyv, &emptyv, &emptyv, &emptyv);
236 ok(hres == S_OK, "Navigate2 failed: %08x\n", hres);
237 SysFreeString(V_BSTR(&urlv));
239 while(!navigate_complete && GetMessageW(&msg, NULL, 0, 0)) {
240 TranslateMessage(&msg);
241 DispatchMessageW(&msg);
244 CHECK_CALLED(Invoke_NAVIGATECOMPLETE2);
247 static void test_InternetExplorer(void)
249 IWebBrowser2 *wb;
250 IUnknown *unk;
251 ULONG ref;
252 HRESULT hres;
254 hres = CoCreateInstance(&CLSID_InternetExplorer, NULL, CLSCTX_SERVER,
255 &IID_IUnknown, (void**)&unk);
256 ok(hres == S_OK, "Could not create InternetExplorer instance: %08x\n", hres);
258 if(hres != S_OK)
259 return;
261 advise_cp(unk, TRUE);
263 hres = IUnknown_QueryInterface(unk, &IID_IWebBrowser2, (void**)&wb);
264 ok(hres == S_OK, "Could not get IWebBrowser2 interface: %08x\n", hres);
266 test_visible(wb);
267 test_html_window(wb);
268 test_window(wb);
269 test_navigate(wb, "http://test.winehq.org/tests/hello.html");
271 advise_cp(unk, FALSE);
273 IWebBrowser2_Release(wb);
274 ref = IUnknown_Release(unk);
275 ok(!ref, "object not destroyed, ref=%u\n", ref);
278 START_TEST(ie)
280 CoInitialize(NULL);
282 test_InternetExplorer();
284 CoUninitialize();