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