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