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