Moved mciavi32 to the top-level dlls directory.
[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 #include "mshtmdid.h"
31 #include "idispids.h"
32 #include "shlguid.h"
33
34 #include "initguid.h"
35 DEFINE_SHLGUID(CGID_Undocumented, 0x000214D4L, 0, 0);
36
37 #define DEFINE_EXPECT(func) \
38     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
39
40 #define SET_EXPECT(func) \
41     expect_ ## func = TRUE
42
43 #define CHECK_EXPECT(func) \
44     ok(expect_ ##func, "unexpected call\n"); \
45     expect_ ## func = FALSE; \
46     called_ ## func = TRUE
47
48 #define CHECK_EXPECT2(func) \
49     ok(expect_ ##func, "unexpected call\n"); \
50     called_ ## func = TRUE
51
52 #define CHECK_CALLED(func) \
53     ok(called_ ## func, "expected " #func "\n"); \
54     expect_ ## func = called_ ## func = FALSE
55
56 static IOleDocumentView *view = NULL;
57 static HWND container_hwnd = NULL, hwnd = NULL, last_hwnd = NULL;
58
59 DEFINE_EXPECT(LockContainer);
60 DEFINE_EXPECT(SetActiveObject);
61 DEFINE_EXPECT(GetWindow);
62 DEFINE_EXPECT(CanInPlaceActivate);
63 DEFINE_EXPECT(OnInPlaceActivate);
64 DEFINE_EXPECT(OnUIActivate);
65 DEFINE_EXPECT(GetWindowContext);
66 DEFINE_EXPECT(OnUIDeactivate);
67 DEFINE_EXPECT(OnInPlaceDeactivate);
68 DEFINE_EXPECT(GetContainer);
69 DEFINE_EXPECT(ShowUI);
70 DEFINE_EXPECT(ActivateMe);
71 DEFINE_EXPECT(GetHostInfo);
72 DEFINE_EXPECT(HideUI);
73 DEFINE_EXPECT(GetOptionKeyPath);
74 DEFINE_EXPECT(GetOverrideKeyPath);
75 DEFINE_EXPECT(SetStatusText);
76 DEFINE_EXPECT(QueryStatus_SETPROGRESSTEXT);
77 DEFINE_EXPECT(QueryStatus_OPEN);
78 DEFINE_EXPECT(QueryStatus_NEW);
79 DEFINE_EXPECT(Exec_SETPROGRESSMAX);
80 DEFINE_EXPECT(Exec_SETPROGRESSPOS);
81 DEFINE_EXPECT(Invoke_AMBIENT_USERMODE);
82 DEFINE_EXPECT(Invoke_AMBIENT_DLCONTROL);
83 DEFINE_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
84 DEFINE_EXPECT(Invoke_AMBIENT_SILENT);
85 DEFINE_EXPECT(Invoke_AMBIENT_USERAGENT);
86 DEFINE_EXPECT(Invoke_AMBIENT_PALETTE);
87
88 static BOOL expect_LockContainer_fLock;
89 static BOOL expect_SetActiveObject_active;
90
91 static HRESULT QueryInterface(REFIID riid, void **ppv);
92
93 static HRESULT WINAPI OleContainer_QueryInterface(IOleContainer *iface, REFIID riid, void **ppv)
94 {
95     return QueryInterface(riid, ppv);
96 }
97
98 static ULONG WINAPI OleContainer_AddRef(IOleContainer *iface)
99 {
100     return 2;
101 }
102
103 static ULONG WINAPI OleContainer_Release(IOleContainer *iface)
104 {
105     return 1;
106 }
107
108 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer *iface, IBindCtx *pbc,
109         LPOLESTR pszDiaplayName, ULONG *pchEaten, IMoniker **ppmkOut)
110 {
111     ok(0, "unexpected call\n");
112     return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer *iface, DWORD grfFlags,
116         IEnumUnknown **ppenum)
117 {
118     ok(0, "unexpected call\n");
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer *iface, BOOL fLock)
123 {
124     CHECK_EXPECT(LockContainer);
125     ok(expect_LockContainer_fLock == fLock, "fLock=%x, expected %x\n", fLock, expect_LockContainer_fLock);
126     return S_OK;
127 }
128
129 static const IOleContainerVtbl OleContainerVtbl = {
130     OleContainer_QueryInterface,
131     OleContainer_AddRef,
132     OleContainer_Release,
133     OleContainer_ParseDisplayName,
134     OleContainer_EnumObjects,
135     OleContainer_LockContainer
136 };
137
138 static IOleContainer OleContainer = { &OleContainerVtbl };
139
140 static HRESULT WINAPI InPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
141 {
142     return QueryInterface(riid, ppv);
143 }
144
145 static ULONG WINAPI InPlaceFrame_AddRef(IOleInPlaceFrame *iface)
146 {
147     return 2;
148 }
149
150 static ULONG WINAPI InPlaceFrame_Release(IOleInPlaceFrame *iface)
151 {
152     return 1;
153 }
154
155 static HRESULT WINAPI InPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phwnd)
156 {
157     ok(0, "unexpected call\n");
158     return E_NOTIMPL;
159 }
160
161 static HRESULT WINAPI InPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
162 {
163     ok(0, "unexpected call\n");
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI InPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
168 {
169     ok(0, "unexpected call\n");
170     return E_NOTIMPL;
171 }
172
173 static HRESULT WINAPI InPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface,
174         LPCBORDERWIDTHS pborderwidths)
175 {
176     ok(0, "unexpected call\n");
177     return E_NOTIMPL;
178 }
179
180 static HRESULT WINAPI InPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface,
181         LPCBORDERWIDTHS pborderwidths)
182 {
183     ok(0, "unexpected call\n");
184     return E_NOTIMPL;
185 }
186
187 static HRESULT WINAPI InPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface,
188         IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
189 {
190     static const WCHAR wszHTML_Document[] =
191         {'H','T','M','L',' ','D','o','c','u','m','e','n','t',0};
192
193     ok(expect_SetActiveObject, "unexpected call\n");
194     called_SetActiveObject = TRUE;
195
196     if(expect_SetActiveObject_active) {
197         ok(pActiveObject != NULL, "pActiveObject = NULL\n");
198         ok(!lstrcmpW(wszHTML_Document, pszObjName), "pszObjName != \"HTML Document\"\n");
199     }else {
200         ok(pActiveObject == NULL, "pActiveObject=%p, expected NULL\n", pActiveObject);
201         ok(pszObjName == NULL, "pszObjName=%p, expected NULL\n", pszObjName);
202     }
203
204     return S_OK;
205 }
206
207 static HRESULT WINAPI InPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared,
208         LPOLEMENUGROUPWIDTHS lpMenuWidths)
209 {
210     ok(0, "unexpected call\n");
211     return E_NOTIMPL;
212 }
213
214 static HRESULT WINAPI InPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared,
215         HOLEMENU holemenu, HWND hwndActiveObject)
216 {
217     ok(0, "unexpected call\n");
218     return E_NOTIMPL;
219 }
220
221 static HRESULT WINAPI InPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
222 {
223     ok(0, "unexpected call\n");
224     return E_NOTIMPL;
225 }
226
227 static HRESULT WINAPI InPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
228 {
229     CHECK_EXPECT(SetStatusText);
230     ok(pszStatusText == NULL, "pszStatusText=%p, expected NULL\n", pszStatusText);
231     return S_OK;
232 }
233
234 static HRESULT WINAPI InPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
235 {
236     ok(0, "unexpected call\n");
237     return E_NOTIMPL;
238 }
239
240 static HRESULT WINAPI InPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
241 {
242     ok(0, "unexpected call\n");
243     return E_NOTIMPL;
244 }
245
246 static const IOleInPlaceFrameVtbl InPlaceFrameVtbl = {
247     InPlaceFrame_QueryInterface,
248     InPlaceFrame_AddRef,
249     InPlaceFrame_Release,
250     InPlaceFrame_GetWindow,
251     InPlaceFrame_ContextSensitiveHelp,
252     InPlaceFrame_GetBorder,
253     InPlaceFrame_RequestBorderSpace,
254     InPlaceFrame_SetBorderSpace,
255     InPlaceFrame_SetActiveObject,
256     InPlaceFrame_InsertMenus,
257     InPlaceFrame_SetMenu,
258     InPlaceFrame_RemoveMenus,
259     InPlaceFrame_SetStatusText,
260     InPlaceFrame_EnableModeless,
261     InPlaceFrame_TranslateAccelerator
262 };
263
264 static IOleInPlaceFrame InPlaceFrame = { &InPlaceFrameVtbl };
265
266 static HRESULT WINAPI InPlaceSite_QueryInterface(IOleInPlaceSite *iface, REFIID riid, void **ppv)
267 {
268     return QueryInterface(riid, ppv);
269 }
270
271 static ULONG WINAPI InPlaceSite_AddRef(IOleInPlaceSite *iface)
272 {
273     return 2;
274 }
275
276 static ULONG WINAPI InPlaceSite_Release(IOleInPlaceSite *iface)
277 {
278     return 1;
279 }
280
281 static HRESULT WINAPI InPlaceSite_GetWindow(IOleInPlaceSite *iface, HWND *phwnd)
282 {
283     CHECK_EXPECT(GetWindow);
284     ok(phwnd != NULL, "phwnd = NULL\n");
285     *phwnd = container_hwnd;
286     return S_OK;
287 }
288
289 static HRESULT WINAPI InPlaceSite_ContextSensitiveHelp(IOleInPlaceSite *iface, BOOL fEnterMode)
290 {
291     ok(0, "unexpected call\n");
292     return E_NOTIMPL;
293 }
294
295 static HRESULT WINAPI InPlaceSite_CanInPlaceActivate(IOleInPlaceSite *iface)
296 {
297     CHECK_EXPECT(CanInPlaceActivate);
298     return S_OK;
299 }
300
301 static HRESULT WINAPI InPlaceSite_OnInPlaceActivate(IOleInPlaceSite *iface)
302 {
303     CHECK_EXPECT(OnInPlaceActivate);
304     return S_OK;
305 }
306
307 static HRESULT WINAPI InPlaceSite_OnUIActivate(IOleInPlaceSite *iface)
308 {
309     CHECK_EXPECT(OnUIActivate);
310     return S_OK;
311 }
312
313 static HRESULT WINAPI InPlaceSite_GetWindowContext(IOleInPlaceSite *iface,
314         IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
315         LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
316 {
317     static const RECT rect = {0,0,500,500};
318
319     CHECK_EXPECT(GetWindowContext);
320
321     ok(ppFrame != NULL, "ppFrame = NULL\n");
322     if(ppFrame)
323         *ppFrame = &InPlaceFrame;
324     ok(ppDoc != NULL, "ppDoc = NULL\n");
325     if(ppDoc)
326         *ppDoc = NULL;
327     ok(lprcPosRect != NULL, "lprcPosRect = NULL\n");
328     if(lprcPosRect)
329         memcpy(lprcPosRect, &rect, sizeof(RECT));
330     ok(lprcClipRect != NULL, "lprcClipRect = NULL\n");
331     if(lprcClipRect)
332         memcpy(lprcClipRect, &rect, sizeof(RECT));
333     ok(lpFrameInfo != NULL, "lpFrameInfo = NULL\n");
334     if(lpFrameInfo) {
335         lpFrameInfo->cb = sizeof(*lpFrameInfo);
336         lpFrameInfo->fMDIApp = FALSE;
337         lpFrameInfo->hwndFrame = container_hwnd;
338         lpFrameInfo->haccel = NULL;
339         lpFrameInfo->cAccelEntries = 0;
340     }
341
342     return S_OK;
343 }
344
345 static HRESULT WINAPI InPlaceSite_Scroll(IOleInPlaceSite *iface, SIZE scrollExtant)
346 {
347     ok(0, "unexpected call\n");
348     return E_NOTIMPL;
349 }
350
351 static HRESULT WINAPI InPlaceSite_OnUIDeactivate(IOleInPlaceSite *iface, BOOL fUndoable)
352 {
353     CHECK_EXPECT(OnUIDeactivate);
354     ok(!fUndoable, "fUndoable = TRUE\n");
355     return S_OK;
356 }
357
358 static HRESULT WINAPI InPlaceSite_OnInPlaceDeactivate(IOleInPlaceSite *iface)
359 {
360     CHECK_EXPECT(OnInPlaceDeactivate);
361     return S_OK;
362 }
363
364 static HRESULT WINAPI InPlaceSite_DiscardUndoState(IOleInPlaceSite *iface)
365 {
366     ok(0, "unexpected call\n");
367     return E_NOTIMPL;
368 }
369
370 static HRESULT WINAPI InPlaceSite_DeactivateAndUndo(IOleInPlaceSite *iface)
371 {
372     ok(0, "unexpected call\n");
373     return E_NOTIMPL;
374 }
375
376 static HRESULT WINAPI InPlaceSite_OnPosRectChange(IOleInPlaceSite *iface, LPCRECT lprcPosRect)
377 {
378     ok(0, "unexpected call\n");
379     return E_NOTIMPL;
380 }
381
382 static const IOleInPlaceSiteVtbl InPlaceSiteVtbl = {
383     InPlaceSite_QueryInterface,
384     InPlaceSite_AddRef,
385     InPlaceSite_Release,
386     InPlaceSite_GetWindow,
387     InPlaceSite_ContextSensitiveHelp,
388     InPlaceSite_CanInPlaceActivate,
389     InPlaceSite_OnInPlaceActivate,
390     InPlaceSite_OnUIActivate,
391     InPlaceSite_GetWindowContext,
392     InPlaceSite_Scroll,
393     InPlaceSite_OnUIDeactivate,
394     InPlaceSite_OnInPlaceDeactivate,
395     InPlaceSite_DiscardUndoState,
396     InPlaceSite_DeactivateAndUndo,
397     InPlaceSite_OnPosRectChange
398 };
399
400 static IOleInPlaceSite InPlaceSite = { &InPlaceSiteVtbl };
401
402 static HRESULT WINAPI ClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
403 {
404     return QueryInterface(riid, ppv);
405 }
406
407 static ULONG WINAPI ClientSite_AddRef(IOleClientSite *iface)
408 {
409     return 2;
410 }
411
412 static ULONG WINAPI ClientSite_Release(IOleClientSite *iface)
413 {
414     return 1;
415 }
416
417 static HRESULT WINAPI ClientSite_SaveObject(IOleClientSite *iface)
418 {
419     ok(0, "unexpected call\n");
420     return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI ClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAsign, DWORD dwWhichMoniker,
424         IMoniker **ppmon)
425 {
426     ok(0, "unexpected call\n");
427     return E_NOTIMPL;
428 }
429
430 static HRESULT WINAPI ClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
431 {
432     CHECK_EXPECT(GetContainer);
433     ok(ppContainer != NULL, "ppContainer = NULL\n");
434     *ppContainer = &OleContainer;
435     return S_OK;
436 }
437
438 static HRESULT WINAPI ClientSite_ShowObject(IOleClientSite *iface)
439 {
440     ok(0, "unexpected call\n");
441     return E_NOTIMPL;
442 }
443
444 static HRESULT WINAPI ClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
445 {
446     ok(0, "unexpected call\n");
447     return E_NOTIMPL;
448 }
449
450 static HRESULT WINAPI ClientSite_RequestNewObjectLayout(IOleClientSite *iface)
451 {
452     ok(0, "unexpected call\n");
453     return E_NOTIMPL;
454 }
455
456 static const IOleClientSiteVtbl ClientSiteVtbl = {
457     ClientSite_QueryInterface,
458     ClientSite_AddRef,
459     ClientSite_Release,
460     ClientSite_SaveObject,
461     ClientSite_GetMoniker,
462     ClientSite_GetContainer,
463     ClientSite_ShowObject,
464     ClientSite_OnShowWindow,
465     ClientSite_RequestNewObjectLayout
466 };
467
468 static IOleClientSite ClientSite = { &ClientSiteVtbl };
469
470 static HRESULT WINAPI DocumentSite_QueryInterface(IOleDocumentSite *iface, REFIID riid, void **ppv)
471 {
472     return QueryInterface(riid, ppv);
473 }
474
475 static ULONG WINAPI DocumentSite_AddRef(IOleDocumentSite *iface)
476 {
477     return 2;
478 }
479
480 static ULONG WINAPI DocumentSite_Release(IOleDocumentSite *iface)
481 {
482     return 1;
483 }
484
485 static BOOL call_UIActivate = TRUE;
486 static HRESULT WINAPI DocumentSite_ActivateMe(IOleDocumentSite *iface, IOleDocumentView *pViewToActivate)
487 {
488     IOleDocument *document;
489     HRESULT hres;
490
491     CHECK_EXPECT(ActivateMe);
492     ok(pViewToActivate != NULL, "pViewToActivate = NULL\n");
493
494     hres = IOleDocumentView_QueryInterface(pViewToActivate, &IID_IOleDocument, (void**)&document);
495     ok(hres == S_OK, "could not get IOleDocument: %08lx\n", hres);
496
497     if(SUCCEEDED(hres)) {
498         hres = IOleDocument_CreateView(document, &InPlaceSite, NULL, 0, &view);
499         ok(hres == S_OK, "CreateView failed: %08lx\n", hres);
500
501         if(SUCCEEDED(hres)) {
502             IOleInPlaceActiveObject *activeobj = NULL;
503             IOleInPlaceSite *inplacesite = NULL;
504             HWND tmp_hwnd = NULL;
505             static RECT rect = {0,0,400,500};
506
507             hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
508             ok(hres == S_OK, "GetInPlaceSite failed: %08lx\n", hres);
509             ok(inplacesite == &InPlaceSite, "inplacesite=%p, expected %p\n",
510                     inplacesite, &InPlaceSite);
511
512             hres = IOleDocumentView_SetInPlaceSite(view, &InPlaceSite);
513             ok(hres == S_OK, "SetInPlaceSite failed: %08lx\n", hres);
514
515             hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
516             ok(hres == S_OK, "GetInPlaceSite failed: %08lx\n", hres);
517             ok(inplacesite == &InPlaceSite, "inplacesite=%p, expected %p\n",
518                     inplacesite, &InPlaceSite);
519
520             hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobj);
521             ok(hres == S_OK, "Could not get IOleInPlaceActiveObject: %08lx\n", hres);
522
523             if(activeobj) {
524                 IOleInPlaceActiveObject_GetWindow(activeobj, &hwnd);
525                 ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
526                 ok(hwnd == NULL, "hwnd=%p, expeted NULL\n", hwnd);
527             }
528             
529             if(call_UIActivate) {
530                 SET_EXPECT(CanInPlaceActivate);
531                 SET_EXPECT(GetWindowContext);
532                 SET_EXPECT(GetWindow);
533                 SET_EXPECT(OnInPlaceActivate);
534                 SET_EXPECT(SetStatusText);
535                 SET_EXPECT(Exec_SETPROGRESSMAX);
536                 SET_EXPECT(Exec_SETPROGRESSPOS);
537                 SET_EXPECT(OnUIActivate);
538                 SET_EXPECT(SetActiveObject);
539                 SET_EXPECT(ShowUI);
540                 expect_SetActiveObject_active = TRUE;
541
542                 hres = IOleDocumentView_UIActivate(view, TRUE);
543
544                 if(FAILED(hres)) {
545                     trace("UIActivate failed: %08lx\n", hres);
546                     return hres;
547                 }
548                 ok(hres == S_OK, "UIActivate failed: %08lx\n", hres);
549
550                 CHECK_CALLED(CanInPlaceActivate);
551                 CHECK_CALLED(GetWindowContext);
552                 CHECK_CALLED(GetWindow);
553                 CHECK_CALLED(OnInPlaceActivate);
554                 CHECK_CALLED(SetStatusText);
555                 CHECK_CALLED(Exec_SETPROGRESSMAX);
556                 CHECK_CALLED(Exec_SETPROGRESSPOS);
557                 CHECK_CALLED(OnUIActivate);
558                 CHECK_CALLED(SetActiveObject);
559                 CHECK_CALLED(ShowUI);
560
561                 if(activeobj) {
562                     hres = IOleInPlaceActiveObject_GetWindow(activeobj, &hwnd);
563                     ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
564                     ok(hwnd != NULL, "hwnd == NULL\n");
565                     if(last_hwnd)
566                         ok(hwnd == last_hwnd, "hwnd != last_hwnd\n");
567                 }
568
569                 hres = IOleDocumentView_UIActivate(view, TRUE);
570                 ok(hres == S_OK, "UIActivate failed: %08lx\n", hres);
571
572                 if(activeobj) {
573                     hres = IOleInPlaceActiveObject_GetWindow(activeobj, &tmp_hwnd);
574                     ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
575                     ok(tmp_hwnd == hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, hwnd);
576                 }
577             }
578
579             hres = IOleDocumentView_SetRect(view, &rect);
580             ok(hres == S_OK, "SetRect failed: %08lx\n", hres);
581
582             if(call_UIActivate) {
583                 hres = IOleDocumentView_Show(view, TRUE);
584                 ok(hres == S_OK, "Show failed: %08lx\n", hres);
585             }else {
586                 SET_EXPECT(CanInPlaceActivate);
587                 SET_EXPECT(GetWindowContext);
588                 SET_EXPECT(GetWindow);
589                 SET_EXPECT(OnInPlaceActivate);
590                 SET_EXPECT(SetStatusText);
591                 SET_EXPECT(Exec_SETPROGRESSMAX);
592                 SET_EXPECT(Exec_SETPROGRESSPOS);
593                 SET_EXPECT(OnUIActivate);
594                 hres = IOleDocumentView_Show(view, TRUE);
595                 ok(hres == S_OK, "Show failed: %08lx\n", hres);
596                 CHECK_CALLED(CanInPlaceActivate);
597                 CHECK_CALLED(GetWindowContext);
598                 CHECK_CALLED(GetWindow);
599                 CHECK_CALLED(OnInPlaceActivate);
600                 CHECK_CALLED(SetStatusText);
601                 CHECK_CALLED(Exec_SETPROGRESSMAX);
602                 CHECK_CALLED(Exec_SETPROGRESSPOS);
603
604                 if(activeobj) {
605                     hres = IOleInPlaceActiveObject_GetWindow(activeobj, &hwnd);
606                     ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
607                     ok(hwnd != NULL, "hwnd == NULL\n");
608                     if(last_hwnd)
609                         ok(hwnd == last_hwnd, "hwnd != last_hwnd\n");
610                 }
611             }
612
613             if(activeobj)
614                 IOleInPlaceActiveObject_Release(activeobj);
615         }
616
617         IOleDocument_Release(document);
618     }
619
620     return S_OK;
621 }
622
623 static const IOleDocumentSiteVtbl DocumentSiteVtbl = {
624     DocumentSite_QueryInterface,
625     DocumentSite_AddRef,
626     DocumentSite_Release,
627     DocumentSite_ActivateMe
628 };
629
630 static IOleDocumentSite DocumentSite = { &DocumentSiteVtbl };
631
632 static HRESULT WINAPI DocHostUIHandler_QueryInterface(IDocHostUIHandler2 *iface, REFIID riid, void **ppv)
633 {
634     return QueryInterface(riid, ppv);
635 }
636
637 static ULONG WINAPI DocHostUIHandler_AddRef(IDocHostUIHandler2 *iface)
638 {
639     return 2;
640 }
641
642 static ULONG WINAPI DocHostUIHandler_Release(IDocHostUIHandler2 *iface)
643 {
644     return 1;
645 }
646
647 static HRESULT WINAPI DocHostUIHandler_ShowContextMenu(IDocHostUIHandler2 *iface, DWORD dwID, POINT *ppt,
648         IUnknown *pcmdtReserved, IDispatch *pdicpReserved)
649 {
650     ok(0, "unexpected call\n");
651     return E_NOTIMPL;
652 }
653
654 static HRESULT WINAPI DocHostUIHandler_GetHostInfo(IDocHostUIHandler2 *iface, DOCHOSTUIINFO *pInfo)
655 {
656     CHECK_EXPECT(GetHostInfo);
657     ok(pInfo != NULL, "pInfo=NULL\n");
658     if(pInfo) {
659         ok(pInfo->cbSize == sizeof(DOCHOSTUIINFO), "pInfo->cbSize=%lu, expected %u\n",
660                 pInfo->cbSize, sizeof(DOCHOSTUIINFO));
661         ok(!pInfo->dwFlags, "pInfo->dwFlags=%08lx, expected 0\n", pInfo->dwFlags);
662         pInfo->dwFlags = DOCHOSTUIFLAG_DISABLE_HELP_MENU | DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE
663             | DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY | DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION
664             | DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION;
665         ok(!pInfo->dwDoubleClick, "pInfo->dwDoubleClick=%08lx, expected 0\n", pInfo->dwDoubleClick);
666         ok(!pInfo->pchHostCss, "pInfo->pchHostCss=%p, expected NULL\n", pInfo->pchHostCss);
667         ok(!pInfo->pchHostNS, "pInfo->pchhostNS=%p, expected NULL\n", pInfo->pchHostNS);
668     }
669     return S_OK;
670 }
671
672 static HRESULT WINAPI DocHostUIHandler_ShowUI(IDocHostUIHandler2 *iface, DWORD dwID,
673         IOleInPlaceActiveObject *pActiveObject, IOleCommandTarget *pCommandTarget,
674         IOleInPlaceFrame *pFrame, IOleInPlaceUIWindow *pDoc)
675 {
676     CHECK_EXPECT(ShowUI);
677
678     ok(dwID == 0, "dwID=%ld, expected 0\n", dwID);
679     ok(pActiveObject != NULL, "pActiveObject = NULL\n");
680     ok(pCommandTarget != NULL, "pCommandTarget = NULL\n");
681     ok(pFrame == &InPlaceFrame, "pFrame=%p, expected %p\n", pFrame, &InPlaceFrame);
682     ok(pDoc == NULL, "pDoc=%p, expected NULL\n", pDoc);
683
684     return S_OK;
685 }
686
687 static HRESULT WINAPI DocHostUIHandler_HideUI(IDocHostUIHandler2 *iface)
688 {
689     CHECK_EXPECT(HideUI);
690     return S_OK;
691 }
692
693 static HRESULT WINAPI DocHostUIHandler_UpdateUI(IDocHostUIHandler2 *iface)
694 {
695     ok(0, "unexpected call\n");
696     return E_NOTIMPL;
697 }
698
699 static HRESULT WINAPI DocHostUIHandler_EnableModeless(IDocHostUIHandler2 *iface, BOOL fEnable)
700 {
701     ok(0, "unexpected call\n");
702     return E_NOTIMPL;
703 }
704
705 static HRESULT WINAPI DocHostUIHandler_OnDocWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
706 {
707     ok(0, "unexpected call\n");
708     return E_NOTIMPL;
709 }
710
711 static HRESULT WINAPI DocHostUIHandler_OnFrameWindowActivate(IDocHostUIHandler2 *iface, BOOL fActivate)
712 {
713     ok(0, "unexpected call\n");
714     return E_NOTIMPL;
715 }
716
717 static HRESULT WINAPI DocHostUIHandler_ResizeBorder(IDocHostUIHandler2 *iface, LPCRECT prcBorder,
718         IOleInPlaceUIWindow *pUIWindow, BOOL fRameWindow)
719 {
720     ok(0, "unexpected call\n");
721     return E_NOTIMPL;
722 }
723
724 static HRESULT WINAPI DocHostUIHandler_TranslateAccelerator(IDocHostUIHandler2 *iface, LPMSG lpMsg,
725         const GUID *pguidCmdGroup, DWORD nCmdID)
726 {
727     ok(0, "unexpected call\n");
728     return E_NOTIMPL;
729 }
730
731 static HRESULT WINAPI DocHostUIHandler_GetOptionKeyPath(IDocHostUIHandler2 *iface,
732         LPOLESTR *pchKey, DWORD dw)
733 {
734     CHECK_EXPECT(GetOptionKeyPath);
735     ok(pchKey != NULL, "pchKey = NULL\n");
736     ok(!dw, "dw=%ld, expected 0\n", dw);
737     if(pchKey)
738         ok(!*pchKey, "*pchKey=%p, expected NULL\n", *pchKey);
739     return S_OK;
740 }
741
742 static HRESULT WINAPI DocHostUIHandler_GetDropTarget(IDocHostUIHandler2 *iface,
743         IDropTarget *pDropTarget, IDropTarget **ppDropTarget)
744 {
745     ok(0, "unexpected call\n");
746     return E_NOTIMPL;
747 }
748
749 static HRESULT WINAPI DocHostUIHandler_GetExternal(IDocHostUIHandler2 *iface, IDispatch **ppDispatch)
750 {
751     ok(0, "unexpected call\n");
752     return E_NOTIMPL;
753 }
754
755 static HRESULT WINAPI DocHostUIHandler_TranslateUrl(IDocHostUIHandler2 *iface, DWORD dwTranslate,
756         OLECHAR *pchURLIn, OLECHAR **ppchURLOut)
757 {
758     ok(0, "unexpected call\n");
759     return E_NOTIMPL;
760 }
761
762 static HRESULT WINAPI DocHostUIHandler_FilterDataObject(IDocHostUIHandler2 *iface, IDataObject *pDO,
763         IDataObject **ppPORet)
764 {
765     ok(0, "unexpected call\n");
766     return E_NOTIMPL;
767 }
768
769 static HRESULT WINAPI DocHostUIHandler_GetOverrideKeyPath(IDocHostUIHandler2 *iface,
770         LPOLESTR *pchKey, DWORD dw)
771 {
772     CHECK_EXPECT(GetOverrideKeyPath);
773     ok(pchKey != NULL, "pchKey = NULL\n");
774     if(pchKey)
775         ok(!*pchKey, "*pchKey=%p, expected NULL\n", *pchKey);
776     ok(!dw, "dw=%ld, xepected 0\n", dw);
777     return S_OK;
778 }
779
780 static const IDocHostUIHandler2Vtbl DocHostUIHandlerVtbl = {
781     DocHostUIHandler_QueryInterface,
782     DocHostUIHandler_AddRef,
783     DocHostUIHandler_Release,
784     DocHostUIHandler_ShowContextMenu,
785     DocHostUIHandler_GetHostInfo,
786     DocHostUIHandler_ShowUI,
787     DocHostUIHandler_HideUI,
788     DocHostUIHandler_UpdateUI,
789     DocHostUIHandler_EnableModeless,
790     DocHostUIHandler_OnDocWindowActivate,
791     DocHostUIHandler_OnFrameWindowActivate,
792     DocHostUIHandler_ResizeBorder,
793     DocHostUIHandler_TranslateAccelerator,
794     DocHostUIHandler_GetOptionKeyPath,
795     DocHostUIHandler_GetDropTarget,
796     DocHostUIHandler_GetExternal,
797     DocHostUIHandler_TranslateUrl,
798     DocHostUIHandler_FilterDataObject,
799     DocHostUIHandler_GetOverrideKeyPath
800 };
801
802 static IDocHostUIHandler2 DocHostUIHandler = { &DocHostUIHandlerVtbl };
803
804 static HRESULT WINAPI OleCommandTarget_QueryInterface(IOleCommandTarget *iface,
805         REFIID riid, void **ppv)
806 {
807     return QueryInterface(riid, ppv);
808 }
809
810 static ULONG WINAPI OleCommandTarget_AddRef(IOleCommandTarget *iface)
811 {
812     return 2;
813 }
814
815 static ULONG WINAPI OleCommandTarget_Release(IOleCommandTarget *iface)
816 {
817     return 1;
818 }
819
820 static HRESULT WINAPI OleCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
821         ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
822 {
823     ok(!pguidCmdGroup, "pguidCmdGroup != MULL\n");
824     ok(cCmds == 1, "cCmds=%ld, expected 1\n", cCmds);
825     ok(!pCmdText, "pCmdText != NULL\n");
826
827     switch(prgCmds[0].cmdID) {
828     case OLECMDID_SETPROGRESSTEXT:
829         CHECK_EXPECT(QueryStatus_SETPROGRESSTEXT);
830         prgCmds[0].cmdf = OLECMDF_ENABLED;
831         return S_OK;
832     case OLECMDID_OPEN:
833         CHECK_EXPECT(QueryStatus_OPEN);
834         prgCmds[0].cmdf = 0;
835         return S_OK;
836     case OLECMDID_NEW:
837         CHECK_EXPECT(QueryStatus_NEW);
838         prgCmds[0].cmdf = 0;
839         return S_OK;
840     default:
841         ok(0, "unexpected command %ld\n", prgCmds[0].cmdID);
842     };
843
844     return E_FAIL;
845 }
846
847 static HRESULT WINAPI OleCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
848         DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
849 {
850     if(!pguidCmdGroup) {
851         switch(nCmdID) {
852         case OLECMDID_SETPROGRESSMAX:
853             CHECK_EXPECT(Exec_SETPROGRESSMAX);
854             ok(pvaIn != NULL, "pvaIn == NULL\n");
855             if(pvaIn) {
856                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
857                 ok(V_I4(pvaIn) == 0, "V_I4(pvaIn)=%ld, expected 0\n", V_I4(pvaIn));
858             }
859             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
860             return S_OK;
861         case OLECMDID_SETPROGRESSPOS:
862             CHECK_EXPECT(Exec_SETPROGRESSPOS);
863             ok(pvaIn != NULL, "pvaIn == NULL\n");
864             if(pvaIn) {
865                 ok(V_VT(pvaIn) == VT_I4, "V_VT(pvaIn)=%d, expected VT_I4\n", V_VT(pvaIn));
866                 ok(V_I4(pvaIn) == 0, "V_I4(pvaIn)=%ld, expected 0\n", V_I4(pvaIn));
867             }
868             ok(pvaOut == NULL, "pvaOut=%p, expected NULL\n", pvaOut);
869             return S_OK;
870         default:
871             ok(0, "unexpected command %ld\n", nCmdID);
872             return E_FAIL;
873         };
874     }
875
876     if(IsEqualGUID(&CGID_Undocumented, pguidCmdGroup))
877         return E_FAIL; /* TODO */
878
879     ok(0, "unexpected call");
880
881     return E_NOTIMPL;
882 }
883
884 static IOleCommandTargetVtbl OleCommandTargetVtbl = {
885     OleCommandTarget_QueryInterface,
886     OleCommandTarget_AddRef,
887     OleCommandTarget_Release,
888     OleCommandTarget_QueryStatus,
889     OleCommandTarget_Exec
890 };
891
892 static IOleCommandTarget OleCommandTarget = { &OleCommandTargetVtbl };
893
894 static HRESULT WINAPI Dispatch_QueryInterface(IDispatch *iface, REFIID riid, void **ppv)
895 {
896     return QueryInterface(riid, ppv);
897 }
898
899 static ULONG WINAPI Dispatch_AddRef(IDispatch *iface)
900 {
901     return 2;
902 }
903
904 static ULONG WINAPI Dispatch_Release(IDispatch *iface)
905 {
906     return 1;
907 }
908
909 static HRESULT WINAPI Dispatch_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
910 {
911     ok(0, "unexpected call\n");
912     return E_NOTIMPL;
913 }
914
915 static HRESULT WINAPI Dispatch_GetTypeInfo(IDispatch *iface, UINT iTInfo, LCID lcid,
916         ITypeInfo **ppTInfo)
917 {
918     ok(0, "unexpected call\n");
919     return E_NOTIMPL;
920 }
921
922 static HRESULT WINAPI Dispatch_GetIDsOfNames(IDispatch *iface, REFIID riid, LPOLESTR *rgszNames,
923         UINT cNames, LCID lcid, DISPID *rgDispId)
924 {
925     ok(0, "unexpected call\n");
926     return E_NOTIMPL;
927 }
928
929 static HRESULT WINAPI Dispatch_Invoke(IDispatch *iface, DISPID dispIdMember, REFIID riid,
930         LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
931         EXCEPINFO *pExcepInfo, UINT *puArgErr)
932 {
933     ok(IsEqualGUID(&IID_NULL, riid), "riid != IID_NULL\n");
934     ok(pDispParams != NULL, "pDispParams == NULL\n");
935     ok(pExcepInfo == NULL, "pExcepInfo=%p, expected NULL\n", pExcepInfo);
936     ok(puArgErr != NULL, "puArgErr == NULL\n");
937     ok(V_VT(pVarResult) == 0, "V_VT(pVarResult)=%d, expected 0\n", V_VT(pVarResult));
938     ok(wFlags == DISPATCH_PROPERTYGET, "wFlags=%08x, expected DISPATCH_PROPERTYGET\n", wFlags);
939
940     switch(dispIdMember) {
941     case DISPID_AMBIENT_USERMODE:
942         CHECK_EXPECT2(Invoke_AMBIENT_USERMODE);
943         V_VT(pVarResult) = VT_BOOL;
944         V_BOOL(pVarResult) = VARIANT_TRUE;
945         return S_OK;
946     case DISPID_AMBIENT_DLCONTROL:
947         CHECK_EXPECT2(Invoke_AMBIENT_DLCONTROL);
948         return E_FAIL;
949     case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
950         CHECK_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
951         return E_FAIL;
952     case DISPID_AMBIENT_SILENT:
953         CHECK_EXPECT(Invoke_AMBIENT_SILENT);
954         V_VT(pVarResult) = VT_BOOL;
955         V_BOOL(pVarResult) = VARIANT_FALSE;
956         return S_OK;
957     case DISPID_AMBIENT_USERAGENT:
958         CHECK_EXPECT(Invoke_AMBIENT_USERAGENT);
959         return E_FAIL;
960     case DISPID_AMBIENT_PALETTE:
961         CHECK_EXPECT(Invoke_AMBIENT_PALETTE);
962         return E_FAIL;
963     };
964
965     ok(0, "unexpected dispid %ld\n", dispIdMember);
966     return E_FAIL;
967 }
968
969 static IDispatchVtbl DispatchVtbl = {
970     Dispatch_QueryInterface,
971     Dispatch_AddRef,
972     Dispatch_Release,
973     Dispatch_GetTypeInfoCount,
974     Dispatch_GetTypeInfo,
975     Dispatch_GetIDsOfNames,
976     Dispatch_Invoke
977 };
978
979 static IDispatch Dispatch = { &DispatchVtbl };
980
981 static HRESULT QueryInterface(REFIID riid, void **ppv)
982 {
983     *ppv = NULL;
984
985     if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IOleClientSite, riid))
986         *ppv = &ClientSite;
987     else if(IsEqualGUID(&IID_IOleDocumentSite, riid))
988         *ppv = &DocumentSite;
989     else if(IsEqualGUID(&IID_IDocHostUIHandler, riid) || IsEqualGUID(&IID_IDocHostUIHandler2, riid))
990         *ppv = &DocHostUIHandler;
991     else if(IsEqualGUID(&IID_IOleContainer, riid))
992         *ppv = &OleContainer;
993     else if(IsEqualGUID(&IID_IOleWindow, riid) || IsEqualGUID(&IID_IOleInPlaceSite, riid))
994         *ppv = &InPlaceSite;
995     else if(IsEqualGUID(&IID_IOleInPlaceUIWindow, riid) || IsEqualGUID(&IID_IOleInPlaceFrame, riid))
996         *ppv = &InPlaceFrame;
997     else if(IsEqualGUID(&IID_IOleCommandTarget , riid))
998         *ppv = &OleCommandTarget;
999     else if(IsEqualGUID(&IID_IDispatch, riid))
1000         *ppv = &Dispatch;
1001
1002     /* TODO:
1003      * IServiceProvider
1004      * {D48A6EC6-6A4A-11CF-94A7-444553540000}
1005      * {7BB0B520-B1A7-11D2-BB23-00C04F79ABCD}
1006      * {000670BA-0000-0000-C000-000000000046}
1007      */
1008
1009     if(*ppv)
1010         return S_OK;
1011     return E_NOINTERFACE;
1012 }
1013
1014 static LRESULT WINAPI wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1015 {
1016     return DefWindowProc(hwnd, msg, wParam, lParam);
1017 }
1018
1019 static void test_Persist(IUnknown *unk)
1020 {
1021     IPersistMoniker *persist_mon;
1022     IPersistFile *persist_file;
1023     GUID guid;
1024     HRESULT hres;
1025
1026     hres = IUnknown_QueryInterface(unk, &IID_IPersistFile, (void**)&persist_file);
1027     ok(hres == S_OK, "QueryInterface(IID_IPersist) failed: %08lx\n", hres);
1028     if(SUCCEEDED(hres)) {
1029         hres = IPersist_GetClassID(persist_file, NULL);
1030         ok(hres == E_INVALIDARG, "GetClassID returned: %08lx, expected E_INVALIDARG\n", hres);
1031
1032         hres = IPersist_GetClassID(persist_file, &guid);
1033         ok(hres == S_OK, "GetClassID failed: %08lx\n", hres);
1034         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
1035
1036         IPersist_Release(persist_file);
1037     }
1038
1039     hres = IUnknown_QueryInterface(unk, &IID_IPersistMoniker, (void**)&persist_mon);
1040     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker) failed: %08lx\n", hres);
1041     if(SUCCEEDED(hres)) {
1042         hres = IPersistMoniker_GetClassID(persist_mon, NULL);
1043         ok(hres == E_INVALIDARG, "GetClassID returned: %08lx, expected E_INVALIDARG\n", hres);
1044
1045         hres = IPersistMoniker_GetClassID(persist_mon, &guid);
1046         ok(hres == S_OK, "GetClassID failed: %08lx\n", hres);
1047         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
1048
1049         IPersistMoniker_Release(persist_mon);
1050     }
1051 }
1052
1053 static const OLECMDF expect_cmds[OLECMDID_GETPRINTTEMPLATE+1] = {
1054     0,
1055     OLECMDF_SUPPORTED,                  /* OLECMDID_OPEN */
1056     OLECMDF_SUPPORTED,                  /* OLECMDID_NEW */
1057     OLECMDF_SUPPORTED,                  /* OLECMDID_SAVE */
1058     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_SAVEAS */
1059     OLECMDF_SUPPORTED,                  /* OLECMDID_SAVECOPYAS */
1060     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PRINT */
1061     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PRINTPREVIEW */
1062     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PAGESETUP */
1063     OLECMDF_SUPPORTED,                  /* OLECMDID_SPELL */
1064     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PROPERTIES */
1065     OLECMDF_SUPPORTED,                  /* OLECMDID_CUT */
1066     OLECMDF_SUPPORTED,                  /* OLECMDID_COPY */
1067     OLECMDF_SUPPORTED,                  /* OLECMDID_PASTE */
1068     OLECMDF_SUPPORTED,                  /* OLECMDID_PASTESPECIAL */
1069     OLECMDF_SUPPORTED,                  /* OLECMDID_UNDO */
1070     OLECMDF_SUPPORTED,                  /* OLECMDID_REDO */
1071     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_SELECTALL */
1072     OLECMDF_SUPPORTED,                  /* OLECMDID_CLEARSELECTION */
1073     OLECMDF_SUPPORTED,                  /* OLECMDID_ZOOM */
1074     OLECMDF_SUPPORTED,                  /* OLECMDID_GETZOOMRANGE */
1075     0,
1076     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_REFRESH */
1077     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_STOP */
1078     0,0,0,0,0,0,
1079     OLECMDF_SUPPORTED,                  /* OLECMDID_STOPDOWNLOAD */
1080     0,0,
1081     OLECMDF_SUPPORTED,                  /* OLECMDID_DELETE */
1082     0,0,
1083     OLECMDF_SUPPORTED,                  /* OLECMDID_ENABLE_INTERACTION */
1084     OLECMDF_SUPPORTED,                  /* OLECMDID_ONUNLOAD */
1085     0,0,0,0,0,
1086     OLECMDF_SUPPORTED,                  /* OLECMDID_SHOWPAGESETUP */
1087     OLECMDF_SUPPORTED,                  /* OLECMDID_SHOWPRINT */
1088     0,0,
1089     OLECMDF_SUPPORTED,                  /* OLECMDID_CLOSE */
1090     0,0,0,
1091     OLECMDF_SUPPORTED,                  /* OLECMDID_SETPRINTTEMPLATE */
1092     OLECMDF_SUPPORTED                   /* OLECMDID_GETPRINTTEMPLATE */
1093 };
1094
1095 static void test_OleCommandTarget(IUnknown *unk)
1096 {
1097     IOleCommandTarget *cmdtrg;
1098     OLECMD cmds[OLECMDID_GETPRINTTEMPLATE];
1099     int i;
1100     HRESULT hres;
1101
1102     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1103     ok(hres == S_OK, "QueryInterface(IIDIOleM=CommandTarget failed: %08lx\n", hres);
1104     if(FAILED(hres))
1105         return;
1106
1107     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
1108         cmds[i].cmdID = i+1;
1109         cmds[i].cmdf = 0xf0f0;
1110     }
1111
1112     SET_EXPECT(QueryStatus_OPEN);
1113     SET_EXPECT(QueryStatus_NEW);
1114     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, sizeof(cmds)/sizeof(cmds[0]), cmds, NULL);
1115     ok(hres == S_OK, "QueryStatus failed: %08lx\n", hres);
1116     CHECK_CALLED(QueryStatus_OPEN);
1117     CHECK_CALLED(QueryStatus_NEW);
1118
1119     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
1120         ok(cmds[i].cmdID == i+1, "cmds[%d].cmdID canged to %lx\n", i, cmds[i].cmdID);
1121         ok(cmds[i].cmdf == expect_cmds[i+1], "cmds[%d].cmdf=%lx, expected %x\n",
1122                 i+1, cmds[i].cmdf, expect_cmds[i+1]);
1123     }
1124
1125     IOleCommandTarget_Release(cmdtrg);
1126 }
1127
1128 static void test_OleCommandTarget_fail(IUnknown *unk)
1129 {
1130     IOleCommandTarget *cmdtrg;
1131     int i;
1132     HRESULT hres;
1133
1134     OLECMD cmd[2] = {
1135         {OLECMDID_OPEN, 0xf0f0},
1136         {OLECMDID_GETPRINTTEMPLATE+1, 0xf0f0}
1137     };
1138
1139     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
1140     ok(hres == S_OK, "QueryInterface(IIDIOleM=CommandTarget failed: %08lx\n", hres);
1141     if(FAILED(hres))
1142         return;
1143
1144     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 0, NULL, NULL);
1145     ok(hres == S_OK, "QueryStatus failed: %08lx\n", hres);
1146
1147     SET_EXPECT(QueryStatus_OPEN);
1148     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 2, cmd, NULL);
1149     CHECK_CALLED(QueryStatus_OPEN);
1150
1151     ok(hres == OLECMDERR_E_NOTSUPPORTED,
1152             "QueryStatus failed: %08lx, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
1153     ok(cmd[1].cmdID == OLECMDID_GETPRINTTEMPLATE+1,
1154             "cmd[0].cmdID=%ld, expected OLECMDID_GETPRINTTEMPLATE+1\n", cmd[0].cmdID);
1155     ok(cmd[1].cmdf == 0, "cmd[0].cmdf=%lx, expected 0\n", cmd[0].cmdf);
1156     ok(cmd[0].cmdf == OLECMDF_SUPPORTED,
1157             "cmd[1].cmdf=%lx, expected OLECMDF_SUPPORTED\n", cmd[1].cmdf);
1158
1159     hres = IOleCommandTarget_QueryStatus(cmdtrg, &IID_IHTMLDocument2, 2, cmd, NULL);
1160     ok(hres == OLECMDERR_E_UNKNOWNGROUP,
1161             "QueryStatus failed: %08lx, expected OLECMDERR_E_UNKNOWNGROUP\n", hres);
1162
1163     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
1164         if(!expect_cmds[i]) {
1165             hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS,
1166                     OLECMDEXECOPT_DODEFAULT, NULL, NULL);
1167             ok(hres == OLECMDERR_E_NOTSUPPORTED,
1168                     "Exec failed: %08lx, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
1169         }
1170     }
1171
1172     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_GETPRINTTEMPLATE+1,
1173             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
1174     ok(hres == OLECMDERR_E_NOTSUPPORTED,
1175             "Exec failed: %08lx, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
1176
1177     IOleCommandTarget_Release(cmdtrg);
1178 }
1179
1180 static HWND create_container_window(void)
1181 {
1182     static const WCHAR wszHTMLDocumentTest[] =
1183         {'H','T','M','L','D','o','c','u','m','e','n','t','T','e','s','t',0};
1184     static WNDCLASSEXW wndclass = {
1185         sizeof(WNDCLASSEXW),
1186         0,
1187         wnd_proc,
1188         0, 0, NULL, NULL, NULL, NULL, NULL,
1189         wszHTMLDocumentTest,
1190         NULL
1191     };
1192
1193     RegisterClassExW(&wndclass);
1194     return CreateWindowW(wszHTMLDocumentTest, wszHTMLDocumentTest,
1195             WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
1196             CW_USEDEFAULT, NULL, NULL, NULL, NULL);
1197 }
1198
1199 static HRESULT test_DoVerb(IOleObject *oleobj)
1200 {
1201     RECT rect = {0,0,500,500};
1202     HRESULT hres;
1203
1204     SET_EXPECT(GetContainer);
1205     SET_EXPECT(LockContainer);
1206     SET_EXPECT(ActivateMe);
1207     expect_LockContainer_fLock = TRUE;
1208
1209     hres = IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, &ClientSite, -1, container_hwnd, &rect);
1210     if(FAILED(hres))
1211         return hres;
1212
1213     ok(hres == S_OK, "DoVerb failed: %08lx\n", hres);
1214     CHECK_CALLED(GetContainer);
1215     CHECK_CALLED(LockContainer);
1216     CHECK_CALLED(ActivateMe);
1217
1218     return hres;
1219 }
1220
1221 #define CLIENTSITE_EXPECTPATH 0x00000001
1222 #define CLIENTSITE_SETNULL    0x00000002
1223 #define CLIENTSITE_DONTSET    0x00000004
1224
1225 static void test_ClientSite(IOleObject *oleobj, DWORD flags)
1226 {
1227     IOleClientSite *clientsite;
1228     HRESULT hres;
1229
1230     if(flags & CLIENTSITE_SETNULL) {
1231         hres = IOleObject_GetClientSite(oleobj, &clientsite);
1232         ok(clientsite == &ClientSite, "clientsite=%p, expected %p\n", clientsite, &ClientSite);
1233
1234         hres = IOleObject_SetClientSite(oleobj, NULL);
1235         ok(hres == S_OK, "SetClientSite failed: %08lx\n", hres);
1236     }
1237
1238     if(flags & CLIENTSITE_DONTSET)
1239         return;
1240
1241     hres = IOleObject_GetClientSite(oleobj, &clientsite);
1242     ok(hres == S_OK, "GetClientSite failed: %08lx\n", hres);
1243     ok(clientsite == NULL, "GetClientSite() = %p, expected NULL\n", clientsite);
1244
1245     SET_EXPECT(GetHostInfo);
1246     if(flags & CLIENTSITE_EXPECTPATH) {
1247         SET_EXPECT(GetOptionKeyPath);
1248         SET_EXPECT(GetOverrideKeyPath);
1249     }
1250     SET_EXPECT(GetWindow);
1251     SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
1252     SET_EXPECT(Exec_SETPROGRESSMAX);
1253     SET_EXPECT(Exec_SETPROGRESSPOS);
1254     SET_EXPECT(Invoke_AMBIENT_USERMODE);
1255     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
1256     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
1257     SET_EXPECT(Invoke_AMBIENT_SILENT);
1258     SET_EXPECT(Invoke_AMBIENT_USERAGENT);
1259     SET_EXPECT(Invoke_AMBIENT_PALETTE);
1260     hres = IOleObject_SetClientSite(oleobj, &ClientSite);
1261     ok(hres == S_OK, "SetClientSite failed: %08lx\n", hres);
1262     CHECK_CALLED(GetHostInfo);
1263     if(flags & CLIENTSITE_EXPECTPATH) {
1264         CHECK_CALLED(GetOptionKeyPath);
1265         CHECK_CALLED(GetOverrideKeyPath);
1266     }
1267     CHECK_CALLED(GetWindow);
1268     CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
1269     CHECK_CALLED(Exec_SETPROGRESSMAX);
1270     CHECK_CALLED(Exec_SETPROGRESSPOS);
1271     CHECK_CALLED(Invoke_AMBIENT_USERMODE);
1272     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
1273     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED); 
1274     CHECK_CALLED(Invoke_AMBIENT_SILENT);
1275     CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
1276     CHECK_CALLED(Invoke_AMBIENT_PALETTE);
1277
1278     hres = IOleObject_GetClientSite(oleobj, &clientsite);
1279     ok(hres == S_OK, "GetClientSite failed: %08lx\n", hres);
1280     ok(clientsite == &ClientSite, "GetClientSite() = %p, expected %p\n", clientsite, &ClientSite);
1281 }
1282
1283 static void test_OnAmbientPropertyChange(IUnknown *unk)
1284 {
1285     IOleControl *control = NULL;
1286     HRESULT hres;
1287
1288     hres = IUnknown_QueryInterface(unk, &IID_IOleControl, (void**)&control);
1289     ok(hres == S_OK, "QueryInterface(IID_IOleControl failed: %08lx\n", hres);
1290     if(FAILED(hres))
1291         return;
1292
1293     SET_EXPECT(Invoke_AMBIENT_USERMODE);
1294     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_USERMODE);
1295     ok(hres == S_OK, "OnAmbientChange failed: %08lx\n", hres);
1296     CHECK_CALLED(Invoke_AMBIENT_USERMODE);
1297
1298     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
1299     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_DLCONTROL);
1300     ok(hres == S_OK, "OnAmbientChange failed: %08lx\n", hres);
1301     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
1302
1303     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
1304     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
1305     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
1306     ok(hres == S_OK, "OnAmbientChange failed: %08lx\n", hres);
1307     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
1308     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
1309
1310     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
1311     SET_EXPECT(Invoke_AMBIENT_SILENT);
1312     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_SILENT);
1313     ok(hres == S_OK, "OnAmbientChange failed: %08lx\n", hres);
1314     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
1315     CHECK_CALLED(Invoke_AMBIENT_SILENT);
1316
1317     SET_EXPECT(Invoke_AMBIENT_USERAGENT);
1318     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_USERAGENT);
1319     ok(hres == S_OK, "OnAmbientChange failed: %08lx\n", hres);
1320     CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
1321
1322     SET_EXPECT(Invoke_AMBIENT_PALETTE);
1323     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_PALETTE);
1324     ok(hres == S_OK, "OnAmbientChange failed: %08lx\n", hres);
1325     CHECK_CALLED(Invoke_AMBIENT_PALETTE);
1326
1327     IOleControl_Release(control);
1328 }
1329
1330
1331
1332 static void test_OnAmbientPropertyChange2(IUnknown *unk)
1333 {
1334     IOleControl *control = NULL;
1335     HRESULT hres;
1336
1337     hres = IUnknown_QueryInterface(unk, &IID_IOleControl, (void**)&control);
1338     ok(hres == S_OK, "QueryInterface(IID_IOleControl failed: %08lx\n", hres);
1339     if(FAILED(hres))
1340         return;
1341
1342     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_PALETTE);
1343     ok(hres == S_OK, "OnAmbientPropertyChange failed: %08lx\n", hres);
1344
1345     IOleControl_Release(control);
1346 }
1347
1348 static void test_Close(IUnknown *unk, BOOL set_client)
1349 {
1350     IOleObject *oleobj = NULL;
1351     HRESULT hres;
1352
1353     hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
1354     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08lx\n", hres);
1355     if(FAILED(hres))
1356         return;
1357
1358     SET_EXPECT(GetContainer);
1359     SET_EXPECT(LockContainer);
1360     expect_LockContainer_fLock = FALSE;
1361     hres = IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
1362     ok(hres == S_OK, "Close failed: %08lx\n", hres);
1363     CHECK_CALLED(GetContainer);
1364     CHECK_CALLED(LockContainer);
1365
1366     if(set_client)
1367         test_ClientSite(oleobj, CLIENTSITE_SETNULL|CLIENTSITE_DONTSET);
1368
1369     IOleObject_Release(oleobj);
1370 }
1371
1372 static void test_InPlaceDeactivate(IUnknown *unk, BOOL expect_call)
1373 {
1374     IOleInPlaceObjectWindowless *windowlessobj = NULL;
1375     HRESULT hres;
1376
1377     hres = IUnknown_QueryInterface(unk, &IID_IOleInPlaceObjectWindowless,
1378             (void**)&windowlessobj);
1379     ok(hres == S_OK, "QueryInterface(IID_IOleInPlaceObjectWindowless) failed: %08lx\n", hres);
1380     if(FAILED(hres))
1381         return;
1382
1383     if(expect_call) SET_EXPECT(OnInPlaceDeactivate);
1384     hres = IOleInPlaceObjectWindowless_InPlaceDeactivate(windowlessobj);
1385     ok(hres == S_OK, "InPlaceDeactivate failed: %08lx\n", hres);
1386     if(expect_call) CHECK_CALLED(OnInPlaceDeactivate);
1387
1388     IOleInPlaceObjectWindowless_Release(windowlessobj);
1389 }
1390
1391 static HRESULT test_Activate(IUnknown *unk, DWORD flags)
1392 {
1393     IOleObject *oleobj = NULL;
1394     GUID guid;
1395     HRESULT hres;
1396
1397     last_hwnd = hwnd;
1398
1399     if(view)
1400         IOleDocumentView_Release(view);
1401     view = NULL;
1402
1403     hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
1404     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08lx\n", hres);
1405     if(FAILED(hres))
1406         return hres;
1407
1408     hres = IOleObject_GetUserClassID(oleobj, NULL);
1409     ok(hres == E_INVALIDARG, "GetUserClassID returned: %08lx, expected E_INVALIDARG\n", hres);
1410
1411     hres = IOleObject_GetUserClassID(oleobj, &guid);
1412     ok(hres == S_OK, "GetUserClassID failed: %08lx\n", hres);
1413     ok(IsEqualGUID(&guid, &CLSID_HTMLDocument), "guid != CLSID_HTMLDocument\n");
1414
1415     test_ClientSite(oleobj, flags);
1416     test_InPlaceDeactivate(unk, FALSE);
1417
1418     hres = test_DoVerb(oleobj);
1419
1420     IOleObject_Release(oleobj);
1421     return hres;
1422 }
1423
1424 static void test_Window(IUnknown *unk, BOOL expect_success)
1425 {
1426     IOleInPlaceActiveObject *activeobject = NULL;
1427     HWND tmp_hwnd;
1428     HRESULT hres;
1429
1430     hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobject);
1431     ok(hres == S_OK, "Could not get IOleInPlaceActiveObject interface: %08lx\n", hres);
1432     if(FAILED(hres))
1433         return;
1434
1435     hres = IOleInPlaceActiveObject_GetWindow(activeobject, &tmp_hwnd);
1436
1437     if(expect_success) {
1438         ok(hres == S_OK, "GetWindow failed: %08lx\n", hres);
1439         ok(tmp_hwnd == hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, hwnd);
1440     }else {
1441         ok(hres == E_FAIL, "GetWindow returned %08lx, expected E_FAIL\n", hres);
1442         ok(IsWindow(hwnd), "hwnd is destroyed\n");
1443     }
1444
1445     IOleInPlaceActiveObject_Release(activeobject);
1446 }
1447
1448 static void test_CloseView(void)
1449 {
1450     IOleInPlaceSite *inplacesite = (IOleInPlaceSite*)0xff00ff00;
1451     HRESULT hres;
1452
1453     if(!view)
1454         return;
1455
1456     hres = IOleDocumentView_Show(view, FALSE);
1457     ok(hres == S_OK, "Show failed: %08lx\n", hres);
1458
1459     hres = IOleDocumentView_CloseView(view, 0);
1460     ok(hres == S_OK, "CloseView failed: %08lx\n", hres);
1461
1462     hres = IOleDocumentView_SetInPlaceSite(view, NULL);
1463     ok(hres == S_OK, "SetInPlaceSite failed: %08lx\n", hres);
1464
1465     hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
1466     ok(hres == S_OK, "SetInPlaceSite failed: %08lx\n", hres);
1467     ok(inplacesite == NULL, "inplacesite=%p, expected NULL\n", inplacesite);
1468 }
1469
1470 static void test_UIDeactivate(void)
1471 {
1472     HRESULT hres;
1473
1474     if(call_UIActivate) {
1475         SET_EXPECT(SetActiveObject);
1476         SET_EXPECT(HideUI);
1477         SET_EXPECT(OnUIDeactivate);
1478     }
1479
1480     expect_SetActiveObject_active = FALSE;
1481     hres = IOleDocumentView_UIActivate(view, FALSE);
1482     ok(hres == S_OK, "UIActivate failed: %08lx\n", hres);
1483
1484     if(call_UIActivate) {
1485         CHECK_CALLED(SetActiveObject);
1486         CHECK_CALLED(HideUI);
1487         CHECK_CALLED(OnUIDeactivate);
1488     }
1489 }
1490
1491 static void test_Hide(void)
1492 {
1493     HRESULT hres;
1494
1495     if(!view)
1496         return;
1497
1498     hres = IOleDocumentView_Show(view, FALSE);
1499     ok(hres == S_OK, "Show failed: %08lx\n", hres);
1500 }
1501
1502 static void test_HTMLDocument(void)
1503 {
1504     IUnknown *unk;
1505     HRESULT hres;
1506     ULONG ref;
1507
1508     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
1509             &IID_IUnknown, (void**)&unk);
1510     ok(hres == S_OK, "CoCreateInstance failed: %08lx\n", hres);
1511     if(FAILED(hres))
1512         return;
1513
1514     test_Persist(unk);
1515
1516     test_OnAmbientPropertyChange2(unk);
1517     hres = test_Activate(unk, CLIENTSITE_EXPECTPATH);
1518     if(FAILED(hres)) {
1519         IUnknown_Release(unk);
1520         return;
1521     }
1522
1523     test_OleCommandTarget_fail(unk);
1524     test_OleCommandTarget(unk);
1525     test_OnAmbientPropertyChange(unk);
1526     test_Window(unk, TRUE);
1527     test_UIDeactivate();
1528     test_OleCommandTarget(unk);
1529     test_Window(unk, TRUE);
1530     test_InPlaceDeactivate(unk, TRUE);
1531
1532     /* Calling test_OleCommandTarget here couses Segmentation Fault with native
1533      * MSHTML. It doesn't with Wine. */
1534
1535     test_Window(unk, FALSE);
1536     test_Hide();
1537     test_InPlaceDeactivate(unk, FALSE);
1538     test_CloseView();
1539     test_Close(unk, FALSE);
1540
1541     /* Activate HTMLDocument again */
1542     test_Activate(unk, CLIENTSITE_SETNULL);
1543     test_Window(unk, TRUE);
1544     test_OleCommandTarget(unk);
1545     test_UIDeactivate();
1546     test_InPlaceDeactivate(unk, TRUE);
1547     test_Close(unk, FALSE);
1548
1549     /* Activate HTMLDocument again, this time without UIActivate */
1550     call_UIActivate = FALSE;
1551     test_Activate(unk, CLIENTSITE_SETNULL);
1552     test_Window(unk, TRUE);
1553     test_UIDeactivate();
1554     test_InPlaceDeactivate(unk, TRUE);
1555     test_CloseView();
1556     test_CloseView();
1557     test_Close(unk, TRUE);
1558     test_OnAmbientPropertyChange2(unk);
1559
1560     if(view)
1561         IOleDocumentView_Release(view);
1562     view = NULL;
1563
1564     ok(IsWindow(hwnd), "hwnd is destroyed\n");
1565
1566     ref = IUnknown_Release(unk);
1567     ok(ref == 0, "ref=%ld, expected 0\n", ref);
1568
1569     ok(!IsWindow(hwnd), "hwnd is not destroyed\n");
1570
1571 }
1572
1573 START_TEST(htmldoc)
1574 {
1575     CoInitialize(NULL);
1576     container_hwnd = create_container_window();
1577
1578     test_HTMLDocument();
1579
1580     DestroyWindow(container_hwnd);
1581     CoUninitialize();
1582 }