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