Do filename postprocessing in GetDisplayNameOf (Hide filename
[wine] / dlls / mshtml / tests / htmldoc.c
1 /*
2  * Copyright 2005 Jacek Caban
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #define COBJMACROS
20
21 #include <wine/test.h>
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "ole2.h"
27 #include "mshtml.h"
28 #include "docobj.h"
29 #include "mshtmhst.h"
30
31 #define DEFINE_EXPECT(func) \
32     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
33
34 #define SET_EXPECT(func) \
35     expect_ ## func = TRUE
36
37 #define CHECK_EXPECT(func) \
38     ok(expect_ ##func, "unexpected call\n"); \
39     expect_ ## func = FALSE; \
40     called_ ## func = TRUE
41
42 #define CHECK_CALLED(func) \
43     ok(called_ ## func, "unexpected call\n"); \
44     expect_ ## func = called_ ## func = FALSE
45
46 static IUnknown *htmldoc_unk = NULL;
47 static IOleDocumentView *view = NULL;
48 static HWND container_hwnd = NULL, hwnd = NULL;
49
50 DEFINE_EXPECT(LockContainer);
51 DEFINE_EXPECT(SetActiveObject);
52 DEFINE_EXPECT(GetWindow);
53 DEFINE_EXPECT(CanInPlaceActivate);
54 DEFINE_EXPECT(OnInPlaceActivate);
55 DEFINE_EXPECT(OnUIActivate);
56 DEFINE_EXPECT(GetWindowContext);
57 DEFINE_EXPECT(OnUIDeactivate);
58 DEFINE_EXPECT(OnInPlaceDeactivate);
59 DEFINE_EXPECT(GetContainer);
60 DEFINE_EXPECT(ShowUI);
61 DEFINE_EXPECT(ActivateMe);
62 DEFINE_EXPECT(GetHostInfo);
63 DEFINE_EXPECT(HideUI);
64 DEFINE_EXPECT(GetOptionKeyPath);
65 DEFINE_EXPECT(GetOverrideKeyPath);
66
67 static BOOL expect_LockContainer_fLock;
68 static BOOL expect_SetActiveObject_active;
69
70 static HRESULT QueryInterface(REFIID riid, void **ppv);
71
72 static HRESULT WINAPI OleContainer_QueryInterface(IOleContainer *iface, REFIID riid, void **ppv)
73 {
74     return QueryInterface(riid, ppv);
75 }
76
77 static ULONG WINAPI OleContainer_AddRef(IOleContainer *iface)
78 {
79     return 2;
80 }
81
82 static ULONG WINAPI OleContainer_Release(IOleContainer *iface)
83 {
84     return 1;
85 }
86
87 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer *iface, IBindCtx *pbc,
88         LPOLESTR pszDiaplayName, ULONG *pchEaten, IMoniker **ppmkOut)
89 {
90     ok(0, "unexpected call\n");
91     return E_NOTIMPL;
92 }
93
94 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer *iface, DWORD grfFlags,
95         IEnumUnknown **ppenum)
96 {
97     ok(0, "unexpected call\n");
98     return E_NOTIMPL;
99 }
100
101 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer *iface, BOOL fLock)
102 {
103     CHECK_EXPECT(LockContainer);
104     ok(expect_LockContainer_fLock == fLock, "fLock=%x, expected %x\n", fLock, expect_LockContainer_fLock);
105     return S_OK;
106 }
107
108 static const IOleContainerVtbl OleContainerVtbl = {
109     OleContainer_QueryInterface,
110     OleContainer_AddRef,
111     OleContainer_Release,
112     OleContainer_ParseDisplayName,
113     OleContainer_EnumObjects,
114     OleContainer_LockContainer
115 };
116
117 static IOleContainer OleContainer = { &OleContainerVtbl };
118
119 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
120 {
121     return QueryInterface(riid, ppv);
122 }
123
124 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
125 {
126     return 2;
127 }
128
129 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
130 {
131     return 1;
132 }
133
134 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
135 {
136     ok(0, "unexpected call\n");
137     return E_NOTIMPL;
138 }
139
140 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
141 {
142     ok(0, "unexpected call\n");
143     return E_NOTIMPL;
144 }
145
146 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
147 {
148     ok(0, "unexpected call\n");
149     return E_NOTIMPL;
150 }
151
152 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
153         LPCBORDERWIDTHS pborderwidths)
154 {
155     ok(0, "unexpected call\n");
156     return E_NOTIMPL;
157 }
158
159 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
160         LPCBORDERWIDTHS pborderwidths)
161 {
162     ok(0, "unexpected call\n");
163     return E_NOTIMPL;
164 }
165
166 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
167         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
168 {
169     static const WCHAR wszHTML_Document[] =
170         {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
171
172     ok(expect_SetActiveObject, "unexpected call\n");
173     called_SetActiveObject = TRUE;
174
175     if(expect_SetActiveObject_active) {
176         ok(pActiveObject != NULL, "pActiveObject = NULL\n");
177         ok(!lstrcmpW(wszHTML_Document, pszObjName), "pszObjName != \"HTML Document\"\n");
178     }else {
179         ok(pActiveObject == NULL, "pActiveObject=%p, expected NULL\n", pActiveObject);
180         ok(pszObjName == NULL, "pszObjName=%p, expected NULL\n", pszObjName);
181     }
182
183     return S_OK;
184 }
185
186 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
187         LPOLEMENUGROUPWIDTHS lpMenuWidths)
188 {
189     ok(0, "unexpected call\n");
190     return E_NOTIMPL;
191 }
192
193 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
194         HOLEMENU holemenu, HWND hwndActiveObject)
195 {
196     ok(0, "unexpected call\n");
197     return E_NOTIMPL;
198 }
199
200 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
201 {
202     ok(0, "unexpected call\n");
203     return E_NOTIMPL;
204 }
205
206 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
207 {
208     ok(0, "unexpected call\n");
209     return E_NOTIMPL;
210 }
211
212 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
213 {
214     ok(0, "unexpected call\n");
215     return E_NOTIMPL;
216 }
217
218 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
219 {
220     ok(0, "unexpected call\n");
221     return E_NOTIMPL;
222 }
223
224 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
225     InPlaceFrame_QueryInterface,
226     InPlaceFrame_AddRef,
227     InPlaceFrame_Release,
228     InPlaceFrame_GetWindow,
229     InPlaceFrame_ContextSensitiveHelp,
230     InPlaceFrame_GetBorder,
231     InPlaceFrame_RequestBorderSpace,
232     InPlaceFrame_SetBorderSpace,
233     InPlaceFrame_SetActiveObject,
234     InPlaceFrame_InsertMenus,
235     InPlaceFrame_SetMenu,
236     InPlaceFrame_RemoveMenus,
237     InPlaceFrame_SetStatusText,
238     InPlaceFrame_EnableModeless,
239     InPlaceFrame_TranslateAccelerator
240 };
241
242 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
243
244 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
245 {
246     return QueryInterface(riid, ppv);
247 }
248
249 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
250 {
251     return 2;
252 }
253
254 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
255 {
256     return 1;
257 }
258
259 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
260 {
261     CHECK_EXPECT(GetWindow);
262     ok(phwnd != NULL, "phwnd = NULL\n");
263     *phwnd = container_hwnd;
264     return S_OK;
265 }
266
267 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
268 {
269     ok(0, "unexpected call\n");
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
274 {
275     CHECK_EXPECT(CanInPlaceActivate);
276     return S_OK;
277 }
278
279 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
280 {
281     CHECK_EXPECT(OnInPlaceActivate);
282     return S_OK;
283 }
284
285 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
286 {
287     CHECK_EXPECT(OnUIActivate);
288     return S_OK;
289 }
290
291 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
292         IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
293         LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
294 {
295     static const RECT rect = {0,0,500,500};
296
297     CHECK_EXPECT(GetWindowContext);
298
299     ok(ppFrame != NULL, "ppFrame = NULL\n");
300     if(ppFrame)
301         *ppFrame = &InPlaceFrame;
302     ok(ppDoc != NULL, "ppDoc = NULL\n");
303     if(ppDoc)
304         *ppDoc = NULL;
305     ok(lprcPosRect != NULL, "lprcPosRect = NULL\n");
306     if(lprcPosRect)
307         memcpy(lprcPosRect, &rect, sizeof(RECT));
308     ok(lprcClipRect != NULL, "lprcClipRect = NULL\n");
309     if(lprcClipRect)
310         memcpy(lprcClipRect, &rect, sizeof(RECT));
311     ok(lpFrameInfo != NULL, "lpFrameInfo = NULL\n");
312     if(lpFrameInfo) {
313         lpFrameInfo->cb = sizeof(*lpFrameInfo);
314         lpFrameInfo->fMDIApp = FALSE;
315         lpFrameInfo->hwndFrame = container_hwnd;
316         lpFrameInfo->haccel = NULL;
317         lpFrameInfo->cAccelEntries = 0;
318     }
319
320     return S_OK;
321 }
322
323 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
324 {
325     ok(0, "unexpected call\n");
326     return E_NOTIMPL;
327 }
328
329 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
330 {
331     CHECK_EXPECT(OnUIDeactivate);
332     ok(!fUndoable, "fUndoable = TRUE\n");
333     return S_OK;
334 }
335
336 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
337 {
338     CHECK_EXPECT(OnInPlaceDeactivate);
339     return S_OK;
340 }
341
342 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
343 {
344     ok(0, "unexpected call\n");
345     return E_NOTIMPL;
346 }
347
348 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
349 {
350     ok(0, "unexpected call\n");
351     return E_NOTIMPL;
352 }
353
354 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
355 {
356     ok(0, "unexpected call\n");
357     return E_NOTIMPL;
358 }
359
360 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
361     InPlaceSite_QueryInterface,
362     InPlaceSite_AddRef,
363     InPlaceSite_Release,
364     InPlaceSite_GetWindow,
365     InPlaceSite_ContextSensitiveHelp,
366     InPlaceSite_CanInPlaceActivate,
367     InPlaceSite_OnInPlaceActivate,
368     InPlaceSite_OnUIActivate,
369     InPlaceSite_GetWindowContext,
370     InPlaceSite_Scroll,
371     InPlaceSite_OnUIDeactivate,
372     InPlaceSite_OnInPlaceDeactivate,
373     InPlaceSite_DiscardUndoState,
374     InPlaceSite_DeactivateAndUndo,
375     InPlaceSite_OnPosRectChange
376 };
377
378 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
379
380 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
381 {
382     return QueryInterface(riid, ppv);
383 }
384
385 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
386 {
387     return 2;
388 }
389
390 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
391 {
392     return 1;
393 }
394
395 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
396 {
397     ok(0, "unexpected call\n");
398     return E_NOTIMPL;
399 }
400
401 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAsign, DWORD dwWhichMoniker,
402         IMoniker **ppmon)
403 {
404     ok(0, "unexpected call\n");
405     return E_NOTIMPL;
406 }
407
408 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
409 {
410     CHECK_EXPECT(GetContainer);
411     ok(ppContainer != NULL, "ppContainer = NULL\n");
412     *ppContainer = &OleContainer;
413     return S_OK;
414 }
415
416 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
417 {
418     ok(0, "unexpected call\n");
419     return E_NOTIMPL;
420 }
421
422 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
423 {
424     ok(0, "unexpected call\n");
425     return E_NOTIMPL;
426 }
427
428 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
429 {
430     ok(0, "unexpected call\n");
431     return E_NOTIMPL;
432 }
433
434 static const IOleClientSiteVtbl ClientSiteVtbl = {
435     ClientSite_QueryInterface,
436     ClientSite_AddRef,
437     ClientSite_Release,
438     ClientSite_SaveObject,
439     ClientSite_GetMoniker,
440     ClientSite_GetContainer,
441     ClientSite_ShowObject,
442     ClientSite_OnShowWindow,
443     ClientSite_RequestNewObjectLayout
444 };
445
446 static IOleClientSite ClientSite = { &ClientSiteVtbl };
447
448 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
449 {
450     return QueryInterface(riid, ppv);
451 }
452
453 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
454 {
455     return 2;
456 }
457
458 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
459 {
460     return 1;
461 }
462
463 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
464 {
465     IOleDocument *document;
466     HRESULT hres;
467
468     CHECK_EXPECT(ActivateMe);
469     ok(pViewToActivate != NULL, "pViewToActivate = NULL\n");
470
471     hres = IUnknown_QueryInterface(htmldoc_unk, &IID_IOleDocument, (void**)&document);
472     ok(hres == S_OK, "could not get IOleDocument: %08lx\n", hres);
473
474     if(SUCCEEDED(hres)) {
475         hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
476         ok(hres == S_OK, "CreateView failed: %08lx\n", hres);
477
478         if(SUCCEEDED(hres)) {
479             IOleInPlaceActiveObject *activeobj = NULL;
480             IOleInPlaceSite *inplacesite = NULL;
481             HWND tmp_hwnd = NULL;
482             static RECT rect = {0,0,400,500};
483
484             hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
485             ok(hres == S_OK, "GetInPlaceSite failed: %08lx\n", hres);
486             ok(inplacesite == &InPlaceSite, "inplacesite=%p, expected %p\n",
487                     inplacesite, &InPlaceSite);
488
489             hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
490             ok(hres == S_OK, "SetInPlaceSite failed: %08lx\n", hres);
491
492             hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
493             ok(hres == S_OK, "GetInPlaceSite failed: %08lx\n", hres);
494             ok(inplacesite == &InPlaceSite, "inplacesite=%p, expected %p\n",
495                     inplacesite, &InPlaceSite);
496
497             hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobj);
498             ok(hres == S_OK, "Could not get IOleInPlaceActiveObject: %08lx\n", hres);
499
500             if(activeobj) {
501                 IOleInPlaceActiveObject_GetWindow(activeobj, &hwnd);
502                 ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
503                 ok(hwnd == NULL, "hwnd=%p, expeted NULL\n", hwnd);
504             }
505             
506             SET_EXPECT(CanInPlaceActivate);
507             SET_EXPECT(GetWindowContext);
508             SET_EXPECT(GetWindow);
509             SET_EXPECT(OnInPlaceActivate);
510             SET_EXPECT(OnUIActivate);
511             SET_EXPECT(SetActiveObject);
512             SET_EXPECT(ShowUI);
513             expect_SetActiveObject_active = TRUE;
514             hres = IOleDocumentView_UIActivate(view, TRUE);
515             ok(hres == S_OK, "UIActivate failed: %08lx\n", hres);
516             CHECK_CALLED(CanInPlaceActivate);
517             CHECK_CALLED(GetWindowContext);
518             CHECK_CALLED(GetWindow);
519             CHECK_CALLED(OnInPlaceActivate);
520             CHECK_CALLED(OnUIActivate);
521             CHECK_CALLED(SetActiveObject);
522             CHECK_CALLED(ShowUI);
523
524             if(activeobj) {
525                 IOleInPlaceActiveObject_GetWindow(activeobj, &hwnd);
526                 ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
527                 ok(hwnd != NULL, "hwnd == NULL\n");
528             }
529
530             hres = IOleDocumentView_UIActivate(view, TRUE);
531             ok(hres == S_OK, "UIActivate failed: %08lx\n", hres);
532
533             if(activeobj) {
534                 IOleInPlaceActiveObject_GetWindow(activeobj, &tmp_hwnd);
535                 ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
536                 ok(tmp_hwnd == hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, hwnd);
537             }
538
539             hres = IOleDocumentView_SetRect(view, &rect);
540             ok(hres == S_OK, "SetRect failed: %08lx\n", hres);
541
542             hres = IOleDocumentView_Show(view, TRUE);
543             ok(hres == S_OK, "Show failed: %08lx\n", hres);
544             
545             if(activeobj)
546                 IOleInPlaceActiveObject_Release(activeobj);
547         }
548
549         IOleDocument_Release(document);
550     }
551
552     return S_OK;
553 }
554
555 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
556     DocumentSite_QueryInterface,
557     DocumentSite_AddRef,
558     DocumentSite_Release,
559     DocumentSite_ActivateMe
560 };
561
562 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
563
564 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
565 {
566     return QueryInterface(riid, ppv);
567 }
568
569 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
570 {
571     return 2;
572 }
573
574 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
575 {
576     return 1;
577 }
578
579 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
580         IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
581 {
582     ok(0, "unexpected call\n");
583     return E_NOTIMPL;
584 }
585
586 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
587 {
588     CHECK_EXPECT(GetHostInfo);
589     ok(pInfo != NULL, "pInfo=NULL\n");
590     if(pInfo) {
591         ok(pInfo->cbSize == sizeof(DOCHOSTUIINFO), "pInfo->cbSize=%lu, expected %u\n",
592                 pInfo->cbSize, sizeof(DOCHOSTUIINFO));
593         ok(!pInfo->dwFlags, "pInfo->dwFlags=%08lx, expected 0\n", pInfo->dwFlags);
594         pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE
595             | DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
596             | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
597         ok(!pInfo->dwDoubleClick, "pInfo->dwDoubleClick=%08lx, expected 0\n", pInfo->dwDoubleClick);
598         ok(!pInfo->pchHostCss, "pInfo->pchHostCss=%p, expected NULL\n", pInfo->pchHostCss);
599         ok(!pInfo->pchHostNS, "pInfo->pchhostNS=%p, expected NULL\n", pInfo->pchHostNS);
600     }
601     return S_OK;
602 }
603
604 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
605         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
606         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
607 {
608     CHECK_EXPECT(ShowUI);
609
610     ok(dwID == 0, "dwID=%ld, expected 0\n", dwID);
611     ok(pActiveObject != NULL, "pActiveObject = NULL\n");
612     ok(pCommandTarget != NULL, "pCommandTarget = NULL\n");
613     ok(pFrame == &InPlaceFrame, "pFrame=%p, expected %p\n", pFrame, &InPlaceFrame);
614     ok(pDoc == NULL, "pDoc=%p, expected NULL\n", pDoc);
615
616     return S_OK;
617 }
618
619 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
620 {
621     CHECK_EXPECT(HideUI);
622     return S_OK;
623 }
624
625 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
626 {
627     ok(0, "unexpected call\n");
628     return E_NOTIMPL;
629 }
630
631 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
632 {
633     ok(0, "unexpected call\n");
634     return E_NOTIMPL;
635 }
636
637 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
638 {
639     ok(0, "unexpected call\n");
640     return E_NOTIMPL;
641 }
642
643 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
644 {
645     ok(0, "unexpected call\n");
646     return E_NOTIMPL;
647 }
648
649 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
650         IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
651 {
652     ok(0, "unexpected call\n");
653     return E_NOTIMPL;
654 }
655
656 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
657         const GUID *pguidCmdGroup, DWORD nCmdID)
658 {
659     ok(0, "unexpected call\n");
660     return E_NOTIMPL;
661 }
662
663 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
664         LPOLESTR *pchKey, DWORD dw)
665 {
666     CHECK_EXPECT(GetOptionKeyPath);
667     ok(pchKey != NULL, "pchKey = NULL\n");
668     ok(!dw, "dw=%ld, expected 0\n", dw);
669     if(pchKey)
670         ok(!*pchKey, "*pchKey=%p, expected NULL\n", *pchKey);
671     return S_OK;
672 }
673
674 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
675         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
676 {
677     ok(0, "unexpected call\n");
678     return E_NOTIMPL;
679 }
680
681 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
682 {
683     ok(0, "unexpected call\n");
684     return E_NOTIMPL;
685 }
686
687 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
688         OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
689 {
690     ok(0, "unexpected call\n");
691     return E_NOTIMPL;
692 }
693
694 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
695         IDataObject **ppPORet)
696 {
697     ok(0, "unexpected call\n");
698     return E_NOTIMPL;
699 }
700
701 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
702         LPOLESTR *pchKey, DWORD dw)
703 {
704     CHECK_EXPECT(GetOverrideKeyPath);
705     ok(pchKey != NULL, "pchKey = NULL\n");
706     if(pchKey)
707         ok(!*pchKey, "*pchKey=%p, expected NULL\n", *pchKey);
708     ok(!dw, "dw=%ld, xepected 0\n", dw);
709     return S_OK;
710 }
711
712 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
713     DocHostUIHandler_QueryInterface,
714     DocHostUIHandler_AddRef,
715     DocHostUIHandler_Release,
716     DocHostUIHandler_ShowContextMenu,
717     DocHostUIHandler_GetHostInfo,
718     DocHostUIHandler_ShowUI,
719     DocHostUIHandler_HideUI,
720     DocHostUIHandler_UpdateUI,
721     DocHostUIHandler_EnableModeless,
722     DocHostUIHandler_OnDocWindowActivate,
723     DocHostUIHandler_OnFrameWindowActivate,
724     DocHostUIHandler_ResizeBorder,
725     DocHostUIHandler_TranslateAccelerator,
726     DocHostUIHandler_GetOptionKeyPath,
727     DocHostUIHandler_GetDropTarget,
728     DocHostUIHandler_GetExternal,
729     DocHostUIHandler_TranslateUrl,
730     DocHostUIHandler_FilterDataObject,
731     DocHostUIHandler_GetOverrideKeyPath
732 };
733
734 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
735
736 static HRESULT QueryInterface(REFIID riid, void **ppv)
737 {
738     *ppv = NULL;
739
740     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
741         *ppv = &ClientSite;
742     else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
743         *ppv = &DocumentSite;
744     else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid)) {
745         *ppv = &DocHostUIHandler;
746     }
747     else if(IsEqualGUID(&IID_IOleContainer, riid))
748         *ppv = &OleContainer;
749     else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
750         *ppv = &InPlaceSite;
751     else if(IsEqualGUID(&IID_IOleInPlaceUIWindow, riid) || IsEqualGUID(&IID_IOleInPlaceFrame, riid))
752         *ppv = &InPlaceFrame;
753
754     /* TODO:
755      * IDispatch
756      * IServiceProvider
757      * IOleCommandTarget
758      * {D48A6EC6-6A4A-11CF-94A7-444553540000}
759      * {7BB0B520-B1A7-11D2-BB23-00C04F79ABCD}
760      * {000670BA-0000-0000-C000-000000000046}
761      */
762
763     if(*ppv)
764         return S_OK;
765     return E_NOINTERFACE;
766 }
767
768 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
769 {
770     return DefWindowProc(hwnd, msg, wParam, lParam);
771 }
772
773 static void test_Persist()
774 {
775     IPersistMoniker *persist_mon;
776     IPersistFile *persist_file;
777     GUID guid;
778     HRESULT hres;
779
780     hres = IUnknown_QueryInterface(htmldoc_unk, &IID_IPersistFile, (void**)&persist_file);
781     ok(hres == S_OK, "QueryInterface(IID_IPersist) failed: %08lx\n", hres);
782     if(SUCCEEDED(hres)) {
783         hres = IPersist_GetClassID(persist_file, NULL);
784         ok(hres == E_INVALIDARG, "GetClassID returned: %08lx, expected E_INVALIDARG\n", hres);
785
786         hres = IPersist_GetClassID(persist_file, &guid);
787         ok(hres == S_OK, "GetClassID failed: %08lx\n", hres);
788         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
789
790         IPersist_Release(persist_file);
791     }
792
793     hres = IUnknown_QueryInterface(htmldoc_unk, &IID_IPersistMoniker, (void**)&persist_mon);
794     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker) failed: %08lx\n", hres);
795     if(SUCCEEDED(hres)) {
796         hres = IPersistMoniker_GetClassID(persist_mon, NULL);
797         ok(hres == E_INVALIDARG, "GetClassID returned: %08lx, expected E_INVALIDARG\n", hres);
798
799         hres = IPersistMoniker_GetClassID(persist_mon, &guid);
800         ok(hres == S_OK, "GetClassID failed: %08lx\n", hres);
801         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
802
803         IPersistMoniker_Release(persist_mon);
804     }
805 }
806
807 static void test_HTMLDocument(void)
808 {
809     IOleObject *oleobj = NULL;
810     IOleClientSite *clientsite = (LPVOID)0xdeadbeef;
811     IOleInPlaceObjectWindowless *windowlessobj = NULL;
812     IOleInPlaceActiveObject *activeobject = NULL;
813     GUID guid;
814     RECT rect = {0,0,500,500};
815     HRESULT hres;
816     ULONG ref;
817
818     static const WCHAR wszHTMLDocumentTest[] =
819         {'H','T','M','L','D','o','c','u','m','e','n','t','T','e','s','t',0};
820     static const WNDCLASSEXW wndclass = {
821         sizeof(WNDCLASSEXW),
822         0,
823         wnd_proc,
824         0, 0, NULL, NULL, NULL, NULL, NULL,
825         wszHTMLDocumentTest,
826         NULL
827     };
828
829     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
830             &IID_IUnknown, (void**)&htmldoc_unk);
831     ok(hres == S_OK, "CoCreateInstance failed: %08lx\n", hres);
832     if(FAILED(hres))
833         return;
834
835     RegisterClassExW(&wndclass);
836     container_hwnd = CreateWindowW(wszHTMLDocumentTest, wszHTMLDocumentTest,
837             WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
838             CW_USEDEFAULT, NULL, NULL, NULL, NULL);
839
840     test_Persist();
841
842     hres = IUnknown_QueryInterface(htmldoc_unk, &IID_IOleInPlaceObjectWindowless,
843             (void**)&windowlessobj);
844     ok(hres == S_OK, "Could not get IOleInPlaceObjectWindowless interface: %08lx\n", hres);
845              
846     hres = IUnknown_QueryInterface(htmldoc_unk, &IID_IOleObject, (void**)&oleobj);
847     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08lx\n", hres);
848     if(oleobj) {
849         hres = IOleObject_GetUserClassID(oleobj, NULL);
850         ok(hres == E_INVALIDARG, "GetUserClassID returned: %08lx, expected E_INVALIDARG\n", hres);
851
852         hres = IOleObject_GetUserClassID(oleobj, &guid);
853         ok(hres == S_OK, "GetUserClassID failed: %08lx\n", hres);
854         ok(IsEqualGUID(&guid, &CLSID_HTMLDocument), "guid != CLSID_HTMLDocument\n");
855
856         hres = IOleObject_GetClientSite(oleobj, &clientsite);
857         ok(hres == S_OK, "GetClientSite failed: %08lx\n", hres);
858         ok(clientsite == NULL, "GetClientSite() = %p, expected NULL\n", clientsite);
859
860         SET_EXPECT(GetHostInfo);
861         SET_EXPECT(GetOptionKeyPath);
862         SET_EXPECT(GetOverrideKeyPath);
863         SET_EXPECT(GetWindow);
864         hres = IOleObject_SetClientSite(oleobj, &ClientSite);
865         ok(hres == S_OK, "SetClientSite failed: %08lx\n", hres);
866         CHECK_CALLED(GetHostInfo);
867         CHECK_CALLED(GetOptionKeyPath);
868         CHECK_CALLED(GetOverrideKeyPath);
869         CHECK_CALLED(GetWindow);
870
871         hres = IOleObject_GetClientSite(oleobj, &clientsite);
872         ok(hres == S_OK, "GetClientSite failed: %08lx\n", hres);
873         ok(clientsite == &ClientSite, "GetClientSite() = %p, expected %p\n", clientsite, &ClientSite);
874
875         if(windowlessobj) {
876             hres = IOleInPlaceObjectWindowless_InPlaceDeactivate(windowlessobj);
877             ok(hres == S_OK, "InPlaceDeactivate failed: %08lx\n", hres);
878         }
879
880         SET_EXPECT(GetContainer);
881         SET_EXPECT(LockContainer);
882         SET_EXPECT(ActivateMe);
883         expect_LockContainer_fLock = TRUE;
884         hres = IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, &ClientSite, -1, container_hwnd, &rect);
885         ok(hres == S_OK, "DoVerb failed: %08lx\n", hres);
886         CHECK_CALLED(GetContainer);
887         CHECK_CALLED(LockContainer);
888         CHECK_CALLED(ActivateMe);
889     }
890
891     hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobject);
892     ok(hres == S_OK, "Could not get IOleInPlaceActiveObject interface: %08lx\n", hres);
893
894     if(activeobject) {
895         HWND tmp_hwnd;
896         hres = IOleInPlaceActiveObject_GetWindow(activeobject, &tmp_hwnd);
897         ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
898         ok(tmp_hwnd == hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, hwnd);
899     }
900
901     if(view) {
902         SET_EXPECT(SetActiveObject);
903         SET_EXPECT(HideUI);
904         SET_EXPECT(OnUIDeactivate);
905         expect_SetActiveObject_active = FALSE;
906         hres = IOleDocumentView_UIActivate(view, FALSE);
907         ok(hres == S_OK, "UIActivate failed: %08lx\n", hres);
908         CHECK_CALLED(SetActiveObject);
909         CHECK_CALLED(HideUI);
910         CHECK_CALLED(OnUIDeactivate);
911     }
912
913     if(activeobject) {
914         HWND tmp_hwnd;
915         hres = IOleInPlaceActiveObject_GetWindow(activeobject, &tmp_hwnd);
916         ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
917         ok(tmp_hwnd == hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, hwnd);
918     }
919     
920     if(windowlessobj) {
921         SET_EXPECT(OnInPlaceDeactivate);
922         hres = IOleInPlaceObjectWindowless_InPlaceDeactivate(windowlessobj);
923         ok(hres == S_OK, "InPlaceDeactivate failed: %08lx\n", hres);
924         CHECK_CALLED(OnInPlaceDeactivate);
925     }
926
927     if(activeobject) {
928         HWND tmp_hwnd;
929         hres = IOleInPlaceActiveObject_GetWindow(activeobject, &tmp_hwnd);
930         ok(hres == E_FAIL, "GetWindow failed: %08lx\n", hres);
931         ok(IsWindow(hwnd), "hwnd is destroyed\n");
932     }
933     
934     if(view) {
935         hres = IOleDocumentView_Show(view, FALSE);
936         ok(hres == S_OK, "Show failed: %08lx\n", hres);
937     }
938
939     if(windowlessobj) {
940         hres = IOleInPlaceObjectWindowless_InPlaceDeactivate(windowlessobj);
941         ok(hres == S_OK, "InPlaceDeactivate failed: %08lx\n", hres);
942
943         IOleInPlaceObjectWindowless_Release(windowlessobj);
944     }
945
946     if(view) {
947         IOleInPlaceSite *inplacesite = (IOleInPlaceSite*)0xff00ff00;
948
949         hres = IOleDocumentView_Show(view, FALSE);
950         ok(hres == S_OK, "Show failed: %08lx\n", hres);
951
952         hres = IOleDocumentView_CloseView(view, 0);
953         ok(hres == S_OK, "CloseVire failed: %08lx\n", hres);
954
955         hres = IOleDocumentView_SetInPlaceSite(view, NULL);
956         ok(hres == S_OK, "SetInPlaceSite failed: %08lx\n", hres);
957
958         hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
959         ok(hres == S_OK, "SetInPlaceSite failed: %08lx\n", hres);
960         ok(inplacesite == NULL, "inplacesite=%p, expected NULL\n", inplacesite);
961     }
962
963     if(oleobj) {
964         SET_EXPECT(GetContainer);
965         SET_EXPECT(LockContainer);
966         expect_LockContainer_fLock = FALSE;
967         hres = IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
968         ok(hres == S_OK, "Close failed: %08lx\n", hres);
969         CHECK_CALLED(GetContainer);
970         CHECK_CALLED(LockContainer);
971
972         hres = IOleObject_GetClientSite(oleobj, &clientsite);
973         ok(clientsite == &ClientSite, "clientsite=%p, expected %p\n", clientsite, &ClientSite);
974
975         hres = IOleObject_SetClientSite(oleobj, NULL);
976         ok(hres == S_OK, "SetClientSite failed: %08lx\n", hres);
977     }
978
979     if(oleobj)
980         IOleObject_Release(oleobj);
981     if(view)
982         IOleDocumentView_Release(view);
983     if(activeobject)
984         IOleInPlaceActiveObject_Release(activeobject);
985
986     ok(IsWindow(hwnd), "hwnd is destroyed\n");
987
988     ref = IUnknown_Release(htmldoc_unk);
989     ok(ref == 0, "ref=%ld, expected 0\n", ref);
990
991     ok(!IsWindow(hwnd), "hwnd is not destroyed\n");
992
993     DestroyWindow(container_hwnd);
994 }
995
996 START_TEST(htmldoc)
997 {
998     CoInitialize(NULL);
999
1000     test_HTMLDocument();
1001
1002     CoUninitialize();
1003 }