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