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