1 /*
2  * Copyright 2005-2009 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 <mshtml.h>
31 //#include "docobj.h"
32 #include <docobjectservice.h>
33 #include <wininet.h>
34 #include <mshtmhst.h>
35 #include <mshtmdid.h>
36 #include <mshtmcid.h>
37 //#include "hlink.h"
38 //#include "dispex.h"
39 #include <idispids.h>
40 #include <shlguid.h>
41 #include <shdeprecated.h>
42 #include <perhist.h>
43 //#include "shobjidl.h"
44 #include <htiface.h>
45 #include <tlogstg.h>
46 #include <exdispid.h>
47 #include "mshtml_test.h"
48 
49 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
50 DEFINE_GUID(IID_IProxyManager,0x00000008,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
51 DEFINE_OLEGUID(CGID_DocHostCmdPriv, 0x000214D4L, 0, 0);
52 DEFINE_GUID(SID_SContainerDispatch,0xb722be00,0x4e68,0x101b,0xa2,0xbc,0x00,0xaa,0x00,0x40,0x47,0x70);
53 
54 #define DEFINE_EXPECT(func) \
55     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
56 
57 #define SET_EXPECT(func) \
58     expect_ ## func = TRUE
59 
60 #define SET_CALLED(func) \
61     called_ ## func = TRUE
62 
63 #define CHECK_EXPECT2(func) \
64     do { \
65         ok(expect_ ##func, "unexpected call " #func "\n"); \
66         called_ ## func = TRUE; \
67     }while(0)
68 
69 #define CHECK_EXPECT(func) \
70     do { \
71         CHECK_EXPECT2(func); \
72         expect_ ## func = FALSE; \
73     }while(0)
74 
75 #define CHECK_CALLED(func) \
76     do { \
77         ok(called_ ## func, "expected " #func "\n"); \
78         expect_ ## func = called_ ## func = FALSE; \
79     }while(0)
80 
81 #define CHECK_NOT_CALLED(func) \
82     do { \
83         ok(!called_ ## func, "unexpected " #func "\n"); \
84         expect_ ## func = called_ ## func = FALSE; \
85     }while(0)
86 
87 #define CHECK_CALLED_BROKEN(func) \
88     do { \
89         ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
90         expect_ ## func = called_ ## func = FALSE; \
91     }while(0)
92 
93 #define CLEAR_CALLED(func) \
94     expect_ ## func = called_ ## func = FALSE
95 
96 
97 static IOleDocumentView *view = NULL;
98 static HWND container_hwnd = NULL, doc_hwnd = NULL, last_hwnd = NULL;
99 
100 DEFINE_EXPECT(LockContainer);
101 DEFINE_EXPECT(SetActiveObject);
102 DEFINE_EXPECT(SetActiveObject_null);
103 DEFINE_EXPECT(GetWindow);
104 DEFINE_EXPECT(CanInPlaceActivate);
105 DEFINE_EXPECT(OnInPlaceActivate);
106 DEFINE_EXPECT(OnInPlaceActivateEx);
107 DEFINE_EXPECT(OnUIActivate);
108 DEFINE_EXPECT(GetWindowContext);
109 DEFINE_EXPECT(OnUIDeactivate);
110 DEFINE_EXPECT(OnInPlaceDeactivate);
111 DEFINE_EXPECT(OnInPlaceDeactivateEx);
112 DEFINE_EXPECT(GetContainer);
113 DEFINE_EXPECT(ShowUI);
114 DEFINE_EXPECT(ActivateMe);
115 DEFINE_EXPECT(GetHostInfo);
116 DEFINE_EXPECT(HideUI);
117 DEFINE_EXPECT(GetOptionKeyPath);
118 DEFINE_EXPECT(GetOverrideKeyPath);
119 DEFINE_EXPECT(SetStatusText);
120 DEFINE_EXPECT(QueryStatus_SETPROGRESSTEXT);
121 DEFINE_EXPECT(QueryStatus_OPEN);
122 DEFINE_EXPECT(QueryStatus_NEW);
123 DEFINE_EXPECT(Exec_SETPROGRESSMAX);
124 DEFINE_EXPECT(Exec_SETPROGRESSPOS);
125 DEFINE_EXPECT(Exec_HTTPEQUIV_DONE);
126 DEFINE_EXPECT(Exec_SETDOWNLOADSTATE_0);
127 DEFINE_EXPECT(Exec_SETDOWNLOADSTATE_1);
128 DEFINE_EXPECT(Exec_ShellDocView_37);
129 DEFINE_EXPECT(Exec_ShellDocView_62);
130 DEFINE_EXPECT(Exec_ShellDocView_63);
131 DEFINE_EXPECT(Exec_ShellDocView_67);
132 DEFINE_EXPECT(Exec_ShellDocView_84);
133 DEFINE_EXPECT(Exec_ShellDocView_103);
134 DEFINE_EXPECT(Exec_ShellDocView_105);
135 DEFINE_EXPECT(Exec_ShellDocView_138);
136 DEFINE_EXPECT(Exec_ShellDocView_140);
137 DEFINE_EXPECT(Exec_DocHostCommandHandler_2300);
138 DEFINE_EXPECT(Exec_UPDATECOMMANDS);
139 DEFINE_EXPECT(Exec_SETTITLE);
140 DEFINE_EXPECT(Exec_HTTPEQUIV);
141 DEFINE_EXPECT(Exec_MSHTML_PARSECOMPLETE);
142 DEFINE_EXPECT(Exec_Explorer_38);
143 DEFINE_EXPECT(Exec_Explorer_69);
144 DEFINE_EXPECT(Exec_DOCCANNAVIGATE);
145 DEFINE_EXPECT(Exec_DOCCANNAVIGATE_NULL);
146 DEFINE_EXPECT(Invoke_AMBIENT_USERMODE);
147 DEFINE_EXPECT(Invoke_AMBIENT_DLCONTROL);
148 DEFINE_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
149 DEFINE_EXPECT(Invoke_AMBIENT_SILENT);
150 DEFINE_EXPECT(Invoke_AMBIENT_USERAGENT);
151 DEFINE_EXPECT(Invoke_AMBIENT_PALETTE);
152 DEFINE_EXPECT(Invoke_OnReadyStateChange_Interactive);
153 DEFINE_EXPECT(Invoke_OnReadyStateChange_Loading);
154 DEFINE_EXPECT(Invoke_OnReadyStateChange_Complete);
155 DEFINE_EXPECT(GetDropTarget);
156 DEFINE_EXPECT(UpdateUI);
157 DEFINE_EXPECT(Navigate);
158 DEFINE_EXPECT(OnFrameWindowActivate);
159 DEFINE_EXPECT(OnChanged_READYSTATE);
160 DEFINE_EXPECT(OnChanged_1005);
161 DEFINE_EXPECT(OnChanged_1012);
162 DEFINE_EXPECT(OnChanged_1014);
163 DEFINE_EXPECT(GetDisplayName);
164 DEFINE_EXPECT(BindToStorage);
165 DEFINE_EXPECT(IsSystemMoniker);
166 DEFINE_EXPECT(GetBindResult);
167 DEFINE_EXPECT(GetClassID);
168 DEFINE_EXPECT(Abort);
169 DEFINE_EXPECT(Read);
170 DEFINE_EXPECT(CreateInstance);
171 DEFINE_EXPECT(Start);
172 DEFINE_EXPECT(Terminate);
173 DEFINE_EXPECT(Protocol_Read);
174 DEFINE_EXPECT(LockRequest);
175 DEFINE_EXPECT(UnlockRequest);
176 DEFINE_EXPECT(OnFocus_TRUE);
177 DEFINE_EXPECT(OnFocus_FALSE);
178 DEFINE_EXPECT(RequestUIActivate);
179 DEFINE_EXPECT(InPlaceFrame_SetBorderSpace);
180 DEFINE_EXPECT(InPlaceUIWindow_SetActiveObject);
181 DEFINE_EXPECT(GetExternal);
182 DEFINE_EXPECT(EnableModeless_TRUE);
183 DEFINE_EXPECT(EnableModeless_FALSE);
184 DEFINE_EXPECT(Frame_EnableModeless_TRUE);
185 DEFINE_EXPECT(Frame_EnableModeless_FALSE);
186 DEFINE_EXPECT(Frame_GetWindow);
187 DEFINE_EXPECT(TranslateUrl);
188 DEFINE_EXPECT(Advise_Close);
189 DEFINE_EXPECT(OnViewChange);
190 DEFINE_EXPECT(EvaluateNewWindow);
191 DEFINE_EXPECT(GetTravelLog);
192 DEFINE_EXPECT(UpdateBackForwardState);
193 DEFINE_EXPECT(FireBeforeNavigate2);
194 DEFINE_EXPECT(FireNavigateComplete2);
195 DEFINE_EXPECT(FireDocumentComplete);
196 DEFINE_EXPECT(GetPendingUrl);
197 DEFINE_EXPECT(ActiveElementChanged);
198 DEFINE_EXPECT(IsErrorUrl);
199 DEFINE_EXPECT(get_LocationURL);
200 DEFINE_EXPECT(CountEntries);
201 DEFINE_EXPECT(FindConnectionPoint);
202 DEFINE_EXPECT(EnumConnections);
203 DEFINE_EXPECT(EnumConnections_Next);
204 DEFINE_EXPECT(WindowClosing);
205 DEFINE_EXPECT(NavigateWithBindCtx);
206 
207 static BOOL is_ie9plus;
208 static IUnknown *doc_unk;
209 static IMoniker *doc_mon;
210 static BOOL expect_LockContainer_fLock;
211 static BOOL expect_InPlaceUIWindow_SetActiveObject_active = TRUE;
212 static BOOL ipsex, ipsw;
213 static BOOL set_clientsite, container_locked;
214 static BOOL readystate_set_loading = FALSE, readystate_set_interactive = FALSE, load_from_stream;
215 static BOOL editmode = FALSE, ignore_external_qi;
216 static BOOL inplace_deactivated, open_call;
217 static BOOL complete, loading_js, loading_hash, is_refresh;
218 static DWORD status_code = HTTP_STATUS_OK;
219 static BOOL asynchronous_binding = FALSE;
220 static BOOL support_wbapp, allow_new_window, no_travellog;
221 static BOOL report_mime;
222 static BOOL testing_submit;
223 static BOOL resetting_document;
224 static int stream_read, protocol_read;
225 static IStream *history_stream;
226 static enum load_state_t {
227     LD_DOLOAD,
228     LD_LOADING,
229     LD_LOADED,
230     LD_INTERACTIVE,
231     LD_COMPLETE,
232     LD_NO
233 } load_state;
234 
235 static LPCOLESTR expect_status_text = NULL;
236 static const char *nav_url, *nav_serv_url, *prev_url;
237 
238 static const char html_page[] =
239 "<html>"
240 "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"test.css\"></head>"
241 "<body><div>test</div></body>"
242 "</html>";
243 
244 static const char css_data[] = "body {color: red; margin: 0}";
245 
246 static const WCHAR http_urlW[] =
247     {'h','t','t','p',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g','/','t','e','s','t','s','/','w','i','n','e','h','q','_','s','n','a','p','s','h','o','t','/',0};
248 
249 static const WCHAR doc_url[] = {'w','i','n','e','t','e','s','t',':','d','o','c',0};
250 
251 #define DOCHOST_DOCCANNAVIGATE 0
252 #define WM_CONTINUE_BINDING (WM_APP+1)
253 
254 static HRESULT QueryInterface(REFIID riid, void **ppv);
255 static void test_MSHTML_QueryStatus(IHTMLDocument2*,DWORD);
256 
257 #define test_readyState(u) _test_readyState(__LINE__,u)
258 static void _test_readyState(unsigned,IUnknown*);
259 
260 static const WCHAR wszTimesNewRoman[] =
261     {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0};
262 static const WCHAR wszArial[] =
263     {'A','r','i','a','l',0};
264 
265 static int strcmp_wa(LPCWSTR strw, const char *stra)
266 {
267     CHAR buf[512];
268     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
269     return lstrcmpA(stra, buf);
270 }
271 
272 static BOOL wstr_contains(const WCHAR *strw, const char *stra)
273 {
274     CHAR buf[512];
275     WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), NULL, NULL);
276     return strstr(buf, stra) != NULL;
277 }
278 
279 static const WCHAR *strstrW( const WCHAR *str, const WCHAR *sub )
280 {
281     while (*str)
282     {
283         const WCHAR *p1 = str, *p2 = sub;
284         while (*p1 && *p2 && *p1 == *p2) { p1++; p2++; }
285         if (!*p2) return str;
286         str++;
287     }
288     return NULL;
289 }
290 
291 static BSTR a2bstr(const char *str)
292 {
293     BSTR ret;
294     int len;
295 
296     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
297     ret = SysAllocStringLen(NULL, len);
298     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
299 
300     return ret;
301 }
302 
303 /* Returns true if the user interface is in English. Note that this does not
304  * presume of the formatting of dates, numbers, etc.
305  */
306 static BOOL is_lang_english(void)
307 {
308     static HMODULE hkernel32 = NULL;
309     static LANGID (WINAPI *pGetThreadUILanguage)(void) = NULL;
310     static LANGID (WINAPI *pGetUserDefaultUILanguage)(void) = NULL;
311 
312     if (!hkernel32)
313     {
314         hkernel32 = GetModuleHandleA("kernel32.dll");
315         pGetThreadUILanguage = (void*)GetProcAddress(hkernel32, "GetThreadUILanguage");
316         pGetUserDefaultUILanguage = (void*)GetProcAddress(hkernel32, "GetUserDefaultUILanguage");
317     }
318     if (pGetThreadUILanguage)
319         return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH;
320     if (pGetUserDefaultUILanguage)
321         return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH;
322 
323     return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH;
324 }
325 
326 static BOOL iface_cmp(IUnknown *iface1, IUnknown *iface2)
327 {
328     IUnknown *unk1, *unk2;
329 
330     if(iface1 == iface2)
331         return TRUE;
332 
333     IUnknown_QueryInterface(iface1, &IID_IUnknown, (void**)&unk1);
334     IUnknown_Release(unk1);
335     IUnknown_QueryInterface(iface2, &IID_IUnknown, (void**)&unk2);
336     IUnknown_Release(unk2);
337 
338     return unk1 == unk2;
339 }
340 
341 #define EXPECT_UPDATEUI  1
342 #define EXPECT_SETTITLE  2
343 
344 static void test_timer(DWORD flags)
345 {
346     BOOL *b = &called_Exec_SETTITLE;
347     MSG msg;
348 
349     if(flags & EXPECT_UPDATEUI) {
350         SET_EXPECT(UpdateUI);
351         SET_EXPECT(Exec_UPDATECOMMANDS);
352         b = &called_UpdateUI;
353     }
354     if(flags & EXPECT_SETTITLE)
355         SET_EXPECT(Exec_SETTITLE);
356 
357     while(!*b && GetMessageA(&msg, doc_hwnd, 0, 0)) {
358         TranslateMessage(&msg);
359         DispatchMessageA(&msg);
360     }
361 
362     if(flags & EXPECT_UPDATEUI) {
363         CHECK_CALLED(UpdateUI);
364         CHECK_CALLED(Exec_UPDATECOMMANDS);
365     }
366     if(flags & EXPECT_SETTITLE)
367         CHECK_CALLED(Exec_SETTITLE);
368 }
369 
370 static IMoniker Moniker;
371 
372 #define test_GetCurMoniker(u,m,v,t) _test_GetCurMoniker(__LINE__,u,m,v,t)
373 static void _test_GetCurMoniker(unsigned line, IUnknown *unk, IMoniker *exmon, const char *exurl, BOOL is_todo)
374 {
375     IHTMLDocument2 *doc;
376     IPersistMoniker *permon;
377     IMoniker *mon = (void*)0xdeadbeef;
378     BSTR doc_url = (void*)0xdeadbeef;
379     const WCHAR *ptr;
380     HRESULT hres;
381 
382     if(open_call)
383         return; /* FIXME */
384 
385     hres = IUnknown_QueryInterface(unk, &IID_IPersistMoniker, (void**)&permon);
386     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker) failed: %08x\n", hres);
387     if(FAILED(hres))
388         return;
389 
390     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&doc);
391     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument2) failed: %08x\n", hres);
392 
393     hres = IHTMLDocument2_get_URL(doc, &doc_url);
394     ok(hres == S_OK, "get_URL failed: %08x\n", hres);
395     for(ptr = doc_url; *ptr && *ptr != '#'; ptr++);
396 
397     hres = IPersistMoniker_GetCurMoniker(permon, &mon);
398     IPersistMoniker_Release(permon);
399 
400     if(exmon) {
401         LPOLESTR url;
402         BOOL exb = expect_GetDisplayName;
403         BOOL clb = called_GetDisplayName;
404 
405         ok_(__FILE__,line)(hres == S_OK, "GetCurrentMoniker failed: %08x\n", hres);
406         ok_(__FILE__,line)(mon == exmon, "mon(%p) != exmon(%p)\n", mon, exmon);
407 
408         if(mon == &Moniker)
409             SET_EXPECT(GetDisplayName);
410         hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
411         ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
412         if(mon == &Moniker)
413             CHECK_CALLED(GetDisplayName);
414         expect_GetDisplayName = exb;
415         called_GetDisplayName = clb;
416 
417         if(!*ptr)
418             ok(!lstrcmpW(url, doc_url), "url %s != doc_url %s\n", wine_dbgstr_w(url), wine_dbgstr_w(doc_url));
419         else
420             ok(!strcmp_wa(url, nav_serv_url), "url = %s, expected %s\n", wine_dbgstr_w(url), nav_serv_url);
421         CoTaskMemFree(url);
422     }else if(exurl) {
423         LPOLESTR url;
424 
425         ok_(__FILE__,line)(hres == S_OK, "GetCurrentMoniker failed: %08x\n", hres);
426 
427         hres = IMoniker_GetDisplayName(mon, NULL, NULL, &url);
428         ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
429 
430         if(is_todo)
431             todo_wine ok_(__FILE__,line)(!strcmp_wa(url, exurl), "unexpected url %s\n", wine_dbgstr_w(url));
432         else
433             ok_(__FILE__,line)(!strcmp_wa(url, exurl), "unexpected url %s\n", wine_dbgstr_w(url));
434         if(!*ptr)
435             ok_(__FILE__,line)(!lstrcmpW(url, doc_url), "url %s != doc_url %s\n", wine_dbgstr_w(url), wine_dbgstr_w(doc_url));
436 
437         CoTaskMemFree(url);
438     }else {
439         ok_(__FILE__,line)(hres == E_UNEXPECTED,
440            "GetCurrentMoniker failed: %08x, expected E_UNEXPECTED\n", hres);
441         ok_(__FILE__,line)(mon == (IMoniker*)0xdeadbeef, "mon=%p\n", mon);
442         ok_(__FILE__,line)(!strcmp_wa(doc_url, "about:blank"), "doc_url is not about:blank\n");
443     }
444 
445     SysFreeString(doc_url);
446     IHTMLDocument2_Release(doc);
447     if(mon && mon != (void*)0xdeadbeef)
448         IMoniker_Release(mon);
449 }
450 
451 #define test_current_url(a,b) _test_current_url(__LINE__,a,b)
452 static void _test_current_url(unsigned line, IUnknown *unk, const char *exurl)
453 {
454     IHTMLDocument2 *doc;
455     BSTR url;
456     HRESULT hres;
457 
458     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&doc);
459     ok_(__FILE__,line)(hres == S_OK, "QueryInterface(IID_IHTMLDocument2) failed: %08x\n", hres);
460 
461     hres = IHTMLDocument2_get_URL(doc, &url);
462     ok_(__FILE__,line)(hres == S_OK, "get_URL failed: %08x\n", hres);
463     ok_(__FILE__,line)(!strcmp_wa(url, exurl), "Unexpected URL %s, expected %s\n", wine_dbgstr_w(url), exurl);
464     SysFreeString(url);
465 
466     IHTMLDocument2_Release(doc);
467 }
468 
469 DEFINE_GUID(IID_External_unk,0x30510406,0x98B5,0x11CF,0xBB,0x82,0x00,0xAA,0x00,0xBD,0xCE,0x0B);
470 
471 static HRESULT WINAPI External_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
472 {
473     *ppv = NULL;
474 
475     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
476         *ppv = iface;
477         return S_OK;
478     }
479 
480     if(IsEqualGUID(&IID_IProxyManager, riid))
481         return E_NOINTERFACE; /* TODO */
482     if(IsEqualGUID(&IID_IDispatchEx, riid))
483         return E_NOINTERFACE; /* TODO */
484     if(IsEqualGUID(&IID_External_unk, riid))
485         return E_NOINTERFACE; /* TODO */
486 
487     if(!ignore_external_qi)
488         ok(0, "unexpected riid: %s\n", wine_dbgstr_guid(riid));
489     return E_NOINTERFACE;
490 }
491 
492 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
493 {
494     return 2;
495 }
496 
497 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
498 {
499     return 1;
500 }
501 
502 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
503 {
504     ok(0, "unexpected call\n");
505     return E_NOTIMPL;
506 }
507 
508 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
509         ITypeInfo **ppTInfo)
510 {
511     ok(0, "unexpected call\n");
512     return E_NOTIMPL;
513 }
514 
515 static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
516         UINT cNames, LCID lcid, DISPID *rgDispId)
517 {
518     ok(0, "unexpected call\n");
519     return E_NOTIMPL;
520 }
521 
522 static HRESULT WINAPI External_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
523         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
524         EXCEPINFO *pExcepInfo, UINT *puArgErr)
525 {
526     ok(0, "unexpected call\n");
527     return E_NOTIMPL;
528 }
529 
530 static const IDispatchVtbl ExternalVtbl = {
531     External_QueryInterface,
532     Dispatch_AddRef,
533     Dispatch_Release,
534     Dispatch_GetTypeInfoCount,
535     Dispatch_GetTypeInfo,
536     Dispatch_GetIDsOfNames,
537     External_Invoke
538 };
539 
540 static IDispatch External = { &ExternalVtbl };
541 
542 static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
543 {
544     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
545         *ppv = iface;
546         return S_OK;
547     }
548 
549     *ppv = NULL;
550     return E_NOINTERFACE;
551 }
552 
553 static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
554 {
555     return 2;
556 }
557 
558 static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
559 {
560     return 1;
561 }
562 
563 static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
564         IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
565         DWORD grfPI, HANDLE_PTR dwReserved)
566 {
567     BINDINFO bindinfo;
568     DWORD bindf = 0;
569     HRESULT hres;
570 
571     static const WCHAR wszTextCss[] = {'t','e','x','t','/','c','s','s',0};
572     static const WCHAR empty_str = {0};
573 
574     CHECK_EXPECT(Start);
575 
576     ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
577     ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
578     ok(!grfPI, "grfPI = %x\n", grfPI);
579     ok(!dwReserved, "dwReserved = %lx\n", dwReserved);
580 
581     memset(&bindinfo, 0, sizeof(bindinfo));
582     bindinfo.cbSize = sizeof(bindinfo);
583     hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
584     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
585     if(!testing_submit)
586         ok(bindf == (BINDF_FROMURLMON|BINDF_PULLDATA|BINDF_NEEDFILE|BINDF_ASYNCSTORAGE|BINDF_ASYNCHRONOUS),
587            "bindf = %x\n", bindf);
588     else
589         ok(bindf == (BINDF_FROMURLMON|BINDF_FORMS_SUBMIT|BINDF_PRAGMA_NO_CACHE|BINDF_HYPERLINK
590                      |BINDF_PULLDATA|BINDF_NEEDFILE|BINDF_GETNEWESTVERSION|BINDF_ASYNCSTORAGE|BINDF_ASYNCHRONOUS),
591            "bindf = %x\n", bindf);
592 
593     ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize=%d\n", bindinfo.cbSize);
594     ok(bindinfo.szExtraInfo == NULL, "bindinfo.szExtraInfo=%p\n", bindinfo.szExtraInfo);
595     /* TODO: test stgmedData */
596     ok(bindinfo.grfBindInfoF == 0, "bindinfo.grfBinfInfoF=%08x\n", bindinfo.grfBindInfoF);
597     if(!testing_submit) {
598         ok(bindinfo.dwBindVerb == BINDVERB_GET, "bindinfo.dwBindVerb=%d\n", bindinfo.dwBindVerb);
599         ok(bindinfo.cbstgmedData == 0, "bindinfo.cbstgmedData=%d\n", bindinfo.cbstgmedData);
600         ok(bindinfo.stgmedData.tymed == TYMED_NULL, "bindinfo.stgmedData.tymed=%d\n", bindinfo.stgmedData.tymed);
601     }else {
602         ok(bindinfo.dwBindVerb == BINDVERB_POST, "bindinfo.dwBindVerb=%d\n", bindinfo.dwBindVerb);
603         ok(bindinfo.cbstgmedData == 8, "bindinfo.cbstgmedData=%d\n", bindinfo.cbstgmedData);
604         ok(bindinfo.stgmedData.tymed == TYMED_HGLOBAL, "bindinfo.stgmedData.tymed=%d\n", bindinfo.stgmedData.tymed);
605         ok(!memcmp(U(bindinfo.stgmedData).hGlobal, "cmd=TEST", 8), "unexpected hGlobal\n");
606     }
607     ok(bindinfo.szCustomVerb == 0, "bindinfo.szCustomVerb=%p\n", bindinfo.szCustomVerb);
608     ok(bindinfo.dwOptions == 0x80000 ||
609        bindinfo.dwOptions == 0x4080000, /* win2k3 */
610        "bindinfo.dwOptions=%x\n", bindinfo.dwOptions);
611     ok(bindinfo.dwOptionsFlags == 0, "bindinfo.dwOptionsFlags=%d\n", bindinfo.dwOptionsFlags);
612     /* TODO: test dwCodePage */
613     /* TODO: test securityAttributes */
614     ok(IsEqualGUID(&IID_NULL, &bindinfo.iid), "unexpected bindinfo.iid\n");
615     ok(bindinfo.pUnk == NULL, "bindinfo.pUnk=%p\n", bindinfo.pUnk);
616     ok(bindinfo.dwReserved == 0, "bindinfo.dwReserved=%d\n", bindinfo.dwReserved);
617 
618     hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
619             BINDSTATUS_CACHEFILENAMEAVAILABLE, &empty_str);
620     ok(hres == S_OK, "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
621 
622     if(report_mime) {
623         hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
624                 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextCss);
625         ok(hres == S_OK,
626                 "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
627     }
628 
629     hres = IInternetProtocolSink_ReportData(pOIProtSink,
630             BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION, 13, 13);
631     ok(hres == S_OK, "ReportData failed: %08x\n", hres);
632 
633     hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
634     ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
635 
636     return S_OK;
637 }
638 
639 static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
640         PROTOCOLDATA *pProtocolData)
641 {
642     ok(0, "unexpected call\n");
643     return E_NOTIMPL;
644 }
645 
646 static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
647         DWORD dwOptions)
648 {
649     ok(0, "unexpected call\n");
650     return E_NOTIMPL;
651 }
652 
653 static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
654 {
655     CHECK_EXPECT(Terminate);
656     return S_OK;
657 }
658 
659 static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
660 {
661     ok(0, "unexpected call\n");
662     return E_NOTIMPL;
663 }
664 
665 static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
666 {
667     ok(0, "unexpected call\n");
668     return E_NOTIMPL;
669 }
670 
671 static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
672         ULONG cb, ULONG *pcbRead)
673 {
674     CHECK_EXPECT2(Protocol_Read);
675 
676     ok(pv != NULL, "pv == NULL\n");
677     ok(cb > sizeof(css_data), "cb < sizeof(css_data)\n");
678     ok(pcbRead != NULL, "pcbRead == NULL\n");
679     ok(!*pcbRead || *pcbRead==sizeof(css_data)-1, "*pcbRead=%d\n", *pcbRead);
680 
681     if(protocol_read)
682         return S_FALSE;
683 
684     protocol_read += *pcbRead = sizeof(css_data)-1;
685     memcpy(pv, css_data, sizeof(css_data)-1);
686 
687     return S_OK;
688 }
689 
690 static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
691         LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
692 {
693     ok(0, "unexpected call\n");
694     return E_NOTIMPL;
695 }
696 
697 static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
698 {
699     CHECK_EXPECT(LockRequest);
700     return S_OK;
701 }
702 
703 static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
704 {
705     CHECK_EXPECT(UnlockRequest);
706     return S_OK;
707 }
708 
709 static const IInternetProtocolVtbl ProtocolVtbl = {
710     Protocol_QueryInterface,
711     Protocol_AddRef,
712     Protocol_Release,
713     Protocol_Start,
714     Protocol_Continue,
715     Protocol_Abort,
716     Protocol_Terminate,
717     Protocol_Suspend,
718     Protocol_Resume,
719     Protocol_Read,
720     Protocol_Seek,
721     Protocol_LockRequest,
722     Protocol_UnlockRequest
723 };
724 
725 static IInternetProtocol Protocol = { &ProtocolVtbl };
726 
727 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
728 {
729     if(!IsEqualGUID(&IID_IInternetProtocolInfo, riid))
730         ok(0, "unexpected call\n");
731     return E_NOINTERFACE;
732 }
733 
734 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
735 {
736     return 2;
737 }
738 
739 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
740 {
741     return 1;
742 }
743 
744 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
745                                         REFIID riid, void **ppv)
746 {
747     if(IsEqualGUID(&IID_IInternetProtocolInfo, riid))
748         return E_NOINTERFACE;
749 
750     CHECK_EXPECT(CreateInstance);
751     ok(ppv != NULL, "ppv == NULL\n");
752 
753     *ppv = &Protocol;
754     return S_OK;
755 }
756 
757 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
758 {
759     ok(0, "unexpected call\n");
760     return S_OK;
761 }
762 
763 static const IClassFactoryVtbl ClassFactoryVtbl = {
764     ClassFactory_QueryInterface,
765     ClassFactory_AddRef,
766     ClassFactory_Release,
767     ClassFactory_CreateInstance,
768     ClassFactory_LockServer
769 };
770 
771 static IClassFactory ClassFactory = { &ClassFactoryVtbl };
772 
773 static HRESULT WINAPI HlinkFrame_QueryInterface(IHlinkFrame *iface, REFIID riid, void **ppv)
774 {
775     ok(0, "unexpected call\n");
776     return E_NOTIMPL;
777 }
778 
779 static ULONG WINAPI HlinkFrame_AddRef(IHlinkFrame *iface)
780 {
781     return 2;
782 }
783 
784 static ULONG WINAPI HlinkFrame_Release(IHlinkFrame *iface)
785 {
786     return 1;
787 }
788 
789 static HRESULT WINAPI HlinkFrame_SetBrowseContext(IHlinkFrame *iface,
790                                                   IHlinkBrowseContext *pihlbc)
791 {
792     ok(0, "unexpected call\n");
793     return E_NOTIMPL;
794 }
795 
796 static HRESULT WINAPI HlinkFrame_GetBrowseContext(IHlinkFrame *iface,
797                                                   IHlinkBrowseContext **ppihlbc)
798 {
799     ok(0, "unexpected call\n");
800     return E_NOTIMPL;
801 }
802 
803 static HRESULT WINAPI HlinkFrame_Navigate(IHlinkFrame *iface, DWORD grfHLNF, LPBC pbc,
804                                           IBindStatusCallback *pibsc, IHlink *pihlNavigate)
805 {
806     HRESULT hres;
807 
808     CHECK_EXPECT(Navigate);
809 
810     ok(grfHLNF == 0, "grfHLNF=%d, expected 0\n", grfHLNF);
811     ok(pbc != NULL, "pbc == NULL\n");
812     ok(pibsc != NULL, "pubsc == NULL\n");
813     ok(pihlNavigate != NULL, "puhlNavigate == NULL\n");
814 
815     if(pihlNavigate) {
816         LPWSTR frame_name = (LPWSTR)0xdeadbeef;
817         LPWSTR location = (LPWSTR)0xdeadbeef;
818         IHlinkSite *site;
819         IMoniker *mon = NULL;
820         DWORD site_data = 0xdeadbeef;
821 
822         hres = IHlink_GetTargetFrameName(pihlNavigate, &frame_name);
823         ok(hres == S_FALSE, "GetTargetFrameName failed: %08x\n", hres);
824         ok(frame_name == NULL, "frame_name = %p\n", frame_name);
825 
826         hres = IHlink_GetMonikerReference(pihlNavigate, 1, &mon, &location);
827         ok(hres == S_OK, "GetMonikerReference failed: %08x\n", hres);
828         ok(location == NULL, "location = %p\n", location);
829         ok(mon != NULL, "mon == NULL\n");
830 
831         hres = IMoniker_GetDisplayName(mon, NULL, NULL, &location);
832         ok(hres == S_OK, "GetDisplayName failed: %08x\n", hres);
833         ok(!strcmp_wa(location, nav_url), "unexpected display name %s, expected %s\n", wine_dbgstr_w(location), nav_url);
834         CoTaskMemFree(location);
835         IMoniker_Release(mon);
836 
837         hres = IHlink_GetHlinkSite(pihlNavigate, &site, &site_data);
838         ok(hres == S_OK, "GetHlinkSite failed: %08x\n", hres);
839         ok(site == NULL, "site = %p\n, expected NULL\n", site);
840         ok(site_data == 0xdeadbeef, "site_data = %x\n", site_data);
841     }
842 
843     return S_OK;
844 }
845 
846 static HRESULT WINAPI HlinkFrame_OnNavigate(IHlinkFrame *iface, DWORD grfHLNF,
847         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName, DWORD dwreserved)
848 {
849     ok(0, "unexpected call\n");
850     return E_NOTIMPL;
851 }
852 
853 static HRESULT WINAPI HlinkFrame_UpdateHlink(IHlinkFrame *iface, ULONG uHLID,
854         IMoniker *pimkTarget, LPCWSTR pwzLocation, LPCWSTR pwzFriendlyName)
855 {
856     ok(0, "unexpected call\n");
857     return E_NOTIMPL;
858 }
859 
860 static const IHlinkFrameVtbl HlinkFrameVtbl = {
861     HlinkFrame_QueryInterface,
862     HlinkFrame_AddRef,
863     HlinkFrame_Release,
864     HlinkFrame_SetBrowseContext,
865     HlinkFrame_GetBrowseContext,
866     HlinkFrame_Navigate,
867     HlinkFrame_OnNavigate,
868     HlinkFrame_UpdateHlink
869 };
870 
871 static IHlinkFrame HlinkFrame = { &HlinkFrameVtbl };
872 
873 static HRESULT WINAPI NewWindowManager_QueryInterface(INewWindowManager *iface, REFIID riid, void **ppv)
874 {
875     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(riid, &IID_INewWindowManager)) {
876         *ppv = iface;
877         return S_OK;
878     }
879 
880     trace("NewWindowManager_QueryInterface %s\n", wine_dbgstr_guid(riid));
881     *ppv = NULL;
882     return E_NOINTERFACE;
883 }
884 
885 static ULONG WINAPI NewWindowManager_AddRef(INewWindowManager *iface)
886 {
887     return 2;
888 }
889 
890 static ULONG WINAPI NewWindowManager_Release(INewWindowManager *iface)
891 {
892     return 1;
893 }
894 
895 static HRESULT WINAPI NewWindowManager_EvaluateNewWindow(INewWindowManager *iface, LPCWSTR pszUrl,
896         LPCWSTR pszName, LPCWSTR pszUrlContext, LPCWSTR pszFeatures, BOOL fReplace, DWORD dwFlags,
897         DWORD dwUserActionTime)
898 {
899     CHECK_EXPECT(EvaluateNewWindow);
900 
901     ok(!strcmp_wa(pszUrl, "about:blank"), "pszUrl = %s\n", wine_dbgstr_w(pszUrl));
902     ok(!strcmp_wa(pszName, "test"), "pszName = %s\n", wine_dbgstr_w(pszName));
903     ok(!strcmp_wa(pszUrlContext, prev_url), "pszUrlContext = %s\n", wine_dbgstr_w(pszUrlContext));
904     ok(!pszFeatures, "pszFeatures = %s\n", wine_dbgstr_w(pszFeatures));
905     ok(!fReplace, "fReplace = %x\n", fReplace);
906     ok(dwFlags == (allow_new_window ? 0 : NWMF_FIRST), "dwFlags = %x\n", dwFlags);
907     ok(!dwUserActionTime, "dwUserActionime = %d\n", dwUserActionTime);
908 
909     return allow_new_window ? S_OK : E_FAIL;
910 }
911 
912 static const INewWindowManagerVtbl NewWindowManagerVtbl = {
913     NewWindowManager_QueryInterface,
914     NewWindowManager_AddRef,
915     NewWindowManager_Release,
916     NewWindowManager_EvaluateNewWindow
917 };
918 
919 static INewWindowManager NewWindowManager = { &NewWindowManagerVtbl };
920 
921 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
922         REFIID riid, void**ppv)
923 {
924     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
925         *ppv = iface;
926         return S_OK;
927     }
928 
929     ok(0, "unexpected call\n");
930     return E_NOINTERFACE;
931 }
932 
933 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
934 {
935     return 2;
936 }
937 
938 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
939 {
940     return 1;
941 }
942 
943 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
944 {
945     if(resetting_document)
946         return S_OK;
947 
948     switch(dispID) {
949     case DISPID_READYSTATE:
950         CHECK_EXPECT2(OnChanged_READYSTATE);
951 
952         if(!readystate_set_interactive)
953             test_MSHTML_QueryStatus(NULL, OLECMDF_SUPPORTED
954                 | (editmode && (load_state == LD_INTERACTIVE || load_state == LD_COMPLETE)
955                    ? OLECMDF_ENABLED : 0));
956 
957         if(readystate_set_loading) {
958             readystate_set_loading = FALSE;
959             load_state = LD_LOADING;
960         }
961         if(!editmode || load_state != LD_LOADING || !called_Exec_Explorer_69)
962             test_readyState(NULL);
963         return S_OK;
964     case 1005:
965         CHECK_EXPECT2(OnChanged_1005);
966         if(!editmode)
967             test_readyState(NULL);
968         readystate_set_interactive = (load_state != LD_INTERACTIVE);
969         return S_OK;
970     case 1012:
971         CHECK_EXPECT2(OnChanged_1012);
972         return S_OK;
973     case 1014:
974         CHECK_EXPECT2(OnChanged_1014);
975         return S_OK;
976     case 1030:
977     case 3000022:
978     case 3000023:
979     case 3000024:
980     case 3000025:
981     case 3000026:
982     case 3000027:
983     case 3000028:
984     case 3000029:
985     case 3000030:
986     case 3000031:
987     case 3000032:
988         /* TODO */
989         return S_OK;
990     }
991 
992     ok(0, "unexpected id %d\n", dispID);
993     return E_NOTIMPL;
994 }
995 
996 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
997 {
998     ok(0, "unexpected call\n");
999     return E_NOTIMPL;
1000 }
1001 
1002 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
1003     PropertyNotifySink_QueryInterface,
1004     PropertyNotifySink_AddRef,
1005     PropertyNotifySink_Release,
1006     PropertyNotifySink_OnChanged,
1007     PropertyNotifySink_OnRequestEdit
1008 };
1009 
1010 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
1011 
1012 static HRESULT WINAPI Stream_QueryInterface(IStream *iface, REFIID riid, void **ppv)
1013 {
1014     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ISequentialStream, riid) || IsEqualGUID(&IID_IStream, riid)) {
1015         *ppv = iface;
1016         return S_OK;
1017     }
1018 
1019     ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
1020     *ppv = NULL;
1021     return E_NOINTERFACE;
1022 }
1023 
1024 static ULONG WINAPI Stream_AddRef(IStream *iface)
1025 {
1026     return 2;
1027 }
1028 
1029 static ULONG WINAPI Stream_Release(IStream *iface)
1030 {
1031     return 1;
1032 }
1033 
1034 static HRESULT WINAPI Stream_Read(IStream *iface, void *pv,
1035                                   ULONG cb, ULONG *pcbRead)
1036 {
1037     CHECK_EXPECT2(Read);
1038     ok(pv != NULL, "pv == NULL\n");
1039     ok(cb > sizeof(html_page), "cb = %d\n", cb);
1040     ok(pcbRead != NULL, "pcbRead == NULL\n");
1041     ok(!*pcbRead, "*pcbRead = %d\n", *pcbRead);
1042 
1043     if(stream_read)
1044         return S_FALSE;
1045 
1046     memcpy(pv, html_page, sizeof(html_page)-1);
1047     stream_read += *pcbRead = sizeof(html_page)-1;
1048     return S_OK;
1049 }
1050 
1051 static HRESULT WINAPI Stream_Write(IStream *iface, const void *pv,
1052                                           ULONG cb, ULONG *pcbWritten)
1053 {
1054     ok(0, "unexpected call\n");
1055     return E_NOTIMPL;
1056 }
1057 
1058 static HRESULT WINAPI Stream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
1059                                          DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
1060 {
1061     ok(0, "unexpected call\n");
1062     return E_NOTIMPL;
1063 }
1064 
1065 static HRESULT WINAPI Stream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
1066 {
1067     ok(0, "unexpected call\n");
1068     return E_NOTIMPL;
1069 }
1070 
1071 static HRESULT WINAPI Stream_CopyTo(IStream *iface, IStream *pstm,
1072         ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
1073 {
1074     ok(0, "unexpected call\n");
1075     return E_NOTIMPL;
1076 }
1077 
1078 static HRESULT WINAPI Stream_Commit(IStream *iface, DWORD grfCommitFlags)
1079 {
1080     ok(0, "unexpected call\n");
1081     return E_NOTIMPL;
1082 }
1083 
1084 static HRESULT WINAPI Stream_Revert(IStream *iface)
1085 {
1086     ok(0, "unexpected call\n");
1087     return E_NOTIMPL;
1088 }
1089 
1090 static HRESULT WINAPI Stream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
1091                                                ULARGE_INTEGER cb, DWORD dwLockType)
1092 {
1093     ok(0, "unexpected call\n");
1094     return E_NOTIMPL;
1095 }
1096 
1097 static HRESULT WINAPI Stream_UnlockRegion(IStream *iface,
1098         ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
1099 {
1100     ok(0, "unexpected call\n");
1101     return E_NOTIMPL;
1102 }
1103 
1104 static HRESULT WINAPI Stream_Stat(IStream *iface, STATSTG *pstatstg,
1105                                          DWORD dwStatFlag)
1106 {
1107     ok(0, "unexpected call\n");
1108     return E_NOTIMPL;
1109 }
1110 
1111 static HRESULT WINAPI Stream_Clone(IStream *iface, IStream **ppstm)
1112 {
1113     ok(0, "unexpected call\n");
1114     return E_NOTIMPL;
1115 }
1116 
1117 static const IStreamVtbl StreamVtbl = {
1118     Stream_QueryInterface,
1119     Stream_AddRef,
1120     Stream_Release,
1121     Stream_Read,
1122     Stream_Write,
1123     Stream_Seek,
1124     Stream_SetSize,
1125     Stream_CopyTo,
1126     Stream_Commit,
1127     Stream_Revert,
1128     Stream_LockRegion,
1129     Stream_UnlockRegion,
1130     Stream_Stat,
1131     Stream_Clone
1132 };
1133 
1134 static IStream Stream = { &StreamVtbl };
1135 
1136 static HRESULT WINAPI WinInetHttpInfo_QueryInterface(
1137         IWinInetHttpInfo* This,
1138         REFIID riid,
1139         void **ppvObject)
1140 {
1141     *ppvObject = NULL;
1142 
1143     if(IsEqualGUID(&IID_IGetBindHandle, riid))
1144         return E_NOINTERFACE;
1145 
1146     ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
1147     return E_NOINTERFACE;
1148 }
1149 
1150 static ULONG WINAPI WinInetHttpInfo_AddRef(
1151         IWinInetHttpInfo* This)
1152 {
1153     return 2;
1154 }
1155 
1156 static ULONG WINAPI WinInetHttpInfo_Release(
1157         IWinInetHttpInfo* This)
1158 {
1159     return 1;
1160 }
1161 
1162 static HRESULT WINAPI WinInetHttpInfo_QueryOption(
1163         IWinInetHttpInfo* This,
1164         DWORD dwOption,
1165         LPVOID pBuffer,
1166         DWORD *pcbBuf)
1167 {
1168     return E_NOTIMPL; /* TODO */
1169 }
1170 
1171 static HRESULT WINAPI WinInetHttpInfo_QueryInfo(
1172         IWinInetHttpInfo* This,
1173         DWORD dwOption,
1174         LPVOID pBuffer,
1175         DWORD *pcbBuf,
1176         DWORD *pdwFlags,
1177         DWORD *pdwReserved)
1178 {
1179     ok(pdwReserved == NULL, "pdwReserved != NULL\n");
1180 
1181     if(dwOption == (HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER)) {
1182         ok(pBuffer != NULL, "pBuffer == NULL\n");
1183         ok(*pcbBuf == sizeof(DWORD), "*pcbBuf = %d\n", *pcbBuf);
1184         ok(pdwFlags == NULL, "*pdwFlags != NULL\n");
1185         *((DWORD*)pBuffer) = status_code;
1186         return S_OK;
1187     }
1188 
1189     return E_NOTIMPL; /* TODO */
1190 }
1191 
1192 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
1193     WinInetHttpInfo_QueryInterface,
1194     WinInetHttpInfo_AddRef,
1195     WinInetHttpInfo_Release,
1196     WinInetHttpInfo_QueryOption,
1197     WinInetHttpInfo_QueryInfo
1198 };
1199 
1200 static IWinInetHttpInfo WinInetHttpInfo = { &WinInetHttpInfoVtbl };
1201 
1202 DEFINE_GUID(IID_unk_binding, 0xf3d8f080,0xa5eb,0x476f,0x9d,0x19,0xa5,0xef,0x24,0xe5,0xc2,0xe6);
1203 
1204 static HRESULT WINAPI Binding_QueryInterface(IBinding *iface, REFIID riid, void **ppv)
1205 {
1206     if(IsEqualGUID(&IID_IUnknown, riid)) {
1207         *ppv = iface;
1208         return S_OK;
1209     }
1210 
1211     if(IsEqualGUID(&IID_IWinInetInfo, riid) || IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
1212         *ppv = &WinInetHttpInfo;
1213         return S_OK;
1214     }
1215 
1216     if(IsEqualGUID(&IID_unk_binding, riid)) {
1217         *ppv = NULL;
1218         return E_NOINTERFACE;
1219     }
1220 
1221     trace("Binding::QI(%s)\n", wine_dbgstr_guid(riid));
1222     *ppv = NULL;
1223     return E_NOINTERFACE;
1224 }
1225 
1226 static ULONG WINAPI Binding_AddRef(IBinding *iface)
1227 {
1228     return 2;
1229 }
1230 
1231 static ULONG WINAPI Binding_Release(IBinding *iface)
1232 {
1233     return 1;
1234 }
1235 
1236 static HRESULT WINAPI Binding_Abort(IBinding *iface)
1237 {
1238     CHECK_EXPECT(Abort);
1239     if(asynchronous_binding)
1240         PeekMessageA(NULL, container_hwnd, WM_CONTINUE_BINDING, WM_CONTINUE_BINDING, PM_REMOVE);
1241     return S_OK;
1242 }
1243 
1244 static HRESULT WINAPI Binding_Suspend(IBinding *iface)
1245 {
1246     ok(0, "unexpected call\n");
1247     return E_NOTIMPL;
1248 }
1249 
1250 static HRESULT WINAPI Binding_Resume(IBinding *iface)
1251 {
1252     ok(0, "unexpected call\n");
1253     return E_NOTIMPL;
1254 }
1255 
1256 static HRESULT WINAPI Binding_SetPriority(IBinding *iface, LONG nPriority)
1257 {
1258     ok(0, "unexpected call\n");
1259     return E_NOTIMPL;
1260 }
1261 
1262 static HRESULT WINAPI Binding_GetPriority(IBinding *iface, LONG *pnPriority)
1263 {
1264     ok(0, "unexpected call\n");
1265     return E_NOTIMPL;
1266 }
1267 
1268 static HRESULT WINAPI Binding_GetBindResult(IBinding *iface, CLSID *pclsidProtocol,
1269         DWORD *pdwResult, LPOLESTR *pszResult, DWORD *pdwReserved)
1270 {
1271     CHECK_EXPECT(GetBindResult);
1272     return E_NOTIMPL;
1273 }
1274 
1275 static const IBindingVtbl BindingVtbl = {
1276     Binding_QueryInterface,
1277     Binding_AddRef,
1278     Binding_Release,
1279     Binding_Abort,
1280     Binding_Suspend,
1281     Binding_Resume,
1282     Binding_SetPriority,
1283     Binding_GetPriority,
1284     Binding_GetBindResult
1285 };
1286 
1287 static IBinding Binding = { &BindingVtbl };
1288 
1289 DEFINE_GUID(IID_IMoniker_unk,0xA158A630,0xED6F,0x45FB,0xB9,0x87,0xF6,0x86,0x76,0xF5,0x77,0x52);
1290 DEFINE_GUID(IID_IMoniker_unk2, 0x79EAC9D3,0xBAF9,0x11CE,0x8C,0x82,0x00,0xAA,0x00,0x4B,0xA9,0x0B);
1291 
1292 static HRESULT WINAPI Moniker_QueryInterface(IMoniker *iface, REFIID riid, void **ppv)
1293 {
1294     *ppv = NULL;
1295 
1296     if(IsEqualGUID(&IID_IMoniker_unk, riid))
1297         return E_NOINTERFACE; /* TODO */
1298     if(IsEqualGUID(&IID_IMoniker_unk2, riid))
1299         return E_NOINTERFACE; /* TODO */
1300 
1301     ok(0, "unexpected riid: %s\n", wine_dbgstr_guid(riid));
1302     return E_NOINTERFACE;
1303 }
1304 
1305 static ULONG WINAPI Moniker_AddRef(IMoniker *iface)
1306 {
1307     return 2;
1308 }
1309 
1310 static ULONG WINAPI Moniker_Release(IMoniker *iface)
1311 {
1312     return 1;
1313 }
1314 
1315 static HRESULT WINAPI Moniker_GetClassID(IMoniker *iface, CLSID *pClassID)
1316 {
1317     CHECK_EXPECT(GetClassID);
1318     ok(IsEqualGUID(pClassID, &IID_NULL), "pClassID = %s\n", wine_dbgstr_guid(pClassID));
1319     return E_FAIL;
1320 }
1321 
1322 static HRESULT WINAPI Moniker_IsDirty(IMoniker *iface)
1323 {
1324     ok(0, "unexpected call\n");
1325     return E_NOTIMPL;
1326 }
1327 
1328 static HRESULT WINAPI Moniker_Load(IMoniker *iface, IStream *pStm)
1329 {
1330     ok(0, "unexpected call\n");
1331     return E_NOTIMPL;
1332 }
1333 
1334 static HRESULT WINAPI Moniker_Save(IMoniker *iface, IStream *pStm, BOOL fClearDirty)
1335 {
1336     ok(0, "unexpected call\n");
1337     return E_NOTIMPL;
1338 }
1339 
1340 static HRESULT WINAPI Moniker_GetSizeMax(IMoniker *iface, ULARGE_INTEGER *pcbSize)
1341 {
1342     ok(0, "unexpected call\n");
1343     return E_NOTIMPL;
1344 }
1345 
1346 static HRESULT WINAPI Moniker_BindToObject(IMoniker *iface, IBindCtx *pcb, IMoniker *pmkToLeft,
1347         REFIID riidResult, void **ppvResult)
1348 {
1349     ok(0, "unexpected call\n");
1350     return E_NOTIMPL;
1351 }
1352 
1353 static void test_binding_ui(IUnknown *unk)
1354 {
1355     IWindowForBindingUI *binding_ui;
1356     IServiceProvider *serv_prov;
1357     HWND binding_hwnd;
1358     HRESULT hres;
1359 
1360     hres = IUnknown_QueryInterface(unk, &IID_IServiceProvider, (void**)&serv_prov);
1361     ok(hres == S_OK, "Could not get IServiceProvider: %08x\n", hres);
1362 
1363     hres = IServiceProvider_QueryService(serv_prov, &IID_IWindowForBindingUI, &IID_IWindowForBindingUI,
1364             (void**)&binding_ui);
1365     ok(hres == S_OK, "Could not get IWindowForBindingUI: %08x\n", hres);
1366 
1367     hres = IWindowForBindingUI_GetWindow(binding_ui, &IID_IHttpSecurity, &binding_hwnd);
1368     ok(hres == S_OK, "GetWindow(IID_IHttpSecurity) failed: %08x\n", hres);
1369     if(doc_hwnd)
1370         ok(binding_hwnd == doc_hwnd, "binding_hwnd != doc_hwnd\n");
1371     else
1372         todo_wine ok(binding_hwnd != NULL, "binding_hwnd == NULL\n");
1373 
1374     hres = IWindowForBindingUI_GetWindow(binding_ui, &IID_IAuthenticate, &binding_hwnd);
1375     ok(hres == S_OK, "GetWindow(IID_IHttpSecurity) failed: %08x\n", hres);
1376     if(doc_hwnd)
1377         ok(binding_hwnd == doc_hwnd, "binding_hwnd != doc_hwnd\n");
1378     else
1379         todo_wine ok(binding_hwnd != NULL, "binding_hwnd == NULL\n");
1380 
1381     hres = IWindowForBindingUI_GetWindow(binding_ui, &IID_IWindowForBindingUI, &binding_hwnd);
1382     ok(hres == S_OK, "GetWindow(IID_IHttpSecurity) failed: %08x\n", hres);
1383     if(doc_hwnd)
1384         ok(binding_hwnd == doc_hwnd, "binding_hwnd != doc_hwnd\n");
1385     else
1386         todo_wine ok(binding_hwnd != NULL, "binding_hwnd == NULL\n");
1387 
1388     IWindowForBindingUI_Release(binding_ui);
1389     IServiceProvider_Release(serv_prov);
1390 }
1391 
1392 static void continue_binding(IBindStatusCallback *callback)
1393 {
1394     FORMATETC formatetc = {0xc02d, NULL, 1, -1, TYMED_ISTREAM};
1395     STGMEDIUM stgmedium;
1396     HRESULT hres;
1397 
1398     static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};
1399 
1400     test_binding_ui((IUnknown*)callback);
1401 
1402     if(report_mime) {
1403         hres = IBindStatusCallback_OnProgress(callback, 0, 0, BINDSTATUS_MIMETYPEAVAILABLE,
1404                 wszTextHtml);
1405         ok(hres == S_OK, "OnProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
1406     }
1407 
1408     hres = IBindStatusCallback_OnProgress(callback, sizeof(html_page)-1, sizeof(html_page)-1,
1409             BINDSTATUS_BEGINDOWNLOADDATA, doc_url);
1410     ok(hres == S_OK, "OnProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
1411     if(status_code != HTTP_STATUS_OK) {
1412         CHECK_CALLED_BROKEN(IsErrorUrl);
1413         SET_EXPECT(IsErrorUrl);
1414     }
1415 
1416     SET_EXPECT(Read);
1417     stgmedium.tymed = TYMED_ISTREAM;
1418     U(stgmedium).pstm = &Stream;
1419     stgmedium.pUnkForRelease = (IUnknown*)&Moniker;
1420     hres = IBindStatusCallback_OnDataAvailable(callback,
1421             BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION,
1422             sizeof(html_page)-1, &formatetc, &stgmedium);
1423     ok(hres == S_OK, "OnDataAvailable failed: %08x\n", hres);
1424     CHECK_CALLED(Read);
1425 
1426     hres = IBindStatusCallback_OnProgress(callback, sizeof(html_page)-1, sizeof(html_page)-1,
1427             BINDSTATUS_ENDDOWNLOADDATA, NULL);
1428     ok(hres == S_OK, "OnProgress(BINDSTATUS_ENDDOWNLOADDATA) failed: %08x\n", hres);
1429 
1430     SET_EXPECT(GetBindResult);
1431     hres = IBindStatusCallback_OnStopBinding(callback, S_OK, NULL);
1432     ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
1433     CLEAR_CALLED(GetBindResult); /* IE7 */
1434 
1435     IBindStatusCallback_Release(callback);
1436 }
1437 
1438 static HRESULT WINAPI Moniker_BindToStorage(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
1439         REFIID riid, void **ppv)
1440 {
1441     IBindStatusCallback *callback = NULL;
1442     BINDINFO bindinfo;
1443     DWORD bindf;
1444     HRESULT hres;
1445 
1446     static OLECHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
1447 
1448     CHECK_EXPECT(BindToStorage);
1449 
1450     load_state = LD_LOADING;
1451 
1452     ok(pbc != NULL, "pbc == NULL\n");
1453     ok(pmkToLeft == NULL, "pmkToLeft=%p\n", pmkToLeft);
1454     ok(IsEqualGUID(&IID_IStream, riid), "unexpected riid\n");
1455     ok(ppv != NULL, "ppv == NULL\n");
1456     ok(*ppv == NULL, "*ppv=%p\n", *ppv);
1457 
1458     hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, (IUnknown**)&callback);
1459     ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
1460     ok(callback != NULL, "callback == NULL\n");
1461 
1462     memset(&bindinfo, 0xf0, sizeof(bindinfo));
1463     bindinfo.cbSize = sizeof(bindinfo);
1464 
1465     hres = IBindStatusCallback_GetBindInfo(callback, &bindf, &bindinfo);
1466     ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
1467     ok((bindf & ~BINDF_HYPERLINK /* IE9 */) == (BINDF_PULLDATA|BINDF_ASYNCSTORAGE|BINDF_ASYNCHRONOUS), "bindf = %08x\n", bindf);
1468     ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize=%d\n", bindinfo.cbSize);
1469     ok(bindinfo.szExtraInfo == NULL, "bindinfo.szExtraInfo=%p\n", bindinfo.szExtraInfo);
1470     /* TODO: test stgmedData */
1471     ok(bindinfo.grfBindInfoF == 0, "bindinfo.grfBinfInfoF=%08x\n", bindinfo.grfBindInfoF);
1472     ok(bindinfo.dwBindVerb == 0, "bindinfo.dwBindVerb=%d\n", bindinfo.dwBindVerb);
1473     ok(bindinfo.szCustomVerb == 0, "bindinfo.szCustomVerb=%p\n", bindinfo.szCustomVerb);
1474     ok(bindinfo.cbstgmedData == 0, "bindinfo.cbstgmedData=%d\n", bindinfo.cbstgmedData);
1475     ok(bindinfo.dwOptions == 0x80000 || bindinfo.dwOptions == 0x4080000,
1476        "bindinfo.dwOptions=%x\n", bindinfo.dwOptions);
1477     ok(bindinfo.dwOptionsFlags == 0, "bindinfo.dwOptionsFlags=%d\n", bindinfo.dwOptionsFlags);
1478     /* TODO: test dwCodePage */
1479     /* TODO: test securityAttributes */
1480     ok(IsEqualGUID(&IID_NULL, &bindinfo.iid), "unexpected bindinfo.iid\n");
1481     ok(bindinfo.pUnk == NULL, "bindinfo.pUnk=%p\n", bindinfo.pUnk);
1482     ok(bindinfo.dwReserved == 0, "bindinfo.dwReserved=%d\n", bindinfo.dwReserved);
1483 
1484     hres = IBindStatusCallback_OnStartBinding(callback, 0, &Binding);
1485     ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
1486 
1487     if(asynchronous_binding) {
1488         PostMessageW(container_hwnd, WM_CONTINUE_BINDING, (WPARAM)callback, 0);
1489         return MK_S_ASYNCHRONOUS;
1490     }
1491 
1492     continue_binding(callback);
1493     return S_OK;
1494 }
1495 
1496 static HRESULT WINAPI Moniker_Reduce(IMoniker *iface, IBindCtx *pbc, DWORD dwReduceHowFar,
1497         IMoniker **ppmkToLeft, IMoniker **ppmkReduced)
1498 {
1499     ok(0, "unexpected call\n");
1500     return E_NOTIMPL;
1501 }
1502 
1503 static HRESULT WINAPI Moniker_ComposeWith(IMoniker *iface, IMoniker *pmkRight,
1504         BOOL fOnlyIfNotGeneric, IMoniker **ppnkComposite)
1505 {
1506     ok(0, "unexpected call\n");
1507     return E_NOTIMPL;
1508 }
1509 
1510 static HRESULT WINAPI Moniker_Enum(IMoniker *iface, BOOL fForwrd, IEnumMoniker **ppenumMoniker)
1511 {
1512     ok(0, "unexpected call\n");
1513     return E_NOTIMPL;
1514 }
1515 
1516 static HRESULT WINAPI Moniker_IsEqual(IMoniker *iface, IMoniker *pmkOtherMoniker)
1517 {
1518     ok(0, "unexpected call\n");
1519     return E_NOTIMPL;
1520 }
1521 
1522 static HRESULT WINAPI Moniker_Hash(IMoniker *iface, DWORD *pdwHash)
1523 {
1524     ok(0, "unexpected call\n");
1525     return E_NOTIMPL;
1526 }
1527 
1528 static HRESULT WINAPI Moniker_IsRunning(IMoniker *iface, IBindCtx *pbc, IMoniker *pmkToLeft,
1529         IMoniker *pmkNewlyRunning)
1530 {
1531     ok(0, "unexpected call\n");
1532     return E_NOTIMPL;
1533 }
1534 
1535 static HRESULT WINAPI Moniker_GetTimeOfLastChange(IMoniker *iface, IBindCtx *pbc,
1536         IMoniker *pmkToLeft, FILETIME *pFileTime)
1537 {
1538     ok(0, "unexpected call\n");
1539     return E_NOTIMPL;
1540 }
1541 
1542 static HRESULT WINAPI Moniker_Inverse(IMoniker *iface, IMoniker **ppmk)
1543 {
1544     ok(0, "unexpected call\n");
1545     return E_NOTIMPL;
1546 }
1547 
1548 static HRESULT WINAPI Moniker_CommonPrefixWith(IMoniker *iface, IMoniker *pmkOther,
1549         IMoniker **ppmkPrefix)
1550 {
1551     ok(0, "unexpected call\n");
1552     return E_NOTIMPL;
1553 }
1554 
1555 static HRESULT WINAPI Moniker_RelativePathTo(IMoniker *iface, IMoniker *pmkOther,
1556         IMoniker **pmkRelPath)
1557 {
1558     ok(0, "unexpected call\n");
1559     return E_NOTIMPL;
1560 }
1561 
1562 static HRESULT WINAPI Moniker_GetDisplayName(IMoniker *iface, IBindCtx *pbc,
1563         IMoniker *pmkToLeft, LPOLESTR *ppszDisplayName)
1564 {
1565     CHECK_EXPECT2(GetDisplayName);
1566 
1567     /* ok(pbc != NULL, "pbc == NULL\n"); */
1568     ok(pmkToLeft == NULL, "pmkToLeft=%p\n", pmkToLeft);
1569     ok(ppszDisplayName != NULL, "ppszDisplayName == NULL\n");
1570 
1571     *ppszDisplayName = CoTaskMemAlloc(sizeof(doc_url));
1572     memcpy(*ppszDisplayName, doc_url, sizeof(doc_url));
1573 
1574     return S_OK;
1575 }
1576 
1577 static HRESULT WINAPI Moniker_ParseDisplayName(IMoniker *iface, IBindCtx *pbc,
1578         IMoniker *pmkToLeft, LPOLESTR pszDisplayName, ULONG *pchEaten, IMoniker **ppmkOut)
1579 {
1580     ok(0, "unexpected call\n");
1581     return E_NOTIMPL;
1582 }
1583 
1584 static HRESULT WINAPI Moniker_IsSystemMoniker(IMoniker *iface, DWORD *pdwMksys)
1585 {
1586     CHECK_EXPECT(IsSystemMoniker);
1587     return E_NOTIMPL;
1588 }
1589 
1590 static const IMonikerVtbl MonikerVtbl = {
1591     Moniker_QueryInterface,
1592     Moniker_AddRef,
1593     Moniker_Release,
1594     Moniker_GetClassID,
1595     Moniker_IsDirty,
1596     Moniker_Load,
1597     Moniker_Save,
1598     Moniker_GetSizeMax,
1599     Moniker_BindToObject,
1600     Moniker_BindToStorage,
1601     Moniker_Reduce,
1602     Moniker_ComposeWith,
1603     Moniker_Enum,
1604     Moniker_IsEqual,
1605     Moniker_Hash,
1606     Moniker_IsRunning,
1607     Moniker_GetTimeOfLastChange,
1608     Moniker_Inverse,
1609     Moniker_CommonPrefixWith,
1610     Moniker_RelativePathTo,
1611     Moniker_GetDisplayName,
1612     Moniker_ParseDisplayName,
1613     Moniker_IsSystemMoniker
1614 };
1615 
1616 static IMoniker Moniker = { &MonikerVtbl };
1617 
1618 static HRESULT WINAPI OleContainer_QueryInterface(IOleContainer *iface, REFIID riid, void **ppv)
1619 {
1620     return QueryInterface(riid, ppv);
1621 }
1622 
1623 static ULONG WINAPI OleContainer_AddRef(IOleContainer *iface)
1624 {
1625     return 2;
1626 }
1627 
1628 static ULONG WINAPI OleContainer_Release(IOleContainer *iface)
1629 {
1630     return 1;
1631 }
1632 
1633 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer *iface, IBindCtx *pbc,
1634         LPOLESTR pszDiaplayName, ULONG *pchEaten, IMoniker **ppmkOut)
1635 {
1636     ok(0, "unexpected call\n");
1637     return E_NOTIMPL;
1638 }
1639 
1640 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer *iface, DWORD grfFlags,
1641         IEnumUnknown **ppenum)
1642 {
1643     ok(0, "unexpected call\n");
1644     return E_NOTIMPL;
1645 }
1646 
1647 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer *iface, BOOL fLock)
1648 {
1649     CHECK_EXPECT(LockContainer);
1650     ok(expect_LockContainer_fLock == fLock, "fLock=%x, expected %x\n", fLock, expect_LockContainer_fLock);
1651     return S_OK;
1652 }
1653 
1654 static const IOleContainerVtbl OleContainerVtbl = {
1655     OleContainer_QueryInterface,
1656     OleContainer_AddRef,
1657     OleContainer_Release,
1658     OleContainer_ParseDisplayName,
1659     OleContainer_EnumObjects,
1660     OleContainer_LockContainer
1661 };
1662 
1663 static IOleContainer OleContainer = { &OleContainerVtbl };
1664 
1665 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
1666 {
1667     return QueryInterface(riid, ppv);
1668 }
1669 
1670 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
1671 {
1672     return 2;
1673 }
1674 
1675 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
1676 {
1677     return 1;
1678 }
1679 
1680 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
1681 {
1682     ok(0, "unexpected call\n");
1683     return E_NOTIMPL;
1684 }
1685 
1686 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker,
1687         IMoniker **ppmon)
1688 {
1689     ok(0, "unexpected call\n");
1690     return E_NOTIMPL;
1691 }
1692 
1693 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
1694 {
1695     CHECK_EXPECT(GetContainer);
1696     ok(ppContainer != NULL, "ppContainer = NULL\n");
1697     *ppContainer = &OleContainer;
1698     return S_OK;
1699 }
1700 
1701 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
1702 {
1703     ok(0, "unexpected call\n");
1704     return E_NOTIMPL;
1705 }
1706 
1707 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
1708 {
1709     ok(0, "unexpected call\n");
1710     return E_NOTIMPL;
1711 }
1712 
1713 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
1714 {
1715     ok(0, "unexpected call\n");
1716     return E_NOTIMPL;
1717 }
1718 
1719 static const IOleClientSiteVtbl ClientSiteVtbl = {
1720     ClientSite_QueryInterface,
1721     ClientSite_AddRef,
1722     ClientSite_Release,
1723     ClientSite_SaveObject,
1724     ClientSite_GetMoniker,
1725     ClientSite_GetContainer,
1726     ClientSite_ShowObject,
1727     ClientSite_OnShowWindow,
1728     ClientSite_RequestNewObjectLayout
1729 };
1730 
1731 static IOleClientSite ClientSite = { &ClientSiteVtbl };
1732 
1733 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
1734 {
1735     static const GUID undocumented_frame_iid = {0xfbece6c9,0x48d7,0x4a37,{0x8f,0xe3,0x6a,0xd4,0x27,0x2f,0xdd,0xac}};
1736 
1737     if(!IsEqualGUID(&undocumented_frame_iid, riid))
1738         ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
1739 
1740     *ppv = NULL;
1741     return E_NOINTERFACE;
1742 }
1743 
1744 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
1745 {
1746     return 2;
1747 }
1748 
1749 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
1750 {
1751     return 1;
1752 }
1753 
1754 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
1755 {
1756     CHECK_EXPECT(Frame_GetWindow);
1757     return E_NOTIMPL;
1758 }
1759 
1760 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
1761 {
1762     ok(0, "unexpected call\n");
1763     return E_NOTIMPL;
1764 }
1765 
1766 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
1767 {
1768     ok(0, "unexpected call\n");
1769     return E_NOTIMPL;
1770 }
1771 
1772 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
1773         LPCBORDERWIDTHS pborderwidths)
1774 {
1775     ok(0, "unexpected call\n");
1776     return E_NOTIMPL;
1777 }
1778 
1779 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
1780         LPCBORDERWIDTHS pborderwidths)
1781 {
1782     CHECK_EXPECT(InPlaceFrame_SetBorderSpace);
1783     return S_OK;
1784 }
1785 
1786 static HRESULT WINAPI InPlaceUIWindow_SetActiveObject(IOleInPlaceFrame *iface,
1787         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1788 {
1789     static const WCHAR wszHTML_Document[] =
1790         {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
1791 
1792     CHECK_EXPECT2(InPlaceUIWindow_SetActiveObject);
1793 
1794     if(expect_InPlaceUIWindow_SetActiveObject_active) {
1795         ok(pActiveObject != NULL, "pActiveObject = NULL\n");
1796         if(pActiveObject && is_lang_english())
1797             ok(!lstrcmpW(wszHTML_Document, pszObjName), "%s != \"HTML Document\"\n", wine_dbgstr_w(pszObjName));
1798     }
1799     else {
1800         ok(pActiveObject == NULL, "pActiveObject=%p, expected NULL\n", pActiveObject);
1801         ok(pszObjName == NULL, "pszObjName=%p, expected NULL\n", pszObjName);
1802     }
1803     expect_InPlaceUIWindow_SetActiveObject_active = !expect_InPlaceUIWindow_SetActiveObject_active;
1804     return S_OK;
1805 }
1806 
1807 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
1808         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
1809 {
1810     static const WCHAR wszHTML_Document[] =
1811         {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
1812 
1813     if(pActiveObject) {
1814         CHECK_EXPECT2(SetActiveObject);
1815 
1816         if(pActiveObject && is_lang_english())
1817             ok(!lstrcmpW(wszHTML_Document, pszObjName), "%s != \"HTML Document\"\n", wine_dbgstr_w(pszObjName));
1818     }else {
1819         CHECK_EXPECT(SetActiveObject_null);
1820 
1821         ok(pActiveObject == NULL, "pActiveObject=%p, expected NULL\n", pActiveObject);
1822         ok(pszObjName == NULL, "pszObjName=%p, expected NULL\n", pszObjName);
1823     }
1824 
1825     return S_OK;
1826 }
1827 
1828 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
1829         LPOLEMENUGROUPWIDTHS lpMenuWidths)
1830 {
1831     ok(0, "unexpected call\n");
1832     return E_NOTIMPL;
1833 }
1834 
1835 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
1836         HOLEMENU holemenu, HWND hwndActiveObject)
1837 {
1838     ok(0, "unexpected call\n");
1839     return E_NOTIMPL;
1840 }
1841 
1842 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
1843 {
1844     ok(0, "unexpected call\n");
1845     return E_NOTIMPL;
1846 }
1847 
1848 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
1849 {
1850     if(!resetting_document)
1851         CHECK_EXPECT2(SetStatusText);
1852     if(!expect_status_text)
1853         ok(pszStatusText == NULL, "pszStatusText=%p, expected NULL\n", pszStatusText);
1854     return S_OK;
1855 }
1856 
1857 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
1858 {
1859     if(fEnable)
1860         CHECK_EXPECT2(Frame_EnableModeless_TRUE);
1861     else
1862         CHECK_EXPECT2(Frame_EnableModeless_FALSE);
1863     return E_NOTIMPL;
1864 }
1865 
1866 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
1867 {
1868     ok(0, "unexpected call\n");
1869     return E_NOTIMPL;
1870 }
1871 
1872 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
1873     InPlaceFrame_QueryInterface,
1874     InPlaceFrame_AddRef,
1875     InPlaceFrame_Release,
1876     InPlaceFrame_GetWindow,
1877     InPlaceFrame_ContextSensitiveHelp,
1878     InPlaceFrame_GetBorder,
1879     InPlaceFrame_RequestBorderSpace,
1880     InPlaceFrame_SetBorderSpace,
1881     InPlaceFrame_SetActiveObject,
1882     InPlaceFrame_InsertMenus,
1883     InPlaceFrame_SetMenu,
1884     InPlaceFrame_RemoveMenus,
1885     InPlaceFrame_SetStatusText,
1886     InPlaceFrame_EnableModeless,
1887     InPlaceFrame_TranslateAccelerator
1888 };
1889 
1890 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
1891 
1892 static const IOleInPlaceFrameVtbl InPlaceUIWindowVtbl = {
1893     InPlaceFrame_QueryInterface,
1894     InPlaceFrame_AddRef,
1895     InPlaceFrame_Release,
1896     InPlaceFrame_GetWindow,
1897     InPlaceFrame_ContextSensitiveHelp,
1898     InPlaceFrame_GetBorder,
1899     InPlaceFrame_RequestBorderSpace,
1900     InPlaceFrame_SetBorderSpace,
1901     InPlaceUIWindow_SetActiveObject,
1902 };
1903 
1904 static IOleInPlaceFrame InPlaceUIWindow = { &InPlaceUIWindowVtbl };
1905 
1906 static HRESULT WINAPI InPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless *iface, REFIID riid, void **ppv)
1907 {
1908     return QueryInterface(riid, ppv);
1909 }
1910 
1911 static ULONG WINAPI InPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless *iface)
1912 {
1913     return 2;
1914 }
1915 
1916 static ULONG WINAPI InPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless *iface)
1917 {
1918     return 1;
1919 }
1920 
1921 static HRESULT WINAPI InPlaceSiteWindowless_GetWindow(
1922         IOleInPlaceSiteWindowless *iface, HWND *phwnd)
1923 {
1924     IOleClientSite *client_site;
1925     IOleObject *ole_obj;
1926     HRESULT hres;
1927 
1928     CHECK_EXPECT2(GetWindow);
1929     ok(phwnd != NULL, "phwnd = NULL\n");
1930     *phwnd = container_hwnd;
1931 
1932     hres = IUnknown_QueryInterface(doc_unk, &IID_IOleObject, (void**)&ole_obj);
1933     ok(hres == S_OK, "Could not get IOleObject: %08x\n", hres);
1934 
1935     hres = IOleObject_GetClientSite(ole_obj, &client_site);
1936     IOleObject_Release(ole_obj);
1937     ok(hres == S_OK, "GetClientSite failed: %08x\n", hres);
1938     ok(client_site == &ClientSite, "client_site != ClientSite\n");
1939     IOleClientSite_Release(client_site);
1940 
1941     return S_OK;
1942 }
1943 
1944 static HRESULT WINAPI InPlaceSiteWindowless_ContextSensitiveHelp(
1945         IOleInPlaceSiteWindowless *iface, BOOL fEnterMode)
1946 {
1947     ok(0, "unexpected call\n");
1948     return E_NOTIMPL;
1949 }
1950 
1951 static HRESULT WINAPI InPlaceSiteWindowless_CanInPlaceActivate(
1952         IOleInPlaceSiteWindowless *iface)
1953 {
1954     CHECK_EXPECT(CanInPlaceActivate);
1955     return S_OK;
1956 }
1957 
1958 static HRESULT WINAPI InPlaceSiteWindowless_OnInPlaceActivate(
1959         IOleInPlaceSiteWindowless *iface)
1960 {
1961     CHECK_EXPECT(OnInPlaceActivate);
1962     inplace_deactivated = FALSE;
1963     return S_OK;
1964 }
1965 
1966 static HRESULT WINAPI InPlaceSiteWindowless_OnUIActivate(
1967         IOleInPlaceSiteWindowless *iface)
1968 {
1969     CHECK_EXPECT(OnUIActivate);
1970     return S_OK;
1971 }
1972 
1973 static HRESULT WINAPI InPlaceSiteWindowless_GetWindowContext(
1974         IOleInPlaceSiteWindowless *iface, IOleInPlaceFrame **ppFrame,
1975         IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
1976         LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
1977 {
1978     static const RECT rect = {0,0,500,500};
1979 
1980     CHECK_EXPECT(GetWindowContext);
1981 
1982     ok(ppFrame != NULL, "ppFrame = NULL\n");
1983     if(ppFrame)
1984         *ppFrame = &InPlaceFrame;
1985     ok(ppDoc != NULL, "ppDoc = NULL\n");
1986     if(ppDoc)
1987         *ppDoc = (IOleInPlaceUIWindow*)&InPlaceUIWindow;
1988     ok(lprcPosRect != NULL, "lprcPosRect = NULL\n");
1989     if(lprcPosRect)
1990         memcpy(lprcPosRect, &rect, sizeof(RECT));
1991     ok(lprcClipRect != NULL, "lprcClipRect = NULL\n");
1992     if(lprcClipRect)
1993         memcpy(lprcClipRect, &rect, sizeof(RECT));
1994     ok(lpFrameInfo != NULL, "lpFrameInfo = NULL\n");
1995     if(lpFrameInfo) {
1996         ok(lpFrameInfo->cb == sizeof(*lpFrameInfo), "lpFrameInfo->cb = %u, expected %u\n", lpFrameInfo->cb, (unsigned)sizeof(*lpFrameInfo));
1997         lpFrameInfo->fMDIApp = FALSE;
1998         lpFrameInfo->hwndFrame = container_hwnd;
1999         lpFrameInfo->haccel = NULL;
2000         lpFrameInfo->cAccelEntries = 0;
2001     }
2002 
2003     return S_OK;
2004 }
2005 
2006 static HRESULT WINAPI InPlaceSiteWindowless_Scroll(
2007         IOleInPlaceSiteWindowless *iface, SIZE scrollExtent)
2008 {
2009     ok(0, "unexpected call\n");
2010     return E_NOTIMPL;
2011 }
2012 
2013 static HRESULT WINAPI InPlaceSiteWindowless_OnUIDeactivate(
2014         IOleInPlaceSiteWindowless *iface, BOOL fUndoable)
2015 {
2016     CHECK_EXPECT(OnUIDeactivate);
2017     ok(!fUndoable, "fUndoable = TRUE\n");
2018     return S_OK;
2019 }
2020 
2021 static HRESULT WINAPI InPlaceSiteWindowless_OnInPlaceDeactivate(
2022         IOleInPlaceSiteWindowless *iface)
2023 {
2024     CHECK_EXPECT(OnInPlaceDeactivate);
2025     inplace_deactivated = TRUE;
2026     return S_OK;
2027 }
2028 
2029 static HRESULT WINAPI InPlaceSiteWindowless_DiscardUndoState(
2030         IOleInPlaceSiteWindowless *iface)
2031 {
2032     ok(0, "unexpected call\n");
2033     return E_NOTIMPL;
2034 }
2035 
2036 static HRESULT WINAPI InPlaceSiteWindowless_DeactivateAndUndo(
2037         IOleInPlaceSiteWindowless *iface)
2038 {
2039     ok(0, "unexpected call\n");
2040     return E_NOTIMPL;
2041 }
2042 
2043 static HRESULT WINAPI InPlaceSiteWindowless_OnPosRectChange(
2044         IOleInPlaceSiteWindowless *iface, LPCRECT lprcPosRect)
2045 {
2046     ok(0, "unexpected call\n");
2047     return E_NOTIMPL;
2048 }
2049 
2050 static HRESULT WINAPI InPlaceSiteWindowless_OnInPlaceActivateEx(
2051         IOleInPlaceSiteWindowless *iface, BOOL *pfNoRedraw, DWORD dwFlags)
2052 {
2053     CHECK_EXPECT(OnInPlaceActivateEx);
2054 
2055     ok(pfNoRedraw != NULL, "pfNoRedraw == NULL\n");
2056     ok(!*pfNoRedraw, "*pfNoRedraw == TRUE\n");
2057     ok(dwFlags == 0, "dwFlags = %08x\n", dwFlags);
2058 
2059     return S_OK;
2060 }
2061 
2062 static HRESULT WINAPI InPlaceSiteWindowless_OnInPlaceDeactivateEx(
2063         IOleInPlaceSiteWindowless *iface, BOOL fNoRedraw)
2064 {
2065     CHECK_EXPECT(OnInPlaceDeactivateEx);
2066 
2067     ok(fNoRedraw, "fNoRedraw == FALSE\n");
2068 
2069     return S_OK;
2070 }
2071 
2072 static HRESULT WINAPI InPlaceSiteWindowless_RequestUIActivate(
2073         IOleInPlaceSiteWindowless *iface)
2074 {
2075     CHECK_EXPECT2(RequestUIActivate);
2076     return S_OK;
2077 }
2078 
2079 static HRESULT WINAPI InPlaceSiteWindowless_CanWindowlessActivate(
2080         IOleInPlaceSiteWindowless *iface)
2081 {
2082     ok(0, "unexpected call\n");
2083     return E_NOTIMPL;
2084 }
2085 
2086 static HRESULT WINAPI InPlaceSiteWindowless_GetCapture(
2087         IOleInPlaceSiteWindowless *iface)
2088 {
2089     ok(0, "unexpected call\n");
2090     return E_NOTIMPL;
2091 }
2092 
2093 static HRESULT WINAPI InPlaceSiteWindowless_SetCapture(
2094         IOleInPlaceSiteWindowless *iface, BOOL fCapture)
2095 {
2096     ok(0, "unexpected call\n");
2097     return E_NOTIMPL;
2098 }
2099 
2100 static HRESULT WINAPI InPlaceSiteWindowless_GetFocus(
2101         IOleInPlaceSiteWindowless *iface)
2102 {
2103     ok(0, "unexpected call\n");
2104     return E_NOTIMPL;
2105 }
2106 
2107 static HRESULT WINAPI InPlaceSiteWindowless_SetFocus(
2108         IOleInPlaceSiteWindowless *iface, BOOL fFocus)
2109 {
2110     ok(0, "unexpected call\n");
2111     return E_NOTIMPL;
2112 }
2113 
2114 static HRESULT WINAPI InPlaceSiteWindowless_GetDC(
2115         IOleInPlaceSiteWindowless *iface, LPCRECT pRect,
2116         DWORD grfFlags, HDC *phDC)
2117 {
2118     ok(0, "unexpected call\n");
2119     return E_NOTIMPL;
2120 }
2121 
2122 static HRESULT WINAPI InPlaceSiteWindowless_ReleaseDC(
2123         IOleInPlaceSiteWindowless *iface, HDC hDC)
2124 {
2125     ok(0, "unexpected call\n");
2126     return E_NOTIMPL;
2127 }
2128 
2129 static HRESULT WINAPI InPlaceSiteWindowless_InvalidateRect(
2130         IOleInPlaceSiteWindowless *iface, LPCRECT pRect, BOOL fErase)
2131 {
2132     ok(0, "unexpected call\n");
2133     return E_NOTIMPL;
2134 }
2135 
2136 static HRESULT WINAPI InPlaceSiteWindowless_InvalidateRgn(
2137         IOleInPlaceSiteWindowless *iface, HRGN hRGN, BOOL fErase)
2138 {
2139     ok(0, "unexpected call\n");
2140     return E_NOTIMPL;
2141 }
2142 
2143 static HRESULT WINAPI InPlaceSiteWindowless_ScrollRect(
2144         IOleInPlaceSiteWindowless *iface, INT dx, INT dy,
2145         LPCRECT pRectScroll, LPCRECT pRectClip)
2146 {
2147     ok(0, "unexpected call\n");
2148     return E_NOTIMPL;
2149 }
2150 
2151 static HRESULT WINAPI InPlaceSiteWindowless_AdjustRect(
2152         IOleInPlaceSiteWindowless *iface, LPRECT prc)
2153 {
2154     ok(0, "unexpected call\n");
2155     return E_NOTIMPL;
2156 }
2157 
2158 static HRESULT WINAPI InPlaceSiteWindowless_OnDefWindowMessage(
2159         IOleInPlaceSiteWindowless *iface, UINT msg,
2160         WPARAM wParam, LPARAM lParam, LRESULT *plResult)
2161 {
2162     ok(0, "unexpected call\n");
2163     return E_NOTIMPL;
2164 }
2165 
2166 static const IOleInPlaceSiteWindowlessVtbl InPlaceSiteWindowlessVtbl = {
2167     InPlaceSiteWindowless_QueryInterface,
2168     InPlaceSiteWindowless_AddRef,
2169     InPlaceSiteWindowless_Release,
2170     InPlaceSiteWindowless_GetWindow,
2171     InPlaceSiteWindowless_ContextSensitiveHelp,
2172     InPlaceSiteWindowless_CanInPlaceActivate,
2173     InPlaceSiteWindowless_OnInPlaceActivate,
2174     InPlaceSiteWindowless_OnUIActivate,
2175     InPlaceSiteWindowless_GetWindowContext,
2176     InPlaceSiteWindowless_Scroll,
2177     InPlaceSiteWindowless_OnUIDeactivate,
2178     InPlaceSiteWindowless_OnInPlaceDeactivate,
2179     InPlaceSiteWindowless_DiscardUndoState,
2180     InPlaceSiteWindowless_DeactivateAndUndo,
2181     InPlaceSiteWindowless_OnPosRectChange,
2182     InPlaceSiteWindowless_OnInPlaceActivateEx,
2183     InPlaceSiteWindowless_OnInPlaceDeactivateEx,
2184     InPlaceSiteWindowless_RequestUIActivate,
2185     InPlaceSiteWindowless_CanWindowlessActivate,
2186     InPlaceSiteWindowless_GetCapture,
2187     InPlaceSiteWindowless_SetCapture,
2188     InPlaceSiteWindowless_GetFocus,
2189     InPlaceSiteWindowless_SetFocus,
2190     InPlaceSiteWindowless_GetDC,
2191     InPlaceSiteWindowless_ReleaseDC,
2192     InPlaceSiteWindowless_InvalidateRect,
2193     InPlaceSiteWindowless_InvalidateRgn,
2194     InPlaceSiteWindowless_ScrollRect,
2195     InPlaceSiteWindowless_AdjustRect,
2196     InPlaceSiteWindowless_OnDefWindowMessage
2197 };
2198 
2199 static IOleInPlaceSiteWindowless InPlaceSiteWindowless = { &InPlaceSiteWindowlessVtbl };
2200 
2201 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
2202 {
2203     return QueryInterface(riid, ppv);
2204 }
2205 
2206 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
2207 {
2208     return 2;
2209 }
2210 
2211 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
2212 {
2213     return 1;
2214 }
2215 
2216 typedef enum
2217 {
2218     CallUIActivate_None,
2219     CallUIActivate_ActivateMe,
2220     CallUIActivate_AfterShow,
2221 } CallUIActivate;
2222 
2223 static BOOL call_UIActivate = CallUIActivate_ActivateMe;
2224 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
2225 {
2226     IOleDocument *document;
2227     HRESULT hres;
2228 
2229     CHECK_EXPECT(ActivateMe);
2230     ok(pViewToActivate != NULL, "pViewToActivate = NULL\n");
2231 
2232     hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
2233     ok(hres == S_OK, "could not get IOleDocument: %08x\n", hres);
2234 
2235     if(SUCCEEDED(hres)) {
2236         hres = IOleDocument_CreateView(document, (IOleInPlaceSite*)&InPlaceSiteWindowless, NULL, 0, &view);
2237         ok(hres == S_OK, "CreateView failed: %08x\n", hres);
2238 
2239         if(SUCCEEDED(hres)) {
2240             IOleInPlaceActiveObject *activeobj = NULL;
2241             IOleInPlaceSite *inplacesite = NULL;
2242             HWND tmp_hwnd = NULL;
2243             static RECT rect = {0,0,400,500};
2244 
2245             hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
2246             ok(hres == S_OK, "GetInPlaceSite failed: %08x\n", hres);
2247             ok(inplacesite == (IOleInPlaceSite*)&InPlaceSiteWindowless, "inplacesite=%p, expected %p\n",
2248                     inplacesite, &InPlaceSiteWindowless);
2249 
2250             hres = IOleDocumentView_SetInPlaceSite(view, (IOleInPlaceSite*)&InPlaceSiteWindowless);
2251             ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
2252 
2253             hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
2254             ok(hres == S_OK, "GetInPlaceSite failed: %08x\n", hres);
2255             ok(inplacesite == (IOleInPlaceSite*)&InPlaceSiteWindowless, "inplacesite=%p, expected %p\n",
2256                     inplacesite, &InPlaceSiteWindowless);
2257 
2258             hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobj);
2259             ok(hres == S_OK, "Could not get IOleInPlaceActiveObject: %08x\n", hres);
2260 
2261             if(activeobj) {
2262                 HWND hwnd = (void*)0xdeadbeef;
2263                 hres = IOleInPlaceActiveObject_GetWindow(activeobj, &hwnd);
2264                 ok(hres == E_FAIL, "GetWindow returned %08x, expected E_FAIL\n", hres);
2265                 ok(hwnd == NULL, "hwnd=%p, expected NULL\n", hwnd);
2266             }
2267 
2268             if(call_UIActivate == CallUIActivate_ActivateMe) {
2269                 SET_EXPECT(CanInPlaceActivate);
2270                 SET_EXPECT(GetWindowContext);
2271                 SET_EXPECT(GetWindow);
2272                 if(ipsex)
2273                     SET_EXPECT(OnInPlaceActivateEx);
2274                 else
2275                     SET_EXPECT(OnInPlaceActivate);
2276                 SET_EXPECT(SetStatusText);
2277                 SET_EXPECT(Exec_SETPROGRESSMAX);
2278                 SET_EXPECT(Exec_SETPROGRESSPOS);
2279                 SET_EXPECT(OnUIActivate);
2280                 SET_EXPECT(SetActiveObject);
2281                 SET_EXPECT(ShowUI);
2282                 expect_status_text = NULL;
2283 
2284                 hres = IOleDocumentView_UIActivate(view, TRUE);
2285                 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
2286 
2287                 CHECK_CALLED(CanInPlaceActivate);
2288                 CHECK_CALLED(GetWindowContext);
2289                 CHECK_CALLED(GetWindow);
2290                 if(ipsex)
2291                     CHECK_CALLED(OnInPlaceActivateEx);
2292                 else
2293                     CHECK_CALLED(OnInPlaceActivate);
2294                 CHECK_CALLED(SetStatusText);
2295                 CHECK_CALLED(Exec_SETPROGRESSMAX);
2296                 CHECK_CALLED(Exec_SETPROGRESSPOS);
2297                 CHECK_CALLED(OnUIActivate);
2298                 CHECK_CALLED(SetActiveObject);
2299                 CHECK_CALLED(ShowUI);
2300 
2301                 if(activeobj) {
2302                     hres = IOleInPlaceActiveObject_GetWindow(activeobj, &doc_hwnd);
2303                     ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
2304                     ok(doc_hwnd != NULL, "hwnd == NULL\n");
2305                     if(last_hwnd)
2306                         ok(doc_hwnd == last_hwnd, "hwnd != last_hwnd\n");
2307                 }
2308 
2309                 hres = IOleDocumentView_UIActivate(view, TRUE);
2310                 ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
2311 
2312                 if(activeobj) {
2313                     hres = IOleInPlaceActiveObject_GetWindow(activeobj, &tmp_hwnd);
2314                     ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
2315                     ok(tmp_hwnd == doc_hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, doc_hwnd);
2316                 }
2317             }
2318 
2319             hres = IOleDocumentView_SetRect(view, &rect);
2320             ok(hres == S_OK, "SetRect failed: %08x\n", hres);
2321 
2322             if(call_UIActivate == CallUIActivate_ActivateMe) {
2323                 hres = IOleDocumentView_Show(view, TRUE);
2324                 ok(hres == S_OK, "Show failed: %08x\n", hres);
2325             }else {
2326                 SET_EXPECT(CanInPlaceActivate);
2327                 SET_EXPECT(GetWindowContext);
2328                 SET_EXPECT(GetWindow);
2329                 if(ipsex)
2330                     SET_EXPECT(OnInPlaceActivateEx);
2331                 else
2332                     SET_EXPECT(OnInPlaceActivate);
2333                 SET_EXPECT(SetStatusText);
2334                 SET_EXPECT(Exec_SETPROGRESSMAX);
2335                 SET_EXPECT(Exec_SETPROGRESSPOS);
2336                 SET_EXPECT(OnUIActivate);
2337                 expect_status_text = (load_state == LD_COMPLETE ? (LPCOLESTR)0xdeadbeef : NULL);
2338 
2339                 hres = IOleDocumentView_Show(view, TRUE);
2340                 ok(hres == S_OK, "Show failed: %08x\n", hres);
2341 
2342                 CHECK_CALLED(CanInPlaceActivate);
2343                 CHECK_CALLED(GetWindowContext);
2344                 CHECK_CALLED(GetWindow);
2345                 if(ipsex)
2346                     CHECK_CALLED(OnInPlaceActivateEx);
2347                 else
2348                     CHECK_CALLED(OnInPlaceActivate);
2349                 CHECK_CALLED(SetStatusText);
2350                 CHECK_CALLED(Exec_SETPROGRESSMAX);
2351                 CHECK_CALLED(Exec_SETPROGRESSPOS);
2352 
2353                 if(activeobj) {
2354                     hres = IOleInPlaceActiveObject_GetWindow(activeobj, &doc_hwnd);
2355                     ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
2356                     ok(doc_hwnd != NULL, "doc_hwnd == NULL\n");
2357                     if(last_hwnd)
2358                         ok(doc_hwnd == last_hwnd, "doc_hwnd != last_hwnd\n");
2359                 }
2360             }
2361 
2362             test_timer(EXPECT_UPDATEUI | ((load_state == LD_LOADING) ? EXPECT_SETTITLE : 0));
2363 
2364             if(activeobj)
2365                 IOleInPlaceActiveObject_Release(activeobj);
2366         }
2367 
2368         IOleDocument_Release(document);
2369     }
2370 
2371     return S_OK;
2372 }
2373 
2374 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
2375     DocumentSite_QueryInterface,
2376     DocumentSite_AddRef,
2377     DocumentSite_Release,
2378     DocumentSite_ActivateMe
2379 };
2380 
2381 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
2382 
2383 static HRESULT WINAPI OleControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
2384 {
2385     return QueryInterface(riid, ppv);
2386 }
2387 
2388 static ULONG WINAPI OleControlSite_AddRef(IOleControlSite *iface)
2389 {
2390     return 2;
2391 }
2392 
2393 static ULONG WINAPI OleControlSite_Release(IOleControlSite *iface)
2394 {
2395     return 1;
2396 }
2397 
2398 static HRESULT WINAPI OleControlSite_OnControlInfoChanged(IOleControlSite *iface)
2399 {
2400     ok(0, "unexpected call\n");
2401     return E_NOTIMPL;
2402 }
2403 
2404 static HRESULT WINAPI OleControlSite_LockInPlaceActive(IOleControlSite *iface, BOOL fLock)
2405 {
2406     ok(0, "unexpected call\n");
2407     return E_NOTIMPL;
2408 }
2409 
2410 static HRESULT WINAPI OleControlSite_GetExtendedControl(IOleControlSite *iface, IDispatch **ppDisp)
2411 {
2412     ok(0, "unexpected call\n");
2413     return E_NOTIMPL;
2414 }
2415 
2416 static HRESULT WINAPI OleControlSite_TransformCoords(IOleControlSite *iface, POINTL *pPtHimetric,
2417         POINTF *pPtfContainer, DWORD dwFlags)
2418 {
2419     ok(0, "unexpected call\n");
2420     return E_NOTIMPL;
2421 }
2422 
2423 static HRESULT WINAPI OleControlSite_TranslateAccelerator(IOleControlSite *iface,
2424         MSG *pMsg, DWORD grfModifiers)
2425 {
2426     ok(0, "unexpected call\n");
2427     return E_NOTIMPL;
2428 }
2429 
2430 static HRESULT WINAPI OleControlSite_OnFocus(IOleControlSite *iface, BOOL fGotFocus)
2431 {
2432     if(fGotFocus)
2433         CHECK_EXPECT(OnFocus_TRUE);
2434     else
2435         CHECK_EXPECT2(OnFocus_FALSE);
2436     return S_OK;
2437 }
2438 
2439 static HRESULT WINAPI OleControlSite_ShowPropertyFrame(IOleControlSite *iface)
2440 {
2441     ok(0, "unexpected call\n");
2442     return E_NOTIMPL;
2443 }
2444 
2445 static const IOleControlSiteVtbl OleControlSiteVtbl = {
2446     OleControlSite_QueryInterface,
2447     OleControlSite_AddRef,
2448     OleControlSite_Release,
2449     OleControlSite_OnControlInfoChanged,
2450     OleControlSite_LockInPlaceActive,
2451     OleControlSite_GetExtendedControl,
2452     OleControlSite_TransformCoords,
2453     OleControlSite_TranslateAccelerator,
2454     OleControlSite_OnFocus,
2455     OleControlSite_ShowPropertyFrame
2456 };
2457 
2458 static IOleControlSite OleControlSite = { &OleControlSiteVtbl };
2459 
2460 static IDocHostUIHandler2 *expect_uihandler_iface;
2461 
2462 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
2463 {
2464     return QueryInterface(riid, ppv);
2465 }
2466 
2467 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
2468 {
2469     return 2;
2470 }
2471 
2472 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
2473 {
2474     return 1;
2475 }
2476 
2477 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
2478         IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
2479 {
2480     ok(0, "unexpected call\n");
2481     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2482     return E_NOTIMPL;
2483 }
2484 
2485 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
2486 {
2487     if(!resetting_document)
2488         CHECK_EXPECT(GetHostInfo);
2489     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2490     ok(pInfo != NULL, "pInfo=NULL\n");
2491     if(pInfo) {
2492         ok(pInfo->cbSize == sizeof(DOCHOSTUIINFO), "pInfo->cbSize=%u\n", pInfo->cbSize);
2493         ok(!pInfo->dwFlags, "pInfo->dwFlags=%08x, expected 0\n", pInfo->dwFlags);
2494         pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE
2495             | DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
2496             | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
2497         ok(!pInfo->dwDoubleClick, "pInfo->dwDoubleClick=%08x, expected 0\n", pInfo->dwDoubleClick);
2498         ok(!pInfo->pchHostCss, "pInfo->pchHostCss=%p, expected NULL\n", pInfo->pchHostCss);
2499         ok(!pInfo->pchHostNS, "pInfo->pchhostNS=%p, expected NULL\n", pInfo->pchHostNS);
2500     }
2501     return S_OK;
2502 }
2503 
2504 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
2505         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
2506         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
2507 {
2508     CHECK_EXPECT(ShowUI);
2509     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2510 
2511     if (editmode)
2512         ok(dwID == DOCHOSTUITYPE_AUTHOR, "dwID=%d, expected DOCHOSTUITYPE_AUTHOR\n", dwID);
2513     else
2514         ok(dwID == DOCHOSTUITYPE_BROWSE, "dwID=%d, expected DOCHOSTUITYPE_BROWSE\n", dwID);
2515     ok(pActiveObject != NULL, "pActiveObject = NULL\n");
2516     ok(pCommandTarget != NULL, "pCommandTarget = NULL\n");
2517     ok(pFrame == &InPlaceFrame, "pFrame=%p, expected %p\n", pFrame, &InPlaceFrame);
2518     if (expect_InPlaceUIWindow_SetActiveObject_active)
2519         ok(pDoc == (IOleInPlaceUIWindow *)&InPlaceUIWindow, "pDoc=%p, expected %p\n", pDoc, &InPlaceUIWindow);
2520     else
2521         ok(pDoc == NULL, "pDoc=%p, expected NULL\n", pDoc);
2522 
2523     return S_OK;
2524 }
2525 
2526 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
2527 {
2528     CHECK_EXPECT(HideUI);
2529     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2530     return S_OK;
2531 }
2532 
2533 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
2534 {
2535     CHECK_EXPECT(UpdateUI);
2536     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2537     return S_OK;
2538 }
2539 
2540 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
2541 {
2542     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2543     if(fEnable)
2544         CHECK_EXPECT2(EnableModeless_TRUE);
2545     else
2546         CHECK_EXPECT2(EnableModeless_FALSE);
2547     return E_NOTIMPL;
2548 }
2549 
2550 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
2551 {
2552     ok(0, "unexpected call\n");
2553     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2554     return E_NOTIMPL;
2555 }
2556 
2557 static BOOL expect_OnFrameWindowActivate_fActivate;
2558 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
2559 {
2560     CHECK_EXPECT2(OnFrameWindowActivate);
2561     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2562     ok(fActivate == expect_OnFrameWindowActivate_fActivate, "fActivate=%x\n", fActivate);
2563     return S_OK;
2564 }
2565 
2566 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
2567         IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
2568 {
2569     ok(0, "unexpected call\n");
2570     return E_NOTIMPL;
2571 }
2572 
2573 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
2574         const GUID *pguidCmdGroup, DWORD nCmdID)
2575 {
2576     ok(0, "unexpected call\n");
2577     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2578     return E_NOTIMPL;
2579 }
2580 
2581 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
2582         LPOLESTR *pchKey, DWORD dw)
2583 {
2584     CHECK_EXPECT(GetOptionKeyPath);
2585     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2586     ok(pchKey != NULL, "pchKey = NULL\n");
2587     ok(!dw, "dw=%d, expected 0\n", dw);
2588     if(pchKey)
2589         ok(!*pchKey, "*pchKey=%p, expected NULL\n", *pchKey);
2590     return S_OK;
2591 }
2592 
2593 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
2594         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
2595 {
2596     CHECK_EXPECT(GetDropTarget);
2597     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2598     /* TODO */
2599     return E_NOTIMPL;
2600 }
2601 
2602 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
2603 {
2604     CHECK_EXPECT(GetExternal);
2605     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2606     *ppDispatch = &External;
2607     return S_FALSE;
2608 }
2609 
2610 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
2611         OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
2612 {
2613     CHECK_EXPECT(TranslateUrl);
2614     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2615     ok(!dwTranslate, "dwTranslate = %x\n", dwTranslate);
2616     if(!loading_hash)
2617         ok(!strcmp_wa(pchURLIn, nav_serv_url), "pchURLIn = %s, expected %s\n", wine_dbgstr_w(pchURLIn), nav_serv_url);
2618     else
2619         todo_wine ok(!strcmp_wa(pchURLIn, nav_serv_url), "pchURLIn = %s, expected %s\n", wine_dbgstr_w(pchURLIn), nav_serv_url);
2620     ok(ppchURLOut != NULL, "ppchURLOut == NULL\n");
2621     ok(!*ppchURLOut, "*ppchURLOut = %p\n", *ppchURLOut);
2622 
2623     /* Not related to hash navigation, just return NULL and S_OK in some cases. */
2624     if(loading_hash) {
2625         *ppchURLOut = NULL;
2626         return S_OK;
2627     }
2628 
2629     return S_FALSE;
2630 }
2631 
2632 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
2633         IDataObject **ppPORet)
2634 {
2635     ok(0, "unexpected call\n");
2636     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2637     return E_NOTIMPL;
2638 }
2639 
2640 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
2641         LPOLESTR *pchKey, DWORD dw)
2642 {
2643     CHECK_EXPECT(GetOverrideKeyPath);
2644     ok(iface == expect_uihandler_iface, "called on unexpected iface\n");
2645     ok(pchKey != NULL, "pchKey = NULL\n");
2646     if(pchKey)
2647         ok(!*pchKey, "*pchKey=%p, expected NULL\n", *pchKey);
2648     ok(!dw, "dw=%d, expected 0\n", dw);
2649     return S_OK;
2650 }
2651 
2652 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
2653     DocHostUIHandler_QueryInterface,
2654     DocHostUIHandler_AddRef,
2655     DocHostUIHandler_Release,
2656     DocHostUIHandler_ShowContextMenu,
2657     DocHostUIHandler_GetHostInfo,
2658     DocHostUIHandler_ShowUI,
2659     DocHostUIHandler_HideUI,
2660     DocHostUIHandler_UpdateUI,
2661     DocHostUIHandler_EnableModeless,
2662     DocHostUIHandler_OnDocWindowActivate,
2663     DocHostUIHandler_OnFrameWindowActivate,
2664     DocHostUIHandler_ResizeBorder,
2665     DocHostUIHandler_TranslateAccelerator,
2666     DocHostUIHandler_GetOptionKeyPath,
2667     DocHostUIHandler_GetDropTarget,
2668     DocHostUIHandler_GetExternal,
2669     DocHostUIHandler_TranslateUrl,
2670     DocHostUIHandler_FilterDataObject,
2671     DocHostUIHandler_GetOverrideKeyPath
2672 };
2673 
2674 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
2675 
2676 static HRESULT WINAPI CustomDocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
2677 {
2678     if(IsEqualGUID(&IID_IDocHostUIHandler2, riid)) {
2679         *ppv = iface;
2680         return S_OK;
2681     }
2682 
2683     *ppv = NULL;
2684 
2685     if(IsEqualGUID(&IID_IOleCommandTarget, riid))
2686         return E_NOINTERFACE;
2687 
2688     if(IsEqualGUID(&IID_IDocHostShowUI, riid))
2689         return E_NOINTERFACE; /* TODO */
2690 
2691     trace("CustomDocHostUIHandler::QI(%s)\n", wine_dbgstr_guid(riid));
2692     return E_NOINTERFACE;
2693 }
2694 
2695 static const IDocHostUIHandler2Vtbl CustomDocHostUIHandlerVtbl = {
2696     CustomDocHostUIHandler_QueryInterface,
2697     DocHostUIHandler_AddRef,
2698     DocHostUIHandler_Release,
2699     DocHostUIHandler_ShowContextMenu,
2700     DocHostUIHandler_GetHostInfo,
2701     DocHostUIHandler_ShowUI,
2702     DocHostUIHandler_HideUI,
2703     DocHostUIHandler_UpdateUI,
2704     DocHostUIHandler_EnableModeless,
2705     DocHostUIHandler_OnDocWindowActivate,
2706     DocHostUIHandler_OnFrameWindowActivate,
2707     DocHostUIHandler_ResizeBorder,
2708     DocHostUIHandler_TranslateAccelerator,
2709     DocHostUIHandler_GetOptionKeyPath,
2710     DocHostUIHandler_GetDropTarget,
2711     DocHostUIHandler_GetExternal,
2712     DocHostUIHandler_TranslateUrl,
2713     DocHostUIHandler_FilterDataObject,
2714     DocHostUIHandler_GetOverrideKeyPath
2715 };
2716 
2717 static IDocHostUIHandler2 CustomDocHostUIHandler = { &CustomDocHostUIHandlerVtbl };
2718 
2719 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface,
2720         REFIID riid, void **ppv)
2721 {
2722     return QueryInterface(riid, ppv);
2723 }
2724 
2725 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
2726 {
2727     return 2;
2728 }
2729 
2730 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
2731 {
2732     return 1;
2733 }
2734 
2735 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
2736         ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
2737 {
2738     ok(!pguidCmdGroup, "pguidCmdGroup != MULL\n");
2739     ok(cCmds == 1, "cCmds=%d, expected 1\n", cCmds);
2740     ok(!pCmdText, "pCmdText != NULL\n");
2741 
2742     switch(prgCmds[0].cmdID) {
2743     case OLECMDID_SETPROGRESSTEXT:
2744         CHECK_EXPECT(QueryStatus_SETPROGRESSTEXT);
2745         prgCmds[0].cmdf = OLECMDF_ENABLED;
2746         return S_OK;
2747     case OLECMDID_OPEN:
2748         CHECK_EXPECT(QueryStatus_OPEN);
2749         prgCmds[0].cmdf = 0;
2750         return S_OK;
2751     case OLECMDID_NEW:
2752         CHECK_EXPECT(QueryStatus_NEW);
2753         prgCmds[0].cmdf = 0;
2754         return S_OK;
2755     default:
2756         ok(0, "unexpected command %d\n", prgCmds[0].cmdID);
2757     };
2758 
2759     return E_FAIL;
2760 }
2761 
2762 static void test_save_history(IUnknown *unk)
2763 {
2764     IPersistHistory *per_hist;
2765     LARGE_INTEGER li;
2766     IStream *stream;
2767     HRESULT hres;
2768 
2769     hres = IUnknown_QueryInterface(unk, &IID_IPersistHistory, (void**)&per_hist);
2770     ok(hres == S_OK, "Could not get IPersistHistory iface: %08x\n", hres);
2771 
2772     hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
2773     ok(hres == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hres);
2774 
2775     hres = IPersistHistory_SaveHistory(per_hist, stream);
2776     ok(hres == S_OK, "SaveHistory failed: %08x\n", hres);
2777     IPersistHistory_Release(per_hist);
2778 
2779     li.QuadPart = 0;
2780     hres = IStream_Seek(stream, li, STREAM_SEEK_SET, NULL);
2781     ok(hres == S_OK, "Stat failed: %08x\n", hres);
2782     history_stream = stream;
2783 }
2784 
2785 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
2786         DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
2787 {
2788     if(resetting_document)
2789         return E_FAIL;
2790 
2791     if(!pguidCmdGroup) {
2792         test_readyState(NULL);
2793 
2794         switch(nCmdID) {
2795         case OLECMDID_SETPROGRESSMAX:
2796             CHECK_EXPECT2(Exec_SETPROGRESSMAX);
2797             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
2798             ok(pvaIn != NULL, "pvaIn == NULL\n");
2799             if(pvaIn) {
2800                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
2801                 if(load_state == LD_NO)
2802                     ok(V_I4(pvaIn) == 0, "V_I4(pvaIn)=%d, expected 0\n", V_I4(pvaIn));
2803             }
2804             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
2805             return S_OK;
2806         case OLECMDID_SETPROGRESSPOS:
2807             CHECK_EXPECT2(Exec_SETPROGRESSPOS);
2808             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
2809             ok(pvaIn != NULL, "pvaIn == NULL\n");
2810             if(pvaIn) {
2811                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
2812                 if(load_state == LD_NO)
2813                     ok(V_I4(pvaIn) == 0, "V_I4(pvaIn)=%d, expected 0\n", V_I4(pvaIn));
2814             }
2815             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
2816             return S_OK;
2817         case OLECMDID_HTTPEQUIV_DONE:
2818             CHECK_EXPECT(Exec_HTTPEQUIV_DONE);
2819             ok(nCmdexecopt == 0, "nCmdexecopts=%08x\n", nCmdexecopt);
2820             ok(pvaOut == NULL, "pvaOut=%p\n", pvaOut);
2821             ok(pvaIn == NULL, "pvaIn=%p\n", pvaIn);
2822             readystate_set_loading = FALSE;
2823             readystate_set_interactive = FALSE;
2824             load_state = LD_COMPLETE;
2825             return S_OK;
2826         case OLECMDID_SETDOWNLOADSTATE:
2827             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
2828             ok(pvaOut == NULL, "pvaOut=%p\n", pvaOut);
2829             ok(pvaIn != NULL, "pvaIn == NULL\n");
2830             ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d\n", V_VT(pvaIn));
2831 
2832             switch(V_I4(pvaIn)) {
2833             case 0:
2834                 CHECK_EXPECT(Exec_SETDOWNLOADSTATE_0);
2835                 if(!loading_js)
2836                     load_state = LD_INTERACTIVE;
2837                 break;
2838             case 1:
2839                 CHECK_EXPECT(Exec_SETDOWNLOADSTATE_1);
2840                 readystate_set_interactive = (load_state != LD_INTERACTIVE);
2841                 break;
2842             default:
2843                 ok(0, "unexpevted V_I4(pvaIn)=%d\n", V_I4(pvaIn));
2844             }
2845 
2846             return S_OK;
2847         case OLECMDID_UPDATECOMMANDS:
2848             CHECK_EXPECT(Exec_UPDATECOMMANDS);
2849             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
2850             ok(pvaIn == NULL, "pvaIn=%p\n", pvaIn);
2851             ok(pvaOut == NULL, "pvaOut=%p\n", pvaOut);
2852             return S_OK;
2853         case OLECMDID_SETTITLE:
2854             CHECK_EXPECT2(Exec_SETTITLE);
2855             ok(nCmdexecopt == OLECMDEXECOPT_DONTPROMPTUSER, "nCmdexecopts=%08x\n", nCmdexecopt);
2856             ok(pvaIn != NULL, "pvaIn == NULL\n");
2857             ok(pvaOut == NULL, "pvaOut=%p\n", pvaOut);
2858             ok(V_VT(pvaIn) == VT_BSTR, "V_VT(pvaIn)=%d\n", V_VT(pvaIn));
2859             ok(V_BSTR(pvaIn) != NULL, "V_BSTR(pvaIn) == NULL\n"); /* TODO */
2860             return S_OK;
2861         case OLECMDID_HTTPEQUIV:
2862             CHECK_EXPECT2(Exec_HTTPEQUIV);
2863             ok(!nCmdexecopt, "nCmdexecopts=%08x\n", nCmdexecopt);
2864             ok(pvaIn != NULL, "pvaIn == NULL\n");
2865             ok(pvaOut == NULL, "pvaOut=%p\n", pvaOut);
2866             ok(V_VT(pvaIn) == VT_BSTR, "V_VT(pvaIn)=%d\n", V_VT(pvaIn));
2867             ok(V_BSTR(pvaIn) != NULL, "V_BSTR(pvaIn) = NULL\n");
2868             test_readyState(NULL);
2869             return S_OK;
2870         case OLECMDID_UPDATETRAVELENTRY_DATARECOVERY:
2871         case OLECMDID_PAGEAVAILABLE:
2872         case 6058:
2873             return E_FAIL; /* FIXME */
2874         default:
2875             ok(0, "unexpected command %d\n", nCmdID);
2876             return E_FAIL;
2877         };
2878     }
2879 
2880     if(IsEqualGUID(&CGID_ShellDocView, pguidCmdGroup)) {
2881         ok(nCmdexecopt == 0, "nCmdexecopts=%08x\n", nCmdexecopt);
2882 
2883         switch(nCmdID) {
2884         case 37:
2885             CHECK_EXPECT2(Exec_ShellDocView_37);
2886 
2887             if(is_refresh && load_state == LD_COMPLETE) {
2888                 load_state = LD_DOLOAD;
2889                 test_readyState(NULL);
2890             }else if(is_refresh && load_state == LD_DOLOAD) {
2891                 test_readyState(NULL);
2892                 load_state = LD_LOADING;
2893             }else {
2894                 if(!is_refresh)
2895                     test_readyState(NULL);
2896                 if(nav_url)
2897                     test_GetCurMoniker(doc_unk, NULL, nav_serv_url, FALSE);
2898                 else if(load_from_stream)
2899                     test_GetCurMoniker(doc_unk, NULL, "about:blank", FALSE);
2900                 else if(!editmode)
2901                     test_GetCurMoniker(doc_unk, doc_mon, NULL, FALSE);
2902             }
2903 
2904             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
2905             ok(pvaIn != NULL, "pvaIn == NULL\n");
2906             if(pvaIn) {
2907                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
2908                 ok(V_I4(pvaIn) == 0, "V_I4(pvaIn)=%d, expected 0\n", V_I4(pvaIn));
2909             }
2910             return S_OK;
2911 
2912         case 62:
2913             CHECK_EXPECT(Exec_ShellDocView_62);
2914             ok(!pvaIn, "pvaIn != NULL\n");
2915             ok(!pvaOut, "pvaOut != NULL\n");
2916             return S_OK;
2917 
2918         case 63: {
2919             IHTMLPrivateWindow *priv_window;
2920             HRESULT hres;
2921 
2922             CHECK_EXPECT(Exec_ShellDocView_63);
2923             ok(pvaIn != NULL, "pvaIn == NULL\n");
2924             ok(V_VT(pvaIn) == VT_UNKNOWN, "V_VT(pvaIn) = %d\n", V_VT(pvaIn));
2925             ok(V_UNKNOWN(pvaIn) != NULL, "VPUNKNOWN(pvaIn) = NULL\n");
2926             ok(pvaOut != NULL, "pvaOut == NULL\n");
2927             ok(V_VT(pvaOut) == VT_EMPTY, "V_VT(pvaOut) = %d\n", V_VT(pvaOut));
2928 
2929             hres = IUnknown_QueryInterface(V_UNKNOWN(pvaIn), &IID_IHTMLPrivateWindow, (void**)&priv_window);
2930             ok(hres == S_OK, "Could not get IHTMLPrivateWindow: %08x\n", hres);
2931             if(SUCCEEDED(hres))
2932                 IHTMLPrivateWindow_Release(priv_window);
2933 
2934             load_state = loading_js ? LD_COMPLETE : LD_LOADING;
2935             return S_OK; /* TODO */
2936         }
2937 
2938         case 67:
2939             CHECK_EXPECT(Exec_ShellDocView_67);
2940             ok(pvaIn != NULL, "pvaIn == NULL\n");
2941             ok(V_VT(pvaIn) == VT_BSTR, "V_VT(pvaIn) = %d\n", V_VT(pvaIn));
2942             ok(!strcmp_wa(V_BSTR(pvaIn), nav_serv_url), "V_BSTR(pvaIn) = %s, expected \"%s\"\n",
2943                wine_dbgstr_w(V_BSTR(pvaIn)), nav_serv_url);
2944             ok(pvaOut != NULL, "pvaOut == NULL\n");
2945             ok(V_VT(pvaOut) == VT_BOOL, "V_VT(pvaOut) = %d\n", V_VT(pvaOut));
2946             ok(V_BOOL(pvaOut) == VARIANT_TRUE, "V_BOOL(pvaOut) = %x\n", V_BOOL(pvaOut));
2947             if(!loading_hash)
2948                 load_state = LD_DOLOAD;
2949             return S_OK;
2950 
2951         case 84:
2952             CHECK_EXPECT2(Exec_ShellDocView_84);
2953 
2954             ok(pvaIn == NULL, "pvaIn != NULL\n");
2955             ok(pvaOut != NULL, "pvaOut == NULL\n");
2956             if(pvaIn)
2957                 ok(V_VT(pvaOut) == VT_EMPTY, "V_VT(pvaOut)=%d\n", V_VT(pvaOut));
2958 
2959             test_readyState(NULL);
2960             return E_NOTIMPL;
2961 
2962         case 103:
2963             CHECK_EXPECT2(Exec_ShellDocView_103);
2964 
2965             ok(pvaIn == NULL, "pvaIn != NULL\n");
2966             ok(pvaOut == NULL, "pvaOut != NULL\n");
2967 
2968             test_readyState(NULL);
2969             return E_NOTIMPL;
2970 
2971         case 105:
2972             CHECK_EXPECT2(Exec_ShellDocView_105);
2973 
2974             ok(pvaIn != NULL, "pvaIn == NULL\n");
2975             ok(pvaOut == NULL, "pvaOut != NULL\n");
2976 
2977             test_readyState(NULL);
2978             return E_NOTIMPL;
2979 
2980         case 138:
2981             CHECK_EXPECT2(Exec_ShellDocView_138);
2982             ok(!pvaIn, "pvaIn != NULL\n");
2983             ok(!pvaOut, "pvaOut != NULL\n");
2984             test_readyState(NULL);
2985             return S_OK;
2986 
2987         case 140:
2988             CHECK_EXPECT2(Exec_ShellDocView_140);
2989 
2990             ok(pvaIn == NULL, "pvaIn != NULL\n");
2991             ok(pvaOut == NULL, "pvaOut != NULL\n");
2992 
2993             test_readyState(NULL);
2994             return E_NOTIMPL;
2995 
2996         case 83:
2997         case 101:
2998         case 102:
2999         case 132:
3000         case 133:
3001         case 134: /* TODO */
3002         case 135:
3003         case 136: /* TODO */
3004         case 137:
3005         case 139: /* TODO */
3006         case 143: /* TODO */
3007         case 144: /* TODO */
3008         case 178:
3009         case 179:
3010         case 180:
3011         case 181:
3012         case 182:
3013         case 183:
3014             return E_NOTIMPL;
3015 
3016         default:
3017             ok(0, "unexpected command %d\n", nCmdID);
3018             return E_FAIL;
3019         };
3020     }
3021 
3022     if(IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
3023         test_readyState(NULL);
3024         ok(nCmdexecopt == 0, "nCmdexecopts=%08x\n", nCmdexecopt);
3025 
3026         switch(nCmdID) {
3027         case IDM_PARSECOMPLETE:
3028             CHECK_EXPECT(Exec_MSHTML_PARSECOMPLETE);
3029             ok(pvaIn == NULL, "pvaIn != NULL\n");
3030             ok(pvaOut == NULL, "pvaOut != NULL\n");
3031             return S_OK;
3032         default:
3033             ok(0, "unexpected command %d\n", nCmdID);
3034         };
3035     }
3036 
3037     if(IsEqualGUID(&CGID_DocHostCmdPriv, pguidCmdGroup)) {
3038         switch(nCmdID) {
3039         case DOCHOST_DOCCANNAVIGATE:
3040             if(pvaIn) {
3041                 CHECK_EXPECT(Exec_DOCCANNAVIGATE);
3042                 ok(V_VT(pvaIn) == VT_UNKNOWN, "V_VT(pvaIn) != VT_UNKNOWN\n");
3043                 /* FIXME: test V_UNKNOWN(pvaIn) == window */
3044             }else {
3045                 CHECK_EXPECT(Exec_DOCCANNAVIGATE_NULL);
3046             }
3047 
3048             test_readyState(NULL);
3049             ok(pvaOut == NULL, "pvaOut != NULL\n");
3050             return S_OK;
3051         case 1: {
3052             SAFEARRAY *sa;
3053             UINT dim;
3054             LONG ind=0;
3055             VARIANT var;
3056             HRESULT hres;
3057 
3058             test_readyState(NULL);
3059 
3060             ok(pvaIn != NULL, "pvaIn == NULL\n");
3061             ok(pvaOut != NULL || broken(!pvaOut), "pvaOut != NULL\n");
3062             ok(V_VT(pvaIn) == VT_ARRAY, "V_VT(pvaIn) = %d\n", V_VT(pvaIn));
3063             if(pvaOut)
3064                 ok(V_VT(pvaOut) == VT_BOOL, "V_VT(pvaOut) = %d\n", V_VT(pvaOut));
3065             sa = V_ARRAY(pvaIn);
3066 
3067             dim = SafeArrayGetDim(sa);
3068             ok(dim == 1, "dim = %d\n", dim);
3069             hres = SafeArrayGetLBound(sa, 1, &ind);
3070             ok(hres == S_OK, "SafeArrayGetLBound failed: %x\n", hres);
3071             ok(ind == 0, "Lower bound = %d\n", ind);
3072             hres = SafeArrayGetUBound(sa, 1, &ind);
3073             ok(hres == S_OK, "SafeArrayGetUBound failed: %x\n", hres);
3074             ok(ind == 7 || ind == 8 /* IE11 */ ||broken(ind == 5), "Upper bound = %d\n", ind);
3075 
3076             ind = 0;
3077             SafeArrayGetElement(sa, &ind, &var);
3078             ok(V_VT(&var) == VT_I4, "Incorrect data type: %d\n", V_VT(&var));
3079             ok(V_I4(&var) == status_code, "Incorrect error code: %d\n", V_I4(&var));
3080             VariantClear(&var);
3081             ind = 1;
3082             SafeArrayGetElement(sa, &ind, &var);
3083             ok(V_VT(&var) == VT_BSTR, "Incorrect data type: %d\n", V_VT(&var));
3084             ok(!strcmp_wa(V_BSTR(&var), "winetest:doc"), "Page address: %s\n", wine_dbgstr_w(V_BSTR(&var)));
3085             VariantClear(&var);
3086             ind = 2;
3087             SafeArrayGetElement(sa, &ind, &var);
3088             ok(V_VT(&var) == VT_UNKNOWN, "Incorrect data type: %d\n", V_VT(&var));
3089             VariantClear(&var);
3090             ind = 3;
3091             SafeArrayGetElement(sa, &ind, &var);
3092             ok(V_VT(&var) == VT_UNKNOWN, "Incorrect data type: %d\n", V_VT(&var));
3093             VariantClear(&var);
3094             ind = 4;
3095             SafeArrayGetElement(sa, &ind, &var);
3096             ok(V_VT(&var) == VT_BOOL, "Incorrect data type: %d\n", V_VT(&var));
3097             ok(!V_BOOL(&var), "Unknown value is incorrect\n");
3098             VariantClear(&var);
3099             ind = 5;
3100             SafeArrayGetElement(sa, &ind, &var);
3101             ok(V_VT(&var) == VT_BOOL, "Incorrect data type: %d\n", V_VT(&var));
3102             ok(!V_BOOL(&var), "Unknown value is incorrect\n");
3103             VariantClear(&var);
3104         }
3105         default:
3106             return E_FAIL; /* TODO */
3107         }
3108     }
3109 
3110     if(IsEqualGUID(&CGID_Explorer, pguidCmdGroup)) {
3111         test_readyState(NULL);
3112         ok(nCmdexecopt == 0, "nCmdexecopts=%08x\n", nCmdexecopt);
3113 
3114         switch(nCmdID) {
3115         case 38:
3116             CHECK_EXPECT2(Exec_Explorer_38);
3117             ok(pvaIn != NULL, "pvaIn == NULL\n");
3118             ok(V_VT(pvaIn) == VT_I4 , "V_VT(pvaIn) = %d\n", V_VT(pvaIn));
3119             ok(!V_I4(pvaIn), "V_I4(pvaIn) = %d\n", V_I4(pvaIn));
3120             ok(!pvaOut, "pvaOut != NULL\n");
3121 
3122             test_current_url(doc_unk, prev_url);
3123             if(!history_stream)
3124                 test_save_history(doc_unk);
3125 
3126             return S_OK;
3127         case 69:
3128             CHECK_EXPECT2(Exec_Explorer_69);
3129             ok(pvaIn == NULL, "pvaIn != NULL\n");
3130             ok(pvaOut != NULL, "pvaOut == NULL\n");
3131             return E_NOTIMPL;
3132         case 109: /* TODO */
3133             return E_NOTIMPL;
3134         default:
3135             ok(0, "unexpected cmd %d of CGID_Explorer\n", nCmdID);
3136         }
3137         return E_NOTIMPL;
3138     }
3139 
3140     if(IsEqualGUID(&CGID_DocHostCommandHandler, pguidCmdGroup)) {
3141         test_readyState(NULL);
3142 
3143         switch (nCmdID) {
3144         case OLECMDID_PAGEACTIONBLOCKED: /* win2k3 */
3145             SET_EXPECT(SetStatusText);
3146             ok(pvaIn == NULL, "pvaIn != NULL\n");
3147             ok(pvaOut == NULL, "pvaOut != NULL\n");
3148             return S_OK;
3149         case OLECMDID_SHOWSCRIPTERROR:
3150             /* TODO */
3151             return S_OK;
3152         case 2300:
3153             CHECK_EXPECT(Exec_DocHostCommandHandler_2300);
3154             return E_NOTIMPL;
3155         default:
3156             ok(0, "unexpected command %d\n", nCmdID);
3157             return E_FAIL;
3158         }
3159     }
3160 
3161     ok(0, "unexpected pguidCmdGroup: %s\n", wine_dbgstr_guid(pguidCmdGroup));
3162     return E_NOTIMPL;
3163 }
3164 
3165 static IOleCommandTargetVtbl OleCommandTargetVtbl = {
3166     OleCommandTarget_QueryInterface,
3167     OleCommandTarget_AddRef,
3168     OleCommandTarget_Release,
3169     OleCommandTarget_QueryStatus,
3170     OleCommandTarget_Exec
3171 };
3172 
3173 static IOleCommandTarget OleCommandTarget = { &OleCommandTargetVtbl };
3174 
3175 static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
3176 {
3177     return QueryInterface(riid, ppv);
3178 }
3179 
3180 static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
3181         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
3182         EXCEPINFO *pExcepInfo, UINT *puArgErr)
3183 {
3184     if(resetting_document)
3185         return E_FAIL;
3186 
3187     ok(IsEqualGUID(&IID_NULL, riid), "riid != IID_NULL\n");
3188     ok(pDispParams != NULL, "pDispParams == NULL\n");
3189     ok(pExcepInfo == NULL, "pExcepInfo=%p, expected NULL\n", pExcepInfo);
3190     ok(puArgErr != NULL, "puArgErr == NULL\n");
3191     ok(V_VT(pVarResult) == 0, "V_VT(pVarResult)=%d, expected 0\n", V_VT(pVarResult));
3192     ok(wFlags == DISPATCH_PROPERTYGET, "wFlags=%08x, expected DISPATCH_PROPERTYGET\n", wFlags);
3193 
3194     if(dispIdMember != DISPID_AMBIENT_SILENT && dispIdMember != DISPID_AMBIENT_OFFLINEIFNOTCONNECTED)
3195         test_readyState(NULL);
3196 
3197     switch(dispIdMember) {
3198     case DISPID_AMBIENT_USERMODE:
3199         CHECK_EXPECT2(Invoke_AMBIENT_USERMODE);
3200         V_VT(pVarResult) = VT_BOOL;
3201         V_BOOL(pVarResult) = VARIANT_TRUE;
3202         return S_OK;
3203     case DISPID_AMBIENT_DLCONTROL:
3204         CHECK_EXPECT2(Invoke_AMBIENT_DLCONTROL);
3205         return E_FAIL;
3206     case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
3207         CHECK_EXPECT2(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3208         return E_FAIL;
3209     case DISPID_AMBIENT_SILENT:
3210         CHECK_EXPECT2(Invoke_AMBIENT_SILENT);
3211         V_VT(pVarResult) = VT_BOOL;
3212         V_BOOL(pVarResult) = VARIANT_FALSE;
3213         return S_OK;
3214     case DISPID_AMBIENT_USERAGENT:
3215         CHECK_EXPECT(Invoke_AMBIENT_USERAGENT);
3216         return E_FAIL;
3217     case DISPID_AMBIENT_PALETTE:
3218         CHECK_EXPECT(Invoke_AMBIENT_PALETTE);
3219         return E_FAIL;
3220     };
3221 
3222     ok(0, "unexpected dispid %d\n", dispIdMember);
3223     return E_FAIL;
3224 }
3225 
3226 static const IDispatchVtbl DispatchVtbl = {
3227     Dispatch_QueryInterface,
3228     Dispatch_AddRef,
3229     Dispatch_Release,
3230     Dispatch_GetTypeInfoCount,
3231     Dispatch_GetTypeInfo,
3232     Dispatch_GetIDsOfNames,
3233     Dispatch_Invoke
3234 };
3235 
3236 static IDispatch Dispatch = { &DispatchVtbl };
3237 
3238 static HRESULT WINAPI EventDispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
3239 {
3240     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
3241         *ppv = iface;
3242         return S_OK;
3243     }
3244 
3245     ok(0, "Unexpected call\n");
3246     return E_NOINTERFACE;
3247 }
3248 
3249 static HRESULT WINAPI EventDispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
3250         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
3251         EXCEPINFO *pExcepInfo, UINT *puArgErr)
3252 {
3253     HRESULT hres;
3254     IHTMLDocument2 *doc;
3255     BSTR state;
3256 
3257     if(resetting_document)
3258         return E_FAIL;
3259 
3260     ok(IsEqualGUID(&IID_NULL, riid), "riid = %s\n", wine_dbgstr_guid(riid));
3261     ok(pDispParams != NULL, "pDispParams == NULL\n");
3262     ok(pExcepInfo != NULL, "pExcepInfo == NULL\n");
3263     ok(puArgErr != NULL, "puArgErr == NULL\n");
3264     ok(V_VT(pVarResult) == 0, "V_VT(pVarResult) = %d\n", V_VT(pVarResult));
3265     ok(wFlags == DISPATCH_METHOD, "wFlags = %d, expected DISPATCH_METHOD\n", wFlags);
3266 
3267     hres = IUnknown_QueryInterface(doc_unk, &IID_IHTMLDocument2, (void**)&doc);
3268     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument2) failed: %08x\n", hres);
3269 
3270     switch(dispIdMember) {
3271     case DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE:
3272         hres = IHTMLDocument2_get_readyState(doc, &state);
3273         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
3274 
3275         if(!strcmp_wa(state, "interactive"))
3276             CHECK_EXPECT(Invoke_OnReadyStateChange_Interactive);
3277         else if(!strcmp_wa(state, "loading"))
3278             CHECK_EXPECT(Invoke_OnReadyStateChange_Loading);
3279         else if(!strcmp_wa(state, "complete")) {
3280             CHECK_EXPECT(Invoke_OnReadyStateChange_Complete);
3281             complete = TRUE;
3282         } else
3283             ok(0, "Unexpected readyState: %s\n", wine_dbgstr_w(state));
3284 
3285         SysFreeString(state);
3286         break;
3287     case DISPID_HTMLDOCUMENTEVENTS2_ONPROPERTYCHANGE:
3288     case 1026:
3289     case 1027:
3290     case 1034:
3291     case 1035:
3292     case 1037:
3293     case 1047:
3294     case 1045:
3295     case 1044:
3296     case 1048:
3297     case 1049:
3298         break; /* FIXME: Handle these events. */
3299     default:
3300         ok(0, "Unexpected DISPID: %d\n", dispIdMember);
3301     }
3302 
3303     IHTMLDocument2_Release(doc);
3304     return S_OK;
3305 }
3306 
3307 static const IDispatchVtbl EventDispatchVtbl = {
3308     EventDispatch_QueryInterface,
3309     Dispatch_AddRef,
3310     Dispatch_Release,
3311     Dispatch_GetTypeInfoCount,
3312     Dispatch_GetTypeInfo,
3313     Dispatch_GetIDsOfNames,
3314     EventDispatch_Invoke
3315 };
3316 
3317 static IDispatch EventDispatch = { &EventDispatchVtbl };
3318 
3319 static HRESULT WINAPI TravelLog_QueryInterface(ITravelLog *iface, REFIID riid, void **ppv)
3320 {
3321     static const IID IID_IIETravelLog2 = {0xb67cefd2,0xe3f1,0x478a,{0x9b,0xfa,0xd8,0x93,0x70,0x37,0x5e,0x94}};
3322     static const IID IID_unk_travellog = {0x6afc8b7f,0xbc17,0x4a95,{0x90,0x2f,0x6f,0x5c,0xb5,0x54,0xc3,0xd8}};
3323     static const IID IID_unk_travellog2 = {0xf6d02767,0x9c80,0x428d,{0xb9,0x74,0x3f,0x17,0x29,0x45,0x3f,0xdb}};
3324 
3325     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_ITravelLog, riid)) {
3326         *ppv = iface;
3327         return S_OK;
3328     }
3329 
3330     if(!IsEqualGUID(&IID_IIETravelLog2, riid) && !IsEqualGUID(&IID_unk_travellog, riid)
3331        && !IsEqualGUID(&IID_unk_travellog2, riid))
3332         ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
3333 
3334     *ppv = NULL;
3335     return E_NOINTERFACE;
3336 }
3337 
3338 static ULONG WINAPI TravelLog_AddRef(ITravelLog *iface)
3339 {
3340     return 2;
3341 }
3342 
3343 static ULONG WINAPI TravelLog_Release(ITravelLog *iface)
3344 {
3345     return 1;
3346 }
3347 
3348 static HRESULT WINAPI TravelLog_AddEntry(ITravelLog *iface, IUnknown *punk, BOOL fIsLocalAnchor)
3349 {
3350     ok(0, "unexpected call\n");
3351     return E_NOTIMPL;
3352 }
3353 
3354 static HRESULT WINAPI TravelLog_UpdateEntry(ITravelLog *iface, IUnknown *punk, BOOL fIsLocalAnchor)
3355 {
3356     ok(0, "unexpected call\n");
3357     return E_NOTIMPL;
3358 }
3359 
3360 static HRESULT WINAPI TravelLog_UpdateExternal(ITravelLog *iface, IUnknown *punk, IUnknown *punkHLBrowseContext)
3361 {
3362     ok(0, "unexpected call\n");
3363     return E_NOTIMPL;
3364 }
3365 
3366 static HRESULT WINAPI TravelLog_Travel(ITravelLog *iface, IUnknown *punk, int iOffset)
3367 {
3368     ok(0, "unexpected call\n");
3369     return E_NOTIMPL;
3370 }
3371 
3372 static HRESULT WINAPI TravelLog_GetTravelEntry(ITravelLog *iface, IUnknown *punk, int iOffset, ITravelEntry **ppte)
3373 {
3374     ok(0, "unexpected call\n");
3375     return E_NOTIMPL;
3376 }
3377 
3378 static HRESULT WINAPI TravelLog_FindTravelEntry(ITravelLog *iface, IUnknown *punk, LPCITEMIDLIST pidl, ITravelEntry **ppte)
3379 {
3380     ok(0, "unexpected call\n");
3381     return E_NOTIMPL;
3382 }
3383 
3384 static HRESULT WINAPI TravelLog_GetTooltipText(ITravelLog *iface, IUnknown *punk, int iOffset, int idsTemplate,
3385         LPWSTR pwzText, DWORD cchText)
3386 {
3387     ok(0, "unexpected call\n");
3388     return E_NOTIMPL;
3389 }
3390 
3391 static HRESULT WINAPI TravelLog_InsertMenuEntries(ITravelLog *iface, IUnknown *punk, HMENU hmenu, int nPos,
3392         int idFirst, int idLast, DWORD dwFlags)
3393 {
3394     ok(0, "unexpected call\n");
3395     return E_NOTIMPL;
3396 }
3397 
3398 static HRESULT WINAPI TravelLog_Clone(ITravelLog *iface, ITravelLog **pptl)
3399 {
3400     ok(0, "unexpected call\n");
3401     return E_NOTIMPL;
3402 }
3403 
3404 static IBrowserService BrowserService;
3405 static DWORD WINAPI TravelLog_CountEntries(ITravelLog *iface, IUnknown *punk)
3406 {
3407     CHECK_EXPECT(CountEntries);
3408 
3409     ok(punk == (IUnknown*)&BrowserService, "punk != &BrowserService (%p)\n", punk);
3410     return 0;
3411 }
3412 
3413 static HRESULT WINAPI TravelLog_Revert(ITravelLog *iface)
3414 {
3415     ok(0, "unexpected call\n");
3416     return E_NOTIMPL;
3417 }
3418 
3419 static const ITravelLogVtbl TravelLogVtbl = {
3420     TravelLog_QueryInterface,
3421     TravelLog_AddRef,
3422     TravelLog_Release,
3423     TravelLog_AddEntry,
3424     TravelLog_UpdateEntry,
3425     TravelLog_UpdateExternal,
3426     TravelLog_Travel,
3427     TravelLog_GetTravelEntry,
3428     TravelLog_FindTravelEntry,
3429     TravelLog_GetTooltipText,
3430     TravelLog_InsertMenuEntries,
3431     TravelLog_Clone,
3432     TravelLog_CountEntries,
3433     TravelLog_Revert
3434 };
3435 
3436 static ITravelLog TravelLog = { &TravelLogVtbl };
3437 
3438 static HRESULT browserservice_qi(REFIID,void**);
3439 
3440 static HRESULT  WINAPI DocObjectService_QueryInterface(IDocObjectService* This, REFIID riid, void **ppv)
3441 {
3442     return browserservice_qi(riid, ppv);
3443 }
3444 
3445 static ULONG  WINAPI DocObjectService_AddRef(
3446         IDocObjectService* This)
3447 {
3448     return 2;
3449 }
3450 
3451 static ULONG  WINAPI DocObjectService_Release(
3452         IDocObjectService* This)
3453 {
3454     return 1;
3455 }
3456 
3457 static HRESULT  WINAPI DocObjectService_FireBeforeNavigate2(IDocObjectService *iface, IDispatch *pDispatch,
3458         LPCWSTR lpszUrl, DWORD dwFlags, LPCWSTR lpszFrameName, BYTE *pPostData, DWORD cbPostData,
3459         LPCWSTR lpszHeaders, BOOL fPlayNavSound, BOOL *pfCancel)
3460 {
3461     CHECK_EXPECT(FireBeforeNavigate2);
3462 
3463     ok(!pDispatch, "pDispatch = %p\n", pDispatch);
3464     ok(!strcmp_wa(lpszUrl, nav_url), "lpszUrl = %s, expected %s\n", wine_dbgstr_w(lpszUrl), nav_url);
3465     ok(dwFlags == 0x140 /* IE11*/ || dwFlags == 0x40 || !dwFlags || dwFlags == 0x50, "dwFlags = %x\n", dwFlags);
3466     ok(!lpszFrameName, "lpszFrameName = %s\n", wine_dbgstr_w(lpszFrameName));
3467     if(!testing_submit) {
3468         ok(!pPostData, "pPostData = %p\n", pPostData);
3469         ok(!cbPostData, "cbPostData = %d\n", cbPostData);
3470         ok(!lpszHeaders || !strcmp_wa(lpszHeaders, "Referer: http://test.winehq.org/tests/winehq_snapshot/\r\n"),
3471            "lpszHeaders = %s\n", wine_dbgstr_w(lpszHeaders));
3472     }else {
3473         ok(cbPostData == 9, "cbPostData = %d\n", cbPostData);
3474         ok(!memcmp(pPostData, "cmd=TEST", cbPostData), "pPostData = %p\n", pPostData);
3475         ok(wstr_contains(lpszHeaders, "Content-Type: application/x-www-form-urlencoded\r\n"),
3476            "lpszHeaders = %s\n", wine_dbgstr_w(lpszHeaders));
3477 
3478     }
3479     ok(fPlayNavSound, "fPlayNavSound = %x\n", fPlayNavSound);
3480     ok(pfCancel != NULL, "pfCancel = NULL\n");
3481     ok(!*pfCancel, "*pfCancel = %x\n", *pfCancel);
3482 
3483     return S_OK;
3484 }
3485 
3486 static HRESULT  WINAPI DocObjectService_FireNavigateComplete2(
3487         IDocObjectService* This,
3488         IHTMLWindow2 *pHTMLWindow2,
3489         DWORD dwFlags)
3490 {
3491     CHECK_EXPECT(FireNavigateComplete2);
3492     test_readyState(NULL);
3493 
3494     if(loading_hash)
3495         ok(dwFlags == 0x10 || broken(!dwFlags), "dwFlags = %x, expected 0x10\n", dwFlags);
3496     else
3497         ok(!(dwFlags &~1), "dwFlags = %x\n", dwFlags);
3498 
3499     ok(pHTMLWindow2 != NULL, "pHTMLWindow2 = NULL\n");
3500 
3501     return S_OK;
3502 }
3503 
3504 static HRESULT  WINAPI DocObjectService_FireDownloadBegin(
3505         IDocObjectService* This)
3506 {
3507     ok(0, "unexpected call\n");
3508     return E_NOTIMPL;
3509 }
3510 
3511 static HRESULT  WINAPI DocObjectService_FireDownloadComplete(
3512         IDocObjectService* This)
3513 {
3514     ok(0, "unexpected call\n");
3515     return E_NOTIMPL;
3516 }
3517 
3518 static HRESULT  WINAPI DocObjectService_FireDocumentComplete(
3519         IDocObjectService* This,
3520         IHTMLWindow2 *pHTMLWindow,
3521         DWORD dwFlags)
3522 {
3523     CHECK_EXPECT(FireDocumentComplete);
3524 
3525     ok(pHTMLWindow != NULL, "pHTMLWindow == NULL\n");
3526     ok(!dwFlags, "dwFlags = %x\n", dwFlags);
3527 
3528     return S_OK;
3529 }
3530 
3531 static HRESULT  WINAPI DocObjectService_UpdateDesktopComponent(
3532         IDocObjectService* This,
3533         IHTMLWindow2 *pHTMLWindow)
3534 {
3535     ok(0, "unexpected call\n");
3536     return E_NOTIMPL;
3537 }
3538 
3539 static HRESULT  WINAPI DocObjectService_GetPendingUrl(
3540         IDocObjectService* This,
3541         BSTR *pbstrPendingUrl)
3542 {
3543     if(!resetting_document)
3544         CHECK_EXPECT(GetPendingUrl);
3545     return E_NOTIMPL;
3546 }
3547 
3548 static HRESULT  WINAPI DocObjectService_ActiveElementChanged(
3549         IDocObjectService* This,
3550         IHTMLElement *pHTMLElement)
3551 {
3552     CHECK_EXPECT2(ActiveElementChanged);
3553     return E_NOTIMPL;
3554 }
3555 
3556 static HRESULT  WINAPI DocObjectService_GetUrlSearchComponent(
3557         IDocObjectService* This,
3558         BSTR *pbstrSearch)
3559 {
3560     ok(0, "unexpected call\n");
3561     return E_NOTIMPL;
3562 }
3563 
3564 static HRESULT  WINAPI DocObjectService_IsErrorUrl(
3565         IDocObjectService* This,
3566         LPCWSTR lpszUrl,
3567         BOOL *pfIsError)
3568 {
3569     CHECK_EXPECT(IsErrorUrl);
3570     *pfIsError = FALSE;
3571     return S_OK;
3572 }
3573 
3574 static IDocObjectServiceVtbl DocObjectServiceVtbl = {
3575     DocObjectService_QueryInterface,
3576     DocObjectService_AddRef,
3577     DocObjectService_Release,
3578     DocObjectService_FireBeforeNavigate2,
3579     DocObjectService_FireNavigateComplete2,
3580     DocObjectService_FireDownloadBegin,
3581     DocObjectService_FireDownloadComplete,
3582     DocObjectService_FireDocumentComplete,
3583     DocObjectService_UpdateDesktopComponent,
3584     DocObjectService_GetPendingUrl,
3585     DocObjectService_ActiveElementChanged,
3586     DocObjectService_GetUrlSearchComponent,
3587     DocObjectService_IsErrorUrl
3588 };
3589 
3590 static IDocObjectService DocObjectService = { &DocObjectServiceVtbl };
3591 
3592 static HRESULT WINAPI ShellBrowser_QueryInterface(IShellBrowser *iface, REFIID riid, void **ppv)
3593 {
3594     return browserservice_qi(riid, ppv);
3595 }
3596 
3597 static ULONG WINAPI ShellBrowser_AddRef(IShellBrowser *iface)
3598 {
3599     return 2;
3600 }
3601 
3602 static ULONG WINAPI ShellBrowser_Release(IShellBrowser *iface)
3603 {
3604     return 1;
3605 }
3606 
3607 static HRESULT WINAPI ShellBrowser_GetWindow(IShellBrowser *iface, HWND *phwnd)
3608 {
3609     ok(0, "unexpected call\n");
3610     return E_NOTIMPL;
3611 }
3612 
3613 static HRESULT WINAPI ShellBrowser_ContextSensitiveHelp(IShellBrowser *iface, BOOL fEnterMode)
3614 {
3615     ok(0, "unexpected call\n");
3616     return E_NOTIMPL;
3617 }
3618 
3619 static HRESULT WINAPI ShellBrowser_InsertMenusSB(IShellBrowser *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
3620 {
3621     ok(0, "unexpected call\n");
3622     return E_NOTIMPL;
3623 }
3624 
3625 static HRESULT WINAPI ShellBrowser_SetMenuSB(IShellBrowser *iface, HMENU hmenuShared, HOLEMENU holemenuReserved,
3626         HWND hwndActiveObject)
3627 {
3628     ok(0, "unexpected call\n");
3629     return E_NOTIMPL;
3630 }
3631 
3632 static HRESULT WINAPI ShellBrowser_RemoveMenusSB(IShellBrowser *iface, HMENU hmenuShared)
3633 {
3634     ok(0, "unexpected call\n");
3635     return E_NOTIMPL;
3636 }
3637 
3638 static HRESULT WINAPI ShellBrowser_SetStatusTextSB(IShellBrowser *iface, LPCOLESTR pszStatusText)
3639 {
3640     ok(0, "unexpected call\n");
3641     return E_NOTIMPL;
3642 }
3643 
3644 static HRESULT WINAPI ShellBrowser_EnableModelessSB(IShellBrowser *iface, BOOL fEnable)
3645 {
3646     ok(0, "unexpected call\n");
3647     return E_NOTIMPL;
3648 }
3649 
3650 static HRESULT WINAPI ShellBrowser_TranslateAcceleratorSB(IShellBrowser *iface, MSG *pmsg, WORD wID)
3651 {
3652     ok(0, "unexpected call\n");
3653     return E_NOTIMPL;
3654 }
3655 
3656 static HRESULT WINAPI ShellBrowser_BrowseObject(IShellBrowser *iface, LPCITEMIDLIST pidl, UINT wFlags)
3657 {
3658     ok(0, "unexpected call\n");
3659     return E_NOTIMPL;
3660 }
3661 
3662 static HRESULT WINAPI ShellBrowser_GetViewStateStream(IShellBrowser *iface, DWORD grfMode, IStream **ppStrm)
3663 {
3664     ok(0, "unexpected call\n");
3665     return E_NOTIMPL;
3666 }
3667 
3668 static HRESULT WINAPI ShellBrowser_GetControlWindow(IShellBrowser *iface, UINT id, HWND *phwnd)
3669 {
3670     ok(0, "unexpected call\n");
3671     return E_NOTIMPL;
3672 }
3673 
3674 static HRESULT WINAPI ShellBrowser_SendControlMsg(IShellBrowser *iface, UINT id, UINT uMsg, WPARAM wParam,
3675         LPARAM lParam, LRESULT *pret)
3676 {
3677     ok(0, "unexpected call\n");
3678     return E_NOTIMPL;
3679 }
3680 
3681 static HRESULT WINAPI ShellBrowser_QueryActiveShellView(IShellBrowser *iface, IShellView **ppshv)
3682 {
3683     ok(0, "unexpected call\n");
3684     return E_NOTIMPL;
3685 }
3686 
3687 static HRESULT WINAPI ShellBrowser_OnViewWindowActive(IShellBrowser* iface, IShellView *pshv)
3688 {
3689     ok(0, "unexpected call\n");
3690     return E_NOTIMPL;
3691 }
3692 
3693 static HRESULT WINAPI ShellBrowser_SetToolbarItems(IShellBrowser *iface, LPTBBUTTONSB lpButtons,
3694         UINT nButtons, UINT uFlags)
3695 {
3696     ok(0, "unexpected call\n");
3697     return E_NOTIMPL;
3698 }
3699 
3700 static const IShellBrowserVtbl ShellBrowserVtbl = {
3701     ShellBrowser_QueryInterface,
3702     ShellBrowser_AddRef,
3703     ShellBrowser_Release,
3704     ShellBrowser_GetWindow,
3705     ShellBrowser_ContextSensitiveHelp,
3706     ShellBrowser_InsertMenusSB,
3707     ShellBrowser_SetMenuSB,
3708     ShellBrowser_RemoveMenusSB,
3709     ShellBrowser_SetStatusTextSB,
3710     ShellBrowser_EnableModelessSB,
3711     ShellBrowser_TranslateAcceleratorSB,
3712     ShellBrowser_BrowseObject,
3713     ShellBrowser_GetViewStateStream,
3714     ShellBrowser_GetControlWindow,
3715     ShellBrowser_SendControlMsg,
3716     ShellBrowser_QueryActiveShellView,
3717     ShellBrowser_OnViewWindowActive,
3718     ShellBrowser_SetToolbarItems
3719 };
3720 
3721 static IShellBrowser ShellBrowser = { &ShellBrowserVtbl };
3722 
3723 static HRESULT  WINAPI BrowserService_QueryInterface(IBrowserService *iface, REFIID riid, void **ppv)
3724 {
3725     return browserservice_qi(riid, ppv);
3726 }
3727 
3728 static ULONG  WINAPI BrowserService_AddRef(
3729         IBrowserService* This)
3730 {
3731     return 2;
3732 }
3733 
3734 static ULONG  WINAPI BrowserService_Release(
3735         IBrowserService* This)
3736 {
3737     return 1;
3738 }
3739 
3740 static HRESULT  WINAPI BrowserService_GetParentSite(
3741         IBrowserService* This,
3742         IOleInPlaceSite **ppipsite)
3743 {
3744     ok(0, "unexpected call\n");
3745     return E_NOTIMPL;
3746 }
3747 
3748 static HRESULT  WINAPI BrowserService_SetTitle(
3749         IBrowserService* This,
3750         IShellView *psv,
3751         LPCWSTR pszName)
3752 {
3753     ok(0, "unexpected call\n");
3754     return E_NOTIMPL;
3755 }
3756 
3757 static HRESULT  WINAPI BrowserService_GetTitle(
3758         IBrowserService* This,
3759         IShellView *psv,
3760         LPWSTR pszName,
3761         DWORD cchName)
3762 {
3763     ok(0, "unexpected call\n");
3764     return E_NOTIMPL;
3765 }
3766 
3767 static HRESULT  WINAPI BrowserService_GetOleObject(
3768         IBrowserService* This,
3769         IOleObject **ppobjv)
3770 {
3771     ok(0, "unexpected call\n");
3772     return E_NOTIMPL;
3773 }
3774 
3775 static HRESULT  WINAPI BrowserService_GetTravelLog(IBrowserService* This, ITravelLog **pptl)
3776 {
3777     CHECK_EXPECT(GetTravelLog);
3778 
3779     ok(pptl != NULL, "pptl = NULL\n");
3780 
3781     if(!support_wbapp)
3782         return E_NOTIMPL;
3783 
3784     *pptl = &TravelLog;
3785     return S_OK;
3786 }
3787 
3788 static HRESULT  WINAPI BrowserService_ShowControlWindow(
3789         IBrowserService* This,
3790         UINT id,
3791         BOOL fShow)
3792 {
3793     ok(0, "unexpected call\n");
3794     return E_NOTIMPL;
3795 }
3796 
3797 static HRESULT  WINAPI BrowserService_IsControlWindowShown(
3798         IBrowserService* This,
3799         UINT id,
3800         BOOL *pfShown)
3801 {
3802     ok(0, "unexpected call\n");
3803     return E_NOTIMPL;
3804 }
3805 
3806 static HRESULT  WINAPI BrowserService_IEGetDisplayName(
3807         IBrowserService* This,
3808         PCIDLIST_ABSOLUTE pidl,
3809         LPWSTR pwszName,
3810         UINT uFlags)
3811 {
3812     ok(0, "unexpected call\n");
3813     return E_NOTIMPL;
3814 }
3815 
3816 static HRESULT  WINAPI BrowserService_IEParseDisplayName(
3817         IBrowserService* This,
3818         UINT uiCP,
3819         LPCWSTR pwszPath,
3820         PIDLIST_ABSOLUTE *ppidlOut)
3821 {
3822     ok(0, "unexpected call\n");
3823     return E_NOTIMPL;
3824 }
3825 
3826 static HRESULT  WINAPI BrowserService_DisplayParseError(
3827         IBrowserService* This,
3828         HRESULT hres,
3829         LPCWSTR pwszPath)
3830 {
3831     ok(0, "unexpected call\n");
3832     return E_NOTIMPL;
3833 }
3834 
3835 static HRESULT  WINAPI BrowserService_NavigateToPidl(
3836         IBrowserService* This,
3837         PCIDLIST_ABSOLUTE pidl,
3838         DWORD grfHLNF)
3839 {
3840     ok(0, "unexpected call\n");
3841     return E_NOTIMPL;
3842 }
3843 
3844 static HRESULT  WINAPI BrowserService_SetNavigateState(
3845         IBrowserService* This,
3846         BNSTATE bnstate)
3847 {
3848     ok(0, "unexpected call\n");
3849     return E_NOTIMPL;
3850 }
3851 
3852 static HRESULT  WINAPI BrowserService_GetNavigateState(
3853         IBrowserService* This,
3854         BNSTATE *pbnstate)
3855 {
3856     ok(0, "unexpected call\n");
3857     return E_NOTIMPL;
3858 }
3859 
3860 static HRESULT  WINAPI BrowserService_NotifyRedirect(
3861         IBrowserService* This,
3862         IShellView *psv,
3863         PCIDLIST_ABSOLUTE pidl,
3864         BOOL *pfDidBrowse)
3865 {
3866     ok(0, "unexpected call\n");
3867     return E_NOTIMPL;
3868 }
3869 
3870 static HRESULT  WINAPI BrowserService_UpdateWindowList(
3871         IBrowserService* This)
3872 {
3873     ok(0, "unexpected call\n");
3874     return E_NOTIMPL;
3875 }
3876 
3877 static HRESULT  WINAPI BrowserService_UpdateBackForwardState(
3878         IBrowserService* This)
3879 {
3880     CHECK_EXPECT(UpdateBackForwardState);
3881     return S_OK;
3882 }
3883 
3884 static HRESULT  WINAPI BrowserService_SetFlags(
3885         IBrowserService* This,
3886         DWORD dwFlags,
3887         DWORD dwFlagMask)
3888 {
3889     ok(0, "unexpected call\n");
3890     return E_NOTIMPL;
3891 }
3892 
3893 static HRESULT  WINAPI BrowserService_GetFlags(
3894         IBrowserService* This,
3895         DWORD *pdwFlags)
3896 {
3897     ok(0, "unexpected call\n");
3898     return E_NOTIMPL;
3899 }
3900 
3901 static HRESULT  WINAPI BrowserService_CanNavigateNow(
3902         IBrowserService* This)
3903 {
3904     ok(0, "unexpected call\n");
3905     return E_NOTIMPL;
3906 }
3907 
3908 static HRESULT  WINAPI BrowserService_GetPidl(
3909         IBrowserService* This,
3910         PIDLIST_ABSOLUTE *ppidl)
3911 {
3912     ok(0, "unexpected call\n");
3913     return E_NOTIMPL;
3914 }
3915 
3916 static HRESULT  WINAPI BrowserService_SetReferrer(
3917         IBrowserService* This,
3918         PCIDLIST_ABSOLUTE pidl)
3919 {
3920     ok(0, "unexpected call\n");
3921     return E_NOTIMPL;
3922 }
3923 
3924 static DWORD  WINAPI BrowserService_GetBrowserIndex(
3925         IBrowserService* This)
3926 {
3927     ok(0, "unexpected call\n");
3928     return E_NOTIMPL;
3929 }
3930 
3931 static HRESULT  WINAPI BrowserService_GetBrowserByIndex(
3932         IBrowserService* This,
3933         DWORD dwID,
3934         IUnknown **ppunk)
3935 {
3936     ok(0, "unexpected call\n");
3937     return E_NOTIMPL;
3938 }
3939 
3940 static HRESULT  WINAPI BrowserService_GetHistoryObject(
3941         IBrowserService* This,
3942         IOleObject **ppole,
3943         IStream **pstm,
3944         IBindCtx **ppbc)
3945 {
3946     ok(0, "unexpected call\n");
3947     return E_NOTIMPL;
3948 }
3949 
3950 static HRESULT  WINAPI BrowserService_SetHistoryObject(
3951         IBrowserService* This,
3952         IOleObject *pole,
3953         BOOL fIsLocalAnchor)
3954 {
3955     ok(0, "unexpected call\n");
3956     return E_NOTIMPL;
3957 }
3958 
3959 static HRESULT  WINAPI BrowserService_CacheOLEServer(
3960         IBrowserService* This,
3961         IOleObject *pole)
3962 {
3963     ok(0, "unexpected call\n");
3964     return E_NOTIMPL;
3965 }
3966 
3967 static HRESULT  WINAPI BrowserService_GetSetCodePage(
3968         IBrowserService* This,
3969         VARIANT *pvarIn,
3970         VARIANT *pvarOut)
3971 {
3972     ok(0, "unexpected call\n");
3973     return E_NOTIMPL;
3974 }
3975 
3976 static HRESULT  WINAPI BrowserService_OnHttpEquiv(
3977         IBrowserService* This,
3978         IShellView *psv,
3979         BOOL fDone,
3980         VARIANT *pvarargIn,
3981         VARIANT *pvarargOut)
3982 {
3983     ok(0, "unexpected call\n");
3984     return E_NOTIMPL;
3985 }
3986 
3987 static HRESULT  WINAPI BrowserService_GetPalette(
3988         IBrowserService* This,
3989         HPALETTE *hpal)
3990 {
3991     ok(0, "unexpected call\n");
3992     return E_NOTIMPL;
3993 }
3994 
3995 static HRESULT  WINAPI BrowserService_RegisterWindow(
3996         IBrowserService* This,
3997         BOOL fForceRegister,
3998         int swc)
3999 {
4000     ok(0, "unexpected call\n");
4001     return E_NOTIMPL;
4002 }
4003 
4004 static IBrowserServiceVtbl BrowserServiceVtbl = {
4005     BrowserService_QueryInterface,
4006     BrowserService_AddRef,
4007     BrowserService_Release,
4008     BrowserService_GetParentSite,
4009     BrowserService_SetTitle,
4010     BrowserService_GetTitle,
4011     BrowserService_GetOleObject,
4012     BrowserService_GetTravelLog,
4013     BrowserService_ShowControlWindow,
4014     BrowserService_IsControlWindowShown,
4015     BrowserService_IEGetDisplayName,
4016     BrowserService_IEParseDisplayName,
4017     BrowserService_DisplayParseError,
4018     BrowserService_NavigateToPidl,
4019     BrowserService_SetNavigateState,
4020     BrowserService_GetNavigateState,
4021     BrowserService_NotifyRedirect,
4022     BrowserService_UpdateWindowList,
4023     BrowserService_UpdateBackForwardState,
4024     BrowserService_SetFlags,
4025     BrowserService_GetFlags,
4026     BrowserService_CanNavigateNow,
4027     BrowserService_GetPidl,
4028     BrowserService_SetReferrer,
4029     BrowserService_GetBrowserIndex,
4030     BrowserService_GetBrowserByIndex,
4031     BrowserService_GetHistoryObject,
4032     BrowserService_SetHistoryObject,
4033     BrowserService_CacheOLEServer,
4034     BrowserService_GetSetCodePage,
4035     BrowserService_OnHttpEquiv,
4036     BrowserService_GetPalette,
4037     BrowserService_RegisterWindow
4038 };
4039 
4040 static IBrowserService BrowserService = { &BrowserServiceVtbl };
4041 
4042 DEFINE_GUID(IID_ITabBrowserService, 0x5E8FA523,0x83D4,0x4DBE,0x81,0x99,0x4C,0x18,0xE4,0x85,0x87,0x25);
4043 
4044 static HRESULT browserservice_qi(REFIID riid, void **ppv)
4045 {
4046     if(IsEqualGUID(&IID_IShellBrowser, riid)) {
4047         *ppv = &ShellBrowser;
4048         return S_OK;
4049     }
4050 
4051     if(IsEqualGUID(&IID_IDocObjectService, riid)) {
4052         *ppv = &DocObjectService;
4053         return S_OK;
4054     }
4055 
4056     if(IsEqualGUID(&IID_IBrowserService, riid)) {
4057         *ppv = &BrowserService;
4058         return S_OK;
4059     }
4060 
4061     *ppv = NULL;
4062     return E_NOINTERFACE;
4063 }
4064 
4065 static HRESULT WINAPI WBE2Sink_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
4066 {
4067     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IDispatch, riid)) {
4068         *ppv = iface;
4069         return S_OK;
4070     }
4071 
4072     *ppv = NULL;
4073     ok(0, "unexpected riid: %s\n", wine_dbgstr_guid(riid));
4074     return E_NOINTERFACE;
4075 }
4076 
4077 static HRESULT WINAPI WBE2Sink_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
4078         LCID lcid, WORD wFlags, DISPPARAMS *pdp, VARIANT *pVarResult,
4079         EXCEPINFO *pExcepInfo, UINT *puArgErr)
4080 {
4081     ok(IsEqualGUID(&IID_NULL, riid), "riid != IID_NULL\n");
4082     ok(pdp != NULL, "pDispParams == NULL\n");
4083     ok(pExcepInfo == NULL, "pExcepInfo=%p, expected NULL\n", pExcepInfo);
4084     ok(puArgErr == NULL, "puArgErr != NULL\n");
4085     ok(pVarResult == NULL, "pVarResult != NULL\n");
4086     ok(wFlags == DISPATCH_METHOD, "wFlags=%08x, expected DISPATCH_METHOD\n", wFlags);
4087     ok(!pdp->cNamedArgs, "pdp->cNamedArgs = %d\n", pdp->cNamedArgs);
4088     ok(!pdp->rgdispidNamedArgs, "rgdispidNamedArgs = %p\n", pdp->rgdispidNamedArgs);
4089 
4090     switch(dispIdMember) {
4091     case DISPID_WINDOWCLOSING: {
4092         VARIANT *is_child = pdp->rgvarg+1, *cancel = pdp->rgvarg;
4093 
4094         CHECK_EXPECT(WindowClosing);
4095 
4096         ok(pdp->cArgs == 2, "pdp->cArgs = %d\n", pdp->cArgs);
4097         ok(V_VT(is_child) == VT_BOOL, "V_VT(is_child) = %d\n", V_VT(is_child));
4098         ok(!V_BOOL(is_child), "V_BOOL(is_child) = %x\n", V_BOOL(is_child));
4099         ok(V_VT(cancel) == (VT_BYREF|VT_BOOL), "V_VT(cancel) = %d\n", V_VT(cancel));
4100         ok(!*V_BOOLREF(cancel), "*V_BOOLREF(cancel) = %x\n", *V_BOOLREF(cancel));
4101 
4102         *V_BOOLREF(cancel) = VARIANT_TRUE;
4103         return S_OK;
4104     }
4105     default:
4106         ok(0, "unexpected id %d\n", dispIdMember);
4107     }
4108 
4109     return E_NOTIMPL;
4110 }
4111 
4112 static const IDispatchVtbl WBE2SinkVtbl = {
4113     WBE2Sink_QueryInterface,
4114     Dispatch_AddRef,
4115     Dispatch_Release,
4116     Dispatch_GetTypeInfoCount,
4117     Dispatch_GetTypeInfo,
4118     Dispatch_GetIDsOfNames,
4119     WBE2Sink_Invoke
4120 };
4121 
4122 static IDispatch WBE2Sink = { &WBE2SinkVtbl };
4123 
4124 static HRESULT WINAPI EnumConnections_QueryInterface(IEnumConnections *iface, REFIID riid, LPVOID *ppv)
4125 {
4126     ok(0, "unexpected call\n");
4127     return E_NOINTERFACE;
4128 }
4129 
4130 static ULONG WINAPI EnumConnections_AddRef(IEnumConnections *iface)
4131 {
4132     return 2;
4133 }
4134 
4135 static ULONG WINAPI EnumConnections_Release(IEnumConnections *iface)
4136 {
4137     return 1;
4138 }
4139 
4140 static BOOL next_called;
4141 
4142 static HRESULT WINAPI EnumConnections_Next(IEnumConnections *iface, ULONG cConnections, CONNECTDATA *rgcd, ULONG *pcFetched)
4143 {
4144     CHECK_EXPECT2(EnumConnections_Next);
4145 
4146     ok(cConnections == 1, "cConnections = %d\n", cConnections);
4147     ok(pcFetched != NULL, "pcFetched == NULL\n");
4148 
4149     if(next_called) {
4150         *pcFetched = 0;
4151         return S_FALSE;
4152     }
4153 
4154     next_called = TRUE;
4155     rgcd->pUnk = (IUnknown*)&WBE2Sink;
4156     rgcd->dwCookie = 0xdeadbeef;
4157     *pcFetched = 1;
4158     return S_OK;
4159 }
4160 
4161 static HRESULT WINAPI EnumConnections_Skip(IEnumConnections *iface, ULONG ulConnections)
4162 {
4163     ok(0, "unexpected call\n");
4164     return E_NOINTERFACE;
4165 }
4166 
4167 static HRESULT WINAPI EnumConnections_Reset(IEnumConnections *iface)
4168 {
4169     ok(0, "unexpected call\n");
4170     return E_NOINTERFACE;
4171 }
4172 
4173 static HRESULT WINAPI EnumConnections_Clone(IEnumConnections *iface, IEnumConnections **ppEnum)
4174 {
4175     ok(0, "unexpected call\n");
4176     return E_NOINTERFACE;
4177 }
4178 
4179 static const IEnumConnectionsVtbl EnumConnectionsVtbl = {
4180     EnumConnections_QueryInterface,
4181     EnumConnections_AddRef,
4182     EnumConnections_Release,
4183     EnumConnections_Next,
4184     EnumConnections_Skip,
4185     EnumConnections_Reset,
4186     EnumConnections_Clone
4187 };
4188 
4189 static IEnumConnections EnumConnections = { &EnumConnectionsVtbl };
4190 
4191 static HRESULT WINAPI ConnectionPoint_QueryInterface(IConnectionPoint *iface, REFIID riid, LPVOID *ppv)
4192 {
4193     ok(0, "unexpected call\n");
4194     return E_NOINTERFACE;
4195 }
4196 
4197 static ULONG WINAPI ConnectionPoint_AddRef(IConnectionPoint *iface)
4198 {
4199     return 2;
4200 }
4201 
4202 static ULONG WINAPI ConnectionPoint_Release(IConnectionPoint *iface)
4203 {
4204     return 1;
4205 }
4206 
4207 static HRESULT WINAPI ConnectionPoint_GetConnectionInterface(IConnectionPoint *iface, IID *pIID)
4208 {
4209     ok(0, "unexpected call\n");
4210     return E_NOTIMPL;
4211 }
4212 
4213 static HRESULT WINAPI ConnectionPoint_GetConnectionPointContainer(IConnectionPoint *iface,
4214         IConnectionPointContainer **ppCPC)
4215 {
4216     ok(0, "unexpected call\n");
4217     return E_NOTIMPL;
4218 }
4219 
4220 static HRESULT WINAPI ConnectionPoint_Advise(IConnectionPoint *iface, IUnknown *pUnkSink, DWORD *pdwCookie)
4221 {
4222     ok(0, "unexpected call\n");
4223     return E_NOTIMPL;
4224 }
4225 
4226 static HRESULT WINAPI ConnectionPoint_Unadvise(IConnectionPoint *iface, DWORD dwCookie)
4227 {
4228     ok(0, "unexpected call\n");
4229     return E_NOTIMPL;
4230 }
4231 
4232 static HRESULT WINAPI ConnectionPoint_EnumConnections(IConnectionPoint *iface, IEnumConnections **ppEnum)
4233 {
4234     CHECK_EXPECT(EnumConnections);
4235 
4236     *ppEnum = &EnumConnections;
4237     next_called = FALSE;
4238     return S_OK;
4239 }
4240 
4241 static const IConnectionPointVtbl ConnectionPointVtbl =
4242 {
4243     ConnectionPoint_QueryInterface,
4244     ConnectionPoint_AddRef,
4245     ConnectionPoint_Release,
4246     ConnectionPoint_GetConnectionInterface,
4247     ConnectionPoint_GetConnectionPointContainer,
4248     ConnectionPoint_Advise,
4249     ConnectionPoint_Unadvise,
4250     ConnectionPoint_EnumConnections
4251 };
4252 
4253 static IConnectionPoint ConnectionPointWBE2 = { &ConnectionPointVtbl };
4254 
4255 static HRESULT WINAPI ConnectionPointContainer_QueryInterface(IConnectionPointContainer *iface,
4256                                                               REFIID riid, void **ppv)
4257 {
4258     ok(0, "unexpected call\n");
4259     return E_NOINTERFACE;
4260 }
4261 
4262 static ULONG WINAPI ConnectionPointContainer_AddRef(IConnectionPointContainer *iface)
4263 {
4264     return 2;
4265 }
4266 
4267 static ULONG WINAPI ConnectionPointContainer_Release(IConnectionPointContainer *iface)
4268 {
4269     return 1;
4270 }
4271 
4272 static HRESULT WINAPI ConnectionPointContainer_EnumConnectionPoints(IConnectionPointContainer *iface,
4273         IEnumConnectionPoints **ppEnum)
4274 {
4275     ok(0, "unexpected call\n");
4276     return E_NOTIMPL;
4277 }
4278 
4279 static HRESULT WINAPI ConnectionPointContainer_FindConnectionPoint(IConnectionPointContainer *iface,
4280         REFIID riid, IConnectionPoint **ppCP)
4281 {
4282     CHECK_EXPECT(FindConnectionPoint);
4283 
4284     if(IsEqualGUID(riid, &DIID_DWebBrowserEvents2)) {
4285         *ppCP = &ConnectionPointWBE2;
4286         return S_OK;
4287     }
4288 
4289     ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
4290     return E_NOTIMPL;
4291 }
4292 
4293 static const IConnectionPointContainerVtbl ConnectionPointContainerVtbl = {
4294     ConnectionPointContainer_QueryInterface,
4295     ConnectionPointContainer_AddRef,
4296     ConnectionPointContainer_Release,
4297     ConnectionPointContainer_EnumConnectionPoints,
4298     ConnectionPointContainer_FindConnectionPoint
4299 };
4300 
4301 static IConnectionPointContainer ConnectionPointContainer = { &ConnectionPointContainerVtbl };
4302 
4303 static void test_NavigateWithBindCtx(BSTR uri, VARIANT *flags, VARIANT *target_frame, VARIANT *post_data,
4304         VARIANT *headers, IBindCtx *bind_ctx, LPOLESTR url_fragment)
4305 {
4306     ok(!strcmp_wa(uri, nav_url), "uri = %s\n", wine_dbgstr_w(uri));
4307     ok(V_VT(flags) == VT_I4, "V_VT(flags) = %d\n", V_VT(flags));
4308     ok(V_I4(flags) == navHyperlink, "V_I4(flags) = %x\n", V_I4(flags));
4309     ok(!target_frame, "target_frame != NULL\n");
4310     ok(!post_data, "post_data != NULL\n");
4311     ok(!headers, "headers != NULL\n");
4312     ok(bind_ctx != NULL, "bind_ctx == NULL\n");
4313     ok(!url_fragment, "url_dragment = %s\n", wine_dbgstr_w(url_fragment));
4314 }
4315 
4316 static HRESULT wb_qi(REFIID riid, void **ppv);
4317 
4318 static HRESULT WINAPI WebBrowserPriv_QueryInterface(IWebBrowserPriv *iface, REFIID riid, void **ppv)
4319 {
4320     return wb_qi(riid, ppv);
4321 }
4322 
4323 static ULONG WINAPI WebBrowserPriv_AddRef(IWebBrowserPriv *iface)
4324 {
4325     return 2;
4326 }
4327 
4328 static ULONG WINAPI WebBrowserPriv_Release(IWebBrowserPriv *iface)
4329 {
4330     return 1;
4331 }
4332 
4333 static HRESULT WINAPI WebBrowserPriv_NavigateWithBindCtx(IWebBrowserPriv *iface, VARIANT *uri, VARIANT *flags,
4334         VARIANT *target_frame, VARIANT *post_data, VARIANT *headers, IBindCtx *bind_ctx, LPOLESTR url_fragment)
4335 {
4336     trace("NavigateWithBindCtx\n");
4337 
4338     CHECK_EXPECT(NavigateWithBindCtx);
4339 
4340     ok(V_VT(uri) == VT_BSTR, "V_VT(uri) = %d\n", V_VT(uri));
4341     test_NavigateWithBindCtx(V_BSTR(uri), flags, target_frame, post_data, headers, bind_ctx, url_fragment);
4342     return S_OK;
4343 }
4344 
4345 static HRESULT WINAPI WebBrowserPriv_OnClose(IWebBrowserPriv *iface)
4346 {
4347     ok(0, "unexpected call\n");
4348     return E_NOTIMPL;
4349 }
4350 
4351 static const IWebBrowserPrivVtbl WebBrowserPrivVtbl = {
4352     WebBrowserPriv_QueryInterface,
4353     WebBrowserPriv_AddRef,
4354     WebBrowserPriv_Release,
4355     WebBrowserPriv_NavigateWithBindCtx,
4356     WebBrowserPriv_OnClose
4357 };
4358 
4359 static IWebBrowserPriv WebBrowserPriv = { &WebBrowserPrivVtbl };
4360 
4361 static HRESULT WINAPI WebBrowserPriv2IE8_QueryInterface(IWebBrowserPriv2IE8 *iface, REFIID riid, void **ppv)
4362 {
4363     return wb_qi(riid, ppv);
4364 }
4365 
4366 static ULONG WINAPI WebBrowserPriv2IE8_AddRef(IWebBrowserPriv2IE8 *iface)
4367 {
4368     return 2;
4369 }
4370 
4371 static ULONG WINAPI WebBrowserPriv2IE8_Release(IWebBrowserPriv2IE8 *iface)
4372 {
4373     return 1;
4374 }
4375 
4376 static HRESULT WINAPI WebBrowserPriv2IE8_NavigateWithBindCtx2(IWebBrowserPriv2IE8 *iface, IUri *uri, VARIANT *flags,
4377         VARIANT *target_frame, VARIANT *post_data, VARIANT *headers, IBindCtx *bind_ctx, LPOLESTR url_fragment)
4378 {
4379     BSTR str;
4380     HRESULT hres;
4381 
4382     trace("IE8: NavigateWithBindCtx2\n");
4383 
4384     CHECK_EXPECT(NavigateWithBindCtx);
4385 
4386     hres = IUri_GetDisplayUri(uri, &str);
4387     ok(hres == S_OK, "GetDisplayUri failed: %08x\n", hres);
4388     test_NavigateWithBindCtx(str, flags, target_frame, post_data, headers, bind_ctx, url_fragment);
4389     SysFreeString(str);
4390     return S_OK;
4391 }
4392 
4393 static HRESULT WINAPI WebBrowserPriv2IE8_SetBrowserFrameOptions(IWebBrowserPriv2IE8 *iface, DWORD opt1, DWORD opt2)
4394 {
4395     ok(0, "unexpected call\n");
4396     return E_NOTIMPL;
4397 }
4398 
4399 static HRESULT WINAPI WebBrowserPriv2IE8_DetachConnectionPoints(IWebBrowserPriv2IE8 *iface)
4400 {
4401     ok(0, "unexpected call\n");
4402     return E_NOTIMPL;
4403 }
4404 
4405 static HRESULT WINAPI WebBrowserPriv2IE8_GetProcessId(IWebBrowserPriv2IE8 *iface, DWORD *pid)
4406 {
4407     ok(0, "unexpected call\n");
4408     return E_NOTIMPL;
4409 }
4410 
4411 static HRESULT WINAPI WebBrowserPriv2IE8_CompatAttachEditEvents(IWebBrowserPriv2IE8 *iface)
4412 {
4413     ok(0, "unexpected call\n");
4414     return E_NOTIMPL;
4415 }
4416 
4417 static HRESULT WINAPI WebBrowserPriv2IE8_HandleOpenOptions(IWebBrowserPriv2IE8 *iface, IUnknown *obj, BSTR bstr, int options)
4418 {
4419     ok(0, "unexpected call\n");
4420     return E_NOTIMPL;
4421 }
4422 
4423 static HRESULT WINAPI WebBrowserPriv2IE8_SetSearchTerm(IWebBrowserPriv2IE8 *iface, BSTR term)
4424 {
4425     ok(0, "unexpected call\n");
4426     return E_NOTIMPL;
4427 }
4428 
4429 static HRESULT WINAPI WebBrowserPriv2IE8_GetSearchTerm(IWebBrowserPriv2IE8 *iface, BSTR *term)
4430 {
4431     ok(0, "unexpected call\n");
4432     return E_NOTIMPL;
4433 }
4434 
4435 static HRESULT WINAPI WebBrowserPriv2IE8_GetCurrentDocument(IWebBrowserPriv2IE8 *iface, IDispatch **doc)
4436 {
4437     ok(0, "unexpected call\n");
4438     return E_NOTIMPL;
4439 }
4440 
4441 static const IWebBrowserPriv2IE8Vtbl WebBrowserPriv2IE8Vtbl = {
4442     WebBrowserPriv2IE8_QueryInterface,
4443     WebBrowserPriv2IE8_AddRef,
4444     WebBrowserPriv2IE8_Release,
4445     WebBrowserPriv2IE8_NavigateWithBindCtx2,
4446     WebBrowserPriv2IE8_SetBrowserFrameOptions,
4447     WebBrowserPriv2IE8_DetachConnectionPoints,
4448     WebBrowserPriv2IE8_GetProcessId,
4449     WebBrowserPriv2IE8_CompatAttachEditEvents,
4450     WebBrowserPriv2IE8_HandleOpenOptions,
4451     WebBrowserPriv2IE8_SetSearchTerm,
4452     WebBrowserPriv2IE8_GetSearchTerm,
4453     WebBrowserPriv2IE8_GetCurrentDocument
4454 };
4455 
4456 static IWebBrowserPriv2IE8 WebBrowserPriv2IE8 = { &WebBrowserPriv2IE8Vtbl };
4457 
4458 static HRESULT WINAPI WebBrowserPriv2IE9_QueryInterface(IWebBrowserPriv2IE9 *iface, REFIID riid, void **ppv)
4459 {
4460     return wb_qi(riid, ppv);
4461 }
4462 
4463 static ULONG WINAPI WebBrowserPriv2IE9_AddRef(IWebBrowserPriv2IE9 *iface)
4464 {
4465     return 2;
4466 }
4467 
4468 static ULONG WINAPI WebBrowserPriv2IE9_Release(IWebBrowserPriv2IE9 *iface)
4469 {
4470     return 1;
4471 }
4472 
4473 static HRESULT WINAPI WebBrowserPriv2IE9_NavigateWithBindCtx2(IWebBrowserPriv2IE9 *iface, IUri *uri, VARIANT *flags,
4474         VARIANT *target_frame, VARIANT *post_data, VARIANT *headers, IBindCtx *bind_ctx, LPOLESTR url_fragment, DWORD unknown)
4475 {
4476     BSTR str;
4477     HRESULT hres;
4478 
4479     trace("IE9: NavigateWithBindCtx2\n");
4480 
4481     CHECK_EXPECT(NavigateWithBindCtx);
4482 
4483     hres = IUri_GetDisplayUri(uri, &str);
4484     ok(hres == S_OK, "GetDisplayUri failed: %08x\n", hres);
4485     test_NavigateWithBindCtx(str, flags, target_frame, post_data, headers, bind_ctx, url_fragment);
4486     SysFreeString(str);
4487     return S_OK;
4488 }
4489 
4490 static const IWebBrowserPriv2IE9Vtbl WebBrowserPriv2IE9Vtbl = {
4491     WebBrowserPriv2IE9_QueryInterface,
4492     WebBrowserPriv2IE9_AddRef,
4493     WebBrowserPriv2IE9_Release,
4494     WebBrowserPriv2IE9_NavigateWithBindCtx2
4495 };
4496 
4497 static IWebBrowserPriv2IE9 WebBrowserPriv2IE9 = { &WebBrowserPriv2IE9Vtbl };
4498 
4499 static HRESULT WINAPI WebBrowser_QueryInterface(IWebBrowser2 *iface, REFIID riid, void **ppv)
4500 {
4501     return wb_qi(riid, ppv);
4502 }
4503 
4504 static ULONG WINAPI WebBrowser_AddRef(IWebBrowser2 *iface)
4505 {
4506     return 2;
4507 }
4508 
4509 static ULONG WINAPI WebBrowser_Release(IWebBrowser2 *iface)
4510 {
4511     return 1;
4512 }
4513 
4514 static HRESULT WINAPI WebBrowser_GetTypeInfoCount(IWebBrowser2 *iface, UINT *pctinfo)
4515 {
4516     ok(0, "unexpected call\n");
4517     return E_NOTIMPL;
4518 }
4519 
4520 static HRESULT WINAPI WebBrowser_GetTypeInfo(IWebBrowser2 *iface, UINT iTInfo, LCID lcid,
4521         LPTYPEINFO *ppTInfo)
4522 {
4523     ok(0, "unexpected call\n");
4524     return E_NOTIMPL;
4525 }
4526 
4527 static HRESULT WINAPI WebBrowser_GetIDsOfNames(IWebBrowser2 *iface, REFIID riid,
4528         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
4529 {
4530     ok(0, "unexpected call\n");
4531     return E_NOTIMPL;
4532 }
4533 
4534 static HRESULT WINAPI WebBrowser_Invoke(IWebBrowser2 *iface, DISPID dispIdMember,
4535         REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
4536         EXCEPINFO *pExepInfo, UINT *puArgErr)
4537 {
4538     ok(0, "unexpected call\n");
4539     return E_NOTIMPL;
4540 }
4541 
4542 static HRESULT WINAPI WebBrowser_GoBack(IWebBrowser2 *iface)
4543 {
4544     ok(0, "unexpected call\n");
4545     return E_NOTIMPL;
4546 }
4547 
4548 static HRESULT WINAPI WebBrowser_GoForward(IWebBrowser2 *iface)
4549 {
4550     ok(0, "unexpected call\n");
4551     return E_NOTIMPL;
4552 }
4553 
4554 static HRESULT WINAPI WebBrowser_GoHome(IWebBrowser2 *iface)
4555 {
4556     ok(0, "unexpected call\n");
4557     return E_NOTIMPL;
4558 }
4559 
4560 static HRESULT WINAPI WebBrowser_GoSearch(IWebBrowser2 *iface)
4561 {
4562     ok(0, "unexpected call\n");
4563     return E_NOTIMPL;
4564 }
4565 
4566 static HRESULT WINAPI WebBrowser_Navigate(IWebBrowser2 *iface, BSTR szUrl,
4567         VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
4568 {
4569     ok(0, "unexpected call\n");
4570     return E_NOTIMPL;
4571 }
4572 
4573 static HRESULT WINAPI WebBrowser_Refresh(IWebBrowser2 *iface)
4574 {
4575     ok(0, "unexpected call\n");
4576     return E_NOTIMPL;
4577 }
4578 
4579 static HRESULT WINAPI WebBrowser_Refresh2(IWebBrowser2 *iface, VARIANT *Level)
4580 {
4581     ok(0, "unexpected call\n");
4582     return E_NOTIMPL;
4583 }
4584 
4585 static HRESULT WINAPI WebBrowser_Stop(IWebBrowser2 *iface)
4586 {
4587     ok(0, "unexpected call\n");
4588     return E_NOTIMPL;
4589 }
4590 
4591 static HRESULT WINAPI WebBrowser_get_Application(IWebBrowser2 *iface, IDispatch **ppDisp)
4592 {
4593     ok(0, "unexpected call\n");
4594     return E_NOTIMPL;
4595 }
4596 
4597 static HRESULT WINAPI WebBrowser_get_Parent(IWebBrowser2 *iface, IDispatch **ppDisp)
4598 {
4599     ok(0, "unexpected call\n");
4600     return E_NOTIMPL;
4601 }
4602 
4603 static HRESULT WINAPI WebBrowser_get_Container(IWebBrowser2 *iface, IDispatch **ppDisp)
4604 {
4605     ok(0, "unexpected call\n");
4606     return E_NOTIMPL;
4607 }
4608 
4609 static HRESULT WINAPI WebBrowser_get_Document(IWebBrowser2 *iface, IDispatch **ppDisp)
4610 {
4611     ok(0, "unexpected call\n");
4612     return E_NOTIMPL;
4613 }
4614 
4615 static HRESULT WINAPI WebBrowser_get_TopLevelContainer(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
4616 {
4617     ok(0, "unexpected call\n");
4618     return E_NOTIMPL;
4619 }
4620 
4621 static HRESULT WINAPI WebBrowser_get_Type(IWebBrowser2 *iface, BSTR *Type)
4622 {
4623     ok(0, "unexpected call\n");
4624     return E_NOTIMPL;
4625 }
4626 
4627 static HRESULT WINAPI WebBrowser_get_Left(IWebBrowser2 *iface, LONG *pl)
4628 {
4629     ok(0, "unexpected call\n");
4630     return E_NOTIMPL;
4631 }
4632 
4633 static HRESULT WINAPI WebBrowser_put_Left(IWebBrowser2 *iface, LONG Left)
4634 {
4635     ok(0, "unexpected call\n");
4636     return E_NOTIMPL;
4637 }
4638 
4639 static HRESULT WINAPI WebBrowser_get_Top(IWebBrowser2 *iface, LONG *pl)
4640 {
4641     ok(0, "unexpected call\n");
4642     return E_NOTIMPL;
4643 }
4644 
4645 static HRESULT WINAPI WebBrowser_put_Top(IWebBrowser2 *iface, LONG Top)
4646 {
4647     ok(0, "unexpected call\n");
4648     return E_NOTIMPL;
4649 }
4650 
4651 static HRESULT WINAPI WebBrowser_get_Width(IWebBrowser2 *iface, LONG *pl)
4652 {
4653     ok(0, "unexpected call\n");
4654     return E_NOTIMPL;
4655 }
4656 
4657 static HRESULT WINAPI WebBrowser_put_Width(IWebBrowser2 *iface, LONG Width)
4658 {
4659     ok(0, "unexpected call\n");
4660     return E_NOTIMPL;
4661 }
4662 
4663 static HRESULT WINAPI WebBrowser_get_Height(IWebBrowser2 *iface, LONG *pl)
4664 {
4665     ok(0, "unexpected call\n");
4666     return E_NOTIMPL;
4667 }
4668 
4669 static HRESULT WINAPI WebBrowser_put_Height(IWebBrowser2 *iface, LONG Height)
4670 {
4671     ok(0, "unexpected call\n");
4672     return E_NOTIMPL;
4673 }
4674 
4675 static HRESULT WINAPI WebBrowser_get_LocationName(IWebBrowser2 *iface, BSTR *LocationName)
4676 {
4677     ok(0, "unexpected call\n");
4678     return E_NOTIMPL;
4679 }
4680 
4681 static HRESULT WINAPI WebBrowser_get_LocationURL(IWebBrowser2 *iface, BSTR *LocationURL)
4682 {
4683     CHECK_EXPECT(get_LocationURL);
4684     return E_NOTIMPL;
4685 }
4686 
4687 static HRESULT WINAPI WebBrowser_get_Busy(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
4688 {
4689     ok(0, "unexpected call\n");
4690     return E_NOTIMPL;
4691 }
4692 
4693 static HRESULT WINAPI WebBrowser_Quit(IWebBrowser2 *iface)
4694 {
4695     ok(0, "unexpected call\n");
4696     return E_NOTIMPL;
4697 }
4698 
4699 static HRESULT WINAPI WebBrowser_ClientToWindow(IWebBrowser2 *iface, int *pcx, int *pcy)
4700 {
4701     ok(0, "unexpected call\n");
4702     return E_NOTIMPL;
4703 }
4704 
4705 static HRESULT WINAPI WebBrowser_PutProperty(IWebBrowser2 *iface, BSTR szProperty, VARIANT vtValue)
4706 {
4707     ok(0, "unexpected call\n");
4708     return E_NOTIMPL;
4709 }
4710 
4711 static HRESULT WINAPI WebBrowser_GetProperty(IWebBrowser2 *iface, BSTR szProperty, VARIANT *pvtValue)
4712 {
4713     ok(0, "unexpected call\n");
4714     return E_NOTIMPL;
4715 }
4716 
4717 static HRESULT WINAPI WebBrowser_get_Name(IWebBrowser2 *iface, BSTR *Name)
4718 {
4719     ok(0, "unexpected call\n");
4720     return E_NOTIMPL;
4721 }
4722 
4723 static HRESULT WINAPI WebBrowser_get_HWND(IWebBrowser2 *iface, SHANDLE_PTR *pHWND)
4724 {
4725     ok(0, "unexpected call\n");
4726     return E_NOTIMPL;
4727 }
4728 
4729 static HRESULT WINAPI WebBrowser_get_FullName(IWebBrowser2 *iface, BSTR *FullName)
4730 {
4731     ok(0, "unexpected call\n");
4732     return E_NOTIMPL;
4733 }
4734 
4735 static HRESULT WINAPI WebBrowser_get_Path(IWebBrowser2 *iface, BSTR *Path)
4736 {
4737     ok(0, "unexpected call\n");
4738     return E_NOTIMPL;
4739 }
4740 
4741 static HRESULT WINAPI WebBrowser_get_Visible(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
4742 {
4743     ok(0, "unexpected call\n");
4744     return E_NOTIMPL;
4745 }
4746 
4747 static HRESULT WINAPI WebBrowser_put_Visible(IWebBrowser2 *iface, VARIANT_BOOL Value)
4748 {
4749     ok(0, "unexpected call\n");
4750     return E_NOTIMPL;
4751 }
4752 
4753 static HRESULT WINAPI WebBrowser_get_StatusBar(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
4754 {
4755     ok(0, "unexpected call\n");
4756     return E_NOTIMPL;
4757 }
4758 
4759 static HRESULT WINAPI WebBrowser_put_StatusBar(IWebBrowser2 *iface, VARIANT_BOOL Value)
4760 {
4761     ok(0, "unexpected call\n");
4762     return E_NOTIMPL;
4763 }
4764 
4765 static HRESULT WINAPI WebBrowser_get_StatusText(IWebBrowser2 *iface, BSTR *StatusText)
4766 {
4767     ok(0, "unexpected call\n");
4768     return E_NOTIMPL;
4769 }
4770 
4771 static HRESULT WINAPI WebBrowser_put_StatusText(IWebBrowser2 *iface, BSTR StatusText)
4772 {
4773     ok(0, "unexpected call\n");
4774     return E_NOTIMPL;
4775 }
4776 
4777 static HRESULT WINAPI WebBrowser_get_ToolBar(IWebBrowser2 *iface, int *Value)
4778 {
4779     ok(0, "unexpected call\n");
4780     return E_NOTIMPL;
4781 }
4782 
4783 static HRESULT WINAPI WebBrowser_put_ToolBar(IWebBrowser2 *iface, int Value)
4784 {
4785     ok(0, "unexpected call\n");
4786     return E_NOTIMPL;
4787 }
4788 
4789 static HRESULT WINAPI WebBrowser_get_MenuBar(IWebBrowser2 *iface, VARIANT_BOOL *Value)
4790 {
4791     ok(0, "unexpected call\n");
4792     return E_NOTIMPL;
4793 }
4794 
4795 static HRESULT WINAPI WebBrowser_put_MenuBar(IWebBrowser2 *iface, VARIANT_BOOL Value)
4796 {
4797     ok(0, "unexpected call\n");
4798     return E_NOTIMPL;
4799 }
4800 
4801 static HRESULT WINAPI WebBrowser_get_FullScreen(IWebBrowser2 *iface, VARIANT_BOOL *pbFullScreen)
4802 {
4803     ok(0, "unexpected call\n");
4804     return E_NOTIMPL;
4805 }
4806 
4807 static HRESULT WINAPI WebBrowser_put_FullScreen(IWebBrowser2 *iface, VARIANT_BOOL bFullScreen)
4808 {
4809     ok(0, "unexpected call\n");
4810     return E_NOTIMPL;
4811 }
4812 
4813 static HRESULT WINAPI WebBrowser_Navigate2(IWebBrowser2 *iface, VARIANT *URL, VARIANT *Flags,
4814         VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
4815 {
4816     ok(0, "unexpected call\n");
4817     return E_NOTIMPL;
4818 }
4819 
4820 static HRESULT WINAPI WebBrowser_QueryStatusWB(IWebBrowser2 *iface, OLECMDID cmdID, OLECMDF *pcmdf)
4821 {
4822     ok(0, "unexpected call\n");
4823     return E_NOTIMPL;
4824 }
4825 
4826 static HRESULT WINAPI WebBrowser_ExecWB(IWebBrowser2 *iface, OLECMDID cmdID,
4827         OLECMDEXECOPT cmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
4828 {
4829     ok(0, "unexpected call\n");
4830     return E_NOTIMPL;
4831 }
4832 
4833 static HRESULT WINAPI WebBrowser_ShowBrowserBar(IWebBrowser2 *iface, VARIANT *pvaClsid,
4834         VARIANT *pvarShow, VARIANT *pvarSize)
4835 {
4836     ok(0, "unexpected call\n");
4837     return E_NOTIMPL;
4838 }
4839 
4840 static HRESULT WINAPI WebBrowser_get_ReadyState(IWebBrowser2 *iface, READYSTATE *lpReadyState)
4841 {
4842     ok(0, "unexpected call\n");
4843     return E_NOTIMPL;
4844 }
4845 
4846 static HRESULT WINAPI WebBrowser_get_Offline(IWebBrowser2 *iface, VARIANT_BOOL *pbOffline)
4847 {
4848     ok(0, "unexpected call\n");
4849     return E_NOTIMPL;
4850 }
4851 
4852 static HRESULT WINAPI WebBrowser_put_Offline(IWebBrowser2 *iface, VARIANT_BOOL bOffline)
4853 {
4854     ok(0, "unexpected call\n");
4855     return E_NOTIMPL;
4856 }
4857 
4858 static HRESULT WINAPI WebBrowser_get_Silent(IWebBrowser2 *iface, VARIANT_BOOL *pbSilent)
4859 {
4860     ok(0, "unexpected call\n");
4861     return E_NOTIMPL;
4862 }
4863 
4864 static HRESULT WINAPI WebBrowser_put_Silent(IWebBrowser2 *iface, VARIANT_BOOL bSilent)
4865 {
4866     ok(0, "unexpected call\n");
4867     return E_NOTIMPL;
4868 }
4869 
4870 static HRESULT WINAPI WebBrowser_get_RegisterAsBrowser(IWebBrowser2 *iface,
4871         VARIANT_BOOL *pbRegister)
4872 {
4873     ok(0, "unexpected call\n");
4874     return E_NOTIMPL;
4875 }
4876 
4877 static HRESULT WINAPI WebBrowser_put_RegisterAsBrowser(IWebBrowser2 *iface,
4878         VARIANT_BOOL bRegister)
4879 {
4880     ok(0, "unexpected call\n");
4881     return E_NOTIMPL;
4882 }
4883 
4884 static HRESULT WINAPI WebBrowser_get_RegisterAsDropTarget(IWebBrowser2 *iface,
4885         VARIANT_BOOL *pbRegister)
4886 {
4887     ok(0, "unexpected call\n");
4888     return E_NOTIMPL;
4889 }
4890 
4891 static HRESULT WINAPI WebBrowser_put_RegisterAsDropTarget(IWebBrowser2 *iface,
4892         VARIANT_BOOL bRegister)
4893 {
4894     ok(0, "unexpected call\n");
4895     return E_NOTIMPL;
4896 }
4897 
4898 static HRESULT WINAPI WebBrowser_get_TheaterMode(IWebBrowser2 *iface, VARIANT_BOOL *pbRegister)
4899 {
4900     ok(0, "unexpected call\n");
4901     return E_NOTIMPL;
4902 }
4903 
4904 static HRESULT WINAPI WebBrowser_put_TheaterMode(IWebBrowser2 *iface, VARIANT_BOOL bRegister)
4905 {
4906     ok(0, "unexpected call\n");
4907     return E_NOTIMPL;
4908 }
4909 
4910 static HRESULT WINAPI WebBrowser_get_AddressBar(IWebBrowser2 *iface, VARIANT_BOOL *Value)
4911 {
4912     trace("get_AddressBar: ignoring\n"); /* Some old IEs call it */
4913     return E_NOTIMPL;
4914 }
4915 
4916 static HRESULT WINAPI WebBrowser_put_AddressBar(IWebBrowser2 *iface, VARIANT_BOOL Value)
4917 {
4918     ok(0, "unexpected call\n");
4919     return E_NOTIMPL;
4920 }
4921 
4922 static HRESULT WINAPI WebBrowser_get_Resizable(IWebBrowser2 *iface, VARIANT_BOOL *Value)
4923 {
4924     ok(0, "unexpected call\n");
4925     return E_NOTIMPL;
4926 }
4927 
4928 static HRESULT WINAPI WebBrowser_put_Resizable(IWebBrowser2 *iface, VARIANT_BOOL Value)
4929 {
4930     ok(0, "unexpected call\n");
4931     return E_NOTIMPL;
4932 }
4933 
4934 static const IWebBrowser2Vtbl WebBrowser2Vtbl =
4935 {
4936     WebBrowser_QueryInterface,
4937     WebBrowser_AddRef,
4938     WebBrowser_Release,
4939     WebBrowser_GetTypeInfoCount,
4940     WebBrowser_GetTypeInfo,
4941     WebBrowser_GetIDsOfNames,
4942     WebBrowser_Invoke,
4943     WebBrowser_GoBack,
4944     WebBrowser_GoForward,
4945     WebBrowser_GoHome,
4946     WebBrowser_GoSearch,
4947     WebBrowser_Navigate,
4948     WebBrowser_Refresh,
4949     WebBrowser_Refresh2,
4950     WebBrowser_Stop,
4951     WebBrowser_get_Application,
4952     WebBrowser_get_Parent,
4953     WebBrowser_get_Container,
4954     WebBrowser_get_Document,
4955     WebBrowser_get_TopLevelContainer,
4956     WebBrowser_get_Type,
4957     WebBrowser_get_Left,
4958     WebBrowser_put_Left,
4959     WebBrowser_get_Top,
4960     WebBrowser_put_Top,
4961     WebBrowser_get_Width,
4962     WebBrowser_put_Width,
4963     WebBrowser_get_Height,
4964     WebBrowser_put_Height,
4965     WebBrowser_get_LocationName,
4966     WebBrowser_get_LocationURL,
4967     WebBrowser_get_Busy,
4968     WebBrowser_Quit,
4969     WebBrowser_ClientToWindow,
4970     WebBrowser_PutProperty,
4971     WebBrowser_GetProperty,
4972     WebBrowser_get_Name,
4973     WebBrowser_get_HWND,
4974     WebBrowser_get_FullName,
4975     WebBrowser_get_Path,
4976     WebBrowser_get_Visible,
4977     WebBrowser_put_Visible,
4978     WebBrowser_get_StatusBar,
4979     WebBrowser_put_StatusBar,
4980     WebBrowser_get_StatusText,
4981     WebBrowser_put_StatusText,
4982     WebBrowser_get_ToolBar,
4983     WebBrowser_put_ToolBar,
4984     WebBrowser_get_MenuBar,
4985     WebBrowser_put_MenuBar,
4986     WebBrowser_get_FullScreen,
4987     WebBrowser_put_FullScreen,
4988     WebBrowser_Navigate2,
4989     WebBrowser_QueryStatusWB,
4990     WebBrowser_ExecWB,
4991     WebBrowser_ShowBrowserBar,
4992     WebBrowser_get_ReadyState,
4993     WebBrowser_get_Offline,
4994     WebBrowser_put_Offline,
4995     WebBrowser_get_Silent,
4996     WebBrowser_put_Silent,
4997     WebBrowser_get_RegisterAsBrowser,
4998     WebBrowser_put_RegisterAsBrowser,
4999     WebBrowser_get_RegisterAsDropTarget,
5000     WebBrowser_put_RegisterAsDropTarget,
5001     WebBrowser_get_TheaterMode,
5002     WebBrowser_put_TheaterMode,
5003     WebBrowser_get_AddressBar,
5004     WebBrowser_put_AddressBar,
5005     WebBrowser_get_Resizable,
5006     WebBrowser_put_Resizable
5007 };
5008 
5009 static IWebBrowser2 WebBrowser2 = { &WebBrowser2Vtbl };
5010 
5011 static HRESULT wb_qi(REFIID riid, void **ppv)
5012 {
5013     static const IID IID_IWebBrowserPriv2IE7 = {0x1af32b6c, 0xa3ba,0x48b9,{0xb2,0x4e,0x8a,0xa9,0xc4,0x1f,0x6e,0xcd}};
5014     static const IID IID_IWebBrowserPriv2IE8XP = {0x486f6159,0x9f3f,0x4827,{0x82,0xd4,0x28,0x3c,0xef,0x39,0x77,0x33}};
5015 
5016     *ppv = NULL;
5017 
5018     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IWebBrowser, riid)
5019             || IsEqualGUID(&IID_IWebBrowserApp, riid) || IsEqualGUID(&IID_IWebBrowser2, riid)) {
5020         *ppv = &WebBrowser2;
5021         return S_OK;
5022     }
5023 
5024     if(IsEqualGUID(riid, &IID_IOleObject))
5025         return E_NOINTERFACE; /* TODO */
5026 
5027     if(IsEqualGUID(riid, &IID_IConnectionPointContainer)) {
5028         *ppv = &ConnectionPointContainer;
5029         return S_OK;
5030     }
5031 
5032     if(IsEqualGUID(riid, &IID_IWebBrowserPriv)) {
5033         *ppv = &WebBrowserPriv;
5034         return S_OK;
5035     }
5036 
5037     if(IsEqualGUID(riid, &IID_IWebBrowserPriv2IE8)) {
5038         /* IE8 and IE9 versions use the same IID, but have different declarations. */
5039         *ppv = is_ie9plus ? (void*)&WebBrowserPriv2IE9 : (void*)&WebBrowserPriv2IE8;
5040         return S_OK;
5041     }
5042 
5043     if(IsEqualGUID(riid, &IID_IWebBrowserPriv2IE7)) {
5044         trace("QI(IID_IWebBrowserPriv2IE7)\n");
5045         return E_NOINTERFACE;
5046     }
5047 
5048     if(IsEqualGUID(riid, &IID_IWebBrowserPriv2IE8XP)) {
5049         trace("QI(IID_IWebBrowserPriv2IE8XP)\n");
5050         return E_NOINTERFACE;
5051     }
5052 
5053     ok(0, "unexpected call %s\n", wine_dbgstr_guid(riid));
5054     return E_NOINTERFACE;
5055 }
5056 
5057 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface,
5058                                                      REFIID riid, void **ppv)
5059 {
5060     return QueryInterface(riid, ppv);
5061 }
5062 
5063 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
5064 {
5065     return 2;
5066 }
5067 
5068 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
5069 {
5070     return 1;
5071 }
5072 
5073 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService,
5074                                     REFIID riid, void **ppv)
5075 {
5076     /*
5077      * Services used by HTMLDocument:
5078      *
5079      * IOleUndoManager
5080      * IInternetSecurityManager
5081      * ITargetFrame
5082      * {D5F78C80-5252-11CF-90FA-00AA0042106E}
5083      * HTMLFrameBase
5084      * IShellObject
5085      * {3050F312-98B5-11CF-BB82-00AA00BDCE0B}
5086      * {53A2D5B1-D2FC-11D0-84E0-006097C9987D}
5087      * {AD7F6C62-F6BD-11D2-959B-006097C553C8}
5088      * DefView (?)
5089      * {6D12FE80-7911-11CF-9534-0000C05BAE0B}
5090      * IElementBehaviorFactory
5091      * {3050F429-98B5-11CF-BB82-00AA00BDCE0B}
5092      * STopLevelBrowser
5093      * IHTMLWindow2
5094      * IInternetProtocol
5095      * UrlHostory
5096      * IHTMLEditHost
5097      * IHlinkFrame
5098      */
5099 
5100     if(IsEqualGUID(&IID_IHlinkFrame, guidService)) {
5101         ok(IsEqualGUID(&IID_IHlinkFrame, riid), "unexpected riid\n");
5102         *ppv = &HlinkFrame;
5103         return S_OK;
5104     }
5105 
5106     if(IsEqualGUID(&SID_SNewWindowManager, guidService)) {
5107         ok(IsEqualGUID(&IID_INewWindowManager, riid), "unexpected riid\n");
5108         *ppv = &NewWindowManager;
5109         return S_OK;
5110     }
5111 
5112     if(IsEqualGUID(&IID_IShellBrowser, guidService)) {
5113         ok(IsEqualGUID(&IID_IBrowserService, riid), "unexpected riid\n");
5114         *ppv = &BrowserService;
5115         return S_OK;
5116     }
5117 
5118     if(support_wbapp && IsEqualGUID(&IID_IWebBrowserApp, guidService)) {
5119         if(IsEqualGUID(riid, &IID_IWebBrowser2)) {
5120             *ppv = &WebBrowser2;
5121             return S_OK;
5122         }
5123         ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
5124     }
5125 
5126     return E_NOINTERFACE;
5127 }
5128 
5129 static const IServiceProviderVtbl ServiceProviderVtbl = {
5130     ServiceProvider_QueryInterface,
5131     ServiceProvider_AddRef,
5132     ServiceProvider_Release,
5133     ServiceProvider_QueryService
5134 };
5135 
5136 static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };
5137 
5138 static HRESULT WINAPI AdviseSink_QueryInterface(IAdviseSinkEx *iface,
5139         REFIID riid, void **ppv)
5140 {
5141     return QueryInterface(riid, ppv);
5142 }
5143 
5144 static ULONG WINAPI AdviseSink_AddRef(IAdviseSinkEx *iface)
5145 {
5146     return 2;
5147 }
5148 
5149 static ULONG WINAPI AdviseSink_Release(IAdviseSinkEx *iface)
5150 {
5151     return 1;
5152 }
5153 
5154 static void WINAPI AdviseSink_OnDataChange(IAdviseSinkEx *iface,
5155         FORMATETC *pFormatetc, STGMEDIUM *pStgmed)
5156 {
5157     ok(0, "unexpected call\n");
5158 }
5159 
5160 static void WINAPI AdviseSink_OnViewChange(IAdviseSinkEx *iface,
5161         DWORD dwAspect, LONG lindex)
5162 {
5163     ok(0, "unexpected call\n");
5164 }
5165 
5166 static void WINAPI AdviseSink_OnRename(IAdviseSinkEx *iface, IMoniker *pmk)
5167 {
5168     ok(0, "unexpected call\n");
5169 }
5170 
5171 static void WINAPI AdviseSink_OnSave(IAdviseSinkEx *iface)
5172 {
5173     ok(0, "unexpected call\n");
5174 }
5175 
5176 static void WINAPI AdviseSink_OnClose(IAdviseSinkEx *iface)
5177 {
5178     ok(0, "unexpected call\n");
5179 }
5180 
5181 static void WINAPI AdviseSinkEx_OnViewStatusChange(IAdviseSinkEx *iface, DWORD dwViewStatus)
5182 {
5183     ok(0, "unexpected call\n");
5184 }
5185 
5186 static void WINAPI ObjectAdviseSink_OnClose(IAdviseSinkEx *iface)
5187 {
5188     CHECK_EXPECT(Advise_Close);
5189 }
5190 
5191 static const IAdviseSinkExVtbl AdviseSinkVtbl = {
5192     AdviseSink_QueryInterface,
5193     AdviseSink_AddRef,
5194     AdviseSink_Release,
5195     AdviseSink_OnDataChange,
5196     AdviseSink_OnViewChange,
5197     AdviseSink_OnRename,
5198     AdviseSink_OnSave,
5199     ObjectAdviseSink_OnClose,
5200     AdviseSinkEx_OnViewStatusChange
5201 };
5202 
5203 static IAdviseSinkEx AdviseSink = { &AdviseSinkVtbl };
5204 
5205 static HRESULT WINAPI ViewAdviseSink_QueryInterface(IAdviseSinkEx *iface,
5206         REFIID riid, void **ppv)
5207 {
5208     if(IsEqualGUID(&IID_IAdviseSinkEx, riid)) {
5209         *ppv = iface;
5210         return S_OK;
5211     }
5212 
5213     ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid));
5214     *ppv = NULL;
5215     return E_NOINTERFACE;
5216 }
5217 
5218 static void WINAPI ViewAdviseSink_OnViewChange(IAdviseSinkEx *iface,
5219         DWORD dwAspect, LONG lindex)
5220 {
5221     CHECK_EXPECT2(OnViewChange);
5222 
5223     ok(dwAspect == DVASPECT_CONTENT, "dwAspect = %d\n", dwAspect);
5224     ok(lindex == -1, "lindex = %d\n", lindex);
5225 }
5226 
5227 static const IAdviseSinkExVtbl ViewAdviseSinkVtbl = {
5228     ViewAdviseSink_QueryInterface,
5229     AdviseSink_AddRef,
5230     AdviseSink_Release,
5231     AdviseSink_OnDataChange,
5232     ViewAdviseSink_OnViewChange,
5233     AdviseSink_OnRename,
5234     AdviseSink_OnSave,
5235     AdviseSink_OnClose,
5236     AdviseSinkEx_OnViewStatusChange
5237 };
5238 
5239 static IAdviseSinkEx ViewAdviseSink = { &ViewAdviseSinkVtbl };
5240 
5241 DEFINE_GUID(IID_unk1, 0xD48A6EC6,0x6A4A,0x11CF,0x94,0xA7,0x44,0x45,0x53,0x54,0x00,0x00); /* HTMLWindow2 ? */
5242 DEFINE_GUID(IID_IThumbnailView, 0x7BB0B520,0xB1A7,0x11D2,0xBB,0x23,0x00,0xC0,0x4F,0x79,0xAB,0xCD);
5243 DEFINE_GUID(IID_IRenMailEditor, 0x000670BA,0x0000,0x0000,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
5244 DEFINE_GUID(IID_unk4, 0x305104a6,0x98b5,0x11cf,0xbb,0x82,0x00,0xaa,0x00,0xbd,0xce,0x0b);
5245 DEFINE_GUID(IID_IDocHostUIHandlerPriv, 0xf0d241d1,0x5d0e,0x4e85,0xbc,0xb4,0xfa,0xd7,0xf7,0xc5,0x52,0x8c);
5246 DEFINE_GUID(IID_unk5, 0x5f95accc,0xd7a1,0x4574,0xbc,0xcb,0x69,0x71,0x35,0xbc,0x41,0xde);
5247 
5248 static HRESULT QueryInterface(REFIID riid, void **ppv)
5249 {
5250     *ppv = NULL;
5251 
5252     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
5253         *ppv = &ClientSite;
5254     else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
5255         *ppv = &DocumentSite;
5256     else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
5257         *ppv = &DocHostUIHandler;
5258     else if(IsEqualGUID(&IID_IOleContainer, riid))
5259         *ppv = &OleContainer;
5260     else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
5261         *ppv = &InPlaceSiteWindowless;
5262     else if(IsEqualGUID(&IID_IOleCommandTarget , riid))
5263         *ppv = &OleCommandTarget;
5264     else if(IsEqualGUID(&IID_IDispatch, riid))
5265         *ppv = &Dispatch;
5266     else if(IsEqualGUID(&IID_IServiceProvider, riid))
5267         *ppv = &ServiceProvider;
5268     else if(IsEqualGUID(&IID_IOleInPlaceSiteEx, riid))
5269         *ppv = ipsex ? &InPlaceSiteWindowless : NULL;
5270     else if(IsEqualGUID(&IID_IOleInPlaceSiteWindowless, riid))
5271         *ppv = ipsw ? &InPlaceSiteWindowless : NULL;
5272     else if(IsEqualGUID(&IID_IOleControlSite, riid))
5273         *ppv = &OleControlSite;
5274     else if(IsEqualGUID(&IID_IDocHostShowUI, riid))
5275         return E_NOINTERFACE; /* TODO */
5276     else if(IsEqualGUID(&IID_IProxyManager, riid))
5277         return E_NOINTERFACE; /* ? */
5278     else if(IsEqualGUID(&IID_unk1, riid))
5279         return E_NOINTERFACE; /* HTMLWindow2 ? */
5280     else if(IsEqualGUID(&IID_IThumbnailView, riid))
5281         return E_NOINTERFACE; /* ? */
5282     else if(IsEqualGUID(&IID_IRenMailEditor, riid))
5283         return E_NOINTERFACE; /* ? */
5284     else if(IsEqualGUID(&IID_unk4, riid))
5285         return E_NOINTERFACE; /* ? */
5286     else if(IsEqualGUID(&IID_unk5, riid))
5287         return E_NOINTERFACE; /* IE10 */
5288     else if(IsEqualGUID(&IID_IDocHostUIHandlerPriv, riid))
5289         return E_NOINTERFACE; /* ? */
5290     else
5291         trace("QI(%s)\n", wine_dbgstr_guid(riid));
5292 
5293     if(*ppv)
5294         return S_OK;
5295     return E_NOINTERFACE;
5296 }
5297 
5298 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
5299 {
5300     if(msg == WM_CONTINUE_BINDING) {
5301         IBindStatusCallback *callback = (IBindStatusCallback*)wParam;
5302         continue_binding(callback);
5303     }
5304 
5305     return DefWindowProcW(hwnd, msg, wParam, lParam);
5306 }
5307 
5308 static void test_doscroll(IUnknown *unk)
5309 {
5310     IHTMLDocument3 *doc;
5311     IHTMLElement2 *elem2;
5312     IHTMLElement *elem;
5313     VARIANT v;
5314     HRESULT hres;
5315 
5316     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument3, (void**)&doc);
5317     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
5318     if(FAILED(hres))
5319         return;
5320 
5321     hres = IHTMLDocument3_get_documentElement(doc, &elem);
5322     IHTMLDocument3_Release(doc);
5323     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
5324     switch(load_state) {
5325     case LD_DOLOAD:
5326     case LD_NO:
5327         if(!nav_url && !editmode)
5328             ok(!elem, "elem != NULL\n");
5329     default:
5330         break;
5331     case LD_INTERACTIVE:
5332     case LD_COMPLETE:
5333         ok(elem != NULL, "elem == NULL\n");
5334     }
5335     if(!elem)
5336         return;
5337 
5338     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLElement2, (void**)&elem2);
5339     IHTMLElement_Release(elem);
5340     ok(hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
5341 
5342     V_VT(&v) = VT_BSTR;
5343     V_BSTR(&v) = a2bstr("left");
5344     hres = IHTMLElement2_doScroll(elem2, v);
5345     SysFreeString(V_BSTR(&v));
5346     IHTMLElement2_Release(elem2);
5347 
5348     if(inplace_deactivated)
5349         ok(hres == E_PENDING, "doScroll failed: %08x\n", hres);
5350     else if(load_state == LD_COMPLETE)
5351         ok(hres == S_OK, "doScroll failed: %08x\n", hres);
5352     else
5353         ok(hres == E_PENDING || hres == S_OK, "doScroll failed: %08x\n", hres);
5354 }
5355 
5356 static void _test_readyState(unsigned line, IUnknown *unk)
5357 {
5358     IHTMLDocument2 *htmldoc;
5359     DISPPARAMS dispparams;
5360     IHTMLElement *elem;
5361     BSTR state;
5362     VARIANT out;
5363     HRESULT hres;
5364 
5365     static const LPCSTR expected_state[] = {
5366         "uninitialized",
5367         "loading",
5368         NULL,
5369         "interactive",
5370         "complete",
5371         "uninitialized"
5372     };
5373 
5374     if(open_call || resetting_document)
5375         return; /* FIXME */
5376 
5377     if(!unk)
5378         unk = doc_unk;
5379 
5380     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&htmldoc);
5381     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument2) failed: %08x\n", hres);
5382     if(FAILED(hres))
5383         return;
5384 
5385     hres = IHTMLDocument2_get_readyState(htmldoc, NULL);
5386     ok(hres == E_POINTER, "get_readyState failed: %08x, expected\n", hres);
5387 
5388     hres = IHTMLDocument2_get_readyState(htmldoc, &state);
5389     ok(hres == S_OK, "get_ReadyState failed: %08x\n", hres);
5390 
5391     if(!strcmp_wa(state, "interactive") && load_state == LD_LOADING)
5392         load_state = LD_INTERACTIVE;
5393 
5394     ok_(__FILE__, line)
5395         (!strcmp_wa(state, expected_state[load_state]), "unexpected state %s, expected %d\n",
5396          wine_dbgstr_w(state), load_state);
5397     SysFreeString(state);
5398 
5399     hres = IHTMLDocument2_get_body(htmldoc, &elem);
5400     ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
5401     if(elem) {
5402         IHTMLElement2 *elem2;
5403         VARIANT var;
5404 
5405         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLElement2, (void**)&elem2);
5406         IHTMLElement_Release(elem);
5407         ok(hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
5408 
5409         hres = IHTMLElement2_get_readyState(elem2, &var);
5410         IHTMLElement2_Release(elem2);
5411         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
5412         ok(V_VT(&var) == VT_BSTR, "V_VT(state) = %d\n", V_VT(&var));
5413         ok(!strcmp_wa(V_BSTR(&var), "complete"), "unexpected body state %s\n", wine_dbgstr_w(V_BSTR(&var)));
5414         VariantClear(&var);
5415     }else {
5416         ok_(__FILE__,line)(load_state != LD_COMPLETE, "body is NULL in complete state\n");
5417     }
5418 
5419     dispparams.cArgs = 0;
5420     dispparams.cNamedArgs = 0;
5421     dispparams.rgdispidNamedArgs = NULL;
5422     dispparams.rgvarg = NULL;
5423 
5424     VariantInit(&out);
5425 
5426     hres = IHTMLDocument2_Invoke(htmldoc, DISPID_READYSTATE, &IID_NULL, 0, DISPATCH_PROPERTYGET,
5427                                  &dispparams, &out, NULL, NULL);
5428     ok(hres == S_OK, "Invoke(DISPID_READYSTATE) failed: %08x\n", hres);
5429 
5430     ok_(__FILE__,line) (V_VT(&out) == VT_I4, "V_VT(out)=%d\n", V_VT(&out));
5431     ok_(__FILE__,line) (V_I4(&out) == load_state%5, "VT_I4(out)=%d, expected %d\n", V_I4(&out), load_state%5);
5432 
5433     test_doscroll((IUnknown*)htmldoc);
5434 
5435     IHTMLDocument2_Release(htmldoc);
5436 }
5437 
5438 static void test_ViewAdviseSink(IHTMLDocument2 *doc)
5439 {
5440     IViewObject *view;
5441     HRESULT hres;
5442 
5443     hres = IHTMLDocument2_QueryInterface(doc, &IID_IViewObject, (void**)&view);
5444     ok(hres == S_OK, "QueryInterface(IID_IViewObject) failed: %08x\n", hres);
5445 
5446     hres = IViewObject_SetAdvise(view, DVASPECT_CONTENT, ADVF_PRIMEFIRST, (IAdviseSink*)&ViewAdviseSink);
5447     ok(hres == S_OK, "SetAdvise failed: %08x\n", hres);
5448 
5449     IViewObject_Release(view);
5450 }
5451 
5452 static void test_ConnectionPoint(IConnectionPointContainer *container, REFIID riid)
5453 {
5454     IConnectionPointContainer *tmp_container = NULL;
5455     IConnectionPoint *cp;
5456     IID iid;
5457     HRESULT hres;
5458     DWORD cookie;
5459 
5460     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
5461     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
5462     if(FAILED(hres))
5463         return;
5464 
5465     hres = IConnectionPoint_GetConnectionInterface(cp, &iid);
5466     ok(hres == S_OK, "GetConnectionInterface failed: %08x\n", hres);
5467     ok(IsEqualGUID(riid, &iid), "wrong iid\n");
5468 
5469     hres = IConnectionPoint_GetConnectionInterface(cp, NULL);
5470     ok(hres == E_POINTER, "GetConnectionInterface failed: %08x, expected E_POINTER\n", hres);
5471 
5472     hres = IConnectionPoint_GetConnectionPointContainer(cp, &tmp_container);
5473     ok(hres == S_OK, "GetConnectionPointContainer failed: %08x\n", hres);
5474     ok(tmp_container == container, "container != tmp_container\n");
5475     if(SUCCEEDED(hres))
5476         IConnectionPointContainer_Release(tmp_container);
5477 
5478     hres = IConnectionPoint_GetConnectionPointContainer(cp, NULL);
5479     ok(hres == E_POINTER, "GetConnectionPointContainer failed: %08x, expected E_POINTER\n", hres);
5480 
5481     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
5482         hres = IConnectionPoint_Advise(cp, (IUnknown*)&PropertyNotifySink, &cookie);
5483         ok(hres == S_OK, "Advise failed: %08x\n", hres);
5484         hres = IConnectionPoint_Unadvise(cp, cookie);
5485         ok(hres == S_OK, "Unadvise failed: %08x\n", hres);
5486         hres = IConnectionPoint_Advise(cp, (IUnknown*)&PropertyNotifySink, NULL);
5487         ok(hres == S_OK, "Advise failed: %08x\n", hres);
5488     } else if(IsEqualGUID(&IID_IDispatch, riid)) {
5489         IEnumConnections *enum_conn;
5490         CONNECTDATA conn_data;
5491         ULONG fetched;
5492 
5493         hres = IConnectionPoint_Advise(cp, (IUnknown*)&EventDispatch, &cookie);
5494         ok(hres == S_OK, "Advise failed: %08x\n", hres);
5495 
5496         hres = IConnectionPoint_EnumConnections(cp, &enum_conn);
5497         ok(hres == S_OK, "EnumConnections failed: %08x\n", hres);
5498 
5499         fetched = 0;
5500         hres = IEnumConnections_Next(enum_conn, 1, &conn_data, &fetched);
5501         ok(hres == S_OK, "Next failed: %08x\n", hres);
5502         ok(conn_data.pUnk == (IUnknown*)&EventDispatch, "conn_data.pUnk == EventDispatch\n");
5503         ok(conn_data.dwCookie == cookie, "conn_data.dwCookie != cookie\n");
5504         IUnknown_Release(conn_data.pUnk);
5505 
5506         fetched = 0xdeadbeef;
5507         hres = IEnumConnections_Next(enum_conn, 1, &conn_data, &fetched);
5508         ok(hres == S_FALSE, "Next failed: %08x\n", hres);
5509         ok(!fetched, "fetched = %d\n", fetched);
5510 
5511         IEnumConnections_Release(enum_conn);
5512     }
5513 
5514     IConnectionPoint_Release(cp);
5515 }
5516 
5517 static void test_ConnectionPointContainer(IHTMLDocument2 *doc)
5518 {
5519     IConnectionPointContainer *container;
5520     HRESULT hres;
5521 
5522     hres = IHTMLDocument2_QueryInterface(doc, &IID_IConnectionPointContainer, (void**)&container);
5523     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
5524     if(FAILED(hres))
5525         return;
5526 
5527     test_ConnectionPoint(container, &IID_IDispatch);
5528     test_ConnectionPoint(container, &IID_IPropertyNotifySink);
5529     test_ConnectionPoint(container, &DIID_HTMLDocumentEvents);
5530     test_ConnectionPoint(container, &DIID_HTMLDocumentEvents2);
5531 
5532     IConnectionPointContainer_Release(container);
5533 }
5534 
5535 static void set_custom_uihandler(IHTMLDocument2 *doc, IDocHostUIHandler2 *uihandler)
5536 {
5537     ICustomDoc *custom_doc;
5538     HRESULT hres;
5539 
5540     hres = IHTMLDocument2_QueryInterface(doc, &IID_ICustomDoc, (void**)&custom_doc);
5541     ok(hres == S_OK, "Could not get ICustomDoc iface: %08x\n", hres);
5542 
5543     expect_uihandler_iface = uihandler;
5544 
5545     hres = ICustomDoc_SetUIHandler(custom_doc, (IDocHostUIHandler*)uihandler);
5546     ICustomDoc_Release(custom_doc);
5547     ok(hres == S_OK, "SetUIHandler failed: %08x\n", hres);
5548 }
5549 
5550 static void test_Load(IPersistMoniker *persist, IMoniker *mon)
5551 {
5552     IBindCtx *bind;
5553     HRESULT hres;
5554     WCHAR sz_html_clientsite_objectparam[MAX_PATH];
5555 
5556     lstrcpyW(sz_html_clientsite_objectparam, SZ_HTML_CLIENTSITE_OBJECTPARAM);
5557 
5558     test_readyState((IUnknown*)persist);
5559 
5560     doc_mon = mon;
5561 
5562     CreateBindCtx(0, &bind);
5563     IBindCtx_RegisterObjectParam(bind, sz_html_clientsite_objectparam,
5564                                  (IUnknown*)&ClientSite);
5565 
5566     if(mon == &Moniker)
5567         SET_EXPECT(GetDisplayName);
5568     if(!set_clientsite) {
5569         SET_EXPECT(Invoke_AMBIENT_USERMODE);
5570         SET_EXPECT(GetHostInfo);
5571         SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
5572         SET_EXPECT(Invoke_AMBIENT_SILENT);
5573         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
5574         SET_EXPECT(Invoke_AMBIENT_USERAGENT);
5575         SET_EXPECT(Invoke_AMBIENT_PALETTE);
5576         SET_EXPECT(GetOptionKeyPath);
5577         SET_EXPECT(GetOverrideKeyPath);
5578         SET_EXPECT(GetWindow);
5579         SET_EXPECT(Exec_DOCCANNAVIGATE);
5580         SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
5581         SET_EXPECT(Exec_SETPROGRESSMAX);
5582         SET_EXPECT(Exec_SETPROGRESSPOS);
5583         SET_EXPECT(Exec_ShellDocView_37);
5584     }
5585     if(!container_locked) {
5586         SET_EXPECT(GetContainer);
5587         SET_EXPECT(LockContainer);
5588     }
5589     SET_EXPECT(OnChanged_READYSTATE);
5590     SET_EXPECT(Invoke_OnReadyStateChange_Loading);
5591     SET_EXPECT(IsSystemMoniker);
5592     if(mon == &Moniker)
5593         SET_EXPECT(BindToStorage);
5594     SET_EXPECT(SetActiveObject);
5595     if(set_clientsite) {
5596         SET_EXPECT(Invoke_AMBIENT_SILENT);
5597         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
5598         SET_EXPECT(Exec_ShellDocView_37);
5599         SET_EXPECT(IsErrorUrl);
5600     }else {
5601         SET_EXPECT(GetTravelLog);
5602     }
5603     SET_EXPECT(Exec_ShellDocView_84);
5604     SET_EXPECT(GetPendingUrl);
5605     load_state = LD_DOLOAD;
5606     expect_LockContainer_fLock = TRUE;
5607     readystate_set_loading = TRUE;
5608 
5609     hres = IPersistMoniker_Load(persist, FALSE, mon, bind, 0x12);
5610     ok(hres == S_OK, "Load failed: %08x\n", hres);
5611 
5612     if(mon == &Moniker)
5613         CHECK_CALLED(GetDisplayName);
5614     if(!set_clientsite) {
5615         CHECK_CALLED(Invoke_AMBIENT_USERMODE);
5616         CHECK_CALLED(GetHostInfo);
5617         CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
5618         CHECK_CALLED(Invoke_AMBIENT_SILENT);
5619         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
5620         CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
5621         CLEAR_CALLED(Invoke_AMBIENT_PALETTE); /* not called on IE9 */
5622         CLEAR_CALLED(GetOptionKeyPath); /* not called on some IE9 */
5623         CHECK_CALLED(GetOverrideKeyPath);
5624         CHECK_CALLED(GetWindow);
5625         CHECK_CALLED(Exec_DOCCANNAVIGATE);
5626         CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
5627         CHECK_CALLED(Exec_SETPROGRESSMAX);
5628         CHECK_CALLED(Exec_SETPROGRESSPOS);
5629         CHECK_CALLED(Exec_ShellDocView_37);
5630     }
5631     if(!container_locked) {
5632         CHECK_CALLED(GetContainer);
5633         CHECK_CALLED(LockContainer);
5634         container_locked = TRUE;
5635     }
5636     CHECK_CALLED(OnChanged_READYSTATE);
5637     CHECK_CALLED(Invoke_OnReadyStateChange_Loading);
5638     CLEAR_CALLED(IsSystemMoniker); /* IE7 */
5639     if(mon == &Moniker)
5640         CHECK_CALLED(BindToStorage);
5641     CLEAR_CALLED(SetActiveObject); /* FIXME */
5642     if(set_clientsite) {
5643         CHECK_CALLED(Invoke_AMBIENT_SILENT);
5644         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
5645         CHECK_CALLED(Exec_ShellDocView_37);
5646         todo_wine CHECK_CALLED_BROKEN(IsErrorUrl);
5647     }else {
5648         CHECK_CALLED(GetTravelLog);
5649     }
5650     CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
5651     todo_wine CHECK_CALLED(GetPendingUrl);
5652 
5653     set_clientsite = container_locked = TRUE;
5654 
5655     test_GetCurMoniker((IUnknown*)persist, mon, NULL, FALSE);
5656 
5657     IBindCtx_Release(bind);
5658 
5659     test_readyState((IUnknown*)persist);
5660 }
5661 
5662 #define DWL_VERBDONE           0x0001
5663 #define DWL_CSS                0x0002
5664 #define DWL_TRYCSS             0x0004
5665 #define DWL_HTTP               0x0008
5666 #define DWL_EMPTY              0x0010
5667 #define DWL_JAVASCRIPT         0x0020
5668 #define DWL_ONREADY_LOADING    0x0040
5669 #define DWL_EXPECT_HISTUPDATE  0x0080
5670 #define DWL_FROM_HISTORY       0x0100
5671 #define DWL_REFRESH            0x0200
5672 #define DWL_EX_GETHOSTINFO     0x0400
5673 #define DWL_EXTERNAL           0x0800
5674 
5675 static void test_download(DWORD flags)
5676 {
5677     const BOOL is_extern = (flags & DWL_EXTERNAL) != 0;
5678     const BOOL is_js = (flags & DWL_JAVASCRIPT) != 0;
5679     HWND hwnd;
5680     BOOL *b;
5681     MSG msg;
5682 
5683     if(is_js)
5684         b = &called_Exec_SETDOWNLOADSTATE_0;
5685     else if(is_extern)
5686         b = &called_NavigateWithBindCtx;
5687     else
5688         b = &called_Exec_HTTPEQUIV_DONE;
5689     is_refresh = (flags & DWL_REFRESH) != 0;
5690 
5691     hwnd = FindWindowA("Internet Explorer_Hidden", NULL);
5692     ok(hwnd != NULL, "Could not find hidden window\n");
5693 
5694     test_readyState(NULL);
5695 
5696     if(flags & DWL_REFRESH) {
5697         SET_EXPECT(Invoke_AMBIENT_SILENT);
5698         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
5699     }
5700     if(flags & (DWL_VERBDONE|DWL_HTTP))
5701         SET_EXPECT(Exec_SETPROGRESSMAX);
5702     if(flags & DWL_EX_GETHOSTINFO)
5703         SET_EXPECT(GetHostInfo);
5704     SET_EXPECT(SetStatusText);
5705     if(!(flags & DWL_EMPTY))
5706         SET_EXPECT(Exec_SETDOWNLOADSTATE_1);
5707     if(is_js)
5708         SET_EXPECT(GetExternal);
5709     SET_EXPECT(OnViewChange);
5710     SET_EXPECT(GetDropTarget);
5711     if((flags & DWL_TRYCSS) && !(flags & DWL_EMPTY))
5712         SET_EXPECT(Exec_ShellDocView_84);
5713     if(flags & DWL_CSS) {
5714         SET_EXPECT(CreateInstance);
5715         SET_EXPECT(Start);
5716         SET_EXPECT(LockRequest);
5717         SET_EXPECT(Terminate);
5718         SET_EXPECT(Protocol_Read);
5719         SET_EXPECT(UnlockRequest);
5720     }
5721     if(flags & DWL_ONREADY_LOADING)
5722         SET_EXPECT(Invoke_OnReadyStateChange_Loading);
5723     if(!(flags & (DWL_EMPTY|DWL_JAVASCRIPT)))
5724         SET_EXPECT(Invoke_OnReadyStateChange_Interactive);
5725     if(!is_js && !is_extern)
5726         SET_EXPECT(Invoke_OnReadyStateChange_Complete);
5727     SET_EXPECT(Exec_Explorer_69);
5728     SET_EXPECT(EnableModeless_TRUE); /* IE7 */
5729     SET_EXPECT(Frame_EnableModeless_TRUE); /* IE7 */
5730     SET_EXPECT(EnableModeless_FALSE); /* IE7 */
5731     SET_EXPECT(Frame_EnableModeless_FALSE); /* IE7 */
5732     if((nav_url && !is_js && !is_extern) || (flags & (DWL_CSS|DWL_HTTP)))
5733         SET_EXPECT(Exec_ShellDocView_37);
5734     if(flags & DWL_HTTP) {
5735         if(!(flags & DWL_FROM_HISTORY))
5736             SET_EXPECT(OnChanged_1012);
5737         SET_EXPECT(Exec_HTTPEQUIV);
5738         SET_EXPECT(Exec_SETTITLE);
5739     }
5740     if(!is_js && !is_extern)
5741         SET_EXPECT(OnChanged_1005);
5742     SET_EXPECT(OnChanged_READYSTATE);
5743     SET_EXPECT(Exec_SETPROGRESSPOS);
5744     if(!(flags & DWL_EMPTY))
5745         SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
5746     SET_EXPECT(Exec_ShellDocView_103);
5747     SET_EXPECT(Exec_ShellDocView_105);
5748     SET_EXPECT(Exec_ShellDocView_140);
5749     if(!is_js && !is_extern) {
5750         SET_EXPECT(Exec_MSHTML_PARSECOMPLETE);
5751         if(support_wbapp) /* Called on some Vista installations */
5752             SET_EXPECT(CountEntries);
5753         SET_EXPECT(Exec_HTTPEQUIV_DONE);
5754     }
5755     if(nav_url || support_wbapp) {
5756         SET_EXPECT(UpdateUI);
5757         SET_EXPECT(Exec_UPDATECOMMANDS);
5758         SET_EXPECT(Exec_SETTITLE);
5759         if(flags & DWL_EXPECT_HISTUPDATE)
5760             SET_EXPECT(Exec_Explorer_38);
5761         SET_EXPECT(UpdateBackForwardState);
5762     }
5763     if(!is_js && !is_extern) {
5764         if(!editmode && !(flags & DWL_REFRESH)) {
5765             if(!(flags & DWL_EMPTY))
5766                 SET_EXPECT(FireNavigateComplete2);
5767             SET_EXPECT(FireDocumentComplete);
5768         }
5769         SET_EXPECT(ActiveElementChanged);
5770     }
5771     SET_EXPECT(IsErrorUrl);
5772     if(is_extern) {
5773         SET_EXPECT(Exec_ShellDocView_62);
5774         SET_EXPECT(Exec_DOCCANNAVIGATE_NULL);
5775         SET_EXPECT(NavigateWithBindCtx);
5776         SET_EXPECT(Exec_Explorer_38); /* todo_wine */
5777     }
5778     if(editmode || is_refresh)
5779         SET_EXPECT(Exec_ShellDocView_138);
5780     expect_status_text = (LPWSTR)0xdeadbeef; /* TODO */
5781 
5782     while(!*b && GetMessageW(&msg, NULL, 0, 0)) {
5783         TranslateMessage(&msg);
5784         DispatchMessageA(&msg);
5785     }
5786 
5787     if(flags & DWL_REFRESH) {
5788         CHECK_CALLED(Invoke_AMBIENT_SILENT);
5789         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
5790     }
5791     if(flags & DWL_VERBDONE)
5792         CHECK_CALLED(Exec_SETPROGRESSMAX);
5793     if(flags & DWL_HTTP)
5794         SET_CALLED(Exec_SETPROGRESSMAX);
5795     if(flags &  DWL_EX_GETHOSTINFO) {
5796         if(nav_url)
5797             todo_wine CHECK_CALLED(GetHostInfo);
5798         else
5799             CHECK_CALLED(GetHostInfo);
5800     }
5801     CHECK_CALLED(SetStatusText);
5802     if(!(flags & DWL_EMPTY))
5803         CHECK_CALLED(Exec_SETDOWNLOADSTATE_1);
5804     if(is_js)
5805         CHECK_CALLED(GetExternal);
5806     CHECK_CALLED(OnViewChange);
5807     CLEAR_CALLED(GetDropTarget);
5808     if((flags & DWL_TRYCSS) && !(flags & DWL_EMPTY))
5809         todo_wine CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
5810     if(flags & DWL_CSS) {
5811         CHECK_CALLED(CreateInstance);
5812         CHECK_CALLED(Start);
5813         CHECK_CALLED(LockRequest);
5814         CHECK_CALLED(Terminate);
5815         CHECK_CALLED(Protocol_Read);
5816         CHECK_CALLED(UnlockRequest);
5817     }
5818     if(flags & DWL_ONREADY_LOADING)
5819         CHECK_CALLED(Invoke_OnReadyStateChange_Loading);
5820     if(!(flags & (DWL_EMPTY|DWL_JAVASCRIPT))) {
5821         if(!is_extern)
5822             CHECK_CALLED(Invoke_OnReadyStateChange_Interactive);
5823         else
5824             todo_wine CHECK_CALLED(Invoke_OnReadyStateChange_Interactive);
5825     }
5826     if(!is_js && !is_extern)
5827         CHECK_CALLED(Invoke_OnReadyStateChange_Complete);
5828     SET_CALLED(Exec_Explorer_69);
5829     SET_CALLED(EnableModeless_TRUE); /* IE7 */
5830     SET_CALLED(Frame_EnableModeless_TRUE); /* IE7 */
5831     SET_CALLED(EnableModeless_FALSE); /* IE7 */
5832     SET_CALLED(Frame_EnableModeless_FALSE); /* IE7 */
5833     if(nav_url && !is_js && !is_extern && !(flags & DWL_REFRESH))
5834         todo_wine CHECK_CALLED(Exec_ShellDocView_37);
5835     else if(flags & (DWL_CSS|DWL_HTTP))
5836         CLEAR_CALLED(Exec_ShellDocView_37); /* Called by IE9 */
5837     if(flags & DWL_HTTP)  {
5838         if(!(flags & DWL_FROM_HISTORY))
5839             todo_wine CHECK_CALLED(OnChanged_1012);
5840         todo_wine CHECK_CALLED(Exec_HTTPEQUIV);
5841         if(!(flags & DWL_REFRESH))
5842             todo_wine CHECK_CALLED(Exec_SETTITLE);
5843         else
5844             CHECK_CALLED(Exec_SETTITLE);
5845     }
5846     if(!is_js) {
5847         if(!is_extern)
5848             CHECK_CALLED(OnChanged_1005);
5849         CHECK_CALLED(OnChanged_READYSTATE);
5850         CHECK_CALLED(Exec_SETPROGRESSPOS);
5851     }else {
5852         CLEAR_CALLED(OnChanged_READYSTATE); /* sometimes called */
5853         todo_wine CHECK_CALLED(Exec_SETPROGRESSPOS);
5854     }
5855     if(!(flags & DWL_EMPTY)) {
5856         if(!is_extern)
5857             CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
5858         else
5859             todo_wine CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
5860     }
5861     CLEAR_CALLED(Exec_ShellDocView_103);
5862     CLEAR_CALLED(Exec_ShellDocView_105);
5863     CLEAR_CALLED(Exec_ShellDocView_140);
5864     if(!is_js && !is_extern) {
5865         CHECK_CALLED(Exec_MSHTML_PARSECOMPLETE);
5866         if(support_wbapp) /* Called on some Vista installations */
5867             CLEAR_CALLED(CountEntries);
5868         CHECK_CALLED(Exec_HTTPEQUIV_DONE);
5869     }
5870     SET_CALLED(SetStatusText);
5871     if(nav_url || support_wbapp) { /* avoiding race, FIXME: find better way */
5872         CLEAR_CALLED(UpdateUI);
5873         CLEAR_CALLED(Exec_UPDATECOMMANDS);
5874         CLEAR_CALLED(Exec_SETTITLE);
5875         if(flags & DWL_EXPECT_HISTUPDATE) {
5876             if(flags & DWL_FROM_HISTORY)
5877                 CHECK_CALLED_BROKEN(Exec_Explorer_38); /* Some old IEs don't call it. */
5878             else
5879                 CHECK_CALLED(Exec_Explorer_38);
5880         }
5881         todo_wine CHECK_CALLED_BROKEN(UpdateBackForwardState);
5882     }
5883     if(!is_js && !is_extern) {
5884         if(!editmode && !(flags & DWL_REFRESH)) {
5885             if(!(flags & DWL_EMPTY)) {
5886                 if(support_wbapp)
5887                     CHECK_CALLED(FireNavigateComplete2);
5888                 else
5889                     todo_wine CHECK_CALLED(FireNavigateComplete2);
5890             }
5891             CHECK_CALLED(FireDocumentComplete);
5892         }
5893         todo_wine CHECK_CALLED(ActiveElementChanged);
5894     }
5895     todo_wine CHECK_CALLED_BROKEN(IsErrorUrl);
5896     if(is_extern) {
5897         CHECK_CALLED(Exec_ShellDocView_62);
5898         CHECK_CALLED(Exec_DOCCANNAVIGATE_NULL);
5899         CHECK_CALLED(NavigateWithBindCtx);
5900         todo_wine CHECK_NOT_CALLED(Exec_Explorer_38);
5901     }
5902     if(editmode || is_refresh)
5903         CLEAR_CALLED(Exec_ShellDocView_138); /* IE11 */
5904 
5905     if(!is_extern)
5906         load_state = LD_COMPLETE;
5907 
5908     test_readyState(NULL);
5909 }
5910 
5911 static void test_Persist(IHTMLDocument2 *doc, IMoniker *mon)
5912 {
5913     IPersistMoniker *persist_mon;
5914     IPersistFile *persist_file;
5915     GUID guid;
5916     HRESULT hres;
5917 
5918     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistFile, (void**)&persist_file);
5919     ok(hres == S_OK, "QueryInterface(IID_IPersist) failed: %08x\n", hres);
5920     if(SUCCEEDED(hres)) {
5921         hres = IPersistFile_GetClassID(persist_file, NULL);
5922         ok(hres == E_INVALIDARG, "GetClassID returned: %08x, expected E_INVALIDARG\n", hres);
5923 
5924         hres = IPersistFile_GetClassID(persist_file, &guid);
5925         ok(hres == S_OK, "GetClassID failed: %08x\n", hres);
5926         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
5927 
5928         IPersistFile_Release(persist_file);
5929     }
5930 
5931     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker, (void**)&persist_mon);
5932     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker) failed: %08x\n", hres);
5933     if(SUCCEEDED(hres)) {
5934         hres = IPersistMoniker_GetClassID(persist_mon, NULL);
5935         ok(hres == E_INVALIDARG, "GetClassID returned: %08x, expected E_INVALIDARG\n", hres);
5936 
5937         hres = IPersistMoniker_GetClassID(persist_mon, &guid);
5938         ok(hres == S_OK, "GetClassID failed: %08x\n", hres);
5939         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
5940 
5941         if(load_state == LD_DOLOAD)
5942             test_Load(persist_mon, mon);
5943 
5944         test_readyState((IUnknown*)doc);
5945 
5946         IPersistMoniker_Release(persist_mon);
5947     }
5948 }
5949 
5950 static void test_put_hash(IHTMLDocument2 *doc, const char *new_hash)
5951 {
5952     static char nav_url_buff[256];
5953     IHTMLLocation *location;
5954     BSTR str;
5955     char *psharp;
5956     HRESULT hres;
5957 
5958     trace("put_hash, url = %s, new hash = %s\n", nav_url, new_hash);
5959 
5960     location = NULL;
5961     hres = IHTMLDocument2_get_location(doc, &location);
5962     ok(hres == S_OK, "get_location failed: %08x\n", hres);
5963     ok(location != NULL, "location == NULL\n");
5964 
5965     SET_EXPECT(TranslateUrl);
5966     SET_EXPECT(Exec_ShellDocView_67);
5967     SET_EXPECT(FireBeforeNavigate2);
5968     SET_EXPECT(FireDocumentComplete);
5969     SET_EXPECT(FireNavigateComplete2);
5970 
5971     /* Edit nav_url */
5972     strcpy(nav_url_buff, nav_url);
5973     psharp = strchr(nav_url_buff, '#');
5974     if (psharp)
5975         *psharp = '\0';
5976     strcat(nav_url_buff, new_hash);
5977     nav_url = nav_url_buff;
5978 
5979     str = a2bstr(new_hash);
5980     hres = IHTMLLocation_put_hash(location, str);
5981     ok (hres == S_OK, "put_hash failed: %08x\n", hres);
5982     SysFreeString(str);
5983 
5984     CHECK_CALLED(TranslateUrl);
5985     CHECK_CALLED_BROKEN(Exec_ShellDocView_67); /* Broken on Win7 and 8 */
5986     CHECK_CALLED(FireBeforeNavigate2);
5987     CHECK_CALLED(FireDocumentComplete);
5988     CHECK_CALLED(FireNavigateComplete2);
5989 
5990 
5991     /* Check the result */
5992     hres = IHTMLLocation_get_hash(location, &str);
5993     ok(hres == S_OK, "get_hash failed: %08x\n", hres);
5994     ok(!strcmp_wa(str, new_hash), "expected %s, got %s\n", new_hash, wine_dbgstr_w(str));
5995     SysFreeString(str);
5996 
5997     IHTMLLocation_Release(location);
5998 }
5999 
6000 static void test_put_href(IHTMLDocument2 *doc, BOOL use_replace, const char *href, const char *new_nav_url, BOOL is_js,
6001         BOOL is_hash, DWORD dwl_flags)
6002 {
6003     const char *prev_nav_url = NULL;
6004     IHTMLPrivateWindow *priv_window;
6005     IHTMLLocation *location;
6006     IHTMLWindow2 *window;
6007     BSTR str, str2;
6008     HRESULT hres;
6009 
6010     trace("put_href %s...\n", new_nav_url);
6011 
6012     loading_js = is_js;
6013     loading_hash = is_hash;
6014 
6015     location = NULL;
6016     hres = IHTMLDocument2_get_location(doc, &location);
6017     ok(hres == S_OK, "get_location failed: %08x\n", hres);
6018     ok(location != NULL, "location == NULL\n");
6019 
6020     prev_url = prev_nav_url = nav_url;
6021     nav_url = new_nav_url;
6022     if(!loading_hash)
6023         nav_serv_url = new_nav_url;
6024     if(!href)
6025         href = new_nav_url;
6026 
6027     str = a2bstr(href);
6028     SET_EXPECT(TranslateUrl);
6029     if(support_wbapp) {
6030         SET_EXPECT(FireBeforeNavigate2);
6031         SET_EXPECT(Exec_ShellDocView_67);
6032         if(!is_hash) {
6033             SET_EXPECT(Invoke_AMBIENT_SILENT);
6034             SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6035             SET_EXPECT(Exec_ShellDocView_63);
6036             SET_EXPECT(Exec_ShellDocView_84);
6037         }else {
6038             SET_EXPECT(FireNavigateComplete2);
6039             SET_EXPECT(FireDocumentComplete);
6040         }
6041     }else {
6042         SET_EXPECT(Navigate);
6043     }
6044     if(use_replace) {
6045         hres = IHTMLLocation_replace(location, str);
6046         ok(hres == S_OK, "put_href failed: %08x\n", hres);
6047     }else {
6048         hres = IHTMLLocation_put_href(location, str);
6049         if(is_js && hres == E_ACCESSDENIED)
6050             win_skip("put_href: got E_ACCESSDENIED\n");
6051         else
6052             ok(hres == S_OK, "put_href failed: %08x\n", hres);
6053     }
6054     SysFreeString(str);
6055     if(hres == S_OK) {
6056         CHECK_CALLED(TranslateUrl);
6057         if(support_wbapp) {
6058             CHECK_CALLED(FireBeforeNavigate2);
6059             CLEAR_CALLED(Exec_ShellDocView_67); /* Not called by IE11 */
6060             if(!is_hash) {
6061                 CHECK_CALLED(Invoke_AMBIENT_SILENT);
6062                 CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6063                 CHECK_CALLED(Exec_ShellDocView_63);
6064                 CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
6065             }else {
6066                 CHECK_CALLED(FireNavigateComplete2);
6067                 CHECK_CALLED(FireDocumentComplete);
6068             }
6069         }else {
6070             CHECK_CALLED(Navigate);
6071         }
6072     }else {
6073         CLEAR_CALLED(TranslateUrl);
6074         if(support_wbapp) {
6075             CLEAR_CALLED(FireBeforeNavigate2);
6076             SET_CALLED(Exec_ShellDocView_67);
6077             if(!is_hash) {
6078                 CLEAR_CALLED(Invoke_AMBIENT_SILENT);
6079                 CLEAR_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6080                 CLEAR_CALLED(Exec_ShellDocView_63);
6081                 todo_wine CLEAR_CALLED(Exec_ShellDocView_84);
6082             }else {
6083                 CLEAR_CALLED(FireNavigateComplete2);
6084                 CLEAR_CALLED(FireDocumentComplete);
6085             }
6086         }else {
6087             CLEAR_CALLED(Navigate);
6088         }
6089     }
6090 
6091     IHTMLLocation_Release(location);
6092 
6093     if(is_js && hres == E_ACCESSDENIED) {
6094         nav_url = prev_nav_url;
6095         return;
6096     }
6097 
6098     hres = IHTMLDocument2_get_parentWindow(doc, &window);
6099     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
6100 
6101     hres = IHTMLWindow2_QueryInterface(window, &IID_IHTMLPrivateWindow, (void**)&priv_window);
6102     IHTMLWindow2_Release(window);
6103     ok(hres == S_OK, "QueryInterface(IID_IHTMLPrivateWindow) failed: %08x\n", hres);
6104 
6105     if(!support_wbapp) {
6106         VARIANT vempty;
6107 
6108         readystate_set_loading = TRUE;
6109         SET_EXPECT(TranslateUrl);
6110         SET_EXPECT(Exec_ShellDocView_67);
6111         SET_EXPECT(Invoke_AMBIENT_SILENT);
6112         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6113         SET_EXPECT(Exec_ShellDocView_63);
6114         SET_EXPECT(Exec_ShellDocView_84);
6115 
6116         str = a2bstr(nav_url);
6117         str2 = a2bstr("");
6118         V_VT(&vempty) = VT_EMPTY;
6119         hres = IHTMLPrivateWindow_SuperNavigate(priv_window, str, str2, NULL, NULL, &vempty, &vempty, 0);
6120         SysFreeString(str);
6121         SysFreeString(str2);
6122         ok(hres == S_OK, "SuperNavigate failed: %08x\n", hres);
6123 
6124         CHECK_CALLED(TranslateUrl);
6125         CLEAR_CALLED(Exec_ShellDocView_67); /* Not called by IE11 */
6126         CHECK_CALLED(Invoke_AMBIENT_SILENT);
6127         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6128         CHECK_CALLED(Exec_ShellDocView_63);
6129         CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
6130     }
6131 
6132     if(doc_mon) {
6133         test_GetCurMoniker(doc_unk, doc_mon, NULL, FALSE);
6134         doc_mon = NULL;
6135     }
6136 
6137     if(!is_hash) {
6138         hres = IHTMLPrivateWindow_GetAddressBarUrl(priv_window, &str2);
6139         ok(hres == S_OK, "GetAddressBarUrl failed: %08x\n", hres);
6140         ok(!strcmp_wa(str2, prev_nav_url), "unexpected address bar url:  %s, expected %s\n", wine_dbgstr_w(str2), prev_nav_url);
6141         SysFreeString(str2);
6142 
6143         if(is_js) {
6144             ignore_external_qi = TRUE;
6145             dwl_flags |= DWL_JAVASCRIPT;
6146         }else {
6147             if(!(dwl_flags & DWL_EXTERNAL))
6148                 dwl_flags |= DWL_EX_GETHOSTINFO;
6149             dwl_flags |= DWL_ONREADY_LOADING;
6150         }
6151         test_download(DWL_VERBDONE | dwl_flags);
6152         if(is_js)
6153             ignore_external_qi = FALSE;
6154 
6155     }
6156 
6157     hres = IHTMLPrivateWindow_GetAddressBarUrl(priv_window, &str2);
6158     ok(hres == S_OK, "GetAddressBarUrl failed: %08x\n", hres);
6159     if(is_js)
6160         ok(!strcmp_wa(str2, prev_nav_url), "unexpected address bar url:  %s\n", wine_dbgstr_w(str2));
6161     else if (dwl_flags & DWL_EXTERNAL)
6162         todo_wine ok(!strcmp_wa(str2, prev_nav_url), "unexpected address bar url:  %s\n", wine_dbgstr_w(str2));
6163     else
6164         ok(!strcmp_wa(str2, nav_url), "unexpected address bar url:  %s\n", wine_dbgstr_w(str2));
6165     SysFreeString(str2);
6166     IHTMLPrivateWindow_Release(priv_window);
6167 
6168     loading_js = FALSE;
6169     if(is_js)
6170         nav_url = prev_nav_url;
6171 }
6172 
6173 static void test_load_history(IHTMLDocument2 *doc)
6174 {
6175     IPersistHistory *per_hist;
6176     HRESULT hres;
6177 
6178     trace("LoadHistory...\n");
6179 
6180     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistHistory, (void**)&per_hist);
6181     ok(hres == S_OK, "Could not get IPersistHistory iface: %08x\n", hres);
6182 
6183     prev_url = nav_url;
6184     nav_url = "http://test.winehq.org/tests/winehq_snapshot/#hash_test";
6185     nav_serv_url = "http://test.winehq.org/tests/winehq_snapshot/";
6186 
6187     SET_EXPECT(Exec_ShellDocView_138);
6188     SET_EXPECT(Exec_ShellDocView_67);
6189     SET_EXPECT(FireBeforeNavigate2);
6190     SET_EXPECT(Invoke_AMBIENT_SILENT);
6191     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6192 
6193     hres = IPersistHistory_LoadHistory(per_hist, history_stream, NULL);
6194     ok(hres == S_OK, "LoadHistory failed: %08x\n", hres);
6195 
6196     CLEAR_CALLED(Exec_ShellDocView_138); /* Not called by IE11 */
6197     CLEAR_CALLED(Exec_ShellDocView_67); /* Not called by IE11 */
6198     CHECK_CALLED(FireBeforeNavigate2);
6199     CHECK_CALLED(Invoke_AMBIENT_SILENT);
6200     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6201 
6202     load_state = LD_LOADING;
6203     test_timer(EXPECT_UPDATEUI|EXPECT_SETTITLE);
6204 
6205     test_download(DWL_VERBDONE|DWL_HTTP|DWL_EXPECT_HISTUPDATE|DWL_ONREADY_LOADING|DWL_FROM_HISTORY|DWL_EX_GETHOSTINFO);
6206 
6207     IPersistHistory_Release(per_hist);
6208     IStream_Release(history_stream);
6209     history_stream = NULL;
6210 }
6211 
6212 static void test_OmHistory(IHTMLDocument2 *doc)
6213 {
6214     IHTMLWindow2 *win;
6215     IOmHistory *hist;
6216     short len;
6217     HRESULT hres;
6218 
6219     hres = IHTMLDocument2_get_parentWindow(doc, &win);
6220     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
6221 
6222     hres = IHTMLWindow2_get_history(win, &hist);
6223     ok(hres == S_OK, "get_history failed: %08x\n", hres);
6224     IHTMLWindow2_Release(win);
6225 
6226     SET_EXPECT(CountEntries);
6227     hres = IOmHistory_get_length(hist, &len);
6228     CHECK_CALLED(CountEntries);
6229     ok(hres == S_OK, "get_length failed: %08x\n", hres);
6230     ok(len == 0, "len = %d\n", len);
6231 
6232     IOmHistory_Release(hist);
6233 }
6234 
6235 static void test_refresh(IHTMLDocument2 *doc)
6236 {
6237     IOleCommandTarget *cmdtrg;
6238     VARIANT vin, vout;
6239     HRESULT hres;
6240 
6241     trace("Refresh...\n");
6242 
6243     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleCommandTarget, (void**)&cmdtrg);
6244     ok(hres == S_OK, "Could not get IOleCommandTarget iface: %08x\n", hres);
6245 
6246     V_VT(&vin) = VT_EMPTY;
6247     V_VT(&vout) = VT_EMPTY;
6248     SET_EXPECT(Exec_DocHostCommandHandler_2300);
6249     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_REFRESH, OLECMDEXECOPT_PROMPTUSER, &vin, &vout);
6250     ok(hres == S_OK, "Exec failed: %08x\n", hres);
6251     ok(V_VT(&vout) == VT_EMPTY, "V_VT(vout) = %d\n", V_VT(&vout));
6252     CHECK_CALLED(Exec_DocHostCommandHandler_2300);
6253 
6254     IOleCommandTarget_Release(cmdtrg);
6255 
6256     test_download(DWL_VERBDONE|DWL_HTTP|DWL_ONREADY_LOADING|DWL_REFRESH|DWL_EX_GETHOSTINFO);
6257 }
6258 
6259 static void test_open_window(IHTMLDocument2 *doc, BOOL do_block)
6260 {
6261     IHTMLWindow2 *window, *new_window;
6262     BSTR name, url;
6263     HRESULT hres;
6264 
6265     allow_new_window = !do_block;
6266 
6267     hres = IHTMLDocument2_get_parentWindow(doc, &window);
6268     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
6269 
6270     url = a2bstr(nav_serv_url = nav_url = "about:blank");
6271     name = a2bstr("test");
6272     new_window = (void*)0xdeadbeef;
6273 
6274     trace("open...\n");
6275     open_call = TRUE;
6276 
6277     if(support_wbapp)
6278         SET_EXPECT(get_LocationURL);
6279     SET_EXPECT(TranslateUrl);
6280     SET_EXPECT(EvaluateNewWindow);
6281 
6282     hres = IHTMLWindow2_open(window, url, name, NULL, VARIANT_FALSE, &new_window);
6283     open_call = FALSE;
6284     SysFreeString(url);
6285     SysFreeString(name);
6286 
6287     if(support_wbapp)
6288         todo_wine CHECK_CALLED_BROKEN(get_LocationURL);
6289     todo_wine
6290     CHECK_CALLED(TranslateUrl);
6291 
6292     if(!called_EvaluateNewWindow) {
6293         win_skip("INewWindowManager not supported\n");
6294         if(SUCCEEDED(hres) && new_window)
6295             IHTMLWindow2_Release(new_window);
6296         IHTMLWindow2_Release(window);
6297         return;
6298     }
6299     CHECK_CALLED(EvaluateNewWindow);
6300 
6301     ok(hres == S_OK, "open failed: %08x\n", hres);
6302 
6303     if(do_block) {
6304         ok(!new_window, "new_window != NULL\n");
6305     }else {
6306         ok(new_window != NULL, "new_window == NULL\n");
6307 
6308         hres = IHTMLWindow2_close(new_window);
6309         ok(hres == S_OK, "close failed: %08x\n", hres);
6310         IHTMLWindow2_Release(new_window);
6311     }
6312 
6313     IHTMLWindow2_Release(window);
6314 }
6315 
6316 static void test_window_close(IHTMLDocument2 *doc)
6317 {
6318     IHTMLWindow2 *window;
6319     HRESULT hres;
6320 
6321     hres = IHTMLDocument2_get_parentWindow(doc, &window);
6322     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
6323 
6324     SET_EXPECT(FindConnectionPoint);
6325     SET_EXPECT(EnumConnections);
6326     SET_EXPECT(EnumConnections_Next);
6327     SET_EXPECT(WindowClosing);
6328 
6329     hres = IHTMLWindow2_close(window);
6330     ok(hres == S_OK, "close failed: %08x\n", hres);
6331 
6332     CHECK_CALLED(FindConnectionPoint);
6333     CHECK_CALLED(EnumConnections);
6334     CHECK_CALLED(EnumConnections_Next);
6335     CHECK_CALLED(WindowClosing);
6336 
6337     IHTMLWindow2_Release(window);
6338 }
6339 
6340 static void test_elem_from_point(IHTMLDocument2 *doc)
6341 {
6342     IHTMLElement *elem;
6343     BSTR tag;
6344     HRESULT hres;
6345 
6346     elem = NULL;
6347     hres = IHTMLDocument2_elementFromPoint(doc, 3, 3, &elem);
6348     ok(hres == S_OK, "elementFromPoint failed: %08x\n", hres);
6349     ok(elem != NULL, "elem == NULL\n");
6350 
6351     hres = IHTMLElement_get_tagName(elem, &tag);
6352     IHTMLElement_Release(elem);
6353     ok(hres == S_OK, "get_tagName failed: %08x\n", hres);
6354     ok(!strcmp_wa(tag, "DIV"), "tag = %s\n", wine_dbgstr_w(tag));
6355 }
6356 
6357 static void test_clear(IHTMLDocument2 *doc)
6358 {
6359     HRESULT hres;
6360 
6361     hres = IHTMLDocument2_clear(doc);
6362     ok(hres == S_OK, "clear failed: %08x\n", hres);
6363 }
6364 
6365 static const OLECMDF expect_cmds[] = {
6366     0,
6367     OLECMDF_SUPPORTED,                  /* OLECMDID_OPEN */
6368     OLECMDF_SUPPORTED,                  /* OLECMDID_NEW */
6369     OLECMDF_SUPPORTED,                  /* OLECMDID_SAVE */
6370     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_SAVEAS */
6371     OLECMDF_SUPPORTED,                  /* OLECMDID_SAVECOPYAS */
6372     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PRINT */
6373     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PRINTPREVIEW */
6374     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PAGESETUP */
6375     OLECMDF_SUPPORTED,                  /* OLECMDID_SPELL */
6376     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PROPERTIES */
6377     OLECMDF_SUPPORTED,                  /* OLECMDID_CUT */
6378     OLECMDF_SUPPORTED,                  /* OLECMDID_COPY */
6379     OLECMDF_SUPPORTED,                  /* OLECMDID_PASTE */
6380     OLECMDF_SUPPORTED,                  /* OLECMDID_PASTESPECIAL */
6381     OLECMDF_SUPPORTED,                  /* OLECMDID_UNDO */
6382     OLECMDF_SUPPORTED,                  /* OLECMDID_REDO */
6383     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_SELECTALL */
6384     OLECMDF_SUPPORTED,                  /* OLECMDID_CLEARSELECTION */
6385     OLECMDF_SUPPORTED,                  /* OLECMDID_ZOOM */
6386     OLECMDF_SUPPORTED,                  /* OLECMDID_GETZOOMRANGE */
6387     0,
6388     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_REFRESH */
6389     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_STOP */
6390     0,0,0,0,0,0,
6391     OLECMDF_SUPPORTED,                  /* OLECMDID_STOPDOWNLOAD */
6392     0,0,
6393     OLECMDF_SUPPORTED,                  /* OLECMDID_DELETE */
6394     0,0,
6395     OLECMDF_SUPPORTED,                  /* OLECMDID_ENABLE_INTERACTION */
6396     OLECMDF_SUPPORTED,                  /* OLECMDID_ONUNLOAD */
6397     0,0,0,0,0,
6398     OLECMDF_SUPPORTED,                  /* OLECMDID_SHOWPAGESETUP */
6399     OLECMDF_SUPPORTED,                  /* OLECMDID_SHOWPRINT */
6400     0,0,
6401     OLECMDF_SUPPORTED,                  /* OLECMDID_CLOSE */
6402     0,0,0,
6403     OLECMDF_SUPPORTED,                  /* OLECMDID_SETPRINTTEMPLATE */
6404     OLECMDF_SUPPORTED                   /* OLECMDID_GETPRINTTEMPLATE */
6405 };
6406 
6407 #define test_QueryStatus(u,cgid,cmdid,cmdf) _test_QueryStatus(__LINE__,u,cgid,cmdid,cmdf)
6408 static void _test_QueryStatus(unsigned line, IUnknown *unk, REFIID cgid, ULONG cmdid, DWORD cmdf)
6409 {
6410     IOleCommandTarget *cmdtrg;
6411     OLECMD olecmd = {cmdid, 0};
6412     HRESULT hres;
6413 
6414     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
6415     ok_(__FILE__,line) (hres == S_OK, "QueryInterface(IID_IOleCommandTarget failed: %08x\n", hres);
6416     if(FAILED(hres))
6417         return;
6418 
6419     hres = IOleCommandTarget_QueryStatus(cmdtrg, cgid, 1, &olecmd, NULL);
6420     ok(hres == cmdf ? S_OK : OLECMDERR_E_NOTSUPPORTED, "QueryStatus(%u) failed: %08x\n", cmdid, hres);
6421 
6422     IOleCommandTarget_Release(cmdtrg);
6423 
6424     ok_(__FILE__,line) (olecmd.cmdID == cmdid, "cmdID changed\n");
6425     ok_(__FILE__,line) (olecmd.cmdf == cmdf, "(%u) cmdf=%08x, expected %08x\n", cmdid, olecmd.cmdf, cmdf);
6426 }
6427 
6428 static void test_MSHTML_QueryStatus(IHTMLDocument2 *doc, DWORD cmdf)
6429 {
6430     IUnknown *unk = doc ? (IUnknown*)doc : doc_unk;
6431 
6432     test_QueryStatus(unk, &CGID_MSHTML, IDM_FONTNAME, cmdf);
6433     test_QueryStatus(unk, &CGID_MSHTML, IDM_FONTSIZE, cmdf);
6434     test_QueryStatus(unk, &CGID_MSHTML, IDM_SELECTALL, cmdf|OLECMDF_ENABLED);
6435     test_QueryStatus(unk, &CGID_MSHTML, IDM_BOLD, cmdf);
6436     test_QueryStatus(unk, &CGID_MSHTML, IDM_FORECOLOR, cmdf);
6437     test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYCENTER, cmdf);
6438     test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYLEFT, cmdf);
6439     test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYRIGHT, cmdf);
6440     test_QueryStatus(unk, &CGID_MSHTML, IDM_ITALIC, cmdf);
6441     test_QueryStatus(unk, &CGID_MSHTML, IDM_UNDERLINE, cmdf);
6442     test_QueryStatus(unk, &CGID_MSHTML, IDM_HORIZONTALLINE, cmdf);
6443     test_QueryStatus(unk, &CGID_MSHTML, IDM_ORDERLIST, cmdf);
6444     test_QueryStatus(unk, &CGID_MSHTML, IDM_UNORDERLIST, cmdf);
6445     test_QueryStatus(unk, &CGID_MSHTML, IDM_INDENT, cmdf);
6446     test_QueryStatus(unk, &CGID_MSHTML, IDM_OUTDENT, cmdf);
6447     test_QueryStatus(unk, &CGID_MSHTML, IDM_DELETE, cmdf);
6448 }
6449 
6450 static void test_OleCommandTarget(IHTMLDocument2 *doc)
6451 {
6452     IOleCommandTarget *cmdtrg;
6453     OLECMD cmds[sizeof(expect_cmds)/sizeof(*expect_cmds)-1];
6454     int i;
6455     HRESULT hres;
6456 
6457     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleCommandTarget, (void**)&cmdtrg);
6458     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget failed: %08x\n", hres);
6459     if(FAILED(hres))
6460         return;
6461 
6462     for(i=0; i < sizeof(cmds)/sizeof(*cmds); i++) {
6463         cmds[i].cmdID = i+1;
6464         cmds[i].cmdf = 0xf0f0;
6465     }
6466 
6467     SET_EXPECT(QueryStatus_OPEN);
6468     SET_EXPECT(QueryStatus_NEW);
6469     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, sizeof(cmds)/sizeof(cmds[0]), cmds, NULL);
6470     ok(hres == S_OK, "QueryStatus failed: %08x\n", hres);
6471     CHECK_CALLED(QueryStatus_OPEN);
6472     CHECK_CALLED(QueryStatus_NEW);
6473 
6474     for(i=0; i < sizeof(cmds)/sizeof(*cmds); i++) {
6475         ok(cmds[i].cmdID == i+1, "cmds[%d].cmdID canged to %x\n", i, cmds[i].cmdID);
6476         if(i+1 == OLECMDID_FIND)
6477             continue;
6478         ok(cmds[i].cmdf == expect_cmds[i+1], "cmds[%d].cmdf=%x, expected %x\n",
6479                 i+1, cmds[i].cmdf, expect_cmds[i+1]);
6480     }
6481 
6482     ok(!cmds[OLECMDID_FIND-1].cmdf || cmds[OLECMDID_FIND-1].cmdf == (OLECMDF_SUPPORTED|OLECMDF_ENABLED),
6483        "cmds[OLECMDID_FIND].cmdf=%x\n", cmds[OLECMDID_FIND-1].cmdf);
6484 
6485     IOleCommandTarget_Release(cmdtrg);
6486 }
6487 
6488 static void test_OleCommandTarget_fail(IHTMLDocument2 *doc)
6489 {
6490     IOleCommandTarget *cmdtrg;
6491     int i;
6492     HRESULT hres;
6493 
6494     OLECMD cmd[2] = {
6495         {OLECMDID_OPEN, 0xf0f0},
6496         {OLECMDID_GETPRINTTEMPLATE+1, 0xf0f0}
6497     };
6498 
6499     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleCommandTarget, (void**)&cmdtrg);
6500     ok(hres == S_OK, "QueryInterface(IIDIOleCommandTarget failed: %08x\n", hres);
6501     if(FAILED(hres))
6502         return;
6503 
6504     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 0, NULL, NULL);
6505     ok(hres == S_OK, "QueryStatus failed: %08x\n", hres);
6506 
6507     SET_EXPECT(QueryStatus_OPEN);
6508     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 2, cmd, NULL);
6509     CHECK_CALLED(QueryStatus_OPEN);
6510 
6511     ok(hres == OLECMDERR_E_NOTSUPPORTED,
6512             "QueryStatus failed: %08x, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
6513     ok(cmd[1].cmdID == OLECMDID_GETPRINTTEMPLATE+1,
6514             "cmd[0].cmdID=%d, expected OLECMDID_GETPRINTTEMPLATE+1\n", cmd[0].cmdID);
6515     ok(cmd[1].cmdf == 0, "cmd[0].cmdf=%x, expected 0\n", cmd[0].cmdf);
6516     ok(cmd[0].cmdf == OLECMDF_SUPPORTED,
6517             "cmd[1].cmdf=%x, expected OLECMDF_SUPPORTED\n", cmd[1].cmdf);
6518 
6519     hres = IOleCommandTarget_QueryStatus(cmdtrg, &IID_IHTMLDocument2, 2, cmd, NULL);
6520     ok(hres == OLECMDERR_E_UNKNOWNGROUP,
6521             "QueryStatus failed: %08x, expected OLECMDERR_E_UNKNOWNGROUP\n", hres);
6522 
6523     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
6524         if(!expect_cmds[i]) {
6525             hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS,
6526                     OLECMDEXECOPT_DODEFAULT, NULL, NULL);
6527             ok(hres == OLECMDERR_E_NOTSUPPORTED,
6528                     "Exec failed: %08x, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
6529         }
6530     }
6531 
6532     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_GETPRINTTEMPLATE+1,
6533             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
6534     ok(hres == OLECMDERR_E_NOTSUPPORTED,
6535             "Exec failed: %08x, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
6536 
6537     IOleCommandTarget_Release(cmdtrg);
6538 }
6539 
6540 static void test_exec_onunload(IHTMLDocument2 *doc)
6541 {
6542     IOleCommandTarget *cmdtrg;
6543     VARIANT var;
6544     HRESULT hres;
6545 
6546     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleCommandTarget, (void**)&cmdtrg);
6547     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
6548     if(FAILED(hres))
6549         return;
6550 
6551     memset(&var, 0x0a, sizeof(var));
6552     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_ONUNLOAD,
6553             OLECMDEXECOPT_DODEFAULT, NULL, &var);
6554     ok(hres == S_OK, "Exec(..., OLECMDID_ONUNLOAD, ...) failed: %08x\n", hres);
6555     ok(V_VT(&var) == VT_BOOL, "V_VT(var)=%d, expected VT_BOOL\n", V_VT(&var));
6556     ok(V_BOOL(&var) == VARIANT_TRUE, "V_BOOL(var)=%x, expected VARIANT_TRUE\n", V_BOOL(&var));
6557 
6558     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_ONUNLOAD,
6559             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
6560     ok(hres == S_OK, "Exec(..., OLECMDID_ONUNLOAD, ...) failed: %08x\n", hres);
6561 
6562     IOleCommandTarget_Release(cmdtrg);
6563 }
6564 
6565 static void test_exec_editmode(IUnknown *unk, BOOL loaded)
6566 {
6567     IOleCommandTarget *cmdtrg;
6568     HRESULT hres;
6569 
6570     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
6571     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
6572     if(FAILED(hres))
6573         return;
6574 
6575     editmode = TRUE;
6576 
6577     if(loaded) {
6578         load_state = LD_DOLOAD;
6579         SET_EXPECT(GetClassID);
6580     }
6581     SET_EXPECT(SetStatusText);
6582     SET_EXPECT(Exec_ShellDocView_37);
6583     SET_EXPECT(GetHostInfo);
6584     if(loaded)
6585         SET_EXPECT(GetDisplayName);
6586     SET_EXPECT(Invoke_AMBIENT_SILENT);
6587     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6588     SET_EXPECT(OnChanged_READYSTATE);
6589     SET_EXPECT(Invoke_OnReadyStateChange_Loading);
6590     SET_EXPECT(IsSystemMoniker);
6591     SET_EXPECT(Exec_ShellDocView_84);
6592     if(loaded)
6593         SET_EXPECT(BindToStorage);
6594     SET_EXPECT(InPlaceUIWindow_SetActiveObject);
6595     SET_EXPECT(HideUI);
6596     SET_EXPECT(ShowUI);
6597     SET_EXPECT(InPlaceFrame_SetBorderSpace);
6598 
6599     expect_status_text = NULL;
6600     readystate_set_loading = TRUE;
6601 
6602     hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, IDM_EDITMODE,
6603             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
6604     ok(hres == S_OK, "Exec failed: %08x\n", hres);
6605 
6606     if(loaded)
6607         CHECK_CALLED(GetClassID);
6608     CHECK_CALLED(SetStatusText);
6609     CHECK_CALLED(Exec_ShellDocView_37);
6610     CHECK_CALLED(GetHostInfo);
6611     if(loaded)
6612         CHECK_CALLED(GetDisplayName);
6613     CHECK_CALLED(Invoke_AMBIENT_SILENT);
6614     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6615     CHECK_CALLED(OnChanged_READYSTATE);
6616     CHECK_CALLED(Invoke_OnReadyStateChange_Loading);
6617     CLEAR_CALLED(IsSystemMoniker); /* IE7 */
6618     CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
6619     if(loaded)
6620         CHECK_CALLED(BindToStorage);
6621     CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
6622     CHECK_CALLED(HideUI);
6623     CHECK_CALLED(ShowUI);
6624     CHECK_CALLED(InPlaceFrame_SetBorderSpace);
6625 
6626     test_timer(EXPECT_UPDATEUI|EXPECT_SETTITLE);
6627 
6628     IOleCommandTarget_Release(cmdtrg);
6629 
6630     hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, IDM_EDITMODE,
6631             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
6632     ok(hres == S_OK, "Exec failed: %08x\n", hres);
6633 }
6634 
6635 static void test_exec_fontname(IUnknown *unk, LPCWSTR name, LPCWSTR exname)
6636 {
6637    IOleCommandTarget *cmdtrg;
6638    VARIANT *in = NULL, _in, *out = NULL, _out;
6639    HRESULT hres;
6640 
6641    hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
6642    ok(hres == S_OK, "QueryInterface(IIDIOleM=CommandTarget failed: %08x\n", hres);
6643    if(FAILED(hres))
6644        return;
6645 
6646    if(name) {
6647        in = &_in;
6648        V_VT(in) = VT_BSTR;
6649        V_BSTR(in) = SysAllocString(name);
6650    }
6651 
6652    if(exname) {
6653        out = &_out;
6654        V_VT(out) = VT_I4;
6655        V_I4(out) = 0xdeadbeef;
6656    }
6657 
6658    hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, IDM_FONTNAME, 0, in, out);
6659    ok(hres == S_OK, "Exec(IDM_FONTNAME) failed: %08x\n", hres);
6660 
6661    if(in)
6662        VariantClear(in);
6663 
6664    if(out) {
6665        ok(V_VT(out) == VT_BSTR, "V_VT(out) = %x\n", V_VT(out));
6666        if(V_VT(out) == VT_BSTR) {
6667            if(exname)
6668                ok(!lstrcmpW(V_BSTR(out), name ? name : exname),
6669                   "unexpected fontname %s\n", wine_dbgstr_w(name));
6670            else
6671                ok(V_BSTR(out) == NULL, "V_BSTR(out) != NULL\n");
6672        }
6673        VariantClear(out);
6674    }
6675 
6676    IOleCommandTarget_Release(cmdtrg);
6677 }
6678 
6679 static void test_exec_noargs(IUnknown *unk, DWORD cmdid)
6680 {
6681     IOleCommandTarget *cmdtrg;
6682     HRESULT hres;
6683 
6684     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
6685     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
6686     if(FAILED(hres))
6687         return;
6688 
6689     hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, cmdid,
6690             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
6691     ok(hres == S_OK, "Exec failed: %08x\n", hres);
6692 
6693     IOleCommandTarget_Release(cmdtrg);
6694 }
6695 
6696 static void test_exec_optical_zoom(IHTMLDocument2 *doc, int factor)
6697 {
6698     IOleCommandTarget *cmdtrg;
6699     VARIANT v;
6700     HRESULT hres;
6701 
6702     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleCommandTarget, (void**)&cmdtrg);
6703     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
6704     if(FAILED(hres))
6705         return;
6706 
6707     V_VT(&v) = VT_I4;
6708     V_I4(&v) = factor;
6709 
6710     SET_EXPECT(GetOverrideKeyPath);
6711     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_OPTICAL_ZOOM,
6712             OLECMDEXECOPT_DODEFAULT, &v, NULL);
6713     ok(hres == S_OK || broken(hres == OLECMDERR_E_NOTSUPPORTED) /* IE6 */, "Exec failed: %08x\n", hres);
6714     CLEAR_CALLED(GetOverrideKeyPath);
6715 
6716     IOleCommandTarget_Release(cmdtrg);
6717 
6718     test_QueryStatus((IUnknown*)doc, NULL, OLECMDID_OPTICAL_ZOOM, 0);
6719 }
6720 
6721 static void test_IsDirty(IHTMLDocument2 *doc, HRESULT exhres)
6722 {
6723     IPersistStreamInit *perinit;
6724     IPersistMoniker *permon;
6725     IPersistFile *perfile;
6726     HRESULT hres;
6727 
6728     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&perinit);
6729     ok(hres == S_OK, "QueryInterface(IID_IPersistStreamInit failed: %08x\n", hres);
6730     if(SUCCEEDED(hres)) {
6731         hres = IPersistStreamInit_IsDirty(perinit);
6732         ok(hres == exhres, "IsDirty() = %08x, expected %08x\n", hres, exhres);
6733         IPersistStreamInit_Release(perinit);
6734     }
6735 
6736     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistMoniker, (void**)&permon);
6737     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker failed: %08x\n", hres);
6738     if(SUCCEEDED(hres)) {
6739         hres = IPersistMoniker_IsDirty(permon);
6740         ok(hres == exhres, "IsDirty() = %08x, expected %08x\n", hres, exhres);
6741         IPersistMoniker_Release(permon);
6742     }
6743 
6744     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistFile, (void**)&perfile);
6745     ok(hres == S_OK, "QueryInterface(IID_IPersistFile failed: %08x\n", hres);
6746     if(SUCCEEDED(hres)) {
6747         hres = IPersistFile_IsDirty(perfile);
6748         ok(hres == exhres, "IsDirty() = %08x, expected %08x\n", hres, exhres);
6749         IPersistFile_Release(perfile);
6750     }
6751 }
6752 
6753 static HWND create_container_window(void)
6754 {
6755     static const WCHAR wszHTMLDocumentTest[] =
6756         {'H','T','M','L','D','o','c','u','m','e','n','t','T','e','s','t',0};
6757     static WNDCLASSEXW wndclass = {
6758         sizeof(WNDCLASSEXW),
6759         0,
6760         wnd_proc,
6761         0, 0, NULL, NULL, NULL, NULL, NULL,
6762         wszHTMLDocumentTest,
6763         NULL
6764     };
6765 
6766     RegisterClassExW(&wndclass);
6767     return CreateWindowW(wszHTMLDocumentTest, wszHTMLDocumentTest,
6768             WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
6769             515, 530, NULL, NULL, NULL, NULL);
6770 }
6771 
6772 static void test_DoVerb(IOleObject *oleobj)
6773 {
6774     RECT rect = {0,0,500,500};
6775     HRESULT hres;
6776 
6777     if(!container_locked) {
6778         SET_EXPECT(GetContainer);
6779         SET_EXPECT(LockContainer);
6780     }
6781     SET_EXPECT(ActivateMe);
6782     expect_LockContainer_fLock = TRUE;
6783 
6784     hres = IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, &ClientSite, -1, container_hwnd, &rect);
6785     ok(hres == S_OK, "DoVerb failed: %08x\n", hres);
6786 
6787     if(!container_locked) {
6788         CHECK_CALLED(GetContainer);
6789         CHECK_CALLED(LockContainer);
6790         container_locked = TRUE;
6791     }
6792     CHECK_CALLED(ActivateMe);
6793 }
6794 
6795 #define CLIENTSITE_EXPECTPATH 0x00000001
6796 #define CLIENTSITE_SETNULL    0x00000002
6797 #define CLIENTSITE_DONTSET    0x00000004
6798 
6799 static void test_ClientSite(IOleObject *oleobj, DWORD flags)
6800 {
6801     IOleClientSite *clientsite;
6802     HRESULT hres;
6803 
6804     if(flags & CLIENTSITE_SETNULL) {
6805         hres = IOleObject_GetClientSite(oleobj, &clientsite);
6806         ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
6807         if(set_clientsite)
6808             ok(clientsite == &ClientSite, "clientsite=%p, expected %p\n", clientsite, &ClientSite);
6809         else
6810             ok(!clientsite, "clientsite != NULL\n");
6811 
6812         SET_EXPECT(GetOverrideKeyPath);
6813         hres = IOleObject_SetClientSite(oleobj, NULL);
6814         ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
6815         CLEAR_CALLED(GetOverrideKeyPath); /* IE9 sometimes calls it */
6816 
6817         set_clientsite = FALSE;
6818     }
6819 
6820     if(flags & CLIENTSITE_DONTSET)
6821         return;
6822 
6823     if(!expect_uihandler_iface)
6824         expect_uihandler_iface = &DocHostUIHandler;
6825 
6826     hres = IOleObject_GetClientSite(oleobj, &clientsite);
6827     ok(hres == S_OK, "GetClientSite failed: %08x\n", hres);
6828     ok(clientsite == (set_clientsite ? &ClientSite : NULL), "GetClientSite() = %p, expected %p\n",
6829             clientsite, set_clientsite ? &ClientSite : NULL);
6830 
6831     if(!set_clientsite) {
6832         if(expect_uihandler_iface)
6833             SET_EXPECT(GetHostInfo);
6834         if(flags & CLIENTSITE_EXPECTPATH) {
6835             SET_EXPECT(GetOptionKeyPath);
6836             SET_EXPECT(GetOverrideKeyPath);
6837         }
6838         SET_EXPECT(GetWindow);
6839         if(flags & CLIENTSITE_EXPECTPATH)
6840             SET_EXPECT(Exec_DOCCANNAVIGATE);
6841         SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
6842         SET_EXPECT(Exec_SETPROGRESSMAX);
6843         SET_EXPECT(Exec_SETPROGRESSPOS);
6844         SET_EXPECT(Invoke_AMBIENT_USERMODE);
6845         SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
6846         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6847         SET_EXPECT(Invoke_AMBIENT_SILENT);
6848         SET_EXPECT(Invoke_AMBIENT_USERAGENT);
6849         SET_EXPECT(Invoke_AMBIENT_PALETTE);
6850         SET_EXPECT(GetOverrideKeyPath);
6851         SET_EXPECT(GetTravelLog);
6852         SET_EXPECT(Exec_ShellDocView_84);
6853 
6854         hres = IOleObject_SetClientSite(oleobj, &ClientSite);
6855         ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
6856 
6857         if(expect_uihandler_iface)
6858             CHECK_CALLED(GetHostInfo);
6859         if(flags & CLIENTSITE_EXPECTPATH) {
6860             CLEAR_CALLED(GetOptionKeyPath); /* not called on some IE9 */
6861             CHECK_CALLED(GetOverrideKeyPath);
6862         }
6863         CHECK_CALLED(GetWindow);
6864         if(flags & CLIENTSITE_EXPECTPATH)
6865             CHECK_CALLED(Exec_DOCCANNAVIGATE);
6866         CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
6867         CHECK_CALLED(Exec_SETPROGRESSMAX);
6868         CHECK_CALLED(Exec_SETPROGRESSPOS);
6869         CHECK_CALLED(Invoke_AMBIENT_USERMODE);
6870         CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
6871         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6872         CHECK_CALLED(Invoke_AMBIENT_SILENT);
6873         CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
6874         CLEAR_CALLED(Invoke_AMBIENT_PALETTE); /* not called on IE9 */
6875         CLEAR_CALLED(GetOverrideKeyPath); /* Called by IE9 */
6876         CHECK_CALLED(GetTravelLog);
6877         CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
6878 
6879         set_clientsite = TRUE;
6880     }
6881 
6882     hres = IOleObject_SetClientSite(oleobj, &ClientSite);
6883     ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
6884 
6885     hres = IOleObject_GetClientSite(oleobj, &clientsite);
6886     ok(hres == S_OK, "GetClientSite failed: %08x\n", hres);
6887     ok(clientsite == &ClientSite, "GetClientSite() = %p, expected %p\n", clientsite, &ClientSite);
6888 }
6889 
6890 static void test_OnAmbientPropertyChange(IHTMLDocument2 *doc)
6891 {
6892     IOleControl *control = NULL;
6893     HRESULT hres;
6894 
6895     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleControl, (void**)&control);
6896     ok(hres == S_OK, "QueryInterface(IID_IOleControl failed: %08x\n", hres);
6897     if(FAILED(hres))
6898         return;
6899 
6900     SET_EXPECT(Invoke_AMBIENT_USERMODE);
6901     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_USERMODE);
6902     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
6903     CHECK_CALLED(Invoke_AMBIENT_USERMODE);
6904 
6905     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
6906     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_DLCONTROL);
6907     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
6908     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
6909 
6910     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
6911     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6912     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
6913     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
6914     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
6915     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
6916 
6917     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
6918     SET_EXPECT(Invoke_AMBIENT_SILENT);
6919     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_SILENT);
6920     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
6921     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
6922     CHECK_CALLED(Invoke_AMBIENT_SILENT);
6923 
6924     SET_EXPECT(Invoke_AMBIENT_USERAGENT);
6925     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_USERAGENT);
6926     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
6927     CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
6928 
6929     SET_EXPECT(Invoke_AMBIENT_PALETTE);
6930     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_PALETTE);
6931     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
6932     CLEAR_CALLED(Invoke_AMBIENT_PALETTE); /* not called on IE9 */
6933 
6934     IOleControl_Release(control);
6935 }
6936 
6937 
6938 
6939 static void test_OnAmbientPropertyChange2(IHTMLDocument2 *doc)
6940 {
6941     IOleControl *control = NULL;
6942     HRESULT hres;
6943 
6944     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleControl, (void**)&control);
6945     ok(hres == S_OK, "QueryInterface(IID_IOleControl failed: %08x\n", hres);
6946     if(FAILED(hres))
6947         return;
6948 
6949     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_PALETTE);
6950     ok(hres == S_OK, "OnAmbientPropertyChange failed: %08x\n", hres);
6951 
6952     IOleControl_Release(control);
6953 }
6954 
6955 static void test_Close(IHTMLDocument2 *doc, BOOL set_client)
6956 {
6957     IOleObject *oleobj = NULL;
6958     HRESULT hres;
6959 
6960     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
6961     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
6962     if(FAILED(hres))
6963         return;
6964 
6965     SET_EXPECT(GetContainer);
6966     SET_EXPECT(LockContainer);
6967     expect_LockContainer_fLock = FALSE;
6968     hres = IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
6969     ok(hres == S_OK, "Close failed: %08x\n", hres);
6970     CHECK_CALLED(GetContainer);
6971     CHECK_CALLED(LockContainer);
6972     container_locked = FALSE;
6973 
6974     if(set_client)
6975         test_ClientSite(oleobj, CLIENTSITE_SETNULL|CLIENTSITE_DONTSET);
6976 
6977     IOleObject_Release(oleobj);
6978 }
6979 
6980 static void test_Advise(IHTMLDocument2 *doc)
6981 {
6982     IOleObject *oleobj = NULL;
6983     IEnumSTATDATA *enum_advise = (void*)0xdeadbeef;
6984     DWORD conn;
6985     HRESULT hres;
6986 
6987     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
6988     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
6989     if(FAILED(hres))
6990         return;
6991 
6992     hres = IOleObject_Unadvise(oleobj, 0);
6993     ok(hres == OLE_E_NOCONNECTION, "Unadvise returned: %08x\n", hres);
6994 
6995     hres = IOleObject_EnumAdvise(oleobj, &enum_advise);
6996     ok(hres == S_OK, "EnumAdvise returned: %08x\n", hres);
6997     ok(enum_advise == NULL, "enum_advise != NULL\n");
6998 
6999     conn = -1;
7000     hres = IOleObject_Advise(oleobj, NULL, &conn);
7001     /* Old IE returns S_OK and sets conn to 1 */
7002     ok(hres == E_INVALIDARG || hres == S_OK, "Advise returned: %08x\n", hres);
7003     ok(conn == 0 || conn == 1, "conn = %d\n", conn);
7004 
7005     hres = IOleObject_Advise(oleobj, (IAdviseSink*)&AdviseSink, NULL);
7006     ok(hres == E_INVALIDARG, "Advise returned: %08x\n", hres);
7007 
7008     hres = IOleObject_Advise(oleobj, (IAdviseSink*)&AdviseSink, &conn);
7009     ok(hres == S_OK, "Advise returned: %08x\n", hres);
7010     ok(conn == 1, "conn = %d\n", conn);
7011 
7012     hres = IOleObject_Advise(oleobj, (IAdviseSink*)&AdviseSink, &conn);
7013     ok(hres == S_OK, "Advise returned: %08x\n", hres);
7014     ok(conn == 2, "conn = %d\n", conn);
7015 
7016     hres = IOleObject_Unadvise(oleobj, 1);
7017     ok(hres == S_OK, "Unadvise returned: %08x\n", hres);
7018 
7019     hres = IOleObject_Unadvise(oleobj, 1);
7020     ok(hres == OLE_E_NOCONNECTION, "Unadvise returned: %08x\n", hres);
7021 
7022     hres = IOleObject_Unadvise(oleobj, 2);
7023     ok(hres == S_OK, "Unadvise returned: %08x\n", hres);
7024 
7025     IOleObject_Release(oleobj);
7026 }
7027 
7028 static void test_OnFrameWindowActivate(IUnknown *unk)
7029 {
7030     IOleInPlaceActiveObject *inplaceact;
7031     HRESULT hres;
7032 
7033     hres = IUnknown_QueryInterface(unk, &IID_IOleInPlaceActiveObject, (void**)&inplaceact);
7034     ok(hres == S_OK, "QueryInterface(IID_IOleInPlaceActiveObject) failed: %08x\n", hres);
7035     if(FAILED(hres))
7036         return;
7037 
7038     if(set_clientsite) {
7039         expect_OnFrameWindowActivate_fActivate = TRUE;
7040         SET_EXPECT(OnFrameWindowActivate);
7041         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
7042         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
7043         CHECK_CALLED(OnFrameWindowActivate);
7044 
7045         SET_EXPECT(OnFrameWindowActivate);
7046         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
7047         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
7048         CHECK_CALLED(OnFrameWindowActivate);
7049 
7050         expect_OnFrameWindowActivate_fActivate = FALSE;
7051         SET_EXPECT(OnFrameWindowActivate);
7052         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, FALSE);
7053         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
7054         CHECK_CALLED(OnFrameWindowActivate);
7055 
7056         expect_OnFrameWindowActivate_fActivate = TRUE;
7057         SET_EXPECT(OnFrameWindowActivate);
7058         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
7059         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
7060         CHECK_CALLED(OnFrameWindowActivate);
7061     }else {
7062         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, FALSE);
7063         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
7064 
7065         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
7066         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
7067     }
7068 
7069     IOleInPlaceActiveObject_Release(inplaceact);
7070 }
7071 
7072 static void test_InPlaceDeactivate(IHTMLDocument2 *doc, BOOL expect_call)
7073 {
7074     IOleInPlaceObjectWindowless *windowlessobj = NULL;
7075     HRESULT hres;
7076 
7077     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleInPlaceObjectWindowless,
7078             (void**)&windowlessobj);
7079     ok(hres == S_OK, "QueryInterface(IID_IOleInPlaceObjectWindowless) failed: %08x\n", hres);
7080     if(FAILED(hres))
7081         return;
7082 
7083     if(expect_call) {
7084         SET_EXPECT(SetStatusText);
7085         SET_EXPECT(OnFocus_FALSE);
7086         if(ipsex)
7087             SET_EXPECT(OnInPlaceDeactivateEx);
7088         else
7089             SET_EXPECT(OnInPlaceDeactivate);
7090     }
7091     hres = IOleInPlaceObjectWindowless_InPlaceDeactivate(windowlessobj);
7092     ok(hres == S_OK, "InPlaceDeactivate failed: %08x\n", hres);
7093     if(expect_call) {
7094         CLEAR_CALLED(SetStatusText); /* Called by IE9 */
7095         CHECK_CALLED(OnFocus_FALSE);
7096         if(ipsex)
7097             CHECK_CALLED(OnInPlaceDeactivateEx);
7098         else
7099             CHECK_CALLED(OnInPlaceDeactivate);
7100     }
7101 
7102     IOleInPlaceObjectWindowless_Release(windowlessobj);
7103 }
7104 
7105 static void test_Activate(IHTMLDocument2 *doc, DWORD flags)
7106 {
7107     IOleObject *oleobj = NULL;
7108     IOleDocumentView *docview;
7109     GUID guid;
7110     HRESULT hres;
7111 
7112     last_hwnd = doc_hwnd;
7113 
7114     if(view)
7115         IOleDocumentView_Release(view);
7116     view = NULL;
7117 
7118     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
7119     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
7120 
7121     hres = IOleObject_GetUserClassID(oleobj, NULL);
7122     ok(hres == E_INVALIDARG, "GetUserClassID returned: %08x, expected E_INVALIDARG\n", hres);
7123 
7124     hres = IOleObject_GetUserClassID(oleobj, &guid);
7125     ok(hres == S_OK, "GetUserClassID failed: %08x\n", hres);
7126     ok(IsEqualGUID(&guid, &CLSID_HTMLDocument), "guid != CLSID_HTMLDocument\n");
7127 
7128     test_OnFrameWindowActivate((IUnknown*)doc);
7129 
7130     test_ClientSite(oleobj, flags);
7131     test_InPlaceDeactivate(doc, FALSE);
7132     test_DoVerb(oleobj);
7133 
7134     if(call_UIActivate == CallUIActivate_AfterShow) {
7135         hres = IOleObject_QueryInterface(oleobj, &IID_IOleDocumentView, (void **)&docview);
7136         ok(hres == S_OK, "IOleObject_QueryInterface failed with error 0x%08x\n", hres);
7137 
7138         SET_EXPECT(OnFocus_TRUE);
7139         SET_EXPECT(SetActiveObject);
7140         SET_EXPECT(ShowUI);
7141         SET_EXPECT(InPlaceUIWindow_SetActiveObject);
7142         SET_EXPECT(InPlaceFrame_SetBorderSpace);
7143         expect_status_text = NULL;
7144 
7145         hres = IOleDocumentView_UIActivate(docview, TRUE);
7146         ok(hres == S_OK, "IOleDocumentView_UIActivate failed with error 0x%08x\n", hres);
7147 
7148         CHECK_CALLED(OnFocus_TRUE);
7149         CHECK_CALLED(SetActiveObject);
7150         CHECK_CALLED(ShowUI);
7151         CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
7152         CHECK_CALLED(InPlaceFrame_SetBorderSpace);
7153 
7154         IOleDocumentView_Release(docview);
7155     }
7156 
7157     IOleObject_Release(oleobj);
7158 
7159     test_OnFrameWindowActivate((IUnknown*)doc);
7160 }
7161 
7162 static void test_Window(IHTMLDocument2 *doc, BOOL expect_success)
7163 {
7164     IOleInPlaceActiveObject *activeobject = NULL;
7165     HWND tmp_hwnd;
7166     HRESULT hres;
7167 
7168     hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobject);
7169     ok(hres == S_OK, "Could not get IOleInPlaceActiveObject interface: %08x\n", hres);
7170     if(FAILED(hres))
7171         return;
7172 
7173     hres = IOleInPlaceActiveObject_GetWindow(activeobject, &tmp_hwnd);
7174 
7175     if(expect_success) {
7176         ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
7177         ok(tmp_hwnd == doc_hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, doc_hwnd);
7178     }else {
7179         ok(hres == E_FAIL, "GetWindow returned %08x, expected E_FAIL\n", hres);
7180         ok(IsWindow(doc_hwnd), "hwnd is destroyed\n");
7181     }
7182 
7183     IOleInPlaceActiveObject_Release(activeobject);
7184 }
7185 
7186 static void test_CloseView(void)
7187 {
7188     IOleInPlaceSite *inplacesite = (IOleInPlaceSite*)0xff00ff00;
7189     HRESULT hres;
7190 
7191     if(!view)
7192         return;
7193 
7194     hres = IOleDocumentView_Show(view, FALSE);
7195     ok(hres == S_OK, "Show failed: %08x\n", hres);
7196 
7197     hres = IOleDocumentView_CloseView(view, 0);
7198     ok(hres == S_OK, "CloseView failed: %08x\n", hres);
7199 
7200     hres = IOleDocumentView_SetInPlaceSite(view, NULL);
7201     ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
7202 
7203     hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
7204     ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
7205     ok(inplacesite == NULL, "inplacesite=%p, expected NULL\n", inplacesite);
7206 }
7207 
7208 static void test_UIDeactivate(void)
7209 {
7210     HRESULT hres;
7211 
7212     if(call_UIActivate == CallUIActivate_AfterShow) {
7213         SET_EXPECT(InPlaceUIWindow_SetActiveObject);
7214     }
7215     if(call_UIActivate != CallUIActivate_None) {
7216         SET_EXPECT(SetActiveObject_null);
7217         SET_EXPECT(HideUI);
7218         SET_EXPECT(OnUIDeactivate);
7219     }
7220 
7221     hres = IOleDocumentView_UIActivate(view, FALSE);
7222     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
7223 
7224     if(call_UIActivate != CallUIActivate_None) {
7225         CHECK_CALLED(SetActiveObject_null);
7226         CHECK_CALLED(HideUI);
7227         CHECK_CALLED(OnUIDeactivate);
7228     }
7229     if(call_UIActivate == CallUIActivate_AfterShow) {
7230         CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
7231     }
7232 }
7233 
7234 static void test_Hide(void)
7235 {
7236     HRESULT hres;
7237 
7238     if(!view)
7239         return;
7240 
7241     hres = IOleDocumentView_Show(view, FALSE);
7242     ok(hres == S_OK, "Show failed: %08x\n", hres);
7243 }
7244 
7245 static IHTMLDocument2 *create_document(void)
7246 {
7247     IHTMLDocument2 *doc;
7248     HRESULT hres;
7249 
7250     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
7251             &IID_IHTMLDocument2, (void**)&doc);
7252     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
7253     if(FAILED(hres))
7254         return NULL;
7255 
7256     return doc;
7257 }
7258 
7259 static void release_document(IHTMLDocument2 *doc)
7260 {
7261     IUnknown *unk;
7262     ULONG ref;
7263     HRESULT hres;
7264 
7265     /* Some broken IEs don't like if the last released reference is IHTMLDocument2 iface.
7266      * To workaround it, we release it via IUnknown iface */
7267     hres = IHTMLDocument2_QueryInterface(doc, &IID_IUnknown, (void**)&unk);
7268     ok(hres == S_OK, "Could not get IUnknown iface: %08x\n", hres);
7269 
7270     IHTMLDocument2_Release(doc);
7271     ref = IUnknown_Release(unk);
7272     ok(!ref, "ref = %d\n", ref);
7273 }
7274 
7275 static void test_Navigate(IHTMLDocument2 *doc)
7276 {
7277     IHlinkTarget *hlink;
7278     HRESULT hres;
7279 
7280     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHlinkTarget, (void**)&hlink);
7281     ok(hres == S_OK, "QueryInterface(IID_IHlinkTarget) failed: %08x\n", hres);
7282 
7283     SET_EXPECT(ActivateMe);
7284     hres = IHlinkTarget_Navigate(hlink, 0, NULL);
7285     ok(hres == S_OK, "Navigate failed: %08x\n", hres);
7286     CHECK_CALLED(ActivateMe);
7287 
7288     IHlinkTarget_Release(hlink);
7289 }
7290 
7291 static void test_external(IHTMLDocument2 *doc, BOOL initialized)
7292 {
7293     IDispatch *external;
7294     IHTMLWindow2 *htmlwin;
7295     HRESULT hres;
7296 
7297     hres = IHTMLDocument2_get_parentWindow(doc, &htmlwin);
7298     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
7299 
7300     if(initialized)
7301         SET_EXPECT(GetExternal);
7302     external = (void*)0xdeadbeef;
7303     hres = IHTMLWindow2_get_external(htmlwin, &external);
7304     if(initialized) {
7305         ok(hres == S_FALSE || hres == S_OK, "get_external failed: %08x\n", hres);
7306         CHECK_CALLED(GetExternal);
7307         ok(external != NULL, "external == NULL\n");
7308     }else {
7309         ok(hres == S_OK, "get_external failed: %08x\n", hres);
7310         ok(external == NULL, "external != NULL\n");
7311     }
7312 
7313     IHTMLWindow2_Release(htmlwin);
7314 }
7315 
7316 static void test_enum_objects(IOleContainer *container)
7317 {
7318     IEnumUnknown *enum_unknown;
7319     IUnknown *buf[100] = {(void*)0xdeadbeef};
7320     ULONG fetched;
7321     HRESULT hres;
7322 
7323     enum_unknown = NULL;
7324     hres = IOleContainer_EnumObjects(container, OLECONTF_EMBEDDINGS, &enum_unknown);
7325     ok(hres == S_OK, "EnumObjects failed: %08x\n", hres);
7326     ok(enum_unknown != NULL, "enum_unknown == NULL\n");
7327 
7328     fetched = 0xdeadbeef;
7329     hres = IEnumUnknown_Next(enum_unknown, sizeof(buf)/sizeof(*buf), buf, &fetched);
7330     ok(hres == S_FALSE, "Next returned %08x\n", hres);
7331     ok(!fetched, "fetched = %d\n", fetched);
7332     ok(buf[0] == (void*)0xdeadbeef, "buf[0] = %p\n", buf[0]);
7333 
7334     fetched = 0xdeadbeef;
7335     hres = IEnumUnknown_Next(enum_unknown, 1, buf, &fetched);
7336     ok(hres == S_FALSE, "Next returned %08x\n", hres);
7337     ok(!fetched, "fetched = %d\n", fetched);
7338 
7339     hres = IEnumUnknown_Next(enum_unknown, 1, buf, NULL);
7340     ok(hres == S_FALSE, "Next returned %08x\n", hres);
7341 
7342     IEnumUnknown_Release(enum_unknown);
7343 }
7344 
7345 static void test_target_container(IHTMLDocument2 *doc)
7346 {
7347     IOleContainer *ole_container, *doc_ole_container;
7348     ITargetContainer *target_container;
7349     HRESULT hres;
7350 
7351     hres = IHTMLDocument2_QueryInterface(doc, &IID_ITargetContainer, (void**)&target_container);
7352     ok(hres == S_OK, "Could not get ITargetContainer iface: %08x\n", hres);
7353 
7354     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleContainer, (void**)&doc_ole_container);
7355     ok(hres == S_OK, "Could not get ITargetContainer iface: %08x\n", hres);
7356 
7357     ole_container = (void*)0xdeadbeef;
7358     hres = ITargetContainer_GetFramesContainer(target_container, &ole_container);
7359     ok(hres == S_OK, "GetFramesContainer failed: %08x\n", hres);
7360     ok(ole_container != NULL, "ole_container == NULL\n");
7361     ok(iface_cmp((IUnknown*)ole_container, (IUnknown*)doc_ole_container), "ole_container != doc_ole_container\n");
7362     test_enum_objects(ole_container);
7363     IOleContainer_Release(ole_container);
7364 
7365     ITargetContainer_Release(target_container);
7366     IOleContainer_Release(doc_ole_container);
7367 }
7368 
7369 static void test_travellog(IHTMLDocument2 *doc)
7370 {
7371     ITravelLogClient *travellog_client;
7372     IHTMLWindow2 *window, *top_window;
7373     IUnknown *unk;
7374     HRESULT hres;
7375 
7376     window = NULL;
7377     hres = IHTMLDocument2_get_parentWindow(doc, &window);
7378     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
7379     ok(window != NULL, "window = NULL\n");
7380 
7381     hres = IHTMLWindow2_get_top(window, &top_window);
7382     IHTMLWindow2_Release(window);
7383     ok(hres == S_OK, "get_top failed: %08x\n", hres);
7384 
7385     hres = IHTMLWindow2_QueryInterface(top_window, &IID_ITravelLogClient, (void**)&travellog_client);
7386     IHTMLWindow2_Release(top_window);
7387     if(hres == E_NOINTERFACE) {
7388         win_skip("ITravelLogClient not supported\n");
7389         no_travellog = TRUE;
7390         return;
7391     }
7392     ok(hres == S_OK, "Could not get ITraveLogClient iface: %08x\n", hres);
7393 
7394     unk = (void*)0xdeadbeef;
7395     hres = ITravelLogClient_FindWindowByIndex(travellog_client, 0, &unk);
7396     ok(hres == E_FAIL, "FindWindowByIndex failed: %08x\n", hres);
7397     ok(!unk, "unk != NULL\n");
7398 
7399     ITravelLogClient_Release(travellog_client);
7400 }
7401 
7402 static void test_StreamLoad(IHTMLDocument2 *doc)
7403 {
7404     IPersistStreamInit *init;
7405     HRESULT hres;
7406 
7407     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
7408     ok(hres == S_OK, "QueryInterface(IID_IPersistStreamInit) failed: %08x\n", hres);
7409     if(FAILED(hres))
7410         return;
7411 
7412     SET_EXPECT(Invoke_AMBIENT_SILENT);
7413     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
7414     SET_EXPECT(Exec_ShellDocView_37);
7415     SET_EXPECT(OnChanged_READYSTATE);
7416     SET_EXPECT(Invoke_OnReadyStateChange_Loading);
7417     SET_EXPECT(Read);
7418     SET_EXPECT(GetPendingUrl);
7419     readystate_set_loading = TRUE;
7420 
7421     hres = IPersistStreamInit_Load(init, &Stream);
7422     ok(hres == S_OK, "Load failed: %08x\n", hres);
7423 
7424     CHECK_CALLED(Invoke_AMBIENT_SILENT);
7425     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
7426     CHECK_CALLED(Exec_ShellDocView_37);
7427     CHECK_CALLED(OnChanged_READYSTATE);
7428     CHECK_CALLED(Invoke_OnReadyStateChange_Loading);
7429     CHECK_CALLED(Read);
7430     todo_wine CHECK_CALLED(GetPendingUrl);
7431 
7432     test_timer(EXPECT_SETTITLE);
7433     test_GetCurMoniker((IUnknown*)doc, NULL, "about:blank", FALSE);
7434 
7435     IPersistStreamInit_Release(init);
7436 }
7437 
7438 static void test_StreamInitNew(IHTMLDocument2 *doc)
7439 {
7440     IPersistStreamInit *init;
7441     HRESULT hres;
7442 
7443     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
7444     ok(hres == S_OK, "QueryInterface(IID_IPersistStreamInit) failed: %08x\n", hres);
7445     if(FAILED(hres))
7446         return;
7447 
7448     SET_EXPECT(Invoke_AMBIENT_SILENT);
7449     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
7450     SET_EXPECT(Exec_ShellDocView_37);
7451     SET_EXPECT(OnChanged_READYSTATE);
7452     SET_EXPECT(Invoke_OnReadyStateChange_Loading);
7453     SET_EXPECT(GetPendingUrl);
7454     readystate_set_loading = TRUE;
7455 
7456     hres = IPersistStreamInit_InitNew(init);
7457     ok(hres == S_OK, "Load failed: %08x\n", hres);
7458 
7459     CHECK_CALLED(Invoke_AMBIENT_SILENT);
7460     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
7461     CHECK_CALLED(Exec_ShellDocView_37);
7462     CHECK_CALLED(OnChanged_READYSTATE);
7463     CHECK_CALLED(Invoke_OnReadyStateChange_Loading);
7464     todo_wine CHECK_CALLED(GetPendingUrl);
7465 
7466     test_timer(EXPECT_SETTITLE);
7467     test_GetCurMoniker((IUnknown*)doc, NULL, "about:blank", FALSE);
7468 
7469     IPersistStreamInit_Release(init);
7470 }
7471 
7472 static void test_QueryInterface(IHTMLDocument2 *htmldoc)
7473 {
7474     IUnknown *qi, *doc = (IUnknown*)htmldoc;
7475     HRESULT hres;
7476 
7477     static const IID IID_UndocumentedScriptIface =
7478         {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
7479 
7480     qi = (void*)0xdeadbeef;
7481     hres = IUnknown_QueryInterface(doc, &IID_IRunnableObject, (void**)&qi);
7482     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7483     ok(qi == NULL, "qirunnable=%p, expected NULL\n", qi);
7484 
7485     qi = (void*)0xdeadbeef;
7486     hres = IUnknown_QueryInterface(doc, &IID_IHTMLDOMNode, (void**)&qi);
7487     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7488     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7489 
7490     qi = (void*)0xdeadbeef;
7491     hres = IUnknown_QueryInterface(doc, &IID_IHTMLDOMNode2, (void**)&qi);
7492     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7493     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7494 
7495     qi = (void*)0xdeadbeef;
7496     hres = IUnknown_QueryInterface(doc, &IID_IPersistPropertyBag, (void**)&qi);
7497     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7498     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7499 
7500     qi = (void*)0xdeadbeef;
7501     hres = IUnknown_QueryInterface(doc, &IID_UndocumentedScriptIface, (void**)&qi);
7502     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7503     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7504 
7505     qi = (void*)0xdeadbeef;
7506     hres = IUnknown_QueryInterface(doc, &IID_IMarshal, (void**)&qi);
7507     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7508     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7509 
7510     qi = (void*)0xdeadbeef;
7511     hres = IUnknown_QueryInterface(doc, &IID_IExternalConnection, (void**)&qi);
7512     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7513     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7514 
7515     qi = (void*)0xdeadbeef;
7516     hres = IUnknown_QueryInterface(doc, &IID_IStdMarshalInfo, (void**)&qi);
7517     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7518     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7519 
7520     qi = (void*)0xdeadbeef;
7521     hres = IUnknown_QueryInterface(doc, &IID_ITargetFrame, (void**)&qi);
7522     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
7523     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
7524 
7525     hres = IUnknown_QueryInterface(doc, &IID_IDispatch, (void**)&qi);
7526     ok(hres == S_OK, "Could not get IDispatch interface: %08x\n", hres);
7527     ok(qi != (IUnknown*)doc, "disp == doc\n");
7528     IUnknown_Release(qi);
7529 }
7530 
7531 static void init_test(enum load_state_t ls) {
7532     doc_unk = NULL;
7533     doc_hwnd = last_hwnd = NULL;
7534     set_clientsite = FALSE;
7535     load_from_stream = FALSE;
7536     call_UIActivate = CallUIActivate_None;
7537     load_state = ls;
7538     editmode = FALSE;
7539     stream_read = 0;
7540     protocol_read = 0;
7541     nav_url = NULL;
7542     ipsex = FALSE;
7543     inplace_deactivated = FALSE;
7544     complete = FALSE;
7545     testing_submit = FALSE;
7546     expect_uihandler_iface = &DocHostUIHandler;
7547 }
7548 
7549 static void test_HTMLDocument(BOOL do_load, BOOL mime)
7550 {
7551     IHTMLDocument2 *doc;
7552 
7553     trace("Testing HTMLDocument (%s, %s)...\n", (do_load ? "load" : "no load"),
7554             (report_mime ? "mime" : "no mime"));
7555 
7556     init_test(do_load ? LD_DOLOAD : LD_NO);
7557     report_mime = mime;
7558 
7559     doc = create_document();
7560     doc_unk = (IUnknown*)doc;
7561 
7562     test_QueryInterface(doc);
7563     test_Advise(doc);
7564     test_IsDirty(doc, S_FALSE);
7565     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
7566     test_external(doc, FALSE);
7567     test_ViewAdviseSink(doc);
7568     test_ConnectionPointContainer(doc);
7569     test_GetCurMoniker((IUnknown*)doc, NULL, NULL, FALSE);
7570     test_Persist(doc, &Moniker);
7571     if(!do_load)
7572         test_OnAmbientPropertyChange2(doc);
7573 
7574     test_Activate(doc, CLIENTSITE_EXPECTPATH);
7575 
7576     if(do_load) {
7577         set_custom_uihandler(doc, &CustomDocHostUIHandler);
7578         test_download(DWL_CSS|DWL_TRYCSS);
7579         test_GetCurMoniker((IUnknown*)doc, &Moniker, NULL, FALSE);
7580         test_elem_from_point(doc);
7581     }
7582 
7583     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
7584     test_OleCommandTarget_fail(doc);
7585     test_OleCommandTarget(doc);
7586     test_exec_optical_zoom(doc, 200);
7587     test_exec_optical_zoom(doc, 100);
7588     test_OnAmbientPropertyChange(doc);
7589     test_Window(doc, TRUE);
7590     test_external(doc, TRUE);
7591     test_target_container(doc);
7592 
7593     test_UIDeactivate();
7594     test_OleCommandTarget(doc);
7595     test_Window(doc, TRUE);
7596     test_InPlaceDeactivate(doc, TRUE);
7597 
7598     /* Calling test_OleCommandTarget here causes Segmentation Fault with native
7599      * MSHTML. It doesn't with Wine. */
7600 
7601     test_Window(doc, FALSE);
7602     test_Hide();
7603     test_InPlaceDeactivate(doc, FALSE);
7604     test_CloseView();
7605     test_Close(doc, FALSE);
7606 
7607     /* Activate HTMLDocument again */
7608     test_Activate(doc, CLIENTSITE_SETNULL);
7609     test_Window(doc, TRUE);
7610     test_OleCommandTarget(doc);
7611     test_UIDeactivate();
7612     test_InPlaceDeactivate(doc, TRUE);
7613     test_Close(doc, FALSE);
7614 
7615     /* Activate HTMLDocument again, this time without UIActivate */
7616     call_UIActivate = CallUIActivate_None;
7617     test_Activate(doc, CLIENTSITE_SETNULL);
7618     test_Window(doc, TRUE);
7619 
7620     test_external(doc, TRUE);
7621     set_custom_uihandler(doc, NULL);
7622     test_external(doc, FALSE);
7623 
7624     test_UIDeactivate();
7625     test_InPlaceDeactivate(doc, TRUE);
7626     test_CloseView();
7627     test_CloseView();
7628     test_Close(doc, TRUE);
7629     test_OnAmbientPropertyChange2(doc);
7630     test_GetCurMoniker((IUnknown*)doc, do_load ? &Moniker : NULL, NULL, FALSE);
7631 
7632     if(!do_load) {
7633         /* Activate HTMLDocument again, calling UIActivate after showing the window */
7634         call_UIActivate = CallUIActivate_AfterShow;
7635         test_Activate(doc, 0);
7636         test_Window(doc, TRUE);
7637         test_OleCommandTarget(doc);
7638         test_UIDeactivate();
7639         test_InPlaceDeactivate(doc, TRUE);
7640         test_Close(doc, FALSE);
7641         call_UIActivate = CallUIActivate_None;
7642     }
7643 
7644     if(view)
7645         IOleDocumentView_Release(view);
7646     view = NULL;
7647 
7648     ok(IsWindow(doc_hwnd), "hwnd is destroyed\n");
7649     release_document(doc);
7650     ok(!IsWindow(doc_hwnd), "hwnd is not destroyed\n");
7651 }
7652 
7653 static void test_HTMLDocument_hlink(DWORD status)
7654 {
7655     IHTMLDocument2 *doc;
7656 
7657     trace("Testing HTMLDocument (hlink)...\n");
7658 
7659     init_test(LD_DOLOAD);
7660     ipsex = TRUE;
7661 
7662     doc = create_document();
7663     doc_unk = (IUnknown*)doc;
7664 
7665     set_custom_uihandler(doc, &CustomDocHostUIHandler);
7666     test_ViewAdviseSink(doc);
7667     test_ConnectionPointContainer(doc);
7668     test_GetCurMoniker((IUnknown*)doc, NULL, NULL, FALSE);
7669     test_Persist(doc, &Moniker);
7670     test_Navigate(doc);
7671 
7672     status_code = status;
7673     test_download(DWL_CSS|DWL_TRYCSS);
7674     status_code = HTTP_STATUS_OK;
7675 
7676     test_IsDirty(doc, S_FALSE);
7677     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
7678 
7679     test_exec_onunload(doc);
7680     test_Window(doc, TRUE);
7681     test_InPlaceDeactivate(doc, TRUE);
7682     test_Close(doc, FALSE);
7683     test_IsDirty(doc, S_FALSE);
7684     test_GetCurMoniker((IUnknown*)doc, &Moniker, NULL, FALSE);
7685     test_clear(doc);
7686     test_GetCurMoniker((IUnknown*)doc, &Moniker, NULL, FALSE);
7687 
7688     if(view)
7689         IOleDocumentView_Release(view);
7690     view = NULL;
7691 
7692     release_document(doc);
7693 }
7694 
7695 static void test_cookies(IHTMLDocument2 *doc)
7696 {
7697     WCHAR buf[1024];
7698     DWORD size;
7699     BSTR str, str2;
7700     BOOL b;
7701     HRESULT hres;
7702 
7703     hres = IHTMLDocument2_get_cookie(doc, &str);
7704     ok(hres == S_OK, "get_cookie failed: %08x\n", hres);
7705     if(str) {
7706         size = sizeof(buf)/sizeof(WCHAR);
7707         b = InternetGetCookieW(http_urlW, NULL, buf, &size);
7708         ok(b, "InternetGetCookieW failed: %08x\n", GetLastError());
7709         ok(!lstrcmpW(buf, str), "cookie = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buf));
7710         SysFreeString(str);
7711     }
7712 
7713     str = a2bstr("test=testval");
7714     hres = IHTMLDocument2_put_cookie(doc, str);
7715     ok(hres == S_OK, "put_cookie failed: %08x\n", hres);
7716 
7717     str2 = NULL;
7718     hres = IHTMLDocument2_get_cookie(doc, &str2);
7719     ok(hres == S_OK, "get_cookie failed: %08x\n", hres);
7720     ok(str2 != NULL, "cookie = NULL\n");
7721     size = sizeof(buf)/sizeof(WCHAR);
7722     b = InternetGetCookieW(http_urlW, NULL, buf, &size);
7723     ok(b, "InternetGetCookieW failed: %08x\n", GetLastError());
7724     ok(!lstrcmpW(buf, str2), "cookie = %s, expected %s\n", wine_dbgstr_w(str2), wine_dbgstr_w(buf));
7725     if(str2)
7726         ok(strstrW(str2, str) != NULL, "could not find %s in %s\n", wine_dbgstr_w(str), wine_dbgstr_w(str2));
7727     SysFreeString(str);
7728     SysFreeString(str2);
7729 
7730     str = a2bstr("test=testval2");
7731     hres = IHTMLDocument2_put_cookie(doc, str);
7732     ok(hres == S_OK, "put_cookie failed: %08x\n", hres);
7733 
7734     str2 = NULL;
7735     hres = IHTMLDocument2_get_cookie(doc, &str2);
7736     ok(hres == S_OK, "get_cookie failed: %08x\n", hres);
7737     ok(str2 != NULL, "cookie = NULL\n");
7738     size = sizeof(buf)/sizeof(WCHAR);
7739     b = InternetGetCookieW(http_urlW, NULL, buf, &size);
7740     ok(b, "InternetGetCookieW failed: %08x\n", GetLastError());
7741     ok(!lstrcmpW(buf, str2), "cookie = %s, expected %s\n", wine_dbgstr_w(str2), wine_dbgstr_w(buf));
7742     if(str2)
7743         ok(strstrW(str2, str) != NULL, "could not find %s in %s\n", wine_dbgstr_w(str), wine_dbgstr_w(str2));
7744     SysFreeString(str);
7745     SysFreeString(str2);
7746 }
7747 
7748 static void test_HTMLDocument_http(BOOL with_wbapp)
7749 {
7750     IMoniker *http_mon;
7751     IHTMLDocument2 *doc;
7752     ULONG ref;
7753     HRESULT hres;
7754 
7755     trace("Testing HTMLDocument (http%s)...\n", with_wbapp ? " with IWebBrowserApp" : "");
7756 
7757     support_wbapp = with_wbapp;
7758 
7759     if(!winetest_interactive && is_ie_hardened()) {
7760         win_skip("IE running in Enhanced Security Configuration\n");
7761         return;
7762     }
7763 
7764     init_test(LD_DOLOAD);
7765     ipsex = TRUE;
7766 
7767     doc = create_document();
7768     doc_unk = (IUnknown*)doc;
7769 
7770     hres = CreateURLMoniker(NULL, http_urlW, &http_mon);
7771     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
7772 
7773     test_ViewAdviseSink(doc);
7774     test_ConnectionPointContainer(doc);
7775     test_GetCurMoniker((IUnknown*)doc, NULL, NULL, FALSE);
7776     test_Persist(doc, http_mon);
7777     test_Navigate(doc);
7778     test_download(DWL_HTTP);
7779     test_cookies(doc);
7780     test_IsDirty(doc, S_FALSE);
7781     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
7782     test_GetCurMoniker((IUnknown*)doc, http_mon, NULL, FALSE);
7783     test_travellog(doc);
7784     test_binding_ui((IUnknown*)doc);
7785 
7786     nav_url = nav_serv_url = "http://test.winehq.org/tests/winehq_snapshot/"; /* for valid prev nav_url */
7787     if(support_wbapp) {
7788         test_put_href(doc, FALSE, "#test", "http://test.winehq.org/tests/winehq_snapshot/#test", FALSE, TRUE, 0);
7789         test_put_hash(doc, "#hash_test");
7790         test_travellog(doc);
7791         test_refresh(doc);
7792     }
7793     test_put_href(doc, FALSE, NULL, "javascript:external%20&&undefined", TRUE, FALSE, 0);
7794     test_put_href(doc, FALSE, NULL, "about:blank", FALSE, FALSE, support_wbapp ? DWL_EXPECT_HISTUPDATE : 0);
7795     test_put_href(doc, TRUE, NULL, "about:replace", FALSE, FALSE, 0);
7796     if(support_wbapp) {
7797         test_load_history(doc);
7798         test_OmHistory(doc);
7799         test_put_href(doc, FALSE, NULL, "about:blank", FALSE, FALSE, support_wbapp ? DWL_EXPECT_HISTUPDATE : 0);
7800     }
7801 
7802     prev_url = nav_serv_url;
7803     test_open_window(doc, TRUE);
7804     if(!support_wbapp) /* FIXME */
7805         test_open_window(doc, FALSE);
7806     if(support_wbapp) {
7807         test_put_href(doc, FALSE, NULL, "http://test.winehq.org/tests/file.winetest", FALSE, FALSE, DWL_EXTERNAL);
7808         test_window_close(doc);
7809     }
7810 
7811     test_InPlaceDeactivate(doc, TRUE);
7812     test_Close(doc, FALSE);
7813     test_IsDirty(doc, S_FALSE);
7814     test_GetCurMoniker((IUnknown*)doc, NULL, prev_url, support_wbapp);
7815 
7816     if(view)
7817         IOleDocumentView_Release(view);
7818     view = NULL;
7819 
7820     release_document(doc);
7821 
7822     ref = IMoniker_Release(http_mon);
7823     ok(!ref, "ref=%d, expected 0\n", ref);
7824 }
7825 
7826 static void put_inner_html(IHTMLElement *elem, const char *html)
7827 {
7828     BSTR str = a2bstr(html);
7829     HRESULT hres;
7830 
7831     hres = IHTMLElement_put_innerHTML(elem, str);
7832     ok(hres == S_OK, "put_innerHTML failed: %08x\n", hres);
7833 
7834     SysFreeString(str);
7835 }
7836 
7837 static IHTMLElement *get_elem_by_id(IHTMLDocument2 *doc, const char *id)
7838 {
7839     IHTMLDocument3 *doc3;
7840     BSTR str = a2bstr(id);
7841     IHTMLElement *ret;
7842     HRESULT hres;
7843 
7844     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
7845     ok(hres == S_OK, "Could not get IHTMLDocument3 iface: %08x\n", hres);
7846 
7847     hres = IHTMLDocument3_getElementById(doc3, str, &ret);
7848     ok(hres == S_OK, "getElementById failed: %08x\n", hres);
7849 
7850     IHTMLDocument3_Release(doc3);
7851     return ret;
7852 }
7853 
7854 static void reset_document(IHTMLDocument2 *doc)
7855 {
7856     IPersistStreamInit *init;
7857     HRESULT hres;
7858 
7859     hres = IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
7860     ok(hres == S_OK, "QueryInterface(IID_IPersistStreamInit) failed: %08x\n", hres);
7861     if(FAILED(hres))
7862         return;
7863 
7864     resetting_document = TRUE;
7865 
7866     hres = IPersistStreamInit_InitNew(init);
7867     ok(hres == S_OK, "Load failed: %08x\n", hres);
7868 
7869     resetting_document = FALSE;
7870 
7871     test_GetCurMoniker((IUnknown*)doc, NULL, "about:blank", FALSE);
7872 
7873     IPersistStreamInit_Release(init);
7874 }
7875 
7876 static void test_submit(void)
7877 {
7878     IHTMLElement *body, *form_elem;
7879     IHTMLFormElement *form;
7880     IHTMLDocument2 *doc;
7881     HRESULT hres;
7882 
7883     if(no_travellog)
7884         return;
7885 
7886     trace("Testing submit...\n");
7887 
7888     support_wbapp = TRUE;
7889 
7890     if(!winetest_interactive && is_ie_hardened()) {
7891         win_skip("IE running in Enhanced Security Configuration\n");
7892         return;
7893     }
7894 
7895     init_test(LD_DOLOAD);
7896     ipsex = TRUE;
7897 
7898     doc = create_document();
7899     doc_unk = (IUnknown*)doc;
7900 
7901     test_ConnectionPointContainer(doc);
7902     test_ViewAdviseSink(doc);
7903     test_Persist(doc, &Moniker);
7904     test_Navigate(doc);
7905     test_download(DWL_CSS|DWL_TRYCSS);
7906 
7907     hres = IHTMLDocument2_get_body(doc, &body);
7908     ok(hres == S_OK, "get_body failed: %08x\n", hres);
7909     ok(body != NULL, "body = NULL\n");
7910 
7911     put_inner_html(body, "<form action='test_submit' method='post' id='fid'><input type='hidden' name='cmd' value='TEST'></form>");
7912     IHTMLElement_Release(body);
7913 
7914     form_elem = get_elem_by_id(doc, "fid");
7915     ok(form_elem != NULL, "form = NULL\n");
7916 
7917     hres = IHTMLElement_QueryInterface(form_elem, &IID_IHTMLFormElement, (void**)&form);
7918     ok(hres == S_OK, "Could not get IHTMLFormElement: %08x\n", hres);
7919     IHTMLElement_Release(form_elem);
7920 
7921     nav_url = nav_serv_url = "winetest:test_submit";
7922     testing_submit = TRUE;
7923 
7924     SET_EXPECT(TranslateUrl);
7925     SET_EXPECT(FireBeforeNavigate2);
7926     SET_EXPECT(Exec_ShellDocView_67);
7927     SET_EXPECT(Invoke_AMBIENT_SILENT);
7928     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
7929     SET_EXPECT(Exec_ShellDocView_63);
7930     SET_EXPECT(Exec_ShellDocView_84);
7931     SET_EXPECT(CreateInstance);
7932     SET_EXPECT(Start);
7933     SET_EXPECT(Protocol_Read);
7934     SET_EXPECT(LockRequest);
7935     SET_EXPECT(GetClassID);
7936     SET_EXPECT(Exec_ShellDocView_138);
7937     SET_EXPECT(OnViewChange);
7938 
7939     SET_EXPECT(UnlockRequest);
7940     SET_EXPECT(Terminate);
7941 
7942     hres = IHTMLFormElement_submit(form);
7943     ok(hres == S_OK, "submit failed: %08x\n", hres);
7944 
7945     CHECK_CALLED(TranslateUrl);
7946     CHECK_CALLED(FireBeforeNavigate2);
7947     CLEAR_CALLED(Exec_ShellDocView_67); /* Not called by IE11 */
7948     CHECK_CALLED(Invoke_AMBIENT_SILENT);
7949     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
7950     CHECK_CALLED(Exec_ShellDocView_63);
7951     CLEAR_CALLED(Exec_ShellDocView_84); /* Not called by IE11 */
7952     CHECK_CALLED(CreateInstance);
7953     CHECK_CALLED(Start);
7954     CHECK_CALLED(Protocol_Read);
7955     CHECK_CALLED(LockRequest);
7956     todo_wine CHECK_CALLED(GetClassID);
7957     CLEAR_CALLED(Exec_ShellDocView_138); /* called only by some versions */
7958     CLEAR_CALLED(OnViewChange); /* called only by some versions */
7959 
7960     todo_wine CHECK_NOT_CALLED(UnlockRequest);
7961     todo_wine CHECK_NOT_CALLED(Terminate);
7962 
7963     IHTMLFormElement_Release(form);
7964 
7965     test_GetCurMoniker((IUnknown*)doc, &Moniker, NULL, FALSE);
7966 
7967     SET_EXPECT(UnlockRequest);
7968     reset_document(doc);
7969     todo_wine CHECK_CALLED(UnlockRequest);
7970 
7971     test_InPlaceDeactivate(doc, TRUE);
7972     test_Close(doc, FALSE);
7973 
7974     if(view)
7975         IOleDocumentView_Release(view);
7976     view = NULL;
7977 
7978     release_document(doc);
7979 }
7980 
7981 static void test_QueryService(IHTMLDocument2 *doc, BOOL success)
7982 {
7983     IHTMLWindow2 *window, *sp_window;
7984     IServiceProvider *sp;
7985     IHlinkFrame *hf;
7986     HRESULT hres;
7987 
7988     hres = IHTMLDocument2_QueryInterface(doc, &IID_IServiceProvider, (void**)&sp);
7989     ok(hres == S_OK, "QueryService returned %08x\n", hres);
7990 
7991     hres = IServiceProvider_QueryService(sp, &IID_IHlinkFrame, &IID_IHlinkFrame, (void**)&hf);
7992     if(!success) {
7993         ok(hres == E_NOINTERFACE, "QueryService returned %08x, expected E_NOINTERFACE\n", hres);
7994         IServiceProvider_Release(sp);
7995         return;
7996     }
7997 
7998     ok(hres == S_OK, "QueryService(IID_IHlinkFrame) failed: %08x\n", hres);
7999     ok(hf == &HlinkFrame, "hf != HlinkFrame\n");
8000     IHlinkFrame_Release(hf);
8001 
8002     IServiceProvider_Release(sp);
8003 
8004     hres = IHTMLDocument2_get_parentWindow(doc, &window);
8005     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
8006 
8007     hres = IHTMLWindow2_QueryInterface(window, &IID_IServiceProvider, (void**)&sp);
8008     ok(hres == S_OK, "Could not get IServiceProvider iface: %08x\n", hres);
8009 
8010     hres = IServiceProvider_QueryService(sp, &IID_IHTMLWindow2, &IID_IHTMLWindow2, (void**)&sp_window);
8011     ok(hres == S_OK, "QueryService(IID_IHTMLWindow2) failed: %08x\n", hres);
8012     /* FIXME: test returned window */
8013     IHTMLWindow2_Release(sp_window);
8014 
8015     hres = IServiceProvider_QueryService(sp, &IID_IHlinkFrame, &IID_IHlinkFrame, (void**)&hf);
8016     ok(hres == S_OK, "QueryService(IID_IHlinkFrame) failed: %08x\n", hres);
8017     ok(hf == &HlinkFrame, "hf != HlinkFrame\n");
8018     IHlinkFrame_Release(hf);
8019 
8020     IServiceProvider_Release(sp);
8021     IHTMLWindow2_Release(window);
8022 }
8023 
8024 static void test_HTMLDocument_StreamLoad(void)
8025 {
8026     IHTMLDocument2 *doc;
8027     IOleObject *oleobj;
8028     DWORD conn;
8029     HRESULT hres;
8030 
8031     trace("Testing HTMLDocument (IPersistStreamInit)...\n");
8032 
8033     init_test(LD_DOLOAD);
8034     load_from_stream = TRUE;
8035 
8036     doc = create_document();
8037     doc_unk = (IUnknown*)doc;
8038 
8039     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
8040     ok(hres == S_OK, "Could not get IOleObject: %08x\n", hres);
8041 
8042     hres = IOleObject_Advise(oleobj, (IAdviseSink*)&AdviseSink, &conn);
8043     ok(hres == S_OK, "Advise failed: %08x\n", hres);
8044 
8045     test_readyState((IUnknown*)doc);
8046     test_IsDirty(doc, S_FALSE);
8047     test_ViewAdviseSink(doc);
8048     test_ConnectionPointContainer(doc);
8049     test_QueryService(doc, FALSE);
8050     test_ClientSite(oleobj, CLIENTSITE_EXPECTPATH);
8051     test_QueryService(doc, TRUE);
8052     test_DoVerb(oleobj);
8053     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
8054 
8055     test_GetCurMoniker((IUnknown*)doc, NULL, NULL, FALSE);
8056     test_StreamLoad(doc);
8057     test_download(DWL_VERBDONE|DWL_TRYCSS);
8058     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
8059 
8060     test_UIDeactivate();
8061     test_InPlaceDeactivate(doc, TRUE);
8062     SET_EXPECT(Advise_Close);
8063     test_Close(doc, TRUE);
8064     CHECK_CALLED(Advise_Close);
8065     test_external(doc, FALSE);
8066     test_IsDirty(doc, S_FALSE);
8067 
8068     set_custom_uihandler(doc, &CustomDocHostUIHandler);
8069     test_ClientSite(oleobj, CLIENTSITE_SETNULL);
8070     test_external(doc, TRUE);
8071     test_ClientSite(oleobj, CLIENTSITE_SETNULL|CLIENTSITE_DONTSET);
8072     test_external(doc, TRUE);
8073     set_custom_uihandler(doc, NULL);
8074     test_ClientSite(oleobj, CLIENTSITE_SETNULL|CLIENTSITE_DONTSET);
8075 
8076     IOleObject_Release(oleobj);
8077     if(view) {
8078         IOleDocumentView_Release(view);
8079         view = NULL;
8080     }
8081 
8082     release_document(doc);
8083 }
8084 
8085 static void test_HTMLDocument_StreamInitNew(void)
8086 {
8087     IHTMLDocument2 *doc;
8088     IOleObject *oleobj;
8089     DWORD conn;
8090     HRESULT hres;
8091 
8092     trace("Testing HTMLDocument (IPersistStreamInit::InitNew)...\n");
8093 
8094     init_test(LD_DOLOAD);
8095     load_from_stream = TRUE;
8096 
8097     doc = create_document();
8098     doc_unk = (IUnknown*)doc;
8099 
8100     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
8101     ok(hres == S_OK, "Could not get IOleObject: %08x\n", hres);
8102 
8103     hres = IOleObject_Advise(oleobj, (IAdviseSink*)&AdviseSink, &conn);
8104     ok(hres == S_OK, "Advise failed: %08x\n", hres);
8105 
8106     test_readyState((IUnknown*)doc);
8107     test_IsDirty(doc, S_FALSE);
8108     test_ViewAdviseSink(doc);
8109     test_ConnectionPointContainer(doc);
8110     test_ClientSite(oleobj, CLIENTSITE_EXPECTPATH);
8111     test_DoVerb(oleobj);
8112     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
8113 
8114     IOleObject_Release(oleobj);
8115 
8116     test_GetCurMoniker((IUnknown*)doc, NULL, NULL, FALSE);
8117     test_StreamInitNew(doc);
8118 
8119     SET_EXPECT(Invoke_OnReadyStateChange_Interactive);
8120     test_download(DWL_VERBDONE|DWL_TRYCSS|DWL_EMPTY);
8121     todo_wine CHECK_NOT_CALLED(Invoke_OnReadyStateChange_Interactive);
8122 
8123     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
8124 
8125     test_UIDeactivate();
8126     test_InPlaceDeactivate(doc, TRUE);
8127     SET_EXPECT(Advise_Close);
8128     test_Close(doc, FALSE);
8129     CHECK_CALLED(Advise_Close);
8130     test_IsDirty(doc, S_FALSE);
8131 
8132     if(view) {
8133         IOleDocumentView_Release(view);
8134         view = NULL;
8135     }
8136 
8137     release_document(doc);
8138 }
8139 
8140 static void test_edit_uiactivate(IOleObject *oleobj)
8141 {
8142     IOleDocumentView *docview;
8143     HRESULT hres;
8144 
8145     hres = IOleObject_QueryInterface(oleobj, &IID_IOleDocumentView, (void **)&docview);
8146     ok(hres == S_OK, "IOleObject_QueryInterface failed with error 0x%08x\n", hres);
8147 
8148     SET_EXPECT(OnFocus_TRUE);
8149     SET_EXPECT(SetActiveObject);
8150     SET_EXPECT(ShowUI);
8151     SET_EXPECT(InPlaceUIWindow_SetActiveObject);
8152     SET_EXPECT(InPlaceFrame_SetBorderSpace);
8153     expect_status_text = NULL;
8154 
8155     hres = IOleDocumentView_UIActivate(docview, TRUE);
8156     ok(hres == S_OK, "IOleDocumentView_UIActivate failed with error 0x%08x\n", hres);
8157 
8158     CHECK_CALLED(OnFocus_TRUE);
8159     CHECK_CALLED(SetActiveObject);
8160     CHECK_CALLED(ShowUI);
8161     CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
8162     CHECK_CALLED(InPlaceFrame_SetBorderSpace);
8163 
8164     IOleDocumentView_Release(docview);
8165 }
8166 
8167 static void test_editing_mode(BOOL do_load, BOOL use_design_mode)
8168 {
8169     IHTMLDocument2 *doc;
8170     IUnknown *unk;
8171     IOleObject *oleobj;
8172     DWORD conn;
8173     HRESULT hres;
8174 
8175     trace("Testing HTMLDocument (edit%s%s)...\n", do_load ? " load" : "", use_design_mode ? " using designMode" : "");
8176 
8177     init_test(do_load ? LD_DOLOAD : LD_NO);
8178     call_UIActivate = CallUIActivate_AfterShow;
8179 
8180     doc = create_document();
8181     unk = doc_unk = (IUnknown*)doc;
8182 
8183     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
8184     ok(hres == S_OK, "Could not get IOleObject: %08x\n", hres);
8185 
8186     hres = IOleObject_Advise(oleobj, (IAdviseSink*)&AdviseSink, &conn);
8187     ok(hres == S_OK, "Advise failed: %08x\n", hres);
8188 
8189     test_readyState((IUnknown*)doc);
8190     test_ViewAdviseSink(doc);
8191     test_ConnectionPointContainer(doc);
8192     test_ClientSite(oleobj, CLIENTSITE_EXPECTPATH);
8193     test_DoVerb(oleobj);
8194     test_edit_uiactivate(oleobj);
8195 
8196     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
8197     if(do_load)
8198         test_Persist(doc, &Moniker);
8199     stream_read = protocol_read = 0;
8200 
8201     if(!use_design_mode) {
8202         test_exec_editmode(unk, do_load);
8203         test_UIDeactivate();
8204         call_UIActivate = CallUIActivate_None;
8205     }else {
8206         BSTR on;
8207 
8208         SET_EXPECT(Exec_SETTITLE);
8209         test_download(DWL_VERBDONE|DWL_CSS|DWL_TRYCSS);
8210         CLEAR_CALLED(Exec_SETTITLE);
8211 
8212         editmode = TRUE;
8213         load_state = LD_DOLOAD;
8214         readystate_set_loading = TRUE;
8215 
8216         SET_EXPECT(OnChanged_1005);
8217         SET_EXPECT(ActiveElementChanged);
8218         SET_EXPECT(GetClassID);
8219         SET_EXPECT(SetStatusText);
8220         SET_EXPECT(Exec_ShellDocView_37);
8221         SET_EXPECT(GetHostInfo);
8222         SET_EXPECT(GetDisplayName);
8223         SET_EXPECT(Invoke_AMBIENT_SILENT);
8224         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
8225         SET_EXPECT(OnChanged_READYSTATE);
8226         SET_EXPECT(Invoke_OnReadyStateChange_Loading);
8227         SET_EXPECT(IsSystemMoniker);
8228         SET_EXPECT(Exec_ShellDocView_84);
8229         SET_EXPECT(BindToStorage);
8230         SET_EXPECT(InPlaceUIWindow_SetActiveObject);
8231         SET_EXPECT(HideUI);
8232         SET_EXPECT(ShowUI);
8233         SET_EXPECT(InPlaceFrame_SetBorderSpace);
8234         SET_EXPECT(OnChanged_1014);
8235 
8236         on = a2bstr("On");
8237         hres = IHTMLDocument2_put_designMode(doc, on);
8238         SysFreeString(on);
8239         ok(hres == S_OK, "put_designMode failed: %08x\n", hres);
8240 
8241         todo_wine CHECK_CALLED(OnChanged_1005);
8242         todo_wine CHECK_CALLED(ActiveElementChanged);
8243         CHECK_CALLED(GetClassID);
8244         CHECK_CALLED(SetStatusText);
8245         CHECK_CALLED(Exec_ShellDocView_37);
8246         CHECK_CALLED(GetHostInfo);
8247         CHECK_CALLED(GetDisplayName);
8248         CHECK_CALLED(Invoke_AMBIENT_SILENT);
8249         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
8250         CHECK_CALLED(OnChanged_READYSTATE);
8251         CHECK_CALLED(Invoke_OnReadyStateChange_Loading);
8252         CLEAR_CALLED(IsSystemMoniker); /* IE7 */
8253         CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
8254         CHECK_CALLED(BindToStorage);
8255         CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
8256         CHECK_CALLED(HideUI);
8257         CHECK_CALLED(ShowUI);
8258         CHECK_CALLED(InPlaceFrame_SetBorderSpace);
8259         CHECK_CALLED(OnChanged_1014);
8260 
8261         test_timer(EXPECT_UPDATEUI|EXPECT_SETTITLE);
8262     }
8263 
8264     IOleObject_Release(oleobj);
8265 
8266     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED);
8267     test_download(DWL_VERBDONE | DWL_EX_GETHOSTINFO | (do_load ? DWL_CSS|DWL_TRYCSS : 0));
8268 
8269     SET_EXPECT(SetStatusText); /* ignore race in native mshtml */
8270     test_timer(EXPECT_UPDATEUI);
8271     CLEAR_CALLED(SetStatusText);
8272 
8273     test_MSHTML_QueryStatus(doc, OLECMDF_SUPPORTED|OLECMDF_ENABLED);
8274 
8275     if(!do_load) {
8276         test_exec_fontname(unk, wszArial, wszTimesNewRoman);
8277         test_timer(EXPECT_UPDATEUI);
8278         test_exec_fontname(unk, NULL, wszArial);
8279 
8280         test_exec_noargs(unk, IDM_JUSTIFYRIGHT);
8281         test_timer(EXPECT_UPDATEUI);
8282         test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYRIGHT,
8283                          OLECMDF_SUPPORTED|OLECMDF_ENABLED|OLECMDF_LATCHED);
8284 
8285         test_exec_noargs(unk, IDM_JUSTIFYCENTER);
8286         test_timer(EXPECT_UPDATEUI);
8287         test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYRIGHT,
8288                          OLECMDF_SUPPORTED|OLECMDF_ENABLED);
8289         test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYCENTER,
8290                          OLECMDF_SUPPORTED|OLECMDF_ENABLED|OLECMDF_LATCHED);
8291 
8292         test_exec_noargs(unk, IDM_HORIZONTALLINE);
8293         test_timer(EXPECT_UPDATEUI);
8294         test_QueryStatus(unk, &CGID_MSHTML, IDM_HORIZONTALLINE,
8295                          OLECMDF_SUPPORTED|OLECMDF_ENABLED);
8296     }
8297 
8298     test_UIDeactivate();
8299     test_InPlaceDeactivate(doc, TRUE);
8300     SET_EXPECT(Advise_Close);
8301     test_Close(doc, FALSE);
8302     CHECK_CALLED(Advise_Close);
8303 
8304     if(view) {
8305         IOleDocumentView_Release(view);
8306         view = NULL;
8307     }
8308 
8309     release_document(doc);
8310 }
8311 
8312 static void test_UIActivate(BOOL do_load, BOOL use_ipsex, BOOL use_ipsw)
8313 {
8314     IHTMLDocument2 *doc;
8315     IOleObject *oleobj;
8316     IOleInPlaceSite *inplacesite;
8317     HRESULT hres;
8318 
8319     trace("Running OleDocumentView_UIActivate tests (%d %d %d)\n", do_load, use_ipsex, use_ipsw);
8320 
8321     init_test(do_load ? LD_DOLOAD : LD_NO);
8322 
8323     doc = create_document();
8324     doc_unk = (IUnknown*)doc;
8325 
8326     ipsex = use_ipsex;
8327     ipsw = use_ipsw;
8328 
8329     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleObject, (void**)&oleobj);
8330     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
8331 
8332     hres = IHTMLDocument2_QueryInterface(doc, &IID_IOleDocumentView, (void**)&view);
8333     ok(hres == S_OK, "QueryInterface(IID_IOleDocumentView) failed: %08x\n", hres);
8334 
8335     SET_EXPECT(Invoke_AMBIENT_USERMODE);
8336     SET_EXPECT(GetHostInfo);
8337     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
8338     SET_EXPECT(Invoke_AMBIENT_SILENT);
8339     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
8340     SET_EXPECT(Invoke_AMBIENT_USERAGENT);
8341     SET_EXPECT(Invoke_AMBIENT_PALETTE);
8342     SET_EXPECT(GetOptionKeyPath);
8343     SET_EXPECT(GetOverrideKeyPath);
8344     SET_EXPECT(GetWindow);
8345     SET_EXPECT(Exec_DOCCANNAVIGATE);
8346     SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
8347     SET_EXPECT(Exec_SETPROGRESSMAX);
8348     SET_EXPECT(Exec_SETPROGRESSPOS);
8349     SET_EXPECT(GetTravelLog);
8350     SET_EXPECT(Exec_ShellDocView_84);
8351 
8352     hres = IOleObject_SetClientSite(oleobj, &ClientSite);
8353     ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
8354     set_clientsite = TRUE;
8355 
8356     CHECK_CALLED(Invoke_AMBIENT_USERMODE);
8357     CHECK_CALLED(GetHostInfo);
8358     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
8359     CHECK_CALLED(Invoke_AMBIENT_SILENT);
8360     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
8361     CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
8362     CLEAR_CALLED(Invoke_AMBIENT_PALETTE); /* not called on IE9 */
8363     CLEAR_CALLED(GetOptionKeyPath); /* not called on some IE9 */
8364     CHECK_CALLED(GetOverrideKeyPath);
8365     CHECK_CALLED(GetWindow);
8366     CHECK_CALLED(Exec_DOCCANNAVIGATE);
8367     CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
8368     CHECK_CALLED(Exec_SETPROGRESSMAX);
8369     CHECK_CALLED(Exec_SETPROGRESSPOS);
8370     CHECK_CALLED(GetTravelLog);
8371     CHECK_CALLED_BROKEN(Exec_ShellDocView_84);
8372 
8373     hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
8374     ok(hres == S_OK, "GetInPlaceSite failed: %08x\n", hres);
8375     ok(inplacesite == NULL, "inplacesite = %p, expected NULL\n", inplacesite);
8376 
8377     SET_EXPECT(GetContainer);
8378     SET_EXPECT(LockContainer);
8379     SET_EXPECT(CanInPlaceActivate);
8380     SET_EXPECT(GetWindowContext);
8381     SET_EXPECT(GetWindow);
8382     if(use_ipsex) {
8383         SET_EXPECT(OnInPlaceActivateEx);
8384         SET_EXPECT(RequestUIActivate);
8385     }
8386     else
8387         SET_EXPECT(OnInPlaceActivate);
8388     SET_EXPECT(OnUIActivate);
8389     SET_EXPECT(SetStatusText);
8390     SET_EXPECT(Exec_SETPROGRESSMAX);
8391     SET_EXPECT(Exec_SETPROGRESSPOS);
8392     SET_EXPECT(ShowUI);
8393     SET_EXPECT(InPlaceUIWindow_SetActiveObject);
8394     SET_EXPECT(InPlaceFrame_SetBorderSpace);
8395     SET_EXPECT(OnFocus_TRUE);
8396     SET_EXPECT(SetActiveObject);
8397     expect_LockContainer_fLock = TRUE;
8398 
8399     hres = IOleDocumentView_UIActivate(view, TRUE);
8400     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
8401 
8402     CHECK_CALLED(GetContainer);
8403     CHECK_CALLED(LockContainer);
8404     CHECK_CALLED(CanInPlaceActivate);
8405     CHECK_CALLED(GetWindowContext);
8406     CHECK_CALLED(GetWindow);
8407     if(use_ipsex) {
8408         CHECK_CALLED(OnInPlaceActivateEx);
8409         SET_EXPECT(RequestUIActivate);
8410     }
8411     else
8412         CHECK_CALLED(OnInPlaceActivate);
8413     CHECK_CALLED(OnUIActivate);
8414     CHECK_CALLED(SetStatusText);
8415     CHECK_CALLED(Exec_SETPROGRESSMAX);
8416     CHECK_CALLED(Exec_SETPROGRESSPOS);
8417     CHECK_CALLED(ShowUI);
8418     CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
8419     CHECK_CALLED(InPlaceFrame_SetBorderSpace);
8420     CHECK_CALLED(OnFocus_TRUE);
8421     CHECK_CALLED(SetActiveObject);
8422     container_locked = TRUE;
8423 
8424     SET_EXPECT(SetActiveObject_null);
8425     SET_EXPECT(InPlaceUIWindow_SetActiveObject);
8426     SET_EXPECT(HideUI);
8427     SET_EXPECT(OnUIDeactivate);
8428 
8429     hres = IOleDocumentView_UIActivate(view, FALSE);
8430     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
8431 
8432     CHECK_CALLED(SetActiveObject_null);
8433     CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
8434     CHECK_CALLED(HideUI);
8435     CHECK_CALLED(OnUIDeactivate);
8436 
8437     hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
8438     ok(hres == S_OK, "GetInPlaceSite failed: %08x\n", hres);
8439     ok(inplacesite != NULL, "inplacesite = NULL\n");
8440     IOleInPlaceSite_Release(inplacesite);
8441 
8442     SET_EXPECT(SetStatusText);
8443     SET_EXPECT(OnFocus_FALSE);
8444     if(use_ipsex)
8445         SET_EXPECT(OnInPlaceDeactivateEx);
8446     else
8447         SET_EXPECT(OnInPlaceDeactivate);
8448 
8449     test_CloseView();
8450 
8451     CLEAR_CALLED(SetStatusText); /* Called by IE9 */
8452     CHECK_CALLED(OnFocus_FALSE);
8453     if(use_ipsex)
8454         CHECK_CALLED(OnInPlaceDeactivateEx);
8455     else
8456         CHECK_CALLED(OnInPlaceDeactivate);
8457 
8458     test_Close(doc, TRUE);
8459 
8460     IOleObject_Release(oleobj);
8461     IOleDocumentView_Release(view);
8462     view = NULL;
8463 
8464     release_document(doc);
8465 }
8466 
8467 static void register_protocol(void)
8468 {
8469     IInternetSession *session;
8470     HRESULT hres;
8471 
8472     static const WCHAR wsz_winetest[] = {'w','i','n','e','t','e','s','t',0};
8473 
8474     hres = CoInternetGetSession(0, &session, 0);
8475     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
8476 
8477     hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL,
8478             wsz_winetest, 0, NULL, 0);
8479     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
8480 
8481     IInternetSession_Release(session);
8482 }
8483 
8484 static void test_HTMLDoc_ISupportErrorInfo(void)
8485 {
8486     IHTMLDocument2 *doc;
8487     HRESULT hres;
8488     ISupportErrorInfo *sinfo;
8489 
8490     doc = create_document();
8491 
8492     hres = IHTMLDocument2_QueryInterface(doc, &IID_ISupportErrorInfo, (void**)&sinfo);
8493     ok(hres == S_OK, "got %x\n", hres);
8494     ok(sinfo != NULL, "got %p\n", sinfo);
8495     if(sinfo)
8496     {
8497         hres = ISupportErrorInfo_InterfaceSupportsErrorInfo(sinfo, &IID_IErrorInfo);
8498         ok(hres == S_FALSE, "Expected S_OK, got %x\n", hres);
8499         ISupportErrorInfo_Release(sinfo);
8500     }
8501 
8502     release_document(doc);
8503 }
8504 
8505 static BOOL check_ie(void)
8506 {
8507     IHTMLDocument2 *doc;
8508     IHTMLDocument5 *doc5;
8509     IHTMLDocument7 *doc7;
8510     HRESULT hres;
8511 
8512     doc = create_document();
8513     if(!doc)
8514         return FALSE;
8515 
8516     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument7, (void**)&doc7);
8517     if(SUCCEEDED(hres)) {
8518         is_ie9plus = TRUE;
8519         IHTMLDocument7_Release(doc7);
8520     }
8521 
8522     trace("is_ie9plus %x\n", is_ie9plus);
8523 
8524     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument5, (void**)&doc5);
8525     if(SUCCEEDED(hres))
8526         IHTMLDocument5_Release(doc5);
8527 
8528     release_document(doc);
8529     return SUCCEEDED(hres);
8530 }
8531 
8532 static void test_ServiceProvider(void)
8533 {
8534     IHTMLDocument3 *doc3, *doc3_2;
8535     IServiceProvider *provider;
8536     IHTMLDocument2 *doc, *doc2;
8537     IUnknown *unk;
8538     HRESULT hres;
8539 
8540     doc = create_document();
8541     if(!doc)
8542         return;
8543 
8544     hres = IHTMLDocument2_QueryInterface(doc, &IID_IServiceProvider, (void**)&provider);
8545     ok(hres == S_OK, "got 0x%08x\n", hres);
8546 
8547     hres = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument2, (void**)&doc2);
8548     ok(hres == S_OK, "got 0x%08x\n", hres);
8549     ok(iface_cmp((IUnknown*)doc2, (IUnknown*)doc), "got wrong pointer\n");
8550     IHTMLDocument2_Release(doc2);
8551 
8552     hres = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IHTMLDocument3, (void**)&doc3);
8553     ok(hres == S_OK, "got 0x%08x\n", hres);
8554     ok(iface_cmp((IUnknown*)doc3, (IUnknown*)doc), "got wrong pointer\n");
8555 
8556     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3_2);
8557     ok(hres == S_OK, "got 0x%08x\n", hres);
8558     ok(iface_cmp((IUnknown*)doc3_2, (IUnknown*)doc), "got wrong pointer\n");
8559     ok(iface_cmp((IUnknown*)doc3_2, (IUnknown*)doc3), "got wrong pointer\n");
8560     IHTMLDocument3_Release(doc3);
8561     IHTMLDocument3_Release(doc3_2);
8562 
8563     hres = IServiceProvider_QueryService(provider, &SID_SContainerDispatch, &IID_IUnknown, (void**)&unk);
8564     ok(hres == S_OK, "got 0x%08x\n", hres);
8565     ok(iface_cmp((IUnknown*)doc, unk), "got wrong pointer\n");
8566     IUnknown_Release(unk);
8567 
8568     hres = IServiceProvider_QueryService(provider, &SID_SHTMLEditServices, &IID_IHTMLEditServices, (void**)&unk);
8569     ok(hres == S_OK, "QueryService(HTMLEditServices) failed: %08x\n", hres);
8570     IUnknown_Release(unk);
8571 
8572     IServiceProvider_Release(provider);
8573     release_document(doc);
8574 }
8575 
8576 START_TEST(htmldoc)
8577 {
8578     CoInitialize(NULL);
8579 
8580     if(!check_ie()) {
8581         CoUninitialize();
8582         win_skip("Too old IE\n");
8583         return;
8584     }
8585 
8586     container_hwnd = create_container_window();
8587     register_protocol();
8588 
8589     asynchronous_binding = TRUE;
8590     test_HTMLDocument_hlink(HTTP_STATUS_NOT_FOUND);
8591 
8592     asynchronous_binding = FALSE;
8593     test_HTMLDocument_hlink(HTTP_STATUS_OK);
8594     test_HTMLDocument(FALSE, TRUE);
8595     test_HTMLDocument(TRUE, FALSE);
8596     test_HTMLDocument(TRUE, TRUE);
8597     test_HTMLDocument_StreamLoad();
8598     test_HTMLDocument_StreamInitNew();
8599     test_editing_mode(FALSE, FALSE);
8600     test_editing_mode(TRUE, FALSE);
8601     test_editing_mode(TRUE, TRUE);
8602     test_HTMLDocument_http(FALSE);
8603     test_HTMLDocument_http(TRUE);
8604 
8605     test_submit();
8606     test_UIActivate(FALSE, FALSE, FALSE);
8607     test_UIActivate(FALSE, TRUE, FALSE);
8608     test_UIActivate(FALSE, TRUE, TRUE);
8609     test_UIActivate(TRUE, FALSE, FALSE);
8610     test_UIActivate(TRUE, TRUE, FALSE);
8611     test_UIActivate(TRUE, TRUE, TRUE);
8612     test_HTMLDoc_ISupportErrorInfo();
8613     test_ServiceProvider();
8614 
8615     DestroyWindow(container_hwnd);
8616     CoUninitialize();
8617 }
8618