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