gdiplus/metafile: Support playback for EmfPlusRecordTypeSetAntiAliasMode.
[wine.git] / dlls / ieframe / tests / ie.c
blobac055e248dec70004457f2f05ad5395d12e81b53
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"
31 #include "initguid.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) \
41 do { \
42 ok(expect_ ##func, "unexpected call " #func "\n"); \
43 called_ ## func = TRUE; \
44 }while(0)
46 #define CHECK_EXPECT(func) \
47 do { \
48 CHECK_EXPECT2(func); \
49 expect_ ## func = FALSE; \
50 }while(0)
52 #define CHECK_CALLED(func) \
53 do { \
54 ok(called_ ## func, "expected " #func "\n"); \
55 expect_ ## func = called_ ## func = FALSE; \
56 }while(0)
58 DEFINE_EXPECT(Invoke_NAVIGATECOMPLETE2);
60 static BOOL navigate_complete;
62 static BSTR a2bstr(const char *str)
64 BSTR ret;
65 int len;
67 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
68 ret = SysAllocStringLen(NULL, len);
69 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
71 return ret;
74 static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
76 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
77 *ppv = iface;
78 return S_OK;
81 *ppv = NULL;
82 return E_NOINTERFACE;
85 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
87 return 2;
90 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
92 return 1;
95 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
97 ok(0, "unexpected call\n");
98 return E_NOTIMPL;
101 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
102 ITypeInfo **ppTInfo)
104 ok(0, "unexpected call\n");
105 return E_NOTIMPL;
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");
112 return E_NOTIMPL;
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;
123 return S_OK;
126 return E_NOTIMPL;
129 static IDispatchVtbl DispatchVtbl = {
130 Dispatch_QueryInterface,
131 Dispatch_AddRef,
132 Dispatch_Release,
133 Dispatch_GetTypeInfoCount,
134 Dispatch_GetTypeInfo,
135 Dispatch_GetIDsOfNames,
136 Dispatch_Invoke
139 static IDispatch Dispatch = { &DispatchVtbl };
141 static void advise_cp(IUnknown *unk, BOOL init)
143 IConnectionPointContainer *container;
144 IConnectionPoint *point;
145 HRESULT hres;
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);
151 if(FAILED(hres))
152 return;
154 hres = IConnectionPointContainer_FindConnectionPoint(container, &DIID_DWebBrowserEvents2, &point);
155 IConnectionPointContainer_Release(container);
156 ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
157 if(FAILED(hres))
158 return;
160 if(init) {
161 hres = IConnectionPoint_Advise(point, (IUnknown*)&Dispatch, &cookie);
162 ok(hres == S_OK, "Advise failed: %08x\n", hres);
163 }else {
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)
174 VARIANT_BOOL b;
175 HRESULT hres;
177 b = 0x100;
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);
185 b = 0x100;
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;
198 HRESULT hres;
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;
213 HWND hwnd = NULL;
214 char buf[100];
215 HRESULT hres;
217 hres = IWebBrowser2_get_HWND(wb, &handle);
218 ok(hres == S_OK, "get_HWND faile: %08x\n", hres);
219 ok(handle, "handle == 0\n");
221 hwnd = (HWND)handle;
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;
229 MSG msg;
230 HRESULT hres;
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)
251 IWebBrowser2 *wb;
252 IUnknown *unk;
253 ULONG ref;
254 HRESULT hres;
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);
260 if(hres != S_OK)
261 return;
263 advise_cp(unk, TRUE);
265 hres = IUnknown_QueryInterface(unk, &IID_IWebBrowser2, (void**)&wb);
266 ok(hres == S_OK, "Could not get IWebBrowser2 interface: %08x\n", hres);
268 test_visible(wb);
269 test_html_window(wb);
270 test_window(wb);
271 test_navigate(wb, "http://test.winehq.org/tests/hello.html");
273 advise_cp(unk, FALSE);
275 IWebBrowser2_Release(wb);
276 ref = IUnknown_Release(unk);
277 ok(!ref, "object not destroyed, ref=%u\n", ref);
280 static void test_InternetExplorerManager(void)
282 IUnknown *unk;
283 ULONG ref;
284 HRESULT hres;
286 hres = CoCreateInstance(&CLSID_InternetExplorerManager, NULL, CLSCTX_LOCAL_SERVER,
287 &IID_IInternetExplorerManager, (void**)&unk);
288 ok(hres == S_OK || broken(hres == REGDB_E_CLASSNOTREG), "Could not create InternetExplorerManager instance: %08x\n", hres);
290 if(hres != S_OK)
292 win_skip("InternetExplorerManager not available\n");
293 return;
296 ref = IUnknown_Release(unk);
297 ok(!ref, "object not destroyed, ref=%u\n", ref);
300 START_TEST(ie)
302 CoInitialize(NULL);
304 test_InternetExplorerManager();
306 test_InternetExplorer();
308 CoUninitialize();