d3drm: Avoid LPDDPIXELFORMAT.
[wine] / dlls / ieframe / tests / webbrowser.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "initguid.h"
29 #include "ole2.h"
30 #include "exdisp.h"
31 #include "htiframe.h"
32 #include "mshtmhst.h"
33 #include "mshtmcid.h"
34 #include "mshtml.h"
35 #include "idispids.h"
36 #include "olectl.h"
37 #include "mshtmdid.h"
38 #include "shobjidl.h"
39 #include "shdeprecated.h"
40 #include "shlguid.h"
41 #include "exdispid.h"
42 #include "mimeinfo.h"
43 #include "hlink.h"
44 #include "docobjectservice.h"
45
46 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
47 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
48
49 #define DEFINE_EXPECT(func) \
50     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
51
52 #define SET_EXPECT(func) \
53     expect_ ## func = TRUE
54
55 #define CHECK_EXPECT2(func) \
56     do { \
57         ok(expect_ ##func, "unexpected call " #func "\n"); \
58         called_ ## func = TRUE; \
59     }while(0)
60
61 #define CHECK_EXPECT(func) \
62     do { \
63         CHECK_EXPECT2(func); \
64         expect_ ## func = FALSE; \
65     }while(0)
66
67 #define CHECK_CALLED(func) \
68     do { \
69         ok(called_ ## func, "expected " #func "\n"); \
70         expect_ ## func = called_ ## func = FALSE; \
71     }while(0)
72
73 #define CLEAR_CALLED(func) \
74     expect_ ## func = called_ ## func = FALSE
75
76 DEFINE_EXPECT(GetContainer);
77 DEFINE_EXPECT(Site_GetWindow);
78 DEFINE_EXPECT(ShowObject);
79 DEFINE_EXPECT(CanInPlaceActivate);
80 DEFINE_EXPECT(OnInPlaceActivate);
81 DEFINE_EXPECT(OnUIActivate);
82 DEFINE_EXPECT(GetWindowContext);
83 DEFINE_EXPECT(Frame_GetWindow);
84 DEFINE_EXPECT(Frame_SetActiveObject);
85 DEFINE_EXPECT(UIWindow_SetActiveObject);
86 DEFINE_EXPECT(SetMenu);
87 DEFINE_EXPECT(Invoke_AMBIENT_USERMODE);
88 DEFINE_EXPECT(Invoke_AMBIENT_DLCONTROL);
89 DEFINE_EXPECT(Invoke_AMBIENT_USERAGENT);
90 DEFINE_EXPECT(Invoke_AMBIENT_PALETTE);
91 DEFINE_EXPECT(Invoke_AMBIENT_SILENT);
92 DEFINE_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
93 DEFINE_EXPECT(Invoke_STATUSTEXTCHANGE);
94 DEFINE_EXPECT(Invoke_PROPERTYCHANGE);
95 DEFINE_EXPECT(Invoke_DOWNLOADBEGIN);
96 DEFINE_EXPECT(Invoke_BEFORENAVIGATE2);
97 DEFINE_EXPECT(Invoke_SETSECURELOCKICON);
98 DEFINE_EXPECT(Invoke_FILEDOWNLOAD);
99 DEFINE_EXPECT(Invoke_COMMANDSTATECHANGE);
100 DEFINE_EXPECT(Invoke_DOWNLOADCOMPLETE);
101 DEFINE_EXPECT(Invoke_ONMENUBAR);
102 DEFINE_EXPECT(Invoke_ONADDRESSBAR);
103 DEFINE_EXPECT(Invoke_ONSTATUSBAR);
104 DEFINE_EXPECT(Invoke_ONTOOLBAR);
105 DEFINE_EXPECT(Invoke_ONFULLSCREEN);
106 DEFINE_EXPECT(Invoke_ONTHEATERMODE);
107 DEFINE_EXPECT(Invoke_WINDOWSETRESIZABLE);
108 DEFINE_EXPECT(Invoke_TITLECHANGE);
109 DEFINE_EXPECT(Invoke_NAVIGATECOMPLETE2);
110 DEFINE_EXPECT(Invoke_PROGRESSCHANGE);
111 DEFINE_EXPECT(Invoke_DOCUMENTCOMPLETE);
112 DEFINE_EXPECT(Invoke_282);
113 DEFINE_EXPECT(EnableModeless_TRUE);
114 DEFINE_EXPECT(EnableModeless_FALSE);
115 DEFINE_EXPECT(GetHostInfo);
116 DEFINE_EXPECT(GetOptionKeyPath);
117 DEFINE_EXPECT(GetOverridesKeyPath);
118 DEFINE_EXPECT(SetStatusText);
119 DEFINE_EXPECT(UpdateUI);
120 DEFINE_EXPECT(Exec_SETDOWNLOADSTATE_0);
121 DEFINE_EXPECT(Exec_SETDOWNLOADSTATE_1);
122 DEFINE_EXPECT(Exec_SETPROGRESSMAX);
123 DEFINE_EXPECT(Exec_SETPROGRESSPOS);
124 DEFINE_EXPECT(Exec_UPDATECOMMANDS);
125 DEFINE_EXPECT(Exec_SETTITLE);
126 DEFINE_EXPECT(QueryStatus_SETPROGRESSTEXT);
127 DEFINE_EXPECT(Exec_STOP);
128 DEFINE_EXPECT(Exec_IDM_STOP);
129 DEFINE_EXPECT(Exec_DocHostCommandHandler_2300);
130 DEFINE_EXPECT(QueryStatus_STOP);
131 DEFINE_EXPECT(QueryStatus_IDM_STOP);
132 DEFINE_EXPECT(DocHost_EnableModeless_TRUE);
133 DEFINE_EXPECT(DocHost_EnableModeless_FALSE);
134 DEFINE_EXPECT(DocHost_TranslateAccelerator);
135 DEFINE_EXPECT(GetDropTarget);
136 DEFINE_EXPECT(TranslateUrl);
137 DEFINE_EXPECT(ShowUI);
138 DEFINE_EXPECT(HideUI);
139 DEFINE_EXPECT(OnUIDeactivate);
140 DEFINE_EXPECT(OnInPlaceDeactivate);
141 DEFINE_EXPECT(RequestUIActivate);
142 DEFINE_EXPECT(ControlSite_TranslateAccelerator);
143 DEFINE_EXPECT(OnFocus);
144 DEFINE_EXPECT(GetExternal);
145
146 static const WCHAR wszItem[] = {'i','t','e','m',0};
147 static const WCHAR emptyW[] = {0};
148
149 static VARIANT_BOOL exvb;
150
151 static IWebBrowser2 *wb;
152
153 static HWND container_hwnd, shell_embedding_hwnd;
154 static BOOL is_downloading, is_first_load, use_container_olecmd, test_close, is_http, use_container_dochostui;
155 static HRESULT hr_dochost_TranslateAccelerator = E_NOTIMPL;
156 static HRESULT hr_site_TranslateAccelerator = E_NOTIMPL;
157 static const char *current_url;
158 static int wb_version;
159
160 #define DWL_EXPECT_BEFORE_NAVIGATE  0x01
161 #define DWL_FROM_PUT_HREF           0x02
162 #define DWL_FROM_GOBACK             0x04
163 #define DWL_HTTP                    0x08
164 #define DWL_REFRESH                 0x10
165
166 static DWORD dwl_flags;
167
168
169 /* Returns true if the user interface is in English. Note that this does not
170  * presume of the formatting of dates, numbers, etc.
171  */
172 static BOOL is_lang_english(void)
173 {
174     static HMODULE hkernel32 = NULL;
175     static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
176     static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
177
178     if (!hkernel32)
179     {
180         hkernel32 = GetModuleHandleA("kernel32.dll");
181         pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
182         pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
183     }
184     if (pGetThreadUILanguage)
185         return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
186     if (pGetUserDefaultUILanguage)
187         return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
188
189     return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
190 }
191
192 static int strcmp_wa(LPCWSTR strw, const char *stra)
193 {
194     CHAR buf[512];
195     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
196     return lstrcmpA(stra, buf);
197 }
198
199 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
200 {
201     IUnknown *unk1, *unk2;
202
203     if(iface1 == iface2)
204         return TRUE;
205
206     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
207     IUnknown_Release(unk1);
208     IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
209     IUnknown_Release(unk2);
210
211     return unk1 == unk2;
212 }
213
214 static const char *debugstr_guid(REFIID riid)
215 {
216     static char buf[50];
217
218     sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
219             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
220             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
221             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
222
223     return buf;
224 }
225
226 static BSTR a2bstr(const char *str)
227 {
228     BSTR ret;
229     int len;
230
231     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
232     ret = SysAllocStringLen(NULL, len);
233     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
234
235     return ret;
236 }
237
238 #define create_webbrowser() _create_webbrowser(__LINE__)
239 static IWebBrowser2 *_create_webbrowser(unsigned line)
240 {
241     IWebBrowser2 *ret;
242     HRESULT hres;
243
244     wb_version = 2;
245
246     hres = CoCreateInstance(&CLSID_WebBrowser, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
247             &IID_IWebBrowser2, (void**)&ret);
248     ok_(__FILE__,line)(hres == S_OK, "Creating WebBrowser object failed: %08x\n", hres);
249     return ret;
250 }
251
252 #define test_LocationURL(a,b) _test_LocationURL(__LINE__,a,b)
253 static void _test_LocationURL(unsigned line, IWebBrowser2 *wb, const char *exurl)
254 {
255     BSTR url = (void*)0xdeadbeef;
256     HRESULT hres;
257
258     hres = IWebBrowser2_get_LocationURL(wb, &url);
259     ok_(__FILE__,line) (hres == (*exurl ? S_OK : S_FALSE), "get_LocationURL failed: %08x\n", hres);
260     if (hres == S_OK)
261     {
262         ok_(__FILE__,line) (!strcmp_wa(url, exurl), "unexpected URL: %s\n", wine_dbgstr_w(url));
263         SysFreeString(url);
264     }
265 }
266
267 #define test_ready_state(ex) _test_ready_state(__LINE__,ex);
268 static void _test_ready_state(unsigned line, READYSTATE exstate)
269 {
270     READYSTATE state;
271     HRESULT hres;
272
273     hres = IWebBrowser2_get_ReadyState(wb, &state);
274     ok_(__FILE__,line)(hres == S_OK, "get_ReadyState failed: %08x\n", hres);
275     ok_(__FILE__,line)(state == exstate, "ReadyState = %d, expected %d\n", state, exstate);
276 }
277
278 #define get_document(u) _get_document(__LINE__,u)
279 static IDispatch *_get_document(unsigned line, IWebBrowser2 *wb)
280 {
281     IHTMLDocument2 *html_doc;
282     IDispatch *disp;
283     HRESULT hres;
284
285     disp = NULL;
286     hres = IWebBrowser2_get_Document(wb, &disp);
287     ok_(__FILE__,line)(hres == S_OK, "get_Document failed: %08x\n", hres);
288     ok_(__FILE__,line)(disp != NULL, "doc_disp == NULL\n");
289
290     hres = IDispatch_QueryInterface(disp, &IID_IHTMLDocument2, (void**)&html_doc);
291     ok_(__FILE__,line)(hres == S_OK, "Could not get IHTMLDocument iface: %08x\n", hres);
292     ok(disp == (IDispatch*)html_doc, "disp != html_doc\n");
293     IHTMLDocument2_Release(html_doc);
294
295     return disp;
296 }
297
298 #define get_dochost(u) _get_dochost(__LINE__,u)
299 static IOleClientSite *_get_dochost(unsigned line, IWebBrowser2 *unk)
300 {
301     IOleClientSite *client_site;
302     IOleObject *oleobj;
303     IDispatch *doc;
304     HRESULT hres;
305
306     doc = _get_document(line, unk);
307     hres = IDispatch_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
308     IDispatch_Release(doc);
309     ok_(__FILE__,line)(hres == S_OK, "Got 0x%08x\n", hres);
310
311     hres = IOleObject_GetClientSite(oleobj, &client_site);
312     IOleObject_Release(oleobj);
313     ok_(__FILE__,line)(hres == S_OK, "Got 0x%08x\n", hres);
314
315     return client_site;
316 }
317
318 static HRESULT QueryInterface(REFIID,void**);
319
320 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface,
321         REFIID riid, void **ppv)
322 {
323     ok(0, "unexpected call\n");
324     return E_NOINTERFACE;
325 }
326
327 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
328 {
329     return 2;
330 }
331
332 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
333 {
334     return 1;
335 }
336
337 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
338         ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
339 {
340     ok(!pguidCmdGroup, "pguidCmdGroup != MULL\n");
341     ok(cCmds == 1, "cCmds=%d, expected 1\n", cCmds);
342     ok(!pCmdText, "pCmdText != NULL\n");
343
344     switch(prgCmds[0].cmdID) {
345     case OLECMDID_STOP:
346         CHECK_EXPECT2(QueryStatus_STOP);
347         prgCmds[0].cmdf = OLECMDF_SUPPORTED;
348         return S_OK;
349     case OLECMDID_SETPROGRESSTEXT:
350         CHECK_EXPECT(QueryStatus_SETPROGRESSTEXT);
351         prgCmds[0].cmdf = OLECMDF_ENABLED;
352         return S_OK;
353     case IDM_STOP:
354         /* Note:
355          *  IDM_STOP is a command specific to CGID_MSHTML (not an OLECMDID command).
356          *  This command appears here for the ExecWB and QueryStatusWB tests in order
357          *  to help demonstrate that these routines use a NULL pguidCmdGroup.
358          */
359         CHECK_EXPECT(QueryStatus_IDM_STOP);
360         prgCmds[0].cmdf = 0;
361         return S_OK;
362     default:
363         ok(0, "unexpected command %d\n", prgCmds[0].cmdID);
364     }
365
366     return E_FAIL;
367 }
368
369 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
370         DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
371 {
372     if(!pguidCmdGroup) {
373         switch(nCmdID) {
374         case OLECMDID_SETPROGRESSMAX:
375             CHECK_EXPECT2(Exec_SETPROGRESSMAX);
376             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
377             ok(pvaIn != NULL, "pvaIn == NULL\n");
378             if(pvaIn)
379                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
380             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
381             return S_OK;
382         case OLECMDID_SETPROGRESSPOS:
383             CHECK_EXPECT2(Exec_SETPROGRESSPOS);
384             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
385             ok(pvaIn != NULL, "pvaIn == NULL\n");
386             if(pvaIn)
387                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
388             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
389             return S_OK;
390         case OLECMDID_SETDOWNLOADSTATE:
391             if(is_downloading)
392                 ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER || !nCmdexecopt,
393                    "nCmdexecopts=%08x\n", nCmdexecopt);
394             else
395                 ok(!nCmdexecopt, "nCmdexecopts=%08x\n", nCmdexecopt);
396             ok(pvaOut == NULL, "pvaOut=%p\n", pvaOut);
397             ok(pvaIn != NULL, "pvaIn == NULL\n");
398             ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d\n", V_VT(pvaIn));
399             switch(V_I4(pvaIn)) {
400             case 0:
401                 CHECK_EXPECT2(Exec_SETDOWNLOADSTATE_0);
402                 break;
403             case 1:
404                 CHECK_EXPECT2(Exec_SETDOWNLOADSTATE_1);
405                 break;
406             default:
407                 ok(0, "unexpevted V_I4(pvaIn)=%d\n", V_I4(pvaIn));
408             }
409             return S_OK;
410         case OLECMDID_UPDATECOMMANDS:
411             CHECK_EXPECT2(Exec_UPDATECOMMANDS);
412             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
413             ok(!pvaIn, "pvaIn != NULL\n");
414             ok(!pvaOut, "pvaOut=%p, expected NULL\n", pvaOut);
415             return S_OK;
416         case OLECMDID_SETTITLE:
417             CHECK_EXPECT(Exec_SETTITLE);
418             /* TODO: test args */
419             return S_OK;
420         case OLECMDID_STOP:
421             CHECK_EXPECT(Exec_STOP);
422             return S_OK;
423         case IDM_STOP:
424             /* Note:
425              *  IDM_STOP is a command specific to CGID_MSHTML (not an OLECMDID command).
426              *  This command appears here for the ExecWB and QueryStatusWB tests in order
427              *  to help demonstrate that these routines use a NULL pguidCmdGroup.
428              */
429             CHECK_EXPECT(Exec_IDM_STOP);
430             return OLECMDERR_E_NOTSUPPORTED;
431         case OLECMDID_UPDATETRAVELENTRY_DATARECOVERY:
432         case 6058: /* TODO */
433             return E_NOTIMPL;
434         default:
435             ok(0, "unexpected nsCmdID %d\n", nCmdID);
436         }
437     }else if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
438         switch(nCmdID) {
439         case 20: /* TODO */
440         case 24: /* TODO */
441         case 25: /* IE5 */
442         case 37: /* TODO */
443         case 39: /* TODO */
444         case 66: /* TODO */
445         case 67: /* TODO */
446         case 69: /* TODO */
447         case 101: /* TODO (IE8) */
448         case 109: /* TODO (IE9) */
449             return E_FAIL;
450         default:
451             ok(0, "unexpected nCmdID %d\n", nCmdID);
452         }
453     }else if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
454         switch(nCmdID) {
455         case 105: /* TODO */
456         case 138: /* TODO */
457         case 140: /* TODO (Win7) */
458         case 144: /* TODO */
459             return E_FAIL;
460         default:
461             ok(0, "unexpected nCmdID %d\n", nCmdID);
462         }
463     }else if(IsEqualGUID(&CGID_DocHostCmdPriv, pguidCmdGroup)) {
464         switch(nCmdID) {
465         case 11: /* TODO */
466             break;
467         default:
468             ok(0, "unexpected nCmdID %d of CGID_DocHostCmdPriv\n", nCmdID);
469         }
470     }else if(IsEqualGUID(&CGID_DocHostCommandHandler, pguidCmdGroup)) {
471         switch(nCmdID) {
472         case 6041: /* TODO */
473             break;
474         case 2300:
475             CHECK_EXPECT(Exec_DocHostCommandHandler_2300);
476             return E_NOTIMPL;
477         default:
478             ok(0, "unexpected nCmdID %d of CGID_DocHostCommandHandler\n", nCmdID);
479         }
480     }else {
481         ok(0, "unexpected pguidCmdGroup %s\n", debugstr_guid(pguidCmdGroup));
482     }
483
484     return E_FAIL;
485 }
486
487 static IOleCommandTargetVtbl OleCommandTargetVtbl = {
488     OleCommandTarget_QueryInterface,
489     OleCommandTarget_AddRef,
490     OleCommandTarget_Release,
491     OleCommandTarget_QueryStatus,
492     OleCommandTarget_Exec
493 };
494
495 static IOleCommandTarget OleCommandTarget = { &OleCommandTargetVtbl };
496
497 static HRESULT WINAPI OleContainer_QueryInterface(IOleContainer *iface, REFIID riid, void **ppv)
498 {
499     if(IsEqualGUID(&IID_ITargetContainer, riid))
500         return E_NOINTERFACE; /* TODO */
501
502     if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
503         if(use_container_olecmd)
504         {
505             *ppv = &OleCommandTarget;
506             return S_OK;
507         }
508         else
509             return E_NOINTERFACE;
510     }
511
512     ok(0, "unexpected call\n");
513     return E_NOINTERFACE;
514 }
515
516 static ULONG WINAPI OleContainer_AddRef(IOleContainer *iface)
517 {
518     return 2;
519 }
520
521 static ULONG WINAPI OleContainer_Release(IOleContainer *iface)
522 {
523     return 1;
524 }
525
526 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer *iface, IBindCtx *pbc,
527         LPOLESTR pszDiaplayName, ULONG *pchEaten, IMoniker **ppmkOut)
528 {
529     ok(0, "unexpected call\n");
530     return E_NOTIMPL;
531 }
532
533 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer *iface, DWORD grfFlags,
534         IEnumUnknown **ppenum)
535 {
536     ok(0, "unexpected call\n");
537     return E_NOTIMPL;
538 }
539
540 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer *iface, BOOL fLock)
541 {
542     ok(0, "unexpected call\n");
543     return E_NOTIMPL;
544 }
545
546 static const IOleContainerVtbl OleContainerVtbl = {
547     OleContainer_QueryInterface,
548     OleContainer_AddRef,
549     OleContainer_Release,
550     OleContainer_ParseDisplayName,
551     OleContainer_EnumObjects,
552     OleContainer_LockContainer
553 };
554
555 static IOleContainer OleContainer = { &OleContainerVtbl };
556
557 static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
558 {
559     return QueryInterface(riid, ppv);
560 }
561
562 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
563 {
564     return 2;
565 }
566
567 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
568 {
569     return 1;
570 }
571
572 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
573 {
574     ok(0, "unexpected call\n");
575     return E_NOTIMPL;
576 }
577
578 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
579         ITypeInfo **ppTInfo)
580 {
581     ok(0, "unexpected call\n");
582     return E_NOTIMPL;
583 }
584
585 static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
586         UINT cNames, LCID lcid, DISPID *rgDispId)
587 {
588     ok(0, "unexpected call\n");
589     return E_NOTIMPL;
590 }
591
592 static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
593         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
594         EXCEPINFO *pExcepInfo, UINT *puArgErr)
595 {
596     ok(IsEqualGUID(&IID_NULL, riid), "riid != IID_NULL\n");
597     ok(pDispParams != NULL, "pDispParams == NULL\n");
598     ok(pExcepInfo == NULL, "pExcepInfo=%p, expected NULL\n", pExcepInfo);
599     ok(V_VT(pVarResult) == VT_EMPTY, "V_VT(pVarResult)=%d\n", V_VT(pVarResult));
600     ok(wFlags == DISPATCH_PROPERTYGET, "wFlags=%08x, expected DISPATCH_PROPERTYGET\n", wFlags);
601     ok(pDispParams->rgvarg == NULL, "pDispParams->rgvarg = %p\n", pDispParams->rgvarg);
602     ok(pDispParams->rgdispidNamedArgs == NULL,
603        "pDispParams->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
604     ok(pDispParams->cArgs == 0, "pDispParams->cArgs = %d\n", pDispParams->cArgs);
605     ok(pDispParams->cNamedArgs == 0, "pDispParams->cNamedArgs = %d\n", pDispParams->cNamedArgs);
606
607     switch(dispIdMember) {
608     case DISPID_AMBIENT_USERMODE:
609         CHECK_EXPECT2(Invoke_AMBIENT_USERMODE);
610         return E_FAIL;
611     case DISPID_AMBIENT_DLCONTROL:
612         CHECK_EXPECT(Invoke_AMBIENT_DLCONTROL);
613         ok(puArgErr != NULL, "puArgErr=%p\n", puArgErr);
614         return E_FAIL;
615     case DISPID_AMBIENT_USERAGENT:
616        CHECK_EXPECT(Invoke_AMBIENT_USERAGENT);
617         ok(puArgErr != NULL, "puArgErr=%p\n", puArgErr);
618         return E_FAIL;
619     case DISPID_AMBIENT_PALETTE:
620         CHECK_EXPECT(Invoke_AMBIENT_PALETTE);
621         ok(puArgErr != NULL, "puArgErr=%p\n", puArgErr);
622         return E_FAIL;
623     case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
624         CHECK_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
625         ok(puArgErr == NULL, "puArgErr=%p\n", puArgErr);
626         V_VT(pVarResult) = VT_BOOL;
627         V_BOOL(pVarResult) = VARIANT_FALSE;
628         return S_OK;
629     case DISPID_AMBIENT_SILENT:
630         CHECK_EXPECT(Invoke_AMBIENT_SILENT);
631         ok(puArgErr == NULL, "puArgErr=%p\n", puArgErr);
632         V_VT(pVarResult) = VT_BOOL;
633         V_BOOL(pVarResult) = VARIANT_FALSE;
634         return S_OK;
635     }
636
637     ok(0, "unexpected dispIdMember %d\n", dispIdMember);
638     return E_NOTIMPL;
639 }
640
641 static IDispatchVtbl DispatchVtbl = {
642     Dispatch_QueryInterface,
643     Dispatch_AddRef,
644     Dispatch_Release,
645     Dispatch_GetTypeInfoCount,
646     Dispatch_GetTypeInfo,
647     Dispatch_GetIDsOfNames,
648     Dispatch_Invoke
649 };
650
651 static IDispatch Dispatch = { &DispatchVtbl };
652
653 static HRESULT WINAPI WebBrowserEvents2_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
654 {
655     *ppv = NULL;
656
657     if(IsEqualGUID(&DIID_DWebBrowserEvents2, riid)) {
658         *ppv = iface;
659         return S_OK;
660     }
661
662     ok(0, "unexpected riid %s\n", debugstr_guid(riid));
663     return E_NOINTERFACE;
664 }
665
666 #define test_invoke_bool(p,s) _test_invoke_bool(__LINE__,p,s)
667 static void _test_invoke_bool(unsigned line, const DISPPARAMS *params, BOOL strict)
668 {
669     ok_(__FILE__,line) (params->rgvarg != NULL, "rgvarg == NULL\n");
670     ok_(__FILE__,line) (params->cArgs == 1, "cArgs=%d, expected 1\n", params->cArgs);
671     ok_(__FILE__,line) (V_VT(params->rgvarg) == VT_BOOL, "V_VT(arg)=%d\n", V_VT(params->rgvarg));
672     if(strict)
673         ok_(__FILE__,line) (V_BOOL(params->rgvarg) == exvb, "V_VT(arg)=%x, expected %x\n",
674                             V_BOOL(params->rgvarg), exvb);
675     else
676         ok_(__FILE__,line) (!V_BOOL(params->rgvarg) == !exvb, "V_VT(arg)=%x, expected %x\n",
677                             V_BOOL(params->rgvarg), exvb);
678 }
679
680 static void test_OnBeforeNavigate(const VARIANT *disp, const VARIANT *url, const VARIANT *flags,
681         const VARIANT *frame, const VARIANT *post_data, const VARIANT *headers, const VARIANT *cancel)
682 {
683     ok(V_VT(disp) == VT_DISPATCH, "V_VT(disp)=%d, expected VT_DISPATCH\n", V_VT(disp));
684     ok(V_DISPATCH(disp) != NULL, "V_DISPATCH(disp) == NULL\n");
685     ok(V_DISPATCH(disp) == (IDispatch*)wb, "V_DISPATCH(disp)=%p, wb=%p\n", V_DISPATCH(disp), wb);
686
687     ok(V_VT(url) == (VT_BYREF|VT_VARIANT), "V_VT(url)=%x, expected VT_BYREF|VT_VARIANT\n", V_VT(url));
688     ok(V_VARIANTREF(url) != NULL, "V_VARIANTREF(url) == NULL)\n");
689     if(V_VARIANTREF(url)) {
690         ok(V_VT(V_VARIANTREF(url)) == VT_BSTR, "V_VT(V_VARIANTREF(url))=%d, expected VT_BSTR\n",
691            V_VT(V_VARIANTREF(url)));
692         ok(V_BSTR(V_VARIANTREF(url)) != NULL, "V_BSTR(V_VARIANTREF(url)) == NULL\n");
693         ok(!strcmp_wa(V_BSTR(V_VARIANTREF(url)), current_url), "unexpected url %s, expected %s\n",
694            wine_dbgstr_w(V_BSTR(V_VARIANTREF(url))), current_url);
695     }
696
697     ok(V_VT(flags) == (VT_BYREF|VT_VARIANT), "V_VT(flags)=%x, expected VT_BYREF|VT_VARIANT\n",
698        V_VT(flags));
699     ok(V_VT(flags) == (VT_BYREF|VT_VARIANT), "V_VT(flags)=%x, expected VT_BYREF|VT_VARIANT\n",
700        V_VT(flags));
701     ok(V_VARIANTREF(flags) != NULL, "V_VARIANTREF(flags) == NULL)\n");
702     if(V_VARIANTREF(flags)) {
703         ok(V_VT(V_VARIANTREF(flags)) == VT_I4, "V_VT(V_VARIANTREF(flags))=%d, expected VT_I4\n",
704            V_VT(V_VARIANTREF(flags)));
705         if(is_first_load) {
706             ok(V_I4(V_VARIANTREF(flags)) == 0, "V_I4(V_VARIANTREF(flags)) = %x, expected 0\n",
707                V_I4(V_VARIANTREF(flags)));
708         }else {
709             ok((V_I4(V_VARIANTREF(flags)) & ~0x40) == 0, "V_I4(V_VARIANTREF(flags)) = %x, expected 0x40 or 0\n",
710                V_I4(V_VARIANTREF(flags)));
711         }
712     }
713
714     ok(V_VT(frame) == (VT_BYREF|VT_VARIANT), "V_VT(frame)=%x, expected VT_BYREF|VT_VARIANT\n",
715        V_VT(frame));
716     ok(V_VT(frame) == (VT_BYREF|VT_VARIANT), "V_VT(frame)=%x, expected VT_BYREF|VT_VARIANT\n",
717        V_VT(frame));
718     ok(V_VARIANTREF(frame) != NULL, "V_VARIANTREF(frame) == NULL)\n");
719     if(V_VARIANTREF(frame)) {
720         ok(V_VT(V_VARIANTREF(frame)) == VT_BSTR, "V_VT(V_VARIANTREF(frame))=%d, expected VT_BSTR\n",
721            V_VT(V_VARIANTREF(frame)));
722         ok(V_BSTR(V_VARIANTREF(frame)) == NULL, "V_BSTR(V_VARIANTREF(frame)) = %p, expected NULL\n",
723            V_BSTR(V_VARIANTREF(frame)));
724     }
725
726     ok(V_VT(post_data) == (VT_BYREF|VT_VARIANT), "V_VT(post_data)=%x, expected VT_BYREF|VT_VARIANT\n",
727        V_VT(post_data));
728     ok(V_VT(post_data) == (VT_BYREF|VT_VARIANT), "V_VT(post_data)=%x, expected VT_BYREF|VT_VARIANT\n",
729        V_VT(post_data));
730     ok(V_VARIANTREF(post_data) != NULL, "V_VARIANTREF(post_data) == NULL)\n");
731     if(V_VARIANTREF(post_data)) {
732         ok(V_VT(V_VARIANTREF(post_data)) == (VT_VARIANT|VT_BYREF),
733            "V_VT(V_VARIANTREF(post_data))=%d, expected VT_VARIANT|VT_BYREF\n",
734            V_VT(V_VARIANTREF(post_data)));
735         ok(V_VARIANTREF(V_VARIANTREF(post_data)) != NULL,
736            "V_VARIANTREF(V_VARIANTREF(post_data)) == NULL\n");
737         if(V_VARIANTREF(V_VARIANTREF(post_data))) {
738             ok(V_VT(V_VARIANTREF(V_VARIANTREF(post_data))) == VT_EMPTY,
739                "V_VT(V_VARIANTREF(V_VARIANTREF(post_data))) = %d, expected VT_EMPTY\n",
740                V_VT(V_VARIANTREF(V_VARIANTREF(post_data))));
741
742             if(V_VT(V_VARIANTREF(V_VARIANTREF(post_data))) == (VT_UI1|VT_ARRAY)) {
743                 const SAFEARRAY *sa = V_ARRAY(V_VARIANTREF(V_VARIANTREF(post_data)));
744
745                 ok(sa->cDims == 1, "sa->cDims = %d, expected 1\n", sa->cDims);
746                 ok(sa->fFeatures == 0, "sa->fFeatures = %d, expected 0\n", sa->fFeatures);
747             }
748         }
749     }
750
751     ok(V_VT(headers) == (VT_BYREF|VT_VARIANT), "V_VT(headers)=%x, expected VT_BYREF|VT_VARIANT\n",
752        V_VT(headers));
753     ok(V_VARIANTREF(headers) != NULL, "V_VARIANTREF(headers) == NULL)\n");
754     if(V_VARIANTREF(headers)) {
755         ok(V_VT(V_VARIANTREF(headers)) == VT_BSTR, "V_VT(V_VARIANTREF(headers))=%d, expected VT_BSTR\n",
756            V_VT(V_VARIANTREF(headers)));
757         ok(V_BSTR(V_VARIANTREF(headers)) == NULL, "V_BSTR(V_VARIANTREF(headers)) = %p, expected NULL\n",
758            V_BSTR(V_VARIANTREF(headers)));
759     }
760
761     ok(V_VT(cancel) == (VT_BYREF|VT_BOOL), "V_VT(cancel)=%x, expected VT_BYREF|VT_BOOL\n",
762        V_VT(cancel));
763     ok(V_BOOLREF(cancel) != NULL, "V_BOOLREF(pDispParams->rgvarg[0] == NULL)\n");
764     if(V_BOOLREF(cancel))
765         ok(*V_BOOLREF(cancel) == VARIANT_FALSE, "*V_BOOLREF(cancel) = %x, expected VARIANT_FALSE\n",
766            *V_BOOLREF(cancel));
767 }
768
769 static void test_navigatecomplete2(DISPPARAMS *dp)
770 {
771     VARIANT *v;
772
773     CHECK_EXPECT(Invoke_NAVIGATECOMPLETE2);
774
775     ok(dp->rgvarg != NULL, "rgvarg == NULL\n");
776     ok(dp->cArgs == 2, "cArgs=%d, expected 2\n", dp->cArgs);
777
778     ok(V_VT(dp->rgvarg) == (VT_BYREF|VT_VARIANT), "V_VT(dp->rgvarg) = %d\n", V_VT(dp->rgvarg));
779     v = V_VARIANTREF(dp->rgvarg);
780     ok(V_VT(v) == VT_BSTR, "V_VT(url) = %d\n", V_VT(v));
781     ok(!strcmp_wa(V_BSTR(v), current_url), "url=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), current_url);
782
783     ok(V_VT(dp->rgvarg+1) == VT_DISPATCH, "V_VT(dp->rgvarg+1) = %d\n", V_VT(dp->rgvarg+1));
784     ok(V_DISPATCH(dp->rgvarg+1) == (IDispatch*)wb, "V_DISPATCH=%p, wb=%p\n", V_DISPATCH(dp->rgvarg+1), wb);
785
786     test_ready_state((dwl_flags & (DWL_FROM_PUT_HREF|DWL_FROM_GOBACK)) ? READYSTATE_COMPLETE : READYSTATE_LOADING);
787 }
788
789 static void test_documentcomplete(DISPPARAMS *dp)
790 {
791     VARIANT *v;
792
793     CHECK_EXPECT(Invoke_DOCUMENTCOMPLETE);
794
795     ok(dp->rgvarg != NULL, "rgvarg == NULL\n");
796     ok(dp->cArgs == 2, "cArgs=%d, expected 2\n", dp->cArgs);
797
798     ok(V_VT(dp->rgvarg) == (VT_BYREF|VT_VARIANT), "V_VT(dp->rgvarg) = %d\n", V_VT(dp->rgvarg));
799     v = V_VARIANTREF(dp->rgvarg);
800     ok(V_VT(v) == VT_BSTR, "V_VT(url) = %d\n", V_VT(v));
801     ok(!strcmp_wa(V_BSTR(v), current_url), "url=%s, expected %s\n", wine_dbgstr_w(V_BSTR(v)), current_url);
802
803     ok(V_VT(dp->rgvarg+1) == VT_DISPATCH, "V_VT(dp->rgvarg+1) = %d\n", V_VT(dp->rgvarg+1));
804     ok(V_DISPATCH(dp->rgvarg+1) == (IDispatch*)wb, "V_DISPATCH=%p, wb=%p\n", V_DISPATCH(dp->rgvarg+1), wb);
805
806     test_ready_state(READYSTATE_COMPLETE);
807 }
808
809 static HRESULT WINAPI WebBrowserEvents2_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
810         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
811         EXCEPINFO *pExcepInfo, UINT *puArgErr)
812 {
813     ok(IsEqualGUID(&IID_NULL, riid), "riid != IID_NULL\n");
814     ok(pDispParams != NULL, "pDispParams == NULL\n");
815     ok(pExcepInfo == NULL, "pExcepInfo=%p, expected NULL\n", pExcepInfo);
816     ok(pVarResult == NULL, "pVarResult=%p\n", pVarResult);
817     ok(wFlags == DISPATCH_METHOD, "wFlags=%08x, expected DISPATCH_METHOD\n", wFlags);
818     ok(pDispParams->rgdispidNamedArgs == NULL,
819        "pDispParams->rgdispidNamedArgs = %p\n", pDispParams->rgdispidNamedArgs);
820     ok(pDispParams->cNamedArgs == 0, "pDispParams->cNamedArgs = %d\n", pDispParams->cNamedArgs);
821
822     switch(dispIdMember) {
823     case DISPID_STATUSTEXTCHANGE:
824         CHECK_EXPECT2(Invoke_STATUSTEXTCHANGE);
825
826         ok(pDispParams->rgvarg != NULL, "rgvarg == NULL\n");
827         ok(pDispParams->cArgs == 1, "cArgs=%d, expected 1\n", pDispParams->cArgs);
828         ok(V_VT(pDispParams->rgvarg) == VT_BSTR, "V_VT(pDispParams->rgvarg)=%d, expected VT_BSTR\n",
829            V_VT(pDispParams->rgvarg));
830         /* TODO: Check text */
831         break;
832
833     case DISPID_PROPERTYCHANGE:
834         CHECK_EXPECT2(Invoke_PROPERTYCHANGE);
835
836         ok(pDispParams->rgvarg != NULL, "rgvarg == NULL\n");
837         ok(pDispParams->cArgs == 1, "cArgs=%d, expected 1\n", pDispParams->cArgs);
838         /* TODO: Check args */
839         break;
840
841     case DISPID_DOWNLOADBEGIN:
842         CHECK_EXPECT(Invoke_DOWNLOADBEGIN);
843
844         ok(pDispParams->rgvarg == NULL, "rgvarg=%p, expected NULL\n", pDispParams->rgvarg);
845         ok(pDispParams->cArgs == 0, "cArgs=%d, expected 0\n", pDispParams->cArgs);
846         test_ready_state(READYSTATE_LOADING);
847         break;
848
849     case DISPID_BEFORENAVIGATE2:
850         CHECK_EXPECT(Invoke_BEFORENAVIGATE2);
851
852         ok(pDispParams->rgvarg != NULL, "rgvarg == NULL\n");
853         ok(pDispParams->cArgs == 7, "cArgs=%d, expected 7\n", pDispParams->cArgs);
854         test_OnBeforeNavigate(pDispParams->rgvarg+6, pDispParams->rgvarg+5, pDispParams->rgvarg+4,
855                               pDispParams->rgvarg+3, pDispParams->rgvarg+2, pDispParams->rgvarg+1,
856                               pDispParams->rgvarg);
857         test_ready_state((dwl_flags & DWL_FROM_PUT_HREF) ? READYSTATE_COMPLETE : READYSTATE_LOADING);
858         break;
859
860     case DISPID_SETSECURELOCKICON:
861         CHECK_EXPECT2(Invoke_SETSECURELOCKICON);
862
863         ok(pDispParams->rgvarg != NULL, "rgvarg == NULL\n");
864         ok(pDispParams->cArgs == 1, "cArgs=%d, expected 1\n", pDispParams->cArgs);
865         /* TODO: Check args */
866         break;
867
868     case DISPID_FILEDOWNLOAD:
869         CHECK_EXPECT(Invoke_FILEDOWNLOAD);
870
871         ok(pDispParams->rgvarg != NULL, "rgvarg == NULL\n");
872         ok(pDispParams->cArgs == 2, "cArgs=%d, expected 2\n", pDispParams->cArgs);
873         /* TODO: Check args */
874         break;
875
876     case DISPID_COMMANDSTATECHANGE:
877         CHECK_EXPECT2(Invoke_COMMANDSTATECHANGE);
878
879         ok(pDispParams->rgvarg != NULL, "rgvarg == NULL\n");
880         ok(pDispParams->cArgs == 2, "cArgs=%d, expected 2\n", pDispParams->cArgs);
881
882         ok(V_VT(pDispParams->rgvarg) == VT_BOOL, "V_VT(pDispParams->rgvarg) = %d\n", V_VT(pDispParams->rgvarg));
883         ok(V_VT(pDispParams->rgvarg+1) == VT_I4, "V_VT(pDispParams->rgvarg+1) = %d\n", V_VT(pDispParams->rgvarg+1));
884
885         /* TODO: Check args */
886         break;
887
888     case DISPID_DOWNLOADCOMPLETE:
889         CHECK_EXPECT(Invoke_DOWNLOADCOMPLETE);
890
891         ok(pDispParams->rgvarg == NULL, "rgvarg=%p, expected NULL\n", pDispParams->rgvarg);
892         ok(pDispParams->cArgs == 0, "cArgs=%d, expected 0\n", pDispParams->cArgs);
893         test_ready_state(READYSTATE_LOADING);
894         break;
895
896     case DISPID_ONMENUBAR:
897         CHECK_EXPECT(Invoke_ONMENUBAR);
898         test_invoke_bool(pDispParams, TRUE);
899         break;
900
901     case DISPID_ONADDRESSBAR:
902         CHECK_EXPECT(Invoke_ONADDRESSBAR);
903         test_invoke_bool(pDispParams, TRUE);
904         break;
905
906     case DISPID_ONSTATUSBAR:
907         CHECK_EXPECT(Invoke_ONSTATUSBAR);
908         test_invoke_bool(pDispParams, TRUE);
909         break;
910
911     case DISPID_ONTOOLBAR:
912         CHECK_EXPECT(Invoke_ONTOOLBAR);
913         test_invoke_bool(pDispParams, FALSE);
914         break;
915
916     case DISPID_ONFULLSCREEN:
917         CHECK_EXPECT(Invoke_ONFULLSCREEN);
918         test_invoke_bool(pDispParams, TRUE);
919         break;
920
921     case DISPID_ONTHEATERMODE:
922         CHECK_EXPECT(Invoke_ONTHEATERMODE);
923         test_invoke_bool(pDispParams, TRUE);
924         break;
925
926     case DISPID_WINDOWSETRESIZABLE:
927         CHECK_EXPECT(Invoke_WINDOWSETRESIZABLE);
928         test_invoke_bool(pDispParams, TRUE);
929         break;
930
931     case DISPID_TITLECHANGE:
932         CHECK_EXPECT2(Invoke_TITLECHANGE);
933         /* FIXME */
934         break;
935
936     case DISPID_NAVIGATECOMPLETE2:
937         test_navigatecomplete2(pDispParams);
938         break;
939
940     case DISPID_PROGRESSCHANGE:
941         CHECK_EXPECT2(Invoke_PROGRESSCHANGE);
942         /* FIXME */
943         break;
944
945     case DISPID_DOCUMENTCOMPLETE:
946         test_documentcomplete(pDispParams);
947         break;
948
949     case 282: /* FIXME */
950         CHECK_EXPECT2(Invoke_282);
951         break;
952
953     default:
954         ok(0, "unexpected dispIdMember %d\n", dispIdMember);
955     }
956
957     return S_OK;
958 }
959
960 static IDispatchVtbl WebBrowserEvents2Vtbl = {
961     WebBrowserEvents2_QueryInterface,
962     Dispatch_AddRef,
963     Dispatch_Release,
964     Dispatch_GetTypeInfoCount,
965     Dispatch_GetTypeInfo,
966     Dispatch_GetIDsOfNames,
967     WebBrowserEvents2_Invoke
968 };
969
970 static IDispatch WebBrowserEvents2 = { &WebBrowserEvents2Vtbl };
971
972 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
973 {
974     return QueryInterface(riid, ppv);
975 }
976
977 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
978 {
979     return 2;
980 }
981
982 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
983 {
984     return 1;
985 }
986
987 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
988 {
989     ok(0, "unexpected call\n");
990     return E_NOTIMPL;
991 }
992
993 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
994         IMoniker **ppmon)
995 {
996     ok(0, "unexpected call\n");
997     return E_NOTIMPL;
998 }
999
1000 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1001 {
1002     CHECK_EXPECT(GetContainer);
1003
1004     ok(ppContainer != NULL, "ppContainer == NULL\n");
1005     if(ppContainer)
1006         *ppContainer = &OleContainer;
1007
1008     return S_OK;
1009 }
1010
1011 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1012 {
1013     CHECK_EXPECT(ShowObject);
1014     return S_OK;
1015 }
1016
1017 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1018 {
1019     ok(0, "unexpected call\n");
1020     return E_NOTIMPL;
1021 }
1022
1023 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1024 {
1025     ok(0, "unexpected call\n");
1026     return E_NOTIMPL;
1027 }
1028
1029 static const IOleClientSiteVtbl ClientSiteVtbl = {
1030     ClientSite_QueryInterface,
1031     ClientSite_AddRef,
1032     ClientSite_Release,
1033     ClientSite_SaveObject,
1034     ClientSite_GetMoniker,
1035     ClientSite_GetContainer,
1036     ClientSite_ShowObject,
1037     ClientSite_OnShowWindow,
1038     ClientSite_RequestNewObjectLayout
1039 };
1040
1041 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1042
1043 static HRESULT WINAPI IOleControlSite_fnQueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
1044 {
1045     *ppv = NULL;
1046     return E_NOINTERFACE;
1047 }
1048
1049 static ULONG WINAPI IOleControlSite_fnAddRef(IOleControlSite *iface)
1050 {
1051     return 2;
1052 }
1053
1054 static ULONG WINAPI IOleControlSite_fnRelease(IOleControlSite *iface)
1055 {
1056     return 1;
1057 }
1058
1059 static HRESULT WINAPI IOleControlSite_fnOnControlInfoChanged(IOleControlSite* This)
1060 {
1061     ok(0, "unexpected call\n");
1062     return E_NOTIMPL;
1063 }
1064
1065 static HRESULT WINAPI IOleControlSite_fnLockInPlaceActive(IOleControlSite* This,
1066                                                           BOOL fLock)
1067 {
1068     ok(0, "unexpected call\n");
1069     return E_NOTIMPL;
1070 }
1071
1072 static HRESULT WINAPI IOleControlSite_fnGetExtendedControl(IOleControlSite* This,
1073                                                            IDispatch **ppDisp)
1074 {
1075     ok(0, "unexpected call\n");
1076     return E_NOTIMPL;
1077 }
1078
1079 static HRESULT WINAPI IOleControlSite_fnTransformCoords(IOleControlSite* This,
1080                                                         POINTL *pPtlHimetric,
1081                                                         POINTF *pPtfContainer,
1082                                                         DWORD dwFlags)
1083 {
1084     ok(0, "unexpected call\n");
1085     return E_NOTIMPL;
1086 }
1087
1088 static HRESULT WINAPI IOleControlSite_fnTranslateAccelerator(IOleControlSite* This, MSG *pMsg,
1089                                                              DWORD grfModifiers)
1090 {
1091     CHECK_EXPECT(ControlSite_TranslateAccelerator);
1092     return hr_site_TranslateAccelerator;
1093 }
1094
1095 static HRESULT WINAPI IOleControlSite_fnOnFocus(IOleControlSite* This, BOOL fGotFocus)
1096 {
1097     CHECK_EXPECT2(OnFocus);
1098     return E_NOTIMPL;
1099 }
1100
1101 static HRESULT WINAPI IOleControlSite_fnShowPropertyFrame(IOleControlSite* This)
1102 {
1103     ok(0, "unexpected call\n");
1104     return E_NOTIMPL;
1105 }
1106
1107 static IOleControlSiteVtbl ControlSiteVtbl = {
1108     IOleControlSite_fnQueryInterface,
1109     IOleControlSite_fnAddRef,
1110     IOleControlSite_fnRelease,
1111     IOleControlSite_fnOnControlInfoChanged,
1112     IOleControlSite_fnLockInPlaceActive,
1113     IOleControlSite_fnGetExtendedControl,
1114     IOleControlSite_fnTransformCoords,
1115     IOleControlSite_fnTranslateAccelerator,
1116     IOleControlSite_fnOnFocus,
1117     IOleControlSite_fnShowPropertyFrame
1118 };
1119
1120 static IOleControlSite ControlSite = { &ControlSiteVtbl };
1121
1122 static HRESULT WINAPI InPlaceUIWindow_QueryInterface(IOleInPlaceFrame *iface,
1123                                                      REFIID riid, void **ppv)
1124 {
1125     ok(0, "unexpected call\n");
1126     return E_NOINTERFACE;
1127 }
1128
1129 static ULONG WINAPI InPlaceUIWindow_AddRef(IOleInPlaceFrame *iface)
1130 {
1131     return 2;
1132 }
1133
1134 static ULONG WINAPI InPlaceUIWindow_Release(IOleInPlaceFrame *iface)
1135 {
1136     return 1;
1137 }
1138
1139 static HRESULT WINAPI InPlaceUIWindow_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1140 {
1141     ok(0, "unexpected call\n");
1142     return E_NOTIMPL;
1143 }
1144
1145 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1146 {
1147     CHECK_EXPECT(Frame_GetWindow);
1148     ok(phwnd != NULL, "phwnd == NULL\n");
1149     if(phwnd)
1150         *phwnd = container_hwnd;
1151     return S_OK;
1152 }
1153
1154 static HRESULT WINAPI InPlaceUIWindow_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
1155 {
1156     ok(0, "unexpected call\n");
1157     return E_NOTIMPL;
1158 }
1159
1160 static HRESULT WINAPI InPlaceUIWindow_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
1161 {
1162     ok(0, "unexpected call\n");
1163     return E_NOTIMPL;
1164 }
1165
1166 static HRESULT WINAPI InPlaceUIWindow_RequestBorderSpace(IOleInPlaceFrame *iface,
1167         LPCBORDERWIDTHS pborderwidths)
1168 {
1169     ok(0, "unexpected call\n");
1170     return E_NOTIMPL;
1171 }
1172
1173 static HRESULT WINAPI InPlaceUIWindow_SetBorderSpace(IOleInPlaceFrame *iface,
1174         LPCBORDERWIDTHS pborderwidths)
1175 {
1176     ok(0, "unexpected call\n");
1177     return E_NOTIMPL;
1178 }
1179
1180 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
1181         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1182 {
1183     CHECK_EXPECT(UIWindow_SetActiveObject);
1184     if(!test_close) {
1185         ok(pActiveObject != NULL, "pActiveObject = NULL\n");
1186         ok(!lstrcmpW(pszObjName, wszItem), "unexpected pszObjName\n");
1187     } else {
1188         ok(!pActiveObject, "pActiveObject != NULL\n");
1189         ok(!pszObjName, "pszObjName != NULL\n");
1190     }
1191     return S_OK;
1192 }
1193
1194 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
1195         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1196 {
1197     CHECK_EXPECT(Frame_SetActiveObject);
1198     if(!test_close) {
1199         ok(pActiveObject != NULL, "pActiveObject = NULL\n");
1200         ok(!lstrcmpW(pszObjName, wszItem), "unexpected pszObjName\n");
1201     } else {
1202         ok(!pActiveObject, "pActiveObject != NULL\n");
1203         ok(!pszObjName, "pszObjName != NULL\n");
1204     }
1205     return S_OK;
1206 }
1207
1208 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
1209         LPOLEMENUGROUPWIDTHS lpMenuWidths)
1210 {
1211     ok(0, "unexpected call\n");
1212     return E_NOTIMPL;
1213 }
1214
1215 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
1216         HOLEMENU holemenu, HWND hwndActiveObject)
1217 {
1218     CHECK_EXPECT(SetMenu);
1219     ok(hmenuShared == NULL, "hmenuShared=%p\n", hmenuShared);
1220     ok(holemenu == NULL, "holemenu=%p\n", holemenu);
1221     ok(hwndActiveObject == shell_embedding_hwnd, "hwndActiveObject=%p, expected %p\n",
1222        hwndActiveObject, shell_embedding_hwnd);
1223     return S_OK;
1224 }
1225
1226 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
1227 {
1228     ok(0, "unexpected call\n");
1229     return E_NOTIMPL;
1230 }
1231
1232 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
1233 {
1234     CHECK_EXPECT2(SetStatusText);
1235     /* FIXME: Check pszStatusText */
1236     return S_OK;
1237 }
1238
1239 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
1240 {
1241     if(fEnable)
1242         CHECK_EXPECT2(EnableModeless_TRUE);
1243     else
1244         CHECK_EXPECT2(EnableModeless_FALSE);
1245     return S_OK;
1246 }
1247
1248 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
1249 {
1250     ok(0, "unexpected call\n");
1251     return E_NOTIMPL;
1252 }
1253
1254 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
1255     InPlaceUIWindow_QueryInterface,
1256     InPlaceUIWindow_AddRef,
1257     InPlaceUIWindow_Release,
1258     InPlaceUIWindow_GetWindow,
1259     InPlaceUIWindow_ContextSensitiveHelp,
1260     InPlaceUIWindow_GetBorder,
1261     InPlaceUIWindow_RequestBorderSpace,
1262     InPlaceUIWindow_SetBorderSpace,
1263     InPlaceUIWindow_SetActiveObject,
1264 };
1265
1266 static IOleInPlaceUIWindow InPlaceUIWindow = { (IOleInPlaceUIWindowVtbl*)&InPlaceUIWindowVtbl };
1267
1268 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
1269     InPlaceUIWindow_QueryInterface,
1270     InPlaceUIWindow_AddRef,
1271     InPlaceUIWindow_Release,
1272     InPlaceFrame_GetWindow,
1273     InPlaceUIWindow_ContextSensitiveHelp,
1274     InPlaceUIWindow_GetBorder,
1275     InPlaceUIWindow_RequestBorderSpace,
1276     InPlaceUIWindow_SetBorderSpace,
1277     InPlaceFrame_SetActiveObject,
1278     InPlaceFrame_InsertMenus,
1279     InPlaceFrame_SetMenu,
1280     InPlaceFrame_RemoveMenus,
1281     InPlaceFrame_SetStatusText,
1282     InPlaceFrame_EnableModeless,
1283     InPlaceFrame_TranslateAccelerator
1284 };
1285
1286 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
1287
1288 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSiteEx *iface, REFIID riid, void **ppv)
1289 {
1290     return QueryInterface(riid, ppv);
1291 }
1292
1293 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSiteEx *iface)
1294 {
1295     return 2;
1296 }
1297
1298 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSiteEx *iface)
1299 {
1300     return 1;
1301 }
1302
1303 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSiteEx *iface, HWND *phwnd)
1304 {
1305     CHECK_EXPECT(Site_GetWindow);
1306     ok(phwnd != NULL, "phwnd == NULL\n");
1307     if(phwnd)
1308         *phwnd = container_hwnd;
1309     return S_OK;
1310 }
1311
1312 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSiteEx *iface, BOOL fEnterMode)
1313 {
1314     ok(0, "unexpected call\n");
1315     return E_NOTIMPL;
1316 }
1317
1318 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSiteEx *iface)
1319 {
1320     CHECK_EXPECT(CanInPlaceActivate);
1321     return S_OK;
1322 }
1323
1324 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSiteEx *iface)
1325 {
1326     CHECK_EXPECT(OnInPlaceActivate);
1327     return S_OK;
1328 }
1329
1330 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSiteEx *iface)
1331 {
1332     CHECK_EXPECT(OnUIActivate);
1333     return S_OK;
1334 }
1335
1336 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSiteEx *iface,
1337         IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1338         LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1339 {
1340     static const RECT pos_rect = {2,1,1002,901};
1341     static const RECT clip_rect = {10,10,990,890};
1342
1343     CHECK_EXPECT(GetWindowContext);
1344
1345     ok(ppFrame != NULL, "ppFrame = NULL\n");
1346     if(ppFrame)
1347         *ppFrame = &InPlaceFrame;
1348
1349     ok(ppDoc != NULL, "ppDoc = NULL\n");
1350     if(ppDoc)
1351         *ppDoc = &InPlaceUIWindow;
1352
1353     ok(lprcPosRect != NULL, "lprcPosRect = NULL\n");
1354     if(lprcPosRect)
1355         memcpy(lprcPosRect, &pos_rect, sizeof(RECT));
1356
1357     ok(lprcClipRect != NULL, "lprcClipRect = NULL\n");
1358     if(lprcClipRect)
1359         memcpy(lprcClipRect, &clip_rect, sizeof(RECT));
1360
1361     ok(lpFrameInfo != NULL, "lpFrameInfo = NULL\n");
1362     if(lpFrameInfo) {
1363         ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
1364         lpFrameInfo->fMDIApp = FALSE;
1365         lpFrameInfo->hwndFrame = container_hwnd;
1366         lpFrameInfo->haccel = NULL;
1367         lpFrameInfo->cAccelEntries = 0;
1368     }
1369
1370     return S_OK;
1371 }
1372
1373 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSiteEx *iface, SIZE scrollExtant)
1374 {
1375     ok(0, "unexpected call\n");
1376     return E_NOTIMPL;
1377 }
1378
1379 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSiteEx *iface, BOOL fUndoable)
1380 {
1381     CHECK_EXPECT(OnUIDeactivate);
1382     ok(!fUndoable, "fUndoable should be FALSE\n");
1383     return S_OK;
1384 }
1385
1386 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSiteEx *iface)
1387 {
1388     CHECK_EXPECT(OnInPlaceDeactivate);
1389     return S_OK;
1390 }
1391
1392 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSiteEx *iface)
1393 {
1394     ok(0, "unexpected call\n");
1395     return E_NOTIMPL;
1396 }
1397
1398 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSiteEx *iface)
1399 {
1400     ok(0, "unexpected call\n");
1401     return E_NOTIMPL;
1402 }
1403
1404 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSiteEx *iface, LPCRECT lprcPosRect)
1405 {
1406     ok(0, "unexpected call\n");
1407     return E_NOTIMPL;
1408 }
1409
1410 static HRESULT WINAPI InPlaceSite_OnInPlaceActivateEx(IOleInPlaceSiteEx *iface,
1411                                                       BOOL *pNoRedraw, DWORD dwFlags)
1412 {
1413     ok(0, "unexpected call\n");
1414     return E_NOTIMPL;
1415 }
1416
1417 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivateEx(IOleInPlaceSiteEx *iface,
1418                                                         BOOL fNoRedraw)
1419 {
1420     ok(0, "unexpected call\n");
1421     return E_NOTIMPL;
1422 }
1423
1424 static HRESULT WINAPI InPlaceSite_RequestUIActivate(IOleInPlaceSiteEx *iface)
1425 {
1426     CHECK_EXPECT2(RequestUIActivate);
1427     return S_OK;
1428 }
1429
1430 static const IOleInPlaceSiteExVtbl InPlaceSiteExVtbl = {
1431     InPlaceSite_QueryInterface,
1432     InPlaceSite_AddRef,
1433     InPlaceSite_Release,
1434     InPlaceSite_GetWindow,
1435     InPlaceSite_ContextSensitiveHelp,
1436     InPlaceSite_CanInPlaceActivate,
1437     InPlaceSite_OnInPlaceActivate,
1438     InPlaceSite_OnUIActivate,
1439     InPlaceSite_GetWindowContext,
1440     InPlaceSite_Scroll,
1441     InPlaceSite_OnUIDeactivate,
1442     InPlaceSite_OnInPlaceDeactivate,
1443     InPlaceSite_DiscardUndoState,
1444     InPlaceSite_DeactivateAndUndo,
1445     InPlaceSite_OnPosRectChange,
1446     InPlaceSite_OnInPlaceActivateEx,
1447     InPlaceSite_OnInPlaceDeactivateEx,
1448     InPlaceSite_RequestUIActivate
1449 };
1450
1451 static IOleInPlaceSiteEx InPlaceSite = { &InPlaceSiteExVtbl };
1452
1453 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
1454 {
1455     return QueryInterface(riid, ppv);
1456 }
1457
1458 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
1459 {
1460     return 2;
1461 }
1462
1463 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
1464 {
1465     return 1;
1466 }
1467
1468 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
1469         IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
1470 {
1471     ok(0, "unexpected call %d %p %p %p\n", dwID, ppt, pcmdtReserved, pdicpReserved);
1472     return S_FALSE;
1473 }
1474
1475 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
1476 {
1477     CHECK_EXPECT2(GetHostInfo);
1478     ok(pInfo != NULL, "pInfo=NULL\n");
1479     if(pInfo) {
1480         ok(pInfo->cbSize == sizeof(DOCHOSTUIINFO) || broken(!pInfo->cbSize), "pInfo->cbSize=%u\n", pInfo->cbSize);
1481         ok(!pInfo->dwFlags, "pInfo->dwFlags=%08x, expected 0\n", pInfo->dwFlags);
1482         ok(!pInfo->dwDoubleClick, "pInfo->dwDoubleClick=%08x, expected 0\n", pInfo->dwDoubleClick);
1483         ok(!pInfo->pchHostCss, "pInfo->pchHostCss=%p, expected NULL\n", pInfo->pchHostCss);
1484         ok(!pInfo->pchHostNS, "pInfo->pchhostNS=%p, expected NULL\n", pInfo->pchHostNS);
1485     }
1486     return E_FAIL;
1487 }
1488
1489 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
1490         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
1491         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
1492 {
1493     CHECK_EXPECT(ShowUI);
1494     return E_NOTIMPL;
1495 }
1496
1497 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
1498 {
1499     CHECK_EXPECT(HideUI);
1500     return E_NOTIMPL;
1501 }
1502
1503 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
1504 {
1505     CHECK_EXPECT2(UpdateUI);
1506     return E_NOTIMPL;
1507 }
1508
1509 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
1510 {
1511     if(fEnable)
1512         CHECK_EXPECT(DocHost_EnableModeless_TRUE);
1513     else
1514         CHECK_EXPECT(DocHost_EnableModeless_FALSE);
1515
1516     return S_OK;
1517 }
1518
1519 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
1520 {
1521     ok(0, "unexpected call\n");
1522     return E_NOTIMPL;
1523 }
1524
1525 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
1526 {
1527     ok(0, "unexpected call\n");
1528     return E_NOTIMPL;
1529 }
1530
1531 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
1532         IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
1533 {
1534     ok(0, "unexpected call\n");
1535     return E_NOTIMPL;
1536 }
1537
1538 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
1539         const GUID *pguidCmdGroup, DWORD nCmdID)
1540 {
1541     CHECK_EXPECT(DocHost_TranslateAccelerator);
1542     ok(pguidCmdGroup != NULL, "Got NULL pguidCmdGroup.\n");
1543     if(pguidCmdGroup)
1544         ok(IsEqualGUID(pguidCmdGroup, &CGID_MSHTML), "Unexpected pguidCmdGroup\n");
1545     ok(lpMsg != NULL, "Got NULL lpMsg.\n");
1546     return hr_dochost_TranslateAccelerator;
1547 }
1548
1549 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
1550         LPOLESTR *pchKey, DWORD dw)
1551 {
1552     CHECK_EXPECT(GetOptionKeyPath);
1553     ok(pchKey != NULL, "pchKey==NULL\n");
1554     if(pchKey)
1555         ok(*pchKey == NULL, "*pchKey=%p\n", *pchKey);
1556     ok(!dw, "dw=%x\n", dw);
1557     return E_NOTIMPL;
1558 }
1559
1560 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
1561         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
1562 {
1563     CHECK_EXPECT(GetDropTarget);
1564     return E_NOTIMPL;
1565 }
1566
1567 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
1568 {
1569     CHECK_EXPECT(GetExternal);
1570     *ppDispatch = NULL;
1571     return S_FALSE;
1572 }
1573
1574 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
1575         OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
1576 {
1577     if(is_downloading && !(dwl_flags & DWL_EXPECT_BEFORE_NAVIGATE))
1578         todo_wine CHECK_EXPECT(TranslateUrl);
1579     else
1580         CHECK_EXPECT(TranslateUrl);
1581     return E_NOTIMPL;
1582 }
1583
1584 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
1585         IDataObject **ppPORet)
1586 {
1587     ok(0, "unexpected call\n");
1588     return E_NOTIMPL;
1589 }
1590
1591 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
1592         LPOLESTR *pchKey, DWORD dw)
1593 {
1594     CHECK_EXPECT(GetOverridesKeyPath);
1595     ok(pchKey != NULL, "pchKey==NULL\n");
1596     if(pchKey)
1597         ok(*pchKey == NULL, "*pchKey=%p\n", *pchKey);
1598     ok(!dw, "dw=%x\n", dw);
1599     return E_NOTIMPL;
1600 }
1601
1602 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
1603     DocHostUIHandler_QueryInterface,
1604     DocHostUIHandler_AddRef,
1605     DocHostUIHandler_Release,
1606     DocHostUIHandler_ShowContextMenu,
1607     DocHostUIHandler_GetHostInfo,
1608     DocHostUIHandler_ShowUI,
1609     DocHostUIHandler_HideUI,
1610     DocHostUIHandler_UpdateUI,
1611     DocHostUIHandler_EnableModeless,
1612     DocHostUIHandler_OnDocWindowActivate,
1613     DocHostUIHandler_OnFrameWindowActivate,
1614     DocHostUIHandler_ResizeBorder,
1615     DocHostUIHandler_TranslateAccelerator,
1616     DocHostUIHandler_GetOptionKeyPath,
1617     DocHostUIHandler_GetDropTarget,
1618     DocHostUIHandler_GetExternal,
1619     DocHostUIHandler_TranslateUrl,
1620     DocHostUIHandler_FilterDataObject,
1621     DocHostUIHandler_GetOverrideKeyPath
1622 };
1623
1624 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
1625
1626
1627 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
1628 {
1629     return QueryInterface(riid, ppv);
1630 }
1631
1632 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
1633 {
1634     return 2;
1635 }
1636
1637 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
1638 {
1639     return 1;
1640 }
1641
1642 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
1643                                     REFGUID guidService, REFIID riid, void **ppv)
1644 {
1645     *ppv = NULL;
1646
1647     if(!winetest_interactive)
1648         return E_NOINTERFACE;
1649
1650     if (IsEqualGUID(&SID_STopLevelBrowser, guidService))
1651         trace("Service SID_STopLevelBrowser\n");
1652     else if (IsEqualGUID(&SID_SEditCommandTarget, guidService))
1653         trace("Service SID_SEditCommandTarget\n");
1654     else if (IsEqualGUID(&IID_ITargetFrame2, guidService))
1655         trace("Service IID_ITargetFrame2\n");
1656     else if (IsEqualGUID(&SID_SInternetSecurityManager, guidService))
1657         trace("Service SID_SInternetSecurityManager\n");
1658     else if (IsEqualGUID(&SID_SOleUndoManager, guidService))
1659         trace("Service SID_SOleUndoManager\n");
1660     else if (IsEqualGUID(&SID_IMimeInfo, guidService))
1661         trace("Service SID_IMimeInfo\n");
1662     else if (IsEqualGUID(&SID_STopWindow, guidService))
1663         trace("Service SID_STopWindow\n");
1664
1665     /* 30D02401-6A81-11D0-8274-00C04FD5AE38 Explorer Bar: Search */
1666     /* D1E7AFEC-6A2E-11D0-8C78-00C04FD918B4 no info */
1667     /* A9227C3C-7F8E-11D0-8CB0-00A0C92DBFE8 no info */
1668     /* 371EA634-DC5C-11D1-BA57-00C04FC2040E one reference to IVersionHost */
1669     /* 3050F429-98B5-11CF-BB82-00AA00BDCE0B IID_IElementBehaviorFactory */
1670     /* 6D12FE80-7911-11CF-9534-0000C05BAE0B SID_DefView */
1671     /* AD7F6C62-F6BD-11D2-959B-006097C553C8 no info */
1672     /* 53A2D5B1-D2FC-11D0-84E0-006097C9987D no info */
1673     /* 3050F312-98B5-11CF-BB82-00AA00BDCE0B HTMLFrameBaseClass */
1674     /* 639447BD-B2D3-44B9-9FB0-510F23CB45E4 no info */
1675     /* 20C46561-8491-11CF-960C-0080C7F4EE85 no info */
1676
1677     else
1678         trace("Service %s not supported\n", debugstr_guid(guidService));
1679
1680     return E_NOINTERFACE;
1681 }
1682
1683
1684 static const IServiceProviderVtbl ServiceProviderVtbl = {
1685     ServiceProvider_QueryInterface,
1686     ServiceProvider_AddRef,
1687     ServiceProvider_Release,
1688     ServiceProvider_QueryService
1689 };
1690
1691 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
1692
1693
1694 static HRESULT QueryInterface(REFIID riid, void **ppv)
1695 {
1696     *ppv = NULL;
1697
1698     if(IsEqualGUID(&IID_IUnknown, riid)
1699             || IsEqualGUID(&IID_IOleClientSite, riid))
1700         *ppv = &ClientSite;
1701     else if(IsEqualGUID(&IID_IOleWindow, riid)
1702             || IsEqualGUID(&IID_IOleInPlaceSite, riid)
1703             || IsEqualGUID(&IID_IOleInPlaceSiteEx, riid))
1704         *ppv = &InPlaceSite;
1705     else if(IsEqualGUID(&IID_IDocHostUIHandler, riid)
1706             || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
1707         *ppv = use_container_dochostui ? &DocHostUIHandler : NULL;
1708     else if(IsEqualGUID(&IID_IDispatch, riid))
1709         *ppv = &Dispatch;
1710     else if(IsEqualGUID(&IID_IServiceProvider, riid))
1711         *ppv = &ServiceProvider;
1712     else if(IsEqualGUID(&IID_IDocHostShowUI, riid))
1713         trace("interface IID_IDocHostShowUI\n");
1714     else if(IsEqualGUID(&IID_IOleControlSite, riid))
1715         *ppv = &ControlSite;
1716     else if(IsEqualGUID(&IID_IOleCommandTarget, riid))
1717         trace("interface IID_IOleCommandTarget\n");
1718
1719     /* B6EA2050-048A-11D1-82B9-00C04FB9942E IAxWinHostWindow */
1720
1721     else
1722     {
1723         /* are there more interfaces, that a host can support? */
1724         trace("%s: interface not supported\n", debugstr_guid(riid));
1725     }
1726
1727     return (*ppv) ? S_OK : E_NOINTERFACE;
1728 }
1729
1730 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1731 {
1732     return DefWindowProcW(hwnd, msg, wParam, lParam);
1733 }
1734
1735 static HWND create_container_window(void)
1736 {
1737     static const WCHAR wszWebBrowserContainer[] =
1738         {'W','e','b','B','r','o','w','s','e','r','C','o','n','t','a','i','n','e','r',0};
1739     static WNDCLASSEXW wndclass = {
1740         sizeof(WNDCLASSEXW),
1741         0,
1742         wnd_proc,
1743         0, 0, NULL, NULL, NULL, NULL, NULL,
1744         wszWebBrowserContainer,
1745         NULL
1746     };
1747
1748     RegisterClassExW(&wndclass);
1749     return CreateWindowW(wszWebBrowserContainer, wszWebBrowserContainer,
1750             WS_OVERLAPPEDWINDOW, 10, 10, 600, 600, NULL, NULL, NULL, NULL);
1751 }
1752
1753 static void test_DoVerb(IWebBrowser2 *unk)
1754 {
1755     IOleObject *oleobj;
1756     RECT rect = {0,0,1000,1000};
1757     HRESULT hres;
1758
1759     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
1760     ok(hres == S_OK, "QueryInterface(IID_OleObject) failed: %08x\n", hres);
1761     if(FAILED(hres))
1762         return;
1763
1764     SET_EXPECT(CanInPlaceActivate);
1765     SET_EXPECT(Site_GetWindow);
1766     SET_EXPECT(OnInPlaceActivate);
1767     SET_EXPECT(GetWindowContext);
1768     SET_EXPECT(ShowObject);
1769     SET_EXPECT(GetContainer);
1770     SET_EXPECT(Frame_GetWindow);
1771     SET_EXPECT(OnUIActivate);
1772     SET_EXPECT(Frame_SetActiveObject);
1773     SET_EXPECT(UIWindow_SetActiveObject);
1774     SET_EXPECT(SetMenu);
1775     SET_EXPECT(OnFocus);
1776
1777     hres = IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, &ClientSite,
1778                              0, (HWND)0xdeadbeef, &rect);
1779     ok(hres == S_OK, "DoVerb failed: %08x\n", hres);
1780
1781     CHECK_CALLED(CanInPlaceActivate);
1782     CHECK_CALLED(Site_GetWindow);
1783     CHECK_CALLED(OnInPlaceActivate);
1784     CHECK_CALLED(GetWindowContext);
1785     CHECK_CALLED(ShowObject);
1786     CHECK_CALLED(GetContainer);
1787     CHECK_CALLED(Frame_GetWindow);
1788     CHECK_CALLED(OnUIActivate);
1789     CHECK_CALLED(Frame_SetActiveObject);
1790     CHECK_CALLED(UIWindow_SetActiveObject);
1791     CHECK_CALLED(SetMenu);
1792     todo_wine CHECK_CALLED(OnFocus);
1793
1794     hres = IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, &ClientSite,
1795                            0, (HWND)0xdeadbeef, &rect);
1796     ok(hres == S_OK, "DoVerb failed: %08x\n", hres);
1797
1798     IOleObject_Release(oleobj);
1799 }
1800
1801 static void call_DoVerb(IWebBrowser2 *unk, LONG verb)
1802 {
1803     IOleObject *oleobj;
1804     RECT rect = {60,60,600,600};
1805     HRESULT hres;
1806
1807     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
1808     ok(hres == S_OK, "QueryInterface(IID_OleObject) failed: %08x\n", hres);
1809     if(FAILED(hres))
1810         return;
1811
1812     hres = IOleObject_DoVerb(oleobj, verb, NULL, &ClientSite,
1813                              -1, container_hwnd, &rect);
1814     ok(hres == S_OK, "DoVerb failed: %08x\n", hres);
1815
1816     IOleObject_Release(oleobj);
1817 }
1818
1819 static HWND get_hwnd(IWebBrowser2 *unk)
1820 {
1821     IOleInPlaceObject *inplace;
1822     HWND hwnd;
1823     HRESULT hres;
1824
1825     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleInPlaceObject, (void**)&inplace);
1826     ok(hres == S_OK, "QueryInterface(IID_OleInPlaceObject) failed: %08x\n", hres);
1827
1828     hres = IOleInPlaceObject_GetWindow(inplace, &hwnd);
1829     ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
1830
1831     IOleInPlaceObject_Release(inplace);
1832     return hwnd;
1833 }
1834
1835 static void test_GetMiscStatus(IOleObject *oleobj)
1836 {
1837     DWORD st, i;
1838     HRESULT hres;
1839
1840     for(i=0; i<10; i++) {
1841         st = 0xdeadbeef;
1842         hres = IOleObject_GetMiscStatus(oleobj, i, &st);
1843         ok(hres == S_OK, "GetMiscStatus failed: %08x\n", hres);
1844         ok(st == (OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|OLEMISC_INSIDEOUT
1845                   |OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE),
1846            "st=%08x, expected OLEMISC_SETCLIENTSITEFIRST|OLEMISC_ACTIVATEWHENVISIBLE|"
1847            "OLEMISC_INSIDEOUT|OLEMISC_CANTLINKINSIDE|OLEMISC_RECOMPOSEONRESIZE)\n", st);
1848     }
1849 }
1850
1851 static void test_SetHostNames(IOleObject *oleobj)
1852 {
1853     HRESULT hres;
1854
1855     static const WCHAR test_appW[] =  {'t','e','s','t',' ','a','p','p',0};
1856
1857     hres = IOleObject_SetHostNames(oleobj, test_appW, (void*)0xdeadbeef);
1858     ok(hres == S_OK, "SetHostNames failed: %08x\n", hres);
1859 }
1860
1861 static void test_ClientSite(IWebBrowser2 *unk, IOleClientSite *client, BOOL stop_download)
1862 {
1863     IOleObject *oleobj;
1864     IOleInPlaceObject *inplace;
1865     HWND hwnd;
1866     HRESULT hres;
1867
1868     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
1869     ok(hres == S_OK, "QueryInterface(IID_OleObject) failed: %08x\n", hres);
1870     if(FAILED(hres))
1871         return;
1872
1873     test_GetMiscStatus(oleobj);
1874     test_SetHostNames(oleobj);
1875
1876     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleInPlaceObject, (void**)&inplace);
1877     ok(hres == S_OK, "QueryInterface(IID_OleInPlaceObject) failed: %08x\n", hres);
1878     if(FAILED(hres)) {
1879         IOleObject_Release(oleobj);
1880         return;
1881     }
1882
1883     hres = IOleInPlaceObject_GetWindow(inplace, &hwnd);
1884     ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
1885     ok((hwnd == NULL) ^ (client == NULL), "unexpected hwnd %p\n", hwnd);
1886
1887     if(client) {
1888         SET_EXPECT(GetContainer);
1889         SET_EXPECT(Site_GetWindow);
1890         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
1891         SET_EXPECT(Invoke_AMBIENT_SILENT);
1892     }else if(stop_download) {
1893         SET_EXPECT(Invoke_DOWNLOADCOMPLETE);
1894         if (use_container_olecmd) SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
1895         SET_EXPECT(Invoke_COMMANDSTATECHANGE);
1896     }else {
1897         SET_EXPECT(Invoke_STATUSTEXTCHANGE);
1898         SET_EXPECT(Invoke_PROGRESSCHANGE);
1899     }
1900
1901     hres = IOleObject_SetClientSite(oleobj, client);
1902     ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
1903
1904     if(client) {
1905         CHECK_CALLED(GetContainer);
1906         CHECK_CALLED(Site_GetWindow);
1907         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
1908         CHECK_CALLED(Invoke_AMBIENT_SILENT);
1909     }else if(stop_download) {
1910         todo_wine CHECK_CALLED(Invoke_DOWNLOADCOMPLETE);
1911         if (use_container_olecmd) todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
1912         todo_wine CHECK_CALLED(Invoke_COMMANDSTATECHANGE);
1913     }else {
1914         CLEAR_CALLED(Invoke_STATUSTEXTCHANGE); /* Called by IE9 */
1915         CLEAR_CALLED(Invoke_PROGRESSCHANGE);
1916     }
1917
1918     hres = IOleInPlaceObject_GetWindow(inplace, &hwnd);
1919     ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
1920     ok((hwnd == NULL) == (client == NULL), "unexpected hwnd %p\n", hwnd);
1921
1922     shell_embedding_hwnd = hwnd;
1923
1924     test_SetHostNames(oleobj);
1925
1926     IOleInPlaceObject_Release(inplace);
1927     IOleObject_Release(oleobj);
1928 }
1929
1930 static void test_ClassInfo(IWebBrowser2 *unk)
1931 {
1932     IProvideClassInfo2 *class_info;
1933     TYPEATTR *type_attr;
1934     ITypeInfo *typeinfo;
1935     GUID guid;
1936     HRESULT hres;
1937
1938     hres = IWebBrowser2_QueryInterface(unk, &IID_IProvideClassInfo2, (void**)&class_info);
1939     ok(hres == S_OK, "QueryInterface(IID_IProvideClassInfo)  failed: %08x\n", hres);
1940     if(FAILED(hres))
1941         return;
1942
1943     hres = IProvideClassInfo2_GetGUID(class_info, GUIDKIND_DEFAULT_SOURCE_DISP_IID, &guid);
1944     ok(hres == S_OK, "GetGUID failed: %08x\n", hres);
1945     ok(IsEqualGUID(wb_version > 1 ? &DIID_DWebBrowserEvents2 : &DIID_DWebBrowserEvents, &guid), "wrong guid\n");
1946
1947     hres = IProvideClassInfo2_GetGUID(class_info, 0, &guid);
1948     ok(hres == E_FAIL, "GetGUID failed: %08x, expected E_FAIL\n", hres);
1949     ok(IsEqualGUID(&IID_NULL, &guid), "wrong guid\n");
1950
1951     hres = IProvideClassInfo2_GetGUID(class_info, 2, &guid);
1952     ok(hres == E_FAIL, "GetGUID failed: %08x, expected E_FAIL\n", hres);
1953     ok(IsEqualGUID(&IID_NULL, &guid), "wrong guid\n");
1954
1955     hres = IProvideClassInfo2_GetGUID(class_info, GUIDKIND_DEFAULT_SOURCE_DISP_IID, NULL);
1956     ok(hres == E_POINTER, "GetGUID failed: %08x, expected E_POINTER\n", hres);
1957
1958     hres = IProvideClassInfo2_GetGUID(class_info, 0, NULL);
1959     ok(hres == E_POINTER, "GetGUID failed: %08x, expected E_POINTER\n", hres);
1960
1961     typeinfo = NULL;
1962     hres = IProvideClassInfo2_GetClassInfo(class_info, &typeinfo);
1963     ok(hres == S_OK, "GetClassInfo failed: %08x\n", hres);
1964     ok(typeinfo != NULL, "typeinfo == NULL\n");
1965
1966     hres = ITypeInfo_GetTypeAttr(typeinfo, &type_attr);
1967     ok(hres == S_OK, "GetTypeAtr failed: %08x\n", hres);
1968
1969     ok(IsEqualGUID(&type_attr->guid, wb_version > 1 ? &CLSID_WebBrowser : &CLSID_WebBrowser_V1),
1970        "guid = %s\n", debugstr_guid(&type_attr->guid));
1971
1972     ITypeInfo_ReleaseTypeAttr(typeinfo, type_attr);
1973     ITypeInfo_Release(typeinfo);
1974
1975     IProvideClassInfo2_Release(class_info);
1976 }
1977
1978 static void test_EnumVerbs(IWebBrowser2 *wb)
1979 {
1980     IEnumOLEVERB *enum_verbs;
1981     IOleObject *oleobj;
1982     OLEVERB verbs[20];
1983     ULONG fetched;
1984     HRESULT hres;
1985
1986     hres = IWebBrowser2_QueryInterface(wb, &IID_IOleObject, (void**)&oleobj);
1987     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
1988
1989     hres = IOleObject_EnumVerbs(oleobj, &enum_verbs);
1990     IOleObject_Release(oleobj);
1991     ok(hres == S_OK, "EnumVerbs failed: %08x\n", hres);
1992     ok(enum_verbs != NULL, "enum_verbs == NULL\n");
1993
1994     fetched = 0xdeadbeef;
1995     hres = IEnumOLEVERB_Next(enum_verbs, sizeof(verbs)/sizeof(*verbs), verbs, &fetched);
1996     ok(hres == S_OK, "Next failed: %08x\n", hres);
1997     ok(!fetched, "fetched = %d\n", fetched);
1998
1999     fetched = 0xdeadbeef;
2000     hres = IEnumOLEVERB_Next(enum_verbs, 1, verbs, &fetched);
2001     ok(hres == S_OK, "Next failed: %08x\n", hres);
2002     ok(!fetched, "fetched = %d\n", fetched);
2003
2004     hres = IEnumOLEVERB_Reset(enum_verbs);
2005     ok(hres == S_OK, "Reset failed: %08x\n", hres);
2006
2007     fetched = 0xdeadbeef;
2008     hres = IEnumOLEVERB_Next(enum_verbs, 1, verbs, &fetched);
2009     ok(hres == S_OK, "Next failed: %08x\n", hres);
2010     ok(!fetched, "fetched = %d\n", fetched);
2011
2012     hres = IEnumOLEVERB_Next(enum_verbs, 1, verbs, NULL);
2013     ok(hres == S_OK, "Next failed: %08x\n", hres);
2014
2015     hres = IEnumOLEVERB_Skip(enum_verbs, 20);
2016     ok(hres == S_OK, "Reset failed: %08x\n", hres);
2017
2018     fetched = 0xdeadbeef;
2019     hres = IEnumOLEVERB_Next(enum_verbs, 1, verbs, &fetched);
2020     ok(hres == S_OK, "Next failed: %08x\n", hres);
2021     ok(!fetched, "fetched = %d\n", fetched);
2022
2023     IEnumOLEVERB_Release(enum_verbs);
2024 }
2025
2026 static void test_ie_funcs(IWebBrowser2 *wb)
2027 {
2028     IDispatch *disp;
2029     VARIANT_BOOL b;
2030     int i;
2031     LONG hwnd;
2032     HRESULT hres;
2033     BSTR sName;
2034
2035     /* HWND */
2036
2037     hwnd = 0xdeadbeef;
2038     hres = IWebBrowser2_get_HWND(wb, &hwnd);
2039     ok(hres == E_FAIL, "get_HWND failed: %08x, expected E_FAIL\n", hres);
2040     ok(hwnd == 0, "unexpected hwnd %x\n", hwnd);
2041
2042     /* MenuBar */
2043
2044     hres = IWebBrowser2_get_MenuBar(wb, &b);
2045     ok(hres == S_OK, "get_MenuBar failed: %08x\n", hres);
2046     ok(b == VARIANT_TRUE, "b=%x\n", b);
2047
2048     SET_EXPECT(Invoke_ONMENUBAR);
2049     hres = IWebBrowser2_put_MenuBar(wb, (exvb = VARIANT_FALSE));
2050     ok(hres == S_OK, "put_MenuBar failed: %08x\n", hres);
2051     CHECK_CALLED(Invoke_ONMENUBAR);
2052
2053     hres = IWebBrowser2_get_MenuBar(wb, &b);
2054     ok(hres == S_OK, "get_MenuBar failed: %08x\n", hres);
2055     ok(b == VARIANT_FALSE, "b=%x\n", b);
2056
2057     SET_EXPECT(Invoke_ONMENUBAR);
2058     hres = IWebBrowser2_put_MenuBar(wb, (exvb = 100));
2059     ok(hres == S_OK, "put_MenuBar failed: %08x\n", hres);
2060     CHECK_CALLED(Invoke_ONMENUBAR);
2061
2062     hres = IWebBrowser2_get_MenuBar(wb, &b);
2063     ok(hres == S_OK, "get_MenuBar failed: %08x\n", hres);
2064     ok(b == VARIANT_TRUE, "b=%x\n", b);
2065
2066     /* AddressBar */
2067
2068     hres = IWebBrowser2_get_AddressBar(wb, &b);
2069     ok(hres == S_OK, "get_AddressBar failed: %08x\n", hres);
2070     ok(b == VARIANT_TRUE, "b=%x\n", b);
2071
2072     SET_EXPECT(Invoke_ONADDRESSBAR);
2073     hres = IWebBrowser2_put_AddressBar(wb, (exvb = VARIANT_FALSE));
2074     ok(hres == S_OK, "put_AddressBar failed: %08x\n", hres);
2075     CHECK_CALLED(Invoke_ONADDRESSBAR);
2076
2077     hres = IWebBrowser2_get_AddressBar(wb, &b);
2078     ok(hres == S_OK, "get_MenuBar failed: %08x\n", hres);
2079     ok(b == VARIANT_FALSE, "b=%x\n", b);
2080
2081     SET_EXPECT(Invoke_ONADDRESSBAR);
2082     hres = IWebBrowser2_put_AddressBar(wb, (exvb = 100));
2083     ok(hres == S_OK, "put_AddressBar failed: %08x\n", hres);
2084     CHECK_CALLED(Invoke_ONADDRESSBAR);
2085
2086     hres = IWebBrowser2_get_AddressBar(wb, &b);
2087     ok(hres == S_OK, "get_AddressBar failed: %08x\n", hres);
2088     ok(b == VARIANT_TRUE, "b=%x\n", b);
2089
2090     SET_EXPECT(Invoke_ONADDRESSBAR);
2091     hres = IWebBrowser2_put_AddressBar(wb, (exvb = VARIANT_TRUE));
2092     ok(hres == S_OK, "put_MenuBar failed: %08x\n", hres);
2093     CHECK_CALLED(Invoke_ONADDRESSBAR);
2094
2095     /* StatusBar */
2096
2097     hres = IWebBrowser2_get_StatusBar(wb, &b);
2098     ok(hres == S_OK, "get_StatusBar failed: %08x\n", hres);
2099     ok(b == VARIANT_TRUE, "b=%x\n", b);
2100
2101     SET_EXPECT(Invoke_ONSTATUSBAR);
2102     hres = IWebBrowser2_put_StatusBar(wb, (exvb = VARIANT_TRUE));
2103     ok(hres == S_OK, "put_StatusBar failed: %08x\n", hres);
2104     CHECK_CALLED(Invoke_ONSTATUSBAR);
2105
2106     hres = IWebBrowser2_get_StatusBar(wb, &b);
2107     ok(hres == S_OK, "get_StatusBar failed: %08x\n", hres);
2108     ok(b == VARIANT_TRUE, "b=%x\n", b);
2109
2110     SET_EXPECT(Invoke_ONSTATUSBAR);
2111     hres = IWebBrowser2_put_StatusBar(wb, (exvb = VARIANT_FALSE));
2112     ok(hres == S_OK, "put_StatusBar failed: %08x\n", hres);
2113     CHECK_CALLED(Invoke_ONSTATUSBAR);
2114
2115     hres = IWebBrowser2_get_StatusBar(wb, &b);
2116     ok(hres == S_OK, "get_StatusBar failed: %08x\n", hres);
2117     ok(b == VARIANT_FALSE, "b=%x\n", b);
2118
2119     SET_EXPECT(Invoke_ONSTATUSBAR);
2120     hres = IWebBrowser2_put_StatusBar(wb, (exvb = 100));
2121     ok(hres == S_OK, "put_StatusBar failed: %08x\n", hres);
2122     CHECK_CALLED(Invoke_ONSTATUSBAR);
2123
2124     hres = IWebBrowser2_get_StatusBar(wb, &b);
2125     ok(hres == S_OK, "get_StatusBar failed: %08x\n", hres);
2126     ok(b == VARIANT_TRUE, "b=%x\n", b);
2127
2128     /* ToolBar */
2129
2130     hres = IWebBrowser2_get_ToolBar(wb, &i);
2131     ok(hres == S_OK, "get_ToolBar failed: %08x\n", hres);
2132     ok(i, "i=%x\n", i);
2133
2134     SET_EXPECT(Invoke_ONTOOLBAR);
2135     hres = IWebBrowser2_put_ToolBar(wb, (exvb = VARIANT_FALSE));
2136     ok(hres == S_OK, "put_ToolBar failed: %08x\n", hres);
2137     CHECK_CALLED(Invoke_ONTOOLBAR);
2138
2139     hres = IWebBrowser2_get_ToolBar(wb, &i);
2140     ok(hres == S_OK, "get_ToolBar failed: %08x\n", hres);
2141     ok(i == VARIANT_FALSE, "b=%x\n", i);
2142
2143     SET_EXPECT(Invoke_ONTOOLBAR);
2144     hres = IWebBrowser2_put_ToolBar(wb, (exvb = 100));
2145     ok(hres == S_OK, "put_ToolBar failed: %08x\n", hres);
2146     CHECK_CALLED(Invoke_ONTOOLBAR);
2147
2148     hres = IWebBrowser2_get_ToolBar(wb, &i);
2149     ok(hres == S_OK, "get_ToolBar failed: %08x\n", hres);
2150     ok(i, "i=%x\n", i);
2151
2152     SET_EXPECT(Invoke_ONTOOLBAR);
2153     hres = IWebBrowser2_put_ToolBar(wb, (exvb = VARIANT_TRUE));
2154     ok(hres == S_OK, "put_ToolBar failed: %08x\n", hres);
2155     CHECK_CALLED(Invoke_ONTOOLBAR);
2156
2157     /* FullScreen */
2158
2159     hres = IWebBrowser2_get_FullScreen(wb, &b);
2160     ok(hres == S_OK, "get_FullScreen failed: %08x\n", hres);
2161     ok(b == VARIANT_FALSE, "b=%x\n", b);
2162
2163     SET_EXPECT(Invoke_ONFULLSCREEN);
2164     hres = IWebBrowser2_put_FullScreen(wb, (exvb = VARIANT_TRUE));
2165     ok(hres == S_OK, "put_FullScreen failed: %08x\n", hres);
2166     CHECK_CALLED(Invoke_ONFULLSCREEN);
2167
2168     hres = IWebBrowser2_get_FullScreen(wb, &b);
2169     ok(hres == S_OK, "get_FullScreen failed: %08x\n", hres);
2170     ok(b == VARIANT_TRUE, "b=%x\n", b);
2171
2172     SET_EXPECT(Invoke_ONFULLSCREEN);
2173     hres = IWebBrowser2_put_FullScreen(wb, (exvb = 100));
2174     ok(hres == S_OK, "put_FullScreen failed: %08x\n", hres);
2175     CHECK_CALLED(Invoke_ONFULLSCREEN);
2176
2177     hres = IWebBrowser2_get_FullScreen(wb, &b);
2178     ok(hres == S_OK, "get_FullScreen failed: %08x\n", hres);
2179     ok(b == VARIANT_TRUE, "b=%x\n", b);
2180
2181     SET_EXPECT(Invoke_ONFULLSCREEN);
2182     hres = IWebBrowser2_put_FullScreen(wb, (exvb = VARIANT_FALSE));
2183     ok(hres == S_OK, "put_FullScreen failed: %08x\n", hres);
2184     CHECK_CALLED(Invoke_ONFULLSCREEN);
2185
2186     /* TheaterMode */
2187
2188     hres = IWebBrowser2_get_TheaterMode(wb, &b);
2189     ok(hres == S_OK, "get_TheaterMode failed: %08x\n", hres);
2190     ok(b == VARIANT_FALSE, "b=%x\n", b);
2191
2192     SET_EXPECT(Invoke_ONTHEATERMODE);
2193     hres = IWebBrowser2_put_TheaterMode(wb, (exvb = VARIANT_TRUE));
2194     ok(hres == S_OK, "put_TheaterMode failed: %08x\n", hres);
2195     CHECK_CALLED(Invoke_ONTHEATERMODE);
2196
2197     hres = IWebBrowser2_get_TheaterMode(wb, &b);
2198     ok(hres == S_OK, "get_TheaterMode failed: %08x\n", hres);
2199     ok(b == VARIANT_TRUE, "b=%x\n", b);
2200
2201     SET_EXPECT(Invoke_ONTHEATERMODE);
2202     hres = IWebBrowser2_put_TheaterMode(wb, (exvb = 100));
2203     ok(hres == S_OK, "put_TheaterMode failed: %08x\n", hres);
2204     CHECK_CALLED(Invoke_ONTHEATERMODE);
2205
2206     hres = IWebBrowser2_get_TheaterMode(wb, &b);
2207     ok(hres == S_OK, "get_TheaterMode failed: %08x\n", hres);
2208     ok(b == VARIANT_TRUE, "b=%x\n", b);
2209
2210     SET_EXPECT(Invoke_ONTHEATERMODE);
2211     hres = IWebBrowser2_put_TheaterMode(wb, (exvb = VARIANT_FALSE));
2212     ok(hres == S_OK, "put_TheaterMode failed: %08x\n", hres);
2213     CHECK_CALLED(Invoke_ONTHEATERMODE);
2214
2215     /* Resizable */
2216
2217     b = 0x100;
2218     hres = IWebBrowser2_get_Resizable(wb, &b);
2219     ok(hres == E_NOTIMPL, "get_Resizable failed: %08x\n", hres);
2220     ok(b == 0x100, "b=%x\n", b);
2221
2222     SET_EXPECT(Invoke_WINDOWSETRESIZABLE);
2223     hres = IWebBrowser2_put_Resizable(wb, (exvb = VARIANT_TRUE));
2224     ok(hres == S_OK, "put_Resizable failed: %08x\n", hres);
2225     CHECK_CALLED(Invoke_WINDOWSETRESIZABLE);
2226
2227     SET_EXPECT(Invoke_WINDOWSETRESIZABLE);
2228     hres = IWebBrowser2_put_Resizable(wb, (exvb = VARIANT_FALSE));
2229     ok(hres == S_OK, "put_Resizable failed: %08x\n", hres);
2230     CHECK_CALLED(Invoke_WINDOWSETRESIZABLE);
2231
2232     hres = IWebBrowser2_get_Resizable(wb, &b);
2233     ok(hres == E_NOTIMPL, "get_Resizable failed: %08x\n", hres);
2234     ok(b == 0x100, "b=%x\n", b);
2235
2236     /* Application */
2237
2238     disp = NULL;
2239     hres = IWebBrowser2_get_Application(wb, &disp);
2240     ok(hres == S_OK, "get_Application failed: %08x\n", hres);
2241     ok(disp == (void*)wb, "disp=%p, expected %p\n", disp, wb);
2242     if(disp)
2243         IDispatch_Release(disp);
2244
2245     hres = IWebBrowser2_get_Application(wb, NULL);
2246     ok(hres == E_POINTER, "get_Application failed: %08x, expected E_POINTER\n", hres);
2247
2248     /* Name */
2249     hres = IWebBrowser2_get_Name(wb, &sName);
2250     ok(hres == S_OK, "getName failed: %08x, expected S_OK\n", hres);
2251     if (is_lang_english())
2252         ok(!strcmp_wa(sName, "Microsoft Web Browser Control"), "got '%s', expected 'Microsoft Web Browser Control'\n", wine_dbgstr_w(sName));
2253     else /* Non-English cannot be blank. */
2254         ok(sName!=NULL, "get_Name return a NULL string.\n");
2255     SysFreeString(sName);
2256
2257     /* Quit */
2258
2259     hres = IWebBrowser2_Quit(wb);
2260     ok(hres == E_FAIL, "Quit failed: %08x, expected E_FAIL\n", hres);
2261 }
2262
2263 static void test_Silent(IWebBrowser2 *wb, IOleControl *control, BOOL is_clientsite)
2264 {
2265     VARIANT_BOOL b;
2266     HRESULT hres;
2267
2268     b = 100;
2269     hres = IWebBrowser2_get_Silent(wb, &b);
2270     ok(hres == S_OK, "get_Silent failed: %08x\n", hres);
2271     ok(b == VARIANT_FALSE, "b=%x\n", b);
2272
2273     hres = IWebBrowser2_put_Silent(wb, VARIANT_TRUE);
2274     ok(hres == S_OK, "set_Silent failed: %08x\n", hres);
2275
2276     b = 100;
2277     hres = IWebBrowser2_get_Silent(wb, &b);
2278     ok(hres == S_OK, "get_Silent failed: %08x\n", hres);
2279     ok(b == VARIANT_TRUE, "b=%x\n", b);
2280
2281     hres = IWebBrowser2_put_Silent(wb, 100);
2282     ok(hres == S_OK, "set_Silent failed: %08x\n", hres);
2283
2284     b = 100;
2285     hres = IWebBrowser2_get_Silent(wb, &b);
2286     ok(hres == S_OK, "get_Silent failed: %08x\n", hres);
2287     ok(b == VARIANT_TRUE, "b=%x\n", b);
2288
2289     hres = IWebBrowser2_put_Silent(wb, VARIANT_FALSE);
2290     ok(hres == S_OK, "set_Silent failed: %08x\n", hres);
2291
2292     b = 100;
2293     hres = IWebBrowser2_get_Silent(wb, &b);
2294     ok(hres == S_OK, "get_Silent failed: %08x\n", hres);
2295     ok(b == VARIANT_FALSE, "b=%x\n", b);
2296
2297     if(is_clientsite) {
2298         hres = IWebBrowser2_put_Silent(wb, VARIANT_TRUE);
2299         ok(hres == S_OK, "set_Silent failed: %08x\n", hres);
2300
2301         SET_EXPECT(Invoke_AMBIENT_SILENT);
2302     }
2303
2304     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_SILENT);
2305     ok(hres == S_OK, "OnAmbientPropertyChange failed %08x\n", hres);
2306
2307     if(is_clientsite)
2308         CHECK_CALLED(Invoke_AMBIENT_SILENT);
2309
2310     b = 100;
2311     hres = IWebBrowser2_get_Silent(wb, &b);
2312     ok(hres == S_OK, "get_Silent failed: %08x\n", hres);
2313     ok(b == VARIANT_FALSE, "b=%x\n", b);
2314 }
2315
2316 static void test_Offline(IWebBrowser2 *wb, IOleControl *control, BOOL is_clientsite)
2317 {
2318     VARIANT_BOOL b;
2319     HRESULT hres;
2320
2321     b = 100;
2322     hres = IWebBrowser2_get_Offline(wb, &b);
2323     ok(hres == S_OK, "get_Offline failed: %08x\n", hres);
2324     ok(b == VARIANT_FALSE, "b=%x\n", b);
2325
2326     hres = IWebBrowser2_put_Offline(wb, VARIANT_TRUE);
2327     ok(hres == S_OK, "set_Offline failed: %08x\n", hres);
2328
2329     b = 100;
2330     hres = IWebBrowser2_get_Offline(wb, &b);
2331     ok(hres == S_OK, "get_Offline failed: %08x\n", hres);
2332     ok(b == VARIANT_TRUE, "b=%x\n", b);
2333
2334     hres = IWebBrowser2_put_Offline(wb, 100);
2335     ok(hres == S_OK, "set_Offline failed: %08x\n", hres);
2336
2337     b = 100;
2338     hres = IWebBrowser2_get_Offline(wb, &b);
2339     ok(hres == S_OK, "get_Offline failed: %08x\n", hres);
2340     ok(b == VARIANT_TRUE, "b=%x\n", b);
2341
2342     hres = IWebBrowser2_put_Offline(wb, VARIANT_FALSE);
2343     ok(hres == S_OK, "set_Offline failed: %08x\n", hres);
2344
2345     b = 100;
2346     hres = IWebBrowser2_get_Offline(wb, &b);
2347     ok(hres == S_OK, "get_Offline failed: %08x\n", hres);
2348     ok(b == VARIANT_FALSE, "b=%x\n", b);
2349
2350     if(is_clientsite) {
2351         hres = IWebBrowser2_put_Offline(wb, VARIANT_TRUE);
2352         ok(hres == S_OK, "set_Offline failed: %08x\n", hres);
2353
2354         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2355     }
2356
2357     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
2358     ok(hres == S_OK, "OnAmbientPropertyChange failed %08x\n", hres);
2359
2360     if(is_clientsite)
2361         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2362
2363     b = 100;
2364     hres = IWebBrowser2_get_Offline(wb, &b);
2365     ok(hres == S_OK, "get_Offline failed: %08x\n", hres);
2366     ok(b == VARIANT_FALSE, "b=%x\n", b);
2367 }
2368
2369 static void test_ambient_unknown(IWebBrowser2 *wb, IOleControl *control, BOOL is_clientsite)
2370 {
2371     HRESULT hres;
2372
2373     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2374     SET_EXPECT(Invoke_AMBIENT_SILENT);
2375     SET_EXPECT(Invoke_AMBIENT_USERMODE);
2376     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
2377     SET_EXPECT(Invoke_AMBIENT_USERAGENT);
2378     SET_EXPECT(Invoke_AMBIENT_PALETTE);
2379
2380     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_UNKNOWN);
2381     ok(hres == S_OK, "OnAmbientPropertyChange failed %08x\n", hres);
2382
2383     CHECK_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2384     CHECK_EXPECT(Invoke_AMBIENT_SILENT);
2385     CHECK_EXPECT(Invoke_AMBIENT_USERMODE);
2386     CHECK_EXPECT(Invoke_AMBIENT_DLCONTROL);
2387     CHECK_EXPECT(Invoke_AMBIENT_USERAGENT);
2388     CHECK_EXPECT(Invoke_AMBIENT_PALETTE);
2389
2390     CLEAR_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2391     CLEAR_CALLED(Invoke_AMBIENT_SILENT);
2392     CLEAR_CALLED(Invoke_AMBIENT_USERMODE);
2393     CLEAR_CALLED(Invoke_AMBIENT_DLCONTROL);
2394     CLEAR_CALLED(Invoke_AMBIENT_USERAGENT);
2395     CLEAR_CALLED(Invoke_AMBIENT_PALETTE);
2396 }
2397
2398 static void test_wb_funcs(IWebBrowser2 *wb, BOOL is_clientsite)
2399 {
2400     IOleControl *control;
2401     HRESULT hres;
2402
2403     hres = IWebBrowser2_QueryInterface(wb, &IID_IOleControl, (void**)&control);
2404     ok(hres == S_OK, "Could not get IOleControl interface: %08x\n", hres);
2405
2406     test_Silent(wb, control, is_clientsite);
2407     test_Offline(wb, control, is_clientsite);
2408     test_ambient_unknown(wb, control, is_clientsite);
2409
2410     IOleControl_Release(control);
2411 }
2412
2413 static void test_GetControlInfo(IWebBrowser2 *unk)
2414 {
2415     IOleControl *control;
2416     CONTROLINFO info;
2417     HRESULT hres;
2418
2419     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleControl, (void**)&control);
2420     ok(hres == S_OK, "Could not get IOleControl: %08x\n", hres);
2421     if(FAILED(hres))
2422         return;
2423
2424     hres = IOleControl_GetControlInfo(control, &info);
2425     ok(hres == E_NOTIMPL, "GetControlInfo failed: %08x, expected E_NOTIMPL\n", hres);
2426     hres = IOleControl_GetControlInfo(control, NULL);
2427     ok(hres == E_NOTIMPL, "GetControlInfo failed: %08x, expected E_NOTIMPL\n", hres);
2428
2429     IOleControl_Release(control);
2430 }
2431
2432 static void test_Extent(IWebBrowser2 *unk)
2433 {
2434     IOleObject *oleobj;
2435     SIZE size, expected;
2436     HRESULT hres;
2437     DWORD dpi_x;
2438     DWORD dpi_y;
2439     HDC hdc;
2440
2441     /* default aspect ratio is 96dpi / 96dpi */
2442     hdc = GetDC(0);
2443     dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
2444     dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
2445     ReleaseDC(0, hdc);
2446     if (dpi_x != 96 || dpi_y != 96)
2447         trace("dpi: %d / %d\n", dpi_y, dpi_y);
2448
2449     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
2450     ok(hres == S_OK, "Could not get IOleObkect: %08x\n", hres);
2451     if(FAILED(hres))
2452         return;
2453
2454     size.cx = size.cy = 0xdeadbeef;
2455     hres = IOleObject_GetExtent(oleobj, DVASPECT_CONTENT, &size);
2456     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2457     /* Default size is 50x20 pixels, in himetric units */
2458     expected.cx = MulDiv( 50, 2540, dpi_x );
2459     expected.cy = MulDiv( 20, 2540, dpi_y );
2460     ok(size.cx == expected.cx && size.cy == expected.cy, "size = {%d %d} (expected %d %d)\n",
2461        size.cx, size.cy, expected.cx, expected.cy );
2462
2463     size.cx = 800;
2464     size.cy = 700;
2465     hres = IOleObject_SetExtent(oleobj, DVASPECT_CONTENT, &size);
2466     ok(hres == S_OK, "SetExtent failed: %08x\n", hres);
2467
2468     size.cx = size.cy = 0xdeadbeef;
2469     hres = IOleObject_GetExtent(oleobj, DVASPECT_CONTENT, &size);
2470     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2471     ok(size.cx == 800 && size.cy == 700, "size = {%d %d}\n", size.cx, size.cy);
2472
2473     size.cx = size.cy = 0xdeadbeef;
2474     hres = IOleObject_GetExtent(oleobj, 0, &size);
2475     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2476     ok(size.cx == 800 && size.cy == 700, "size = {%d %d}\n", size.cx, size.cy);
2477
2478     size.cx = 900;
2479     size.cy = 800;
2480     hres = IOleObject_SetExtent(oleobj, 0, &size);
2481     ok(hres == S_OK, "SetExtent failed: %08x\n", hres);
2482
2483     size.cx = size.cy = 0xdeadbeef;
2484     hres = IOleObject_GetExtent(oleobj, 0, &size);
2485     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2486     ok(size.cx == 900 && size.cy == 800, "size = {%d %d}\n", size.cx, size.cy);
2487
2488     size.cx = size.cy = 0xdeadbeef;
2489     hres = IOleObject_GetExtent(oleobj, 0xdeadbeef, &size);
2490     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2491     ok(size.cx == 900 && size.cy == 800, "size = {%d %d}\n", size.cx, size.cy);
2492
2493     size.cx = 1000;
2494     size.cy = 900;
2495     hres = IOleObject_SetExtent(oleobj, 0xdeadbeef, &size);
2496     ok(hres == S_OK, "SetExtent failed: %08x\n", hres);
2497
2498     size.cx = size.cy = 0xdeadbeef;
2499     hres = IOleObject_GetExtent(oleobj, 0xdeadbeef, &size);
2500     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2501     ok(size.cx == 1000 && size.cy == 900, "size = {%d %d}\n", size.cx, size.cy);
2502
2503     size.cx = size.cy = 0xdeadbeef;
2504     hres = IOleObject_GetExtent(oleobj, DVASPECT_CONTENT, &size);
2505     ok(hres == S_OK, "GetExtent failed: %08x\n", hres);
2506     ok(size.cx == 1000 && size.cy == 900, "size = {%d %d}\n", size.cx, size.cy);
2507
2508     IOleObject_Release(oleobj);
2509 }
2510
2511 static void test_ConnectionPoint(IWebBrowser2 *unk, BOOL init)
2512 {
2513     IConnectionPointContainer *container;
2514     IConnectionPoint *point;
2515     HRESULT hres;
2516
2517     static DWORD dw = 100;
2518
2519     hres = IWebBrowser2_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2520     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2521     if(FAILED(hres))
2522         return;
2523
2524     hres = IConnectionPointContainer_FindConnectionPoint(container, &DIID_DWebBrowserEvents2, &point);
2525     IConnectionPointContainer_Release(container);
2526     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2527     if(FAILED(hres))
2528         return;
2529
2530     if(init) {
2531         hres = IConnectionPoint_Advise(point, (IUnknown*)&WebBrowserEvents2, &dw);
2532         ok(hres == S_OK, "Advise failed: %08x\n", hres);
2533         ok(dw == 1, "dw=%d, expected 1\n", dw);
2534     }else {
2535         hres = IConnectionPoint_Unadvise(point, dw);
2536         ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
2537     }
2538
2539     IConnectionPoint_Release(point);
2540 }
2541
2542 static void test_Navigate2(IWebBrowser2 *webbrowser, const char *nav_url)
2543 {
2544     VARIANT url;
2545     BOOL is_file;
2546     HRESULT hres;
2547
2548     test_LocationURL(webbrowser, is_first_load ? "" : current_url);
2549     test_ready_state(is_first_load ? READYSTATE_UNINITIALIZED : READYSTATE_COMPLETE);
2550
2551     is_http = !memcmp(nav_url, "http:", 5);
2552     V_VT(&url) = VT_BSTR;
2553     V_BSTR(&url) = a2bstr(current_url = nav_url);
2554
2555     if((is_file = !strncasecmp(nav_url, "file://", 7)))
2556         current_url = nav_url + 7;
2557
2558     if(is_first_load) {
2559         SET_EXPECT(Invoke_AMBIENT_USERMODE);
2560         SET_EXPECT(Invoke_PROPERTYCHANGE);
2561         SET_EXPECT(Invoke_BEFORENAVIGATE2);
2562         SET_EXPECT(Invoke_DOWNLOADBEGIN);
2563         if (use_container_olecmd) SET_EXPECT(Exec_SETDOWNLOADSTATE_1);
2564         SET_EXPECT(EnableModeless_FALSE);
2565         SET_EXPECT(Invoke_STATUSTEXTCHANGE);
2566         SET_EXPECT(SetStatusText);
2567         if(use_container_dochostui)
2568             SET_EXPECT(GetHostInfo);
2569         SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
2570         SET_EXPECT(Invoke_AMBIENT_USERAGENT);
2571         SET_EXPECT(Invoke_AMBIENT_PALETTE);
2572         if(use_container_dochostui) {
2573             SET_EXPECT(GetOptionKeyPath);
2574             SET_EXPECT(GetOverridesKeyPath);
2575         }
2576         if (use_container_olecmd) SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
2577         if (use_container_olecmd) SET_EXPECT(Exec_SETPROGRESSMAX);
2578         if (use_container_olecmd) SET_EXPECT(Exec_SETPROGRESSPOS);
2579         SET_EXPECT(Invoke_SETSECURELOCKICON);
2580         SET_EXPECT(Invoke_FILEDOWNLOAD);
2581         if (use_container_olecmd) SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
2582         SET_EXPECT(Invoke_COMMANDSTATECHANGE);
2583         SET_EXPECT(EnableModeless_TRUE);
2584         if (!use_container_olecmd) SET_EXPECT(Invoke_DOWNLOADCOMPLETE);
2585         if (is_file) SET_EXPECT(Invoke_PROGRESSCHANGE);
2586     }
2587
2588     hres = IWebBrowser2_Navigate2(webbrowser, &url, NULL, NULL, NULL, NULL);
2589     ok(hres == S_OK, "Navigate2 failed: %08x\n", hres);
2590
2591     if(is_first_load) {
2592         CHECK_CALLED(Invoke_AMBIENT_USERMODE);
2593         todo_wine CHECK_CALLED(Invoke_PROPERTYCHANGE);
2594         CHECK_CALLED(Invoke_BEFORENAVIGATE2);
2595         todo_wine CHECK_CALLED(Invoke_DOWNLOADBEGIN);
2596         if (use_container_olecmd) todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_1);
2597         CHECK_CALLED(EnableModeless_FALSE);
2598         CHECK_CALLED(Invoke_STATUSTEXTCHANGE);
2599         CHECK_CALLED(SetStatusText);
2600         if(use_container_dochostui)
2601             CHECK_CALLED(GetHostInfo);
2602         CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
2603         CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
2604         CLEAR_CALLED(Invoke_AMBIENT_PALETTE); /* Not called by IE9 */
2605         if(use_container_dochostui) {
2606             CLEAR_CALLED(GetOptionKeyPath);
2607             CHECK_CALLED(GetOverridesKeyPath);
2608         }
2609         if (use_container_olecmd) todo_wine CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
2610         if (use_container_olecmd) todo_wine CHECK_CALLED(Exec_SETPROGRESSMAX);
2611         if (use_container_olecmd) todo_wine CHECK_CALLED(Exec_SETPROGRESSPOS);
2612         todo_wine CHECK_CALLED(Invoke_SETSECURELOCKICON);
2613         todo_wine CHECK_CALLED(Invoke_FILEDOWNLOAD);
2614         todo_wine CHECK_CALLED(Invoke_COMMANDSTATECHANGE);
2615         if (use_container_olecmd) todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
2616         CHECK_CALLED(EnableModeless_TRUE);
2617         if (is_file) todo_wine CHECK_CALLED(Invoke_PROGRESSCHANGE);
2618     }
2619
2620     VariantClear(&url);
2621
2622     test_ready_state(READYSTATE_LOADING);
2623 }
2624
2625 static void test_QueryStatusWB(IWebBrowser2 *webbrowser, BOOL use_custom_target, BOOL has_document)
2626 {
2627     HRESULT hres, success_state;
2628     OLECMDF success_flags;
2629     enum OLECMDF status;
2630
2631     /*
2632      * We can tell the difference between the custom container target and the built-in target
2633      * since the custom target returns OLECMDF_SUPPORTED instead of OLECMDF_ENABLED.
2634      */
2635     if (use_custom_target)
2636         success_flags = OLECMDF_SUPPORTED;
2637     else
2638         success_flags = OLECMDF_ENABLED;
2639
2640     /* When no target is available (no document or custom target) an error is returned */
2641     if (has_document)
2642         success_state = S_OK;
2643     else
2644         success_state = E_UNEXPECTED;
2645
2646     /*
2647      * Test a safe operation that exists as both a high-numbered MSHTML id and an OLECMDID.
2648      * These tests show that QueryStatusWB uses a NULL pguidCmdGroup, since OLECMDID_STOP
2649      * is enabled and IDM_STOP is not.
2650      */
2651     status = 0xdeadbeef;
2652     if (use_custom_target) SET_EXPECT(QueryStatus_STOP);
2653     hres = IWebBrowser2_QueryStatusWB(webbrowser, OLECMDID_STOP, &status);
2654     ok(hres == success_state, "QueryStatusWB failed: %08x %08x\n", hres, success_state);
2655     if (!use_custom_target && has_document)
2656         todo_wine ok((has_document && status == success_flags) || (!has_document && status == 0xdeadbeef),
2657                      "OLECMDID_STOP not enabled/supported: %08x %08x\n", status, success_flags);
2658     else
2659         ok((has_document && status == success_flags) || (!has_document && status == 0xdeadbeef),
2660            "OLECMDID_STOP not enabled/supported: %08x %08x\n", status, success_flags);
2661     status = 0xdeadbeef;
2662     if (use_custom_target) SET_EXPECT(QueryStatus_IDM_STOP);
2663     hres = IWebBrowser2_QueryStatusWB(webbrowser, IDM_STOP, &status);
2664     ok(hres == success_state, "QueryStatusWB failed: %08x %08x\n", hres, success_state);
2665     ok((has_document && status == 0) || (!has_document && status == 0xdeadbeef),
2666        "IDM_STOP is enabled/supported: %08x %d\n", status, has_document);
2667 }
2668
2669 static void test_ExecWB(IWebBrowser2 *webbrowser, BOOL use_custom_target, BOOL has_document)
2670 {
2671     HRESULT hres, olecmdid_state, idm_state;
2672
2673     /* When no target is available (no document or custom target) an error is returned */
2674     if (has_document)
2675     {
2676         olecmdid_state = S_OK;
2677         idm_state = OLECMDERR_E_NOTSUPPORTED;
2678     }
2679     else
2680     {
2681         olecmdid_state = E_UNEXPECTED;
2682         idm_state = E_UNEXPECTED;
2683     }
2684
2685     /*
2686      * Test a safe operation that exists as both a high-numbered MSHTML id and an OLECMDID.
2687      * These tests show that QueryStatusWB uses a NULL pguidCmdGroup, since OLECMDID_STOP
2688      * succeeds (S_OK) and IDM_STOP does not (OLECMDERR_E_NOTSUPPORTED).
2689      */
2690     if(use_custom_target) {
2691         SET_EXPECT(Exec_STOP);
2692     }else if(has_document) {
2693         SET_EXPECT(Invoke_STATUSTEXTCHANGE);
2694         SET_EXPECT(SetStatusText);
2695     }
2696     hres = IWebBrowser2_ExecWB(webbrowser, OLECMDID_STOP, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0);
2697     if(!use_custom_target && has_document) {
2698         todo_wine ok(hres == olecmdid_state, "ExecWB failed: %08x %08x\n", hres, olecmdid_state);
2699         CLEAR_CALLED(Invoke_STATUSTEXTCHANGE); /* Called by IE9 */
2700         CLEAR_CALLED(SetStatusText); /* Called by IE9 */
2701     }else {
2702         ok(hres == olecmdid_state, "ExecWB failed: %08x %08x\n", hres, olecmdid_state);
2703     }
2704     if (use_custom_target)
2705         SET_EXPECT(Exec_IDM_STOP);
2706     hres = IWebBrowser2_ExecWB(webbrowser, IDM_STOP, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0);
2707     ok(hres == idm_state, "ExecWB failed: %08x %08x\n", hres, idm_state);
2708 }
2709
2710 static void test_download(DWORD flags)
2711 {
2712     BOOL *b = (flags & DWL_REFRESH) ? &called_Exec_SETDOWNLOADSTATE_0 : &called_Invoke_DOCUMENTCOMPLETE;
2713     MSG msg;
2714
2715     is_downloading = TRUE;
2716     dwl_flags = flags;
2717
2718     test_ready_state((flags & (DWL_FROM_PUT_HREF|DWL_FROM_GOBACK|DWL_REFRESH)) ? READYSTATE_COMPLETE : READYSTATE_LOADING);
2719
2720     if((is_http && !(flags & (DWL_FROM_GOBACK|DWL_REFRESH))) || (flags & DWL_EXPECT_BEFORE_NAVIGATE))
2721         SET_EXPECT(Invoke_PROPERTYCHANGE);
2722
2723     if(flags & DWL_EXPECT_BEFORE_NAVIGATE) {
2724         SET_EXPECT(Invoke_BEFORENAVIGATE2);
2725         SET_EXPECT(TranslateUrl);
2726     }
2727     SET_EXPECT(Exec_SETPROGRESSMAX);
2728     SET_EXPECT(Exec_SETPROGRESSPOS);
2729     SET_EXPECT(Exec_SETDOWNLOADSTATE_1);
2730     SET_EXPECT(DocHost_EnableModeless_FALSE);
2731     SET_EXPECT(DocHost_EnableModeless_TRUE);
2732     SET_EXPECT(Invoke_SETSECURELOCKICON);
2733     SET_EXPECT(Invoke_282);
2734     SET_EXPECT(EnableModeless_FALSE);
2735     SET_EXPECT(Invoke_COMMANDSTATECHANGE);
2736     SET_EXPECT(Invoke_STATUSTEXTCHANGE);
2737     SET_EXPECT(SetStatusText);
2738     SET_EXPECT(EnableModeless_TRUE);
2739     if(!is_first_load)
2740         SET_EXPECT(GetHostInfo);
2741     SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
2742     SET_EXPECT(Invoke_TITLECHANGE);
2743     if(!(flags & DWL_REFRESH))
2744         SET_EXPECT(Invoke_NAVIGATECOMPLETE2);
2745     if(is_first_load)
2746         SET_EXPECT(GetDropTarget);
2747     SET_EXPECT(Invoke_PROGRESSCHANGE);
2748     if(!(flags & DWL_REFRESH))
2749         SET_EXPECT(Invoke_DOCUMENTCOMPLETE);
2750
2751     if(flags & DWL_HTTP)
2752         SET_EXPECT(Exec_SETTITLE);
2753     SET_EXPECT(UpdateUI);
2754     SET_EXPECT(Exec_UPDATECOMMANDS);
2755     SET_EXPECT(QueryStatus_STOP);
2756
2757     while(!*b && GetMessage(&msg, NULL, 0, 0)) {
2758         TranslateMessage(&msg);
2759         DispatchMessage(&msg);
2760     }
2761
2762     if((is_http && !(flags & (DWL_FROM_GOBACK|DWL_REFRESH))) || (flags & DWL_EXPECT_BEFORE_NAVIGATE))
2763         todo_wine CHECK_CALLED(Invoke_PROPERTYCHANGE);
2764
2765     if(flags & DWL_EXPECT_BEFORE_NAVIGATE) {
2766         CHECK_CALLED(Invoke_BEFORENAVIGATE2);
2767         CHECK_CALLED(TranslateUrl);
2768     }
2769     todo_wine CHECK_CALLED(Exec_SETPROGRESSMAX);
2770     todo_wine CHECK_CALLED(Exec_SETPROGRESSPOS);
2771     CHECK_CALLED(Exec_SETDOWNLOADSTATE_1);
2772     CLEAR_CALLED(DocHost_EnableModeless_FALSE); /* IE 7 */
2773     CLEAR_CALLED(DocHost_EnableModeless_TRUE); /* IE 7 */
2774     todo_wine CHECK_CALLED(Invoke_SETSECURELOCKICON);
2775     CLEAR_CALLED(Invoke_282); /* IE 7 */
2776     if(is_first_load)
2777         todo_wine CHECK_CALLED(EnableModeless_FALSE);
2778     else
2779         CLEAR_CALLED(EnableModeless_FALSE); /* IE 8 */
2780     CLEAR_CALLED(Invoke_COMMANDSTATECHANGE);
2781     todo_wine CHECK_CALLED(Invoke_STATUSTEXTCHANGE);
2782     todo_wine CHECK_CALLED(SetStatusText);
2783     if(is_first_load)
2784         todo_wine CHECK_CALLED(EnableModeless_TRUE);
2785     else
2786         CLEAR_CALLED(EnableModeless_FALSE); /* IE 8 */
2787     if(!is_first_load)
2788         todo_wine CHECK_CALLED(GetHostInfo);
2789     CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
2790     todo_wine CHECK_CALLED(Invoke_TITLECHANGE);
2791     if(!(flags & DWL_REFRESH))
2792         CHECK_CALLED(Invoke_NAVIGATECOMPLETE2);
2793     if(is_first_load)
2794         todo_wine CHECK_CALLED(GetDropTarget);
2795     todo_wine CHECK_CALLED(Invoke_PROGRESSCHANGE);
2796     if(!(flags & DWL_REFRESH))
2797         CHECK_CALLED(Invoke_DOCUMENTCOMPLETE);
2798
2799     is_downloading = FALSE;
2800
2801     test_ready_state(READYSTATE_COMPLETE);
2802
2803     while(!called_Exec_UPDATECOMMANDS && GetMessage(&msg, NULL, 0, 0)) {
2804         TranslateMessage(&msg);
2805         DispatchMessage(&msg);
2806     }
2807
2808     if(flags & DWL_HTTP)
2809         CLEAR_CALLED(Exec_SETTITLE); /* FIXME: make it more strict */
2810     CHECK_CALLED(UpdateUI);
2811     CHECK_CALLED(Exec_UPDATECOMMANDS);
2812     CLEAR_CALLED(QueryStatus_STOP);
2813 }
2814
2815 static void test_Refresh(IWebBrowser2 *webbrowser)
2816 {
2817     HRESULT hres;
2818
2819     trace("Refresh...\n");
2820
2821     SET_EXPECT(Exec_DocHostCommandHandler_2300);
2822     hres = IWebBrowser2_Refresh(webbrowser);
2823     ok(hres == S_OK, "Refresh failed: %08x\n", hres);
2824     CHECK_CALLED(Exec_DocHostCommandHandler_2300);
2825
2826     test_download(DWL_REFRESH);
2827 }
2828
2829 static void test_olecmd(IWebBrowser2 *unk, BOOL loaded)
2830 {
2831     IOleCommandTarget *cmdtrg;
2832     OLECMD cmds[3];
2833     HRESULT hres;
2834
2835     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
2836     ok(hres == S_OK, "Could not get IOleCommandTarget iface: %08x\n", hres);
2837     if(FAILED(hres))
2838         return;
2839
2840     cmds[0].cmdID = OLECMDID_SPELL;
2841     cmds[0].cmdf = 0xdeadbeef;
2842     cmds[1].cmdID = OLECMDID_REFRESH;
2843     cmds[1].cmdf = 0xdeadbeef;
2844     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 2, cmds, NULL);
2845     if(loaded) {
2846         ok(hres == S_OK, "QueryStatus failed: %08x\n", hres);
2847         ok(cmds[0].cmdf == OLECMDF_SUPPORTED, "OLECMDID_SPELL cmdf = %x\n", cmds[0].cmdf);
2848         ok(cmds[1].cmdf == (OLECMDF_ENABLED|OLECMDF_SUPPORTED),
2849            "OLECMDID_REFRESH cmdf = %x\n", cmds[1].cmdf);
2850     }else {
2851         ok(hres == 0x80040104, "QueryStatus failed: %08x\n", hres);
2852         ok(cmds[0].cmdf == 0xdeadbeef, "OLECMDID_SPELL cmdf = %x\n", cmds[0].cmdf);
2853         ok(cmds[1].cmdf == 0xdeadbeef, "OLECMDID_REFRESH cmdf = %x\n", cmds[0].cmdf);
2854     }
2855
2856     IOleCommandTarget_Release(cmdtrg);
2857 }
2858
2859 static void test_IServiceProvider(IWebBrowser2 *unk)
2860 {
2861     IServiceProvider *servprov = (void*)0xdeadbeef;
2862     IUnknown *iface;
2863     HRESULT hres;
2864
2865     hres = IWebBrowser2_QueryInterface(unk, &IID_IServiceProvider, (void**)&servprov);
2866     ok(hres == S_OK, "QueryInterface returned %08x, expected S_OK\n", hres);
2867     if(FAILED(hres))
2868         return;
2869
2870     hres = IServiceProvider_QueryService(servprov, &SID_STopLevelBrowser, &IID_IBrowserService2, (LPVOID*)&iface);
2871     ok(hres == E_FAIL, "QueryService returned %08x, expected E_FAIL\n", hres);
2872     ok(!iface, "QueryService returned %p, expected NULL\n", iface);
2873     if(hres == S_OK)
2874         IUnknown_Release(iface);
2875
2876     hres = IServiceProvider_QueryService(servprov, &SID_SHTMLWindow, &IID_IHTMLWindow2, (LPVOID*)&iface);
2877     ok(hres == S_OK, "QueryService returned %08x, expected S_OK\n", hres);
2878     ok(iface != NULL, "QueryService returned NULL\n");
2879     if(hres == S_OK)
2880         IUnknown_Release(iface);
2881
2882     IServiceProvider_Release(servprov);
2883 }
2884
2885 static void test_put_href(IWebBrowser2 *unk, const char *url)
2886 {
2887     IHTMLLocation *location;
2888     IHTMLDocument2 *doc;
2889     IDispatch *doc_disp;
2890     BSTR str;
2891     HRESULT hres;
2892
2893     doc_disp = get_document(unk);
2894
2895     hres = IDispatch_QueryInterface(doc_disp, &IID_IHTMLDocument2, (void**)&doc);
2896     IDispatch_Release(doc_disp);
2897     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument2 failed: %08x\n", hres);
2898
2899     location = NULL;
2900     hres = IHTMLDocument2_get_location(doc, &location);
2901     IHTMLDocument2_Release(doc);
2902     ok(hres == S_OK, "get_location failed: %08x\n", hres);
2903     ok(location != NULL, "location == NULL\n");
2904
2905     SET_EXPECT(TranslateUrl);
2906     SET_EXPECT(Invoke_BEFORENAVIGATE2);
2907     if(!is_http)
2908         SET_EXPECT(Invoke_PROPERTYCHANGE);
2909
2910     dwl_flags = DWL_FROM_PUT_HREF;
2911
2912     is_http = !memcmp(url, "http:", 5);
2913     str = a2bstr(current_url = url);
2914     is_first_load = FALSE;
2915     hres = IHTMLLocation_put_href(location, str);
2916
2917     CHECK_CALLED(TranslateUrl);
2918     CHECK_CALLED(Invoke_BEFORENAVIGATE2);
2919     if(!is_http)
2920         todo_wine CHECK_CALLED(Invoke_PROPERTYCHANGE);
2921
2922     IHTMLLocation_Release(location);
2923     SysFreeString(str);
2924     ok(hres == S_OK, "put_href failed: %08x\n", hres);
2925
2926     test_ready_state(READYSTATE_COMPLETE);
2927 }
2928
2929 static void test_go_back(IWebBrowser2 *wb, const char *back_url)
2930 {
2931     HRESULT hres;
2932
2933     current_url = back_url;
2934
2935     SET_EXPECT(Invoke_BEFORENAVIGATE2);
2936     SET_EXPECT(Invoke_COMMANDSTATECHANGE);
2937     hres = IWebBrowser2_GoBack(wb);
2938     ok(hres == S_OK, "GoBack failed: %08x\n", hres);
2939     CHECK_CALLED(Invoke_BEFORENAVIGATE2);
2940     todo_wine CHECK_CALLED(Invoke_COMMANDSTATECHANGE);
2941 }
2942
2943 static void test_QueryInterface(IWebBrowser2 *wb)
2944 {
2945     IQuickActivate *qa = (IQuickActivate*)0xdeadbeef;
2946     IRunnableObject *runnable = (IRunnableObject*)0xdeadbeef;
2947     IPerPropertyBrowsing *propbrowse = (void*)0xdeadbeef;
2948     IOleInPlaceSite *inplace = (void*)0xdeadbeef;
2949     IOleCache *cache = (void*)0xdeadbeef;
2950     IObjectWithSite *site = (void*)0xdeadbeef;
2951     IViewObjectEx *viewex = (void*)0xdeadbeef;
2952     IOleLink *link = (void*)0xdeadbeef;
2953     IMarshal *marshal = (void*)0xdeadbeef;
2954     IStdMarshalInfo *marshalinfo = (void*)0xdeadbeef;
2955     IUnknown *unk = (IUnknown*)wb;
2956     HRESULT hres;
2957
2958     hres = IUnknown_QueryInterface(unk, &IID_IQuickActivate, (void**)&qa);
2959     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2960     ok(qa == NULL, "qa=%p, expected NULL\n", qa);
2961
2962     hres = IUnknown_QueryInterface(unk, &IID_IRunnableObject, (void**)&runnable);
2963     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2964     ok(runnable == NULL, "runnable=%p, expected NULL\n", runnable);
2965
2966     hres = IUnknown_QueryInterface(unk, &IID_IPerPropertyBrowsing, (void**)&propbrowse);
2967     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2968     ok(propbrowse == NULL, "propbrowse=%p, expected NULL\n", propbrowse);
2969
2970     hres = IUnknown_QueryInterface(unk, &IID_IOleCache, (void**)&cache);
2971     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2972     ok(cache == NULL, "cache=%p, expected NULL\n", cache);
2973
2974     hres = IUnknown_QueryInterface(unk, &IID_IOleInPlaceSite, (void**)&inplace);
2975     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2976     ok(inplace == NULL, "inplace=%p, expected NULL\n", inplace);
2977
2978     hres = IUnknown_QueryInterface(unk, &IID_IObjectWithSite, (void**)&site);
2979     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2980     ok(site == NULL, "site=%p, expected NULL\n", site);
2981
2982     hres = IUnknown_QueryInterface(unk, &IID_IViewObjectEx, (void**)&viewex);
2983     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2984     ok(viewex == NULL, "viewex=%p, expected NULL\n", viewex);
2985
2986     hres = IUnknown_QueryInterface(unk, &IID_IOleLink, (void**)&link);
2987     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2988     ok(link == NULL, "link=%p, expected NULL\n", link);
2989
2990     hres = IUnknown_QueryInterface(unk, &IID_IMarshal, (void**)&marshal);
2991     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2992     ok(marshal == NULL, "marshal=%p, expected NULL\n", marshal);
2993
2994     hres = IUnknown_QueryInterface(unk, &IID_IStdMarshalInfo, (void**)&marshalinfo);
2995     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
2996     ok(marshalinfo == NULL, "marshalinfo=%p, expected NULL\n", marshalinfo);
2997
2998 }
2999
3000 static void test_UIActivate(IWebBrowser2 *unk, BOOL activate)
3001 {
3002     IOleDocumentView *docview;
3003     IDispatch *disp;
3004     HRESULT hres;
3005
3006     disp = get_document(unk);
3007
3008     hres = IDispatch_QueryInterface(disp, &IID_IOleDocumentView, (void**)&docview);
3009     ok(hres == S_OK, "Got 0x%08x\n", hres);
3010     if(SUCCEEDED(hres)) {
3011         if(activate) {
3012             SET_EXPECT(RequestUIActivate);
3013             SET_EXPECT(ShowUI);
3014             SET_EXPECT(HideUI);
3015             SET_EXPECT(OnFocus);
3016         }
3017
3018         hres = IOleDocumentView_UIActivate(docview, activate);
3019         if(activate)
3020             todo_wine ok(hres == S_OK, "Got 0x%08x\n", hres);
3021         else
3022             ok(hres == S_OK, "Got 0x%08x\n", hres);
3023
3024         if(activate) {
3025             todo_wine {
3026                 CHECK_CALLED(RequestUIActivate);
3027                 CHECK_CALLED(ShowUI);
3028                 CHECK_CALLED(HideUI);
3029                 CHECK_CALLED(OnFocus);
3030             }
3031         }
3032
3033         IOleDocumentView_Release(docview);
3034     }
3035
3036     IDispatch_Release(disp);
3037 }
3038
3039 static void test_external(IWebBrowser2 *unk)
3040 {
3041     IDocHostUIHandler2 *dochost;
3042     IOleClientSite *client;
3043     IDispatch *disp;
3044     HRESULT hres;
3045
3046     client = get_dochost(unk);
3047
3048     hres = IOleClientSite_QueryInterface(client, &IID_IDocHostUIHandler2, (void**)&dochost);
3049     ok(hres == S_OK, "Could not get IDocHostUIHandler2 iface: %08x\n", hres);
3050     IOleClientSite_Release(client);
3051
3052     if(use_container_dochostui)
3053         SET_EXPECT(GetExternal);
3054     disp = (void*)0xdeadbeef;
3055     hres = IDocHostUIHandler2_GetExternal(dochost, &disp);
3056     if(use_container_dochostui) {
3057         CHECK_CALLED(GetExternal);
3058         ok(hres == S_FALSE, "GetExternal failed: %08x\n", hres);
3059         ok(!disp, "disp = %p\n", disp);
3060     }else {
3061         IShellUIHelper *uihelper;
3062
3063         ok(hres == S_OK, "GetExternal failed: %08x\n", hres);
3064         ok(disp != NULL, "disp == NULL\n");
3065
3066         hres = IDispatch_QueryInterface(disp, &IID_IShellUIHelper, (void**)&uihelper);
3067         ok(hres == S_OK, "Could not get IShellUIHelper iface: %08x\n", hres);
3068         IShellUIHelper_Release(uihelper);
3069     }
3070
3071     IDocHostUIHandler2_Release(dochost);
3072 }
3073
3074 static void test_TranslateAccelerator(IWebBrowser2 *unk)
3075 {
3076     IOleClientSite *doc_clientsite;
3077     IOleInPlaceActiveObject *pao;
3078     HRESULT hres;
3079     DWORD keycode;
3080     MSG msg_a = {
3081         container_hwnd,
3082         0, 0, 0,
3083         GetTickCount(),
3084         {5, 5}
3085     };
3086
3087     test_Navigate2(unk, "about:blank");
3088
3089     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleInPlaceActiveObject, (void**)&pao);
3090     ok(hres == S_OK, "Got 0x%08x\n", hres);
3091     if(SUCCEEDED(hres)) {
3092         /* One accelerator that should be handled by mshtml */
3093         msg_a.message = WM_KEYDOWN;
3094         msg_a.wParam = VK_F1;
3095         hres = IOleInPlaceActiveObject_TranslateAccelerator(pao, &msg_a);
3096         ok(hres == S_FALSE, "Got 0x%08x (%04x::%02lx)\n", hres, msg_a.message, msg_a.wParam);
3097
3098         /* And one that should not */
3099         msg_a.message = WM_KEYDOWN;
3100         msg_a.wParam = VK_F5;
3101         hres = IOleInPlaceActiveObject_TranslateAccelerator(pao, &msg_a);
3102         ok(hres == S_FALSE, "Got 0x%08x (%04x::%02lx)\n", hres, msg_a.message, msg_a.wParam);
3103
3104         IOleInPlaceActiveObject_Release(pao);
3105     }
3106
3107     test_UIActivate(unk, TRUE);
3108
3109     /* Test again after UIActivate */
3110     hres = IWebBrowser2_QueryInterface(unk, &IID_IOleInPlaceActiveObject, (void**)&pao);
3111     ok(hres == S_OK, "Got 0x%08x\n", hres);
3112     if(SUCCEEDED(hres)) {
3113         /* One accelerator that should be handled by mshtml */
3114         msg_a.message = WM_KEYDOWN;
3115         msg_a.wParam = VK_F1;
3116         SET_EXPECT(DocHost_TranslateAccelerator);
3117         SET_EXPECT(ControlSite_TranslateAccelerator);
3118         hres = IOleInPlaceActiveObject_TranslateAccelerator(pao, &msg_a);
3119         ok(hres == S_FALSE, "Got 0x%08x (%04x::%02lx)\n", hres, msg_a.message, msg_a.wParam);
3120         todo_wine CHECK_CALLED(DocHost_TranslateAccelerator);
3121         todo_wine CHECK_CALLED(ControlSite_TranslateAccelerator);
3122
3123         /* And one that should not */
3124         msg_a.message = WM_KEYDOWN;
3125         msg_a.wParam = VK_F5;
3126         SET_EXPECT(DocHost_TranslateAccelerator);
3127         hres = IOleInPlaceActiveObject_TranslateAccelerator(pao, &msg_a);
3128         todo_wine ok(hres == S_OK, "Got 0x%08x (%04x::%02lx)\n", hres, msg_a.message, msg_a.wParam);
3129         todo_wine CHECK_CALLED(DocHost_TranslateAccelerator);
3130
3131         IOleInPlaceActiveObject_Release(pao);
3132     }
3133
3134     doc_clientsite = get_dochost(unk);
3135     if(doc_clientsite) {
3136         IDocHostUIHandler2 *dochost;
3137         IOleControlSite *doc_controlsite;
3138         IUnknown *unk_test;
3139
3140         hres = IOleClientSite_QueryInterface(doc_clientsite, &IID_IOleInPlaceFrame, (void**)&unk_test);
3141         ok(hres == E_NOINTERFACE, "Got 0x%08x\n", hres);
3142         if(SUCCEEDED(hres)) IUnknown_Release(unk_test);
3143
3144         hres = IOleClientSite_QueryInterface(doc_clientsite, &IID_IDocHostShowUI, (void**)&unk_test);
3145         todo_wine ok(hres == S_OK, "Got 0x%08x\n", hres);
3146         if(SUCCEEDED(hres)) IUnknown_Release(unk_test);
3147
3148         hres = IOleClientSite_QueryInterface(doc_clientsite, &IID_IDocHostUIHandler, (void**)&unk_test);
3149         ok(hres == S_OK, "Got 0x%08x\n", hres);
3150         if(SUCCEEDED(hres)) IUnknown_Release(unk_test);
3151
3152         hres = IOleClientSite_QueryInterface(doc_clientsite, &IID_IDocHostUIHandler2, (void**)&dochost);
3153         ok(hres == S_OK, "Got 0x%08x\n", hres);
3154         if(SUCCEEDED(hres)) {
3155             msg_a.message = WM_KEYDOWN;
3156             hr_dochost_TranslateAccelerator = 0xdeadbeef;
3157             for(keycode = 0; keycode <= 0x100; keycode++) {
3158                 msg_a.wParam = keycode;
3159                 SET_EXPECT(DocHost_TranslateAccelerator);
3160                 hres = IDocHostUIHandler2_TranslateAccelerator(dochost, &msg_a, &CGID_MSHTML, 1234);
3161                 ok(hres == 0xdeadbeef, "Got 0x%08x\n", hres);
3162                 CHECK_CALLED(DocHost_TranslateAccelerator);
3163             }
3164             hr_dochost_TranslateAccelerator = E_NOTIMPL;
3165
3166             SET_EXPECT(DocHost_TranslateAccelerator);
3167             hres = IDocHostUIHandler2_TranslateAccelerator(dochost, &msg_a, &CGID_MSHTML, 1234);
3168             ok(hres == E_NOTIMPL, "Got 0x%08x\n", hres);
3169             CHECK_CALLED(DocHost_TranslateAccelerator);
3170
3171             IDocHostUIHandler2_Release(dochost);
3172         }
3173
3174         hres = IOleClientSite_QueryInterface(doc_clientsite, &IID_IOleControlSite, (void**)&doc_controlsite);
3175         ok(hres == S_OK, "Got 0x%08x\n", hres);
3176         if(SUCCEEDED(hres)) {
3177             msg_a.message = WM_KEYDOWN;
3178             hr_site_TranslateAccelerator = 0xdeadbeef;
3179             for(keycode = 0; keycode < 0x100; keycode++) {
3180                 msg_a.wParam = keycode;
3181                 SET_EXPECT(ControlSite_TranslateAccelerator);
3182                 hres = IOleControlSite_TranslateAccelerator(doc_controlsite, &msg_a, 0);
3183                 if(keycode == 0x9 || keycode == 0x75)
3184                     todo_wine ok(hres == S_OK, "Got 0x%08x (keycode: %04x)\n", hres, keycode);
3185                 else
3186                     ok(hres == S_FALSE, "Got 0x%08x (keycode: %04x)\n", hres, keycode);
3187
3188                 CHECK_CALLED(ControlSite_TranslateAccelerator);
3189             }
3190             msg_a.wParam = VK_LEFT;
3191             SET_EXPECT(ControlSite_TranslateAccelerator);
3192             hres = IOleControlSite_TranslateAccelerator(doc_controlsite, &msg_a, 0);
3193             ok(hres == S_FALSE, "Got 0x%08x (keycode: %04x)\n", hres, keycode);
3194             CHECK_CALLED(ControlSite_TranslateAccelerator);
3195
3196             hr_site_TranslateAccelerator = S_OK;
3197             SET_EXPECT(ControlSite_TranslateAccelerator);
3198             hres = IOleControlSite_TranslateAccelerator(doc_controlsite, &msg_a, 0);
3199             ok(hres == S_OK, "Got 0x%08x (keycode: %04x)\n", hres, keycode);
3200             CHECK_CALLED(ControlSite_TranslateAccelerator);
3201
3202             hr_site_TranslateAccelerator = E_NOTIMPL;
3203             SET_EXPECT(ControlSite_TranslateAccelerator);
3204             hres = IOleControlSite_TranslateAccelerator(doc_controlsite, &msg_a, 0);
3205             ok(hres == S_FALSE, "Got 0x%08x (keycode: %04x)\n", hres, keycode);
3206             CHECK_CALLED(ControlSite_TranslateAccelerator);
3207
3208             IOleControlSite_Release(doc_controlsite);
3209         }
3210
3211         IOleClientSite_Release(doc_clientsite);
3212     }
3213
3214     test_UIActivate(unk, FALSE);
3215 }
3216
3217 static void test_dochost_qs(IWebBrowser2 *webbrowser)
3218 {
3219     IOleClientSite *client_site;
3220     IServiceProvider *serv_prov;
3221     IUnknown *service;
3222     HRESULT hres;
3223
3224     client_site = get_dochost(webbrowser);
3225     hres = IOleClientSite_QueryInterface(client_site, &IID_IServiceProvider, (void**)&serv_prov);
3226     IOleClientSite_Release(client_site);
3227     ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
3228
3229     hres = IServiceProvider_QueryService(serv_prov, &IID_IHlinkFrame, &IID_IHlinkFrame, (void**)&service);
3230     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
3231     ok(iface_cmp(service, (IUnknown*)webbrowser), "service != unk\n");
3232     IUnknown_Release(service);
3233
3234     hres = IServiceProvider_QueryService(serv_prov, &IID_IWebBrowserApp, &IID_IHlinkFrame, (void**)&service);
3235     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
3236     ok(iface_cmp(service, (IUnknown*)webbrowser), "service != unk\n");
3237     IUnknown_Release(service);
3238
3239     hres = IServiceProvider_QueryService(serv_prov, &IID_IShellBrowser, &IID_IShellBrowser, (void**)&service);
3240     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
3241     IUnknown_Release(service);
3242
3243     hres = IServiceProvider_QueryService(serv_prov, &IID_IShellBrowser, &IID_IBrowserService, (void**)&service);
3244     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
3245     IUnknown_Release(service);
3246
3247     hres = IServiceProvider_QueryService(serv_prov, &IID_IShellBrowser, &IID_IDocObjectService, (void**)&service);
3248     ok(hres == S_OK, "QueryService failed: %08x\n", hres);
3249     IUnknown_Release(service);
3250
3251     IServiceProvider_Release(serv_prov);
3252 }
3253
3254 static void test_Close(IWebBrowser2 *wb, BOOL do_download)
3255 {
3256     IOleObject *oo;
3257     IOleClientSite *ocs;
3258     HRESULT hres;
3259
3260     hres = IWebBrowser2_QueryInterface(wb, &IID_IOleObject, (void**)&oo);
3261     ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);
3262     if(hres != S_OK)
3263         return;
3264
3265     test_close = TRUE;
3266
3267     SET_EXPECT(Frame_SetActiveObject);
3268     SET_EXPECT(UIWindow_SetActiveObject);
3269     SET_EXPECT(OnUIDeactivate);
3270     SET_EXPECT(OnFocus);
3271     SET_EXPECT(OnInPlaceDeactivate);
3272     SET_EXPECT(Invoke_STATUSTEXTCHANGE);
3273     if(!do_download) {
3274         SET_EXPECT(Invoke_COMMANDSTATECHANGE);
3275         SET_EXPECT(Invoke_DOWNLOADCOMPLETE);
3276     }
3277     hres = IOleObject_Close(oo, OLECLOSE_NOSAVE);
3278     ok(hres == S_OK, "OleObject_Close failed: %x\n", hres);
3279     CHECK_CALLED(Frame_SetActiveObject);
3280     CHECK_CALLED(UIWindow_SetActiveObject);
3281     CHECK_CALLED(OnUIDeactivate);
3282     todo_wine CHECK_CALLED(OnFocus);
3283     CHECK_CALLED(OnInPlaceDeactivate);
3284     CLEAR_CALLED(Invoke_STATUSTEXTCHANGE); /* Called by IE9 */
3285     if(!do_download) {
3286         todo_wine CHECK_CALLED(Invoke_COMMANDSTATECHANGE);
3287         todo_wine CHECK_CALLED(Invoke_DOWNLOADCOMPLETE);
3288     }
3289
3290     hres = IOleObject_GetClientSite(oo, &ocs);
3291     ok(hres == S_OK, "hres = %x\n", hres);
3292     ok(!ocs, "ocs != NULL\n");
3293
3294     hres = IOleObject_Close(oo, OLECLOSE_NOSAVE);
3295     ok(hres == S_OK, "OleObject_Close failed: %x\n", hres);
3296
3297     test_close = FALSE;
3298     IOleObject_Release(oo);
3299 }
3300
3301 #define TEST_DOWNLOAD    0x0001
3302 #define TEST_NOOLECMD    0x0002
3303 #define TEST_NODOCHOST   0x0004
3304
3305 static void init_test(IWebBrowser2 *webbrowser, DWORD flags)
3306 {
3307     wb = webbrowser;
3308
3309     is_downloading = (flags & TEST_DOWNLOAD) != 0;
3310     is_first_load = TRUE;
3311     use_container_olecmd = !(flags & TEST_NOOLECMD);
3312     use_container_dochostui = !(flags & TEST_NODOCHOST);
3313 }
3314
3315 static void test_WebBrowser(BOOL do_download, BOOL do_close)
3316 {
3317     IWebBrowser2 *webbrowser;
3318     ULONG ref;
3319
3320     webbrowser = create_webbrowser();
3321     if(!webbrowser)
3322         return;
3323
3324     init_test(webbrowser, do_download ? TEST_DOWNLOAD : 0);
3325
3326     test_QueryStatusWB(webbrowser, FALSE, FALSE);
3327     test_ExecWB(webbrowser, FALSE, FALSE);
3328     test_QueryInterface(webbrowser);
3329     test_ready_state(READYSTATE_UNINITIALIZED);
3330     test_ClassInfo(webbrowser);
3331     test_EnumVerbs(webbrowser);
3332     test_LocationURL(webbrowser, "");
3333     test_ConnectionPoint(webbrowser, TRUE);
3334     test_ClientSite(webbrowser, &ClientSite, !do_download);
3335     test_Extent(webbrowser);
3336     test_wb_funcs(webbrowser, TRUE);
3337     test_DoVerb(webbrowser);
3338     test_olecmd(webbrowser, FALSE);
3339     test_Navigate2(webbrowser, "about:blank");
3340     test_QueryStatusWB(webbrowser, TRUE, TRUE);
3341     test_ExecWB(webbrowser, TRUE, TRUE);
3342
3343     if(do_download) {
3344         IDispatch *doc, *doc2;
3345
3346         test_download(0);
3347         test_olecmd(webbrowser, TRUE);
3348         doc = get_document(webbrowser);
3349
3350         test_put_href(webbrowser, "about:test");
3351         test_download(DWL_FROM_PUT_HREF);
3352         doc2 = get_document(webbrowser);
3353         ok(doc == doc2, "doc != doc2\n");
3354         IDispatch_Release(doc2);
3355
3356         trace("Navigate2 repeated...\n");
3357         test_Navigate2(webbrowser, "about:blank");
3358         test_download(DWL_EXPECT_BEFORE_NAVIGATE);
3359         doc2 = get_document(webbrowser);
3360         ok(doc == doc2, "doc != doc2\n");
3361         IDispatch_Release(doc2);
3362         IDispatch_Release(doc);
3363
3364         if(!do_close) {
3365             trace("Navigate2 http URL...\n");
3366             test_ready_state(READYSTATE_COMPLETE);
3367             test_Navigate2(webbrowser, "http://test.winehq.org/tests/hello.html");
3368             test_download(DWL_EXPECT_BEFORE_NAVIGATE|DWL_HTTP);
3369
3370             test_Refresh(webbrowser);
3371
3372             trace("put_href http URL...\n");
3373             test_put_href(webbrowser, "http://www.winehq.org/");
3374             test_download(DWL_FROM_PUT_HREF|DWL_HTTP);
3375
3376             trace("GoBack...\n");
3377             test_go_back(webbrowser, "http://test.winehq.org/tests/hello.html");
3378             test_download(DWL_FROM_GOBACK|DWL_HTTP);
3379         }
3380
3381         test_EnumVerbs(webbrowser);
3382         test_TranslateAccelerator(webbrowser);
3383
3384         test_dochost_qs(webbrowser);
3385     }
3386
3387     test_external(webbrowser);
3388
3389     if(do_close)
3390         test_Close(webbrowser, do_download);
3391     else
3392         test_ClientSite(webbrowser, NULL, !do_download);
3393     test_ie_funcs(webbrowser);
3394     test_GetControlInfo(webbrowser);
3395     test_wb_funcs(webbrowser, FALSE);
3396     test_ConnectionPoint(webbrowser, FALSE);
3397     test_IServiceProvider(webbrowser);
3398
3399     ref = IWebBrowser2_Release(webbrowser);
3400     ok(ref == 0 || broken(do_download && !do_close && ref == 1), "ref=%d, expected 0\n", ref);
3401 }
3402
3403 static void test_WebBrowserV1(void)
3404 {
3405     IWebBrowser2 *wb;
3406     ULONG ref;
3407     HRESULT hres;
3408
3409     hres = CoCreateInstance(&CLSID_WebBrowser_V1, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
3410             &IID_IWebBrowser2, (void**)&wb);
3411     ok(hres == S_OK, "Could not get WebBrowserV1 instance: %08x\n", hres);
3412
3413     init_test(wb, 0);
3414     wb_version = 1;
3415
3416     test_QueryStatusWB(wb, FALSE, FALSE);
3417     test_ExecWB(wb, FALSE, FALSE);
3418     test_QueryInterface(wb);
3419     test_ready_state(READYSTATE_UNINITIALIZED);
3420     test_ClassInfo(wb);
3421     test_EnumVerbs(wb);
3422
3423     ref = IWebBrowser2_Release(wb);
3424     ok(ref == 0, "ref=%d, expected 0\n", ref);
3425 }
3426
3427 static void test_WebBrowser_slim_container(void)
3428 {
3429     IWebBrowser2 *webbrowser;
3430     ULONG ref;
3431
3432     webbrowser = create_webbrowser();
3433     init_test(webbrowser, TEST_NOOLECMD|TEST_NODOCHOST);
3434
3435     test_ConnectionPoint(webbrowser, TRUE);
3436     test_ClientSite(webbrowser, &ClientSite, TRUE);
3437     test_DoVerb(webbrowser);
3438     test_Navigate2(webbrowser, "about:blank");
3439
3440     /* Tests of interest */
3441     test_QueryStatusWB(webbrowser, FALSE, TRUE);
3442     test_ExecWB(webbrowser, FALSE, TRUE);
3443     test_external(webbrowser);
3444
3445     /* Cleanup stage */
3446     test_ClientSite(webbrowser, NULL, TRUE);
3447     test_ConnectionPoint(webbrowser, FALSE);
3448
3449     ref = IWebBrowser2_Release(webbrowser);
3450     ok(ref == 0, "ref=%d, expected 0\n", ref);
3451 }
3452
3453 static void test_WebBrowser_DoVerb(void)
3454 {
3455     IWebBrowser2 *webbrowser;
3456     RECT rect;
3457     HWND hwnd;
3458     ULONG ref;
3459     BOOL res;
3460
3461     webbrowser = create_webbrowser();
3462     init_test(webbrowser, 0);
3463
3464     test_ClientSite(webbrowser, &ClientSite, FALSE);
3465
3466     SET_EXPECT(CanInPlaceActivate);
3467     SET_EXPECT(Site_GetWindow);
3468     SET_EXPECT(OnInPlaceActivate);
3469     SET_EXPECT(GetWindowContext);
3470     SET_EXPECT(ShowObject);
3471     SET_EXPECT(GetContainer);
3472     SET_EXPECT(Frame_GetWindow);
3473     call_DoVerb(webbrowser, OLEIVERB_INPLACEACTIVATE);
3474     CHECK_CALLED(CanInPlaceActivate);
3475     CHECK_CALLED(Site_GetWindow);
3476     CHECK_CALLED(OnInPlaceActivate);
3477     CHECK_CALLED(GetWindowContext);
3478     CHECK_CALLED(ShowObject);
3479     CHECK_CALLED(GetContainer);
3480     CHECK_CALLED(Frame_GetWindow);
3481
3482     hwnd = get_hwnd(webbrowser);
3483
3484     memset(&rect, 0xa, sizeof(rect));
3485     res = GetWindowRect(hwnd, &rect);
3486     ok(res, "GetWindowRect failed: %u\n", GetLastError());
3487
3488     SET_EXPECT(OnInPlaceDeactivate);
3489     call_DoVerb(webbrowser, OLEIVERB_HIDE);
3490     CHECK_CALLED(OnInPlaceDeactivate);
3491
3492     test_ClientSite(webbrowser, NULL, FALSE);
3493
3494     ref = IWebBrowser2_Release(webbrowser);
3495     ok(ref == 0, "ref=%d, expected 0\n", ref);
3496 }
3497
3498
3499 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
3500 /* Note: this code is duplicated in dlls/mshtml/tests/mshtml_test.h and dlls/urlmon/tests/sec_mgr.c */
3501 static BOOL is_ie_hardened(void)
3502 {
3503     HKEY zone_map;
3504     DWORD ie_harden, type, size;
3505
3506     ie_harden = 0;
3507     if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
3508                     0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
3509         size = sizeof(DWORD);
3510         if (RegQueryValueEx(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
3511             type != REG_DWORD) {
3512             ie_harden = 0;
3513         }
3514         RegCloseKey(zone_map);
3515     }
3516
3517     return ie_harden != 0;
3518 }
3519
3520 static void test_FileProtocol(void)
3521 {
3522     IWebBrowser2 *webbrowser;
3523     HANDLE file;
3524     ULONG ref;
3525     char file_path[MAX_PATH];
3526     char file_url[MAX_PATH] = "File://";
3527
3528     static const char test_file[] = "wine_test.html";
3529
3530     GetTempPathA(MAX_PATH, file_path);
3531     strcat(file_path, test_file);
3532     GetLongPathNameA(file_path, file_path, sizeof(file_path));
3533     strcat(file_url, file_path);
3534
3535     webbrowser = create_webbrowser();
3536     if(!webbrowser)
3537         return;
3538
3539     init_test(webbrowser, 0);
3540
3541     file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL,
3542             CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
3543     if(file == INVALID_HANDLE_VALUE && GetLastError() != ERROR_FILE_EXISTS){
3544         ok(0, "CreateFile failed\n");
3545         return;
3546     }
3547     CloseHandle(file);
3548
3549     test_ConnectionPoint(webbrowser, TRUE);
3550     test_ClientSite(webbrowser, &ClientSite, TRUE);
3551     test_DoVerb(webbrowser);
3552     test_Navigate2(webbrowser, file_url);
3553     test_ClientSite(webbrowser, NULL, TRUE);
3554
3555     ref = IWebBrowser2_Release(webbrowser);
3556     ok(ref == 0, "ref=%u, expected 0\n", ref);
3557
3558     if(file != INVALID_HANDLE_VALUE)
3559         DeleteFileA(file_path);
3560 }
3561
3562 START_TEST(webbrowser)
3563 {
3564     OleInitialize(NULL);
3565
3566     container_hwnd = create_container_window();
3567
3568     trace("Testing WebBrowser (no download)...\n");
3569     test_WebBrowser(FALSE, FALSE);
3570     test_WebBrowser(FALSE, TRUE);
3571
3572     if(!is_ie_hardened()) {
3573         trace("Testing WebBrowser...\n");
3574         test_WebBrowser(TRUE, FALSE);
3575     }else {
3576         win_skip("Skipping http tests in hardened mode\n");
3577     }
3578
3579     trace("Testing WebBrowser DoVerb\n");
3580     test_WebBrowser_DoVerb();
3581     trace("Testing WebBrowser (with close)...\n");
3582     test_WebBrowser(TRUE, TRUE);
3583     trace("Testing WebBrowser w/o container-based olecmd...\n");
3584     test_WebBrowser_slim_container();
3585     trace("Testing WebBrowserV1...\n");
3586     test_WebBrowserV1();
3587     test_FileProtocol();
3588
3589     OleUninitialize();
3590 }