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