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