mshtml: Add stub implementation of IHTMLFormElement.
[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     IHTMLElement *elem;
2642     BSTR state;
2643     VARIANT out;
2644     HRESULT hres;
2645
2646     static const LPCSTR expected_state[] = {
2647         "uninitialized",
2648         "loading",
2649         NULL,
2650         "interactive",
2651         "complete",
2652         "uninitialized"
2653     };
2654
2655     if(!unk)
2656         unk = doc_unk;
2657
2658     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&htmldoc);
2659     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument2) failed: %08x\n", hres);
2660     if(FAILED(hres))
2661         return;
2662
2663     hres = IHTMLDocument2_get_readyState(htmldoc, NULL);
2664     ok(hres == E_POINTER, "get_readyState failed: %08x, expected\n", hres);
2665
2666     hres = IHTMLDocument2_get_readyState(htmldoc, &state);
2667     ok(hres == S_OK, "get_ReadyState failed: %08x\n", hres);
2668
2669     if(!strcmp_wa(state, "interactive") && load_state == LD_LOADING)
2670         load_state = LD_INTERACTIVE;
2671
2672     ok_(__FILE__, line)
2673         (!strcmp_wa(state, expected_state[load_state]), "unexpected state %s, expected %d\n",
2674          wine_dbgstr_w(state), load_state);
2675     SysFreeString(state);
2676
2677     hres = IHTMLDocument2_get_body(htmldoc, &elem);
2678     ok_(__FILE__,line)(hres == S_OK, "get_body failed: %08x\n", hres);
2679     if(elem) {
2680         IHTMLElement2 *elem2;
2681         VARIANT var;
2682
2683         hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLElement2, (void**)&elem2);
2684         IHTMLElement_Release(elem);
2685         ok(hres == S_OK, "Could not get IHTMLElement2 iface: %08x\n", hres);
2686
2687         hres = IHTMLElement2_get_readyState(elem2, &var);
2688         IHTMLElement2_Release(elem2);
2689         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
2690         ok(V_VT(&var) == VT_BSTR, "V_VT(state) = %d\n", V_VT(&var));
2691         ok(!strcmp_wa(V_BSTR(&var), "complete"), "unexpected body state %s\n", wine_dbgstr_w(V_BSTR(&var)));
2692         VariantClear(&var);
2693     }else {
2694         ok_(__FILE__,line)(load_state != LD_COMPLETE, "body is NULL in complete state\n");
2695     }
2696
2697     dispparams.cArgs = 0;
2698     dispparams.cNamedArgs = 0;
2699     dispparams.rgdispidNamedArgs = NULL;
2700     dispparams.rgvarg = NULL;
2701
2702     VariantInit(&out);
2703
2704     hres = IHTMLDocument2_Invoke(htmldoc, DISPID_READYSTATE, &IID_NULL, 0, DISPATCH_PROPERTYGET,
2705                                  &dispparams, &out, NULL, NULL);
2706     ok(hres == S_OK, "Invoke(DISPID_READYSTATE) failed: %08x\n", hres);
2707
2708     ok_(__FILE__,line) (V_VT(&out) == VT_I4, "V_VT(out)=%d\n", V_VT(&out));
2709     ok_(__FILE__,line) (V_I4(&out) == load_state%5, "VT_I4(out)=%d, expected %d\n", V_I4(&out), load_state%5);
2710
2711     test_doscroll((IUnknown*)htmldoc);
2712
2713     IHTMLDocument2_Release(htmldoc);
2714 }
2715
2716 static void test_ConnectionPoint(IConnectionPointContainer *container, REFIID riid)
2717 {
2718     IConnectionPointContainer *tmp_container = NULL;
2719     IConnectionPoint *cp;
2720     IID iid;
2721     HRESULT hres;
2722
2723     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
2724     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
2725     if(FAILED(hres))
2726         return;
2727
2728     hres = IConnectionPoint_GetConnectionInterface(cp, &iid);
2729     ok(hres == S_OK, "GetConnectionInterface failed: %08x\n", hres);
2730     ok(IsEqualGUID(riid, &iid), "wrong iid\n");
2731
2732     hres = IConnectionPoint_GetConnectionInterface(cp, NULL);
2733     ok(hres == E_POINTER, "GetConnectionInterface failed: %08x, expected E_POINTER\n", hres);
2734
2735     hres = IConnectionPoint_GetConnectionPointContainer(cp, &tmp_container);
2736     ok(hres == S_OK, "GetConnectionPointContainer failed: %08x\n", hres);
2737     ok(tmp_container == container, "container != tmp_container\n");
2738     if(SUCCEEDED(hres))
2739         IConnectionPointContainer_Release(tmp_container);
2740
2741     hres = IConnectionPoint_GetConnectionPointContainer(cp, NULL);
2742     ok(hres == E_POINTER, "GetConnectionPointContainer failed: %08x, expected E_POINTER\n", hres);
2743
2744     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
2745         DWORD cookie;
2746
2747         hres = IConnectionPoint_Advise(cp, (IUnknown*)&PropertyNotifySink, &cookie);
2748         ok(hres == S_OK, "Advise failed: %08x\n", hres);
2749     }
2750
2751     IConnectionPoint_Release(cp);
2752 }
2753
2754 static void test_ConnectionPointContainer(IUnknown *unk)
2755 {
2756     IConnectionPointContainer *container;
2757     HRESULT hres;
2758
2759     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
2760     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
2761     if(FAILED(hres))
2762         return;
2763
2764     test_ConnectionPoint(container, &IID_IPropertyNotifySink);
2765     test_ConnectionPoint(container, &DIID_HTMLDocumentEvents);
2766     test_ConnectionPoint(container, &DIID_HTMLDocumentEvents2);
2767
2768     IConnectionPointContainer_Release(container);
2769 }
2770
2771 static void test_Load(IPersistMoniker *persist, IMoniker *mon)
2772 {
2773     IBindCtx *bind;
2774     HRESULT hres;
2775     WCHAR sz_html_clientsite_objectparam[MAX_PATH];
2776
2777     lstrcpyW(sz_html_clientsite_objectparam, SZ_HTML_CLIENTSITE_OBJECTPARAM);
2778
2779     test_readyState((IUnknown*)persist);
2780
2781     doc_mon = mon;
2782
2783     CreateBindCtx(0, &bind);
2784     IBindCtx_RegisterObjectParam(bind, sz_html_clientsite_objectparam,
2785                                  (IUnknown*)&ClientSite);
2786
2787     if(mon == &Moniker)
2788         SET_EXPECT(GetDisplayName);
2789     if(!set_clientsite) {
2790         SET_EXPECT(Invoke_AMBIENT_USERMODE);
2791         SET_EXPECT(GetHostInfo);
2792         SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
2793         SET_EXPECT(Invoke_AMBIENT_SILENT);
2794         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2795         SET_EXPECT(Invoke_AMBIENT_USERAGENT);
2796         SET_EXPECT(Invoke_AMBIENT_PALETTE);
2797         SET_EXPECT(GetOptionKeyPath);
2798         SET_EXPECT(GetOverrideKeyPath);
2799         SET_EXPECT(GetWindow);
2800         SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
2801         SET_EXPECT(Exec_SETPROGRESSMAX);
2802         SET_EXPECT(Exec_SETPROGRESSPOS);
2803         SET_EXPECT(Exec_ShellDocView_37);
2804     }
2805     if(!container_locked) {
2806         SET_EXPECT(GetContainer);
2807         SET_EXPECT(LockContainer);
2808     }
2809     SET_EXPECT(OnChanged_READYSTATE);
2810     SET_EXPECT(Exec_ShellDocView_84);
2811     SET_EXPECT(IsSystemMoniker);
2812     if(mon == &Moniker)
2813         SET_EXPECT(BindToStorage);
2814     SET_EXPECT(SetActiveObject);
2815     if(set_clientsite) {
2816         SET_EXPECT(Invoke_AMBIENT_SILENT);
2817         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2818         SET_EXPECT(Exec_ShellDocView_37);
2819     }
2820     load_state = LD_DOLOAD;
2821     expect_LockContainer_fLock = TRUE;
2822     readystate_set_loading = TRUE;
2823
2824     hres = IPersistMoniker_Load(persist, FALSE, mon, bind, 0x12);
2825     ok(hres == S_OK, "Load failed: %08x\n", hres);
2826
2827     if(mon == &Moniker)
2828         CHECK_CALLED(GetDisplayName);
2829     if(!set_clientsite) {
2830         CHECK_CALLED(Invoke_AMBIENT_USERMODE);
2831         CHECK_CALLED(GetHostInfo);
2832         CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
2833         CHECK_CALLED(Invoke_AMBIENT_SILENT);
2834         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2835         CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
2836         CHECK_CALLED(Invoke_AMBIENT_PALETTE);
2837         CHECK_CALLED(GetOptionKeyPath);
2838         CHECK_CALLED(GetOverrideKeyPath);
2839         CHECK_CALLED(GetWindow);
2840         CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
2841         CHECK_CALLED(Exec_SETPROGRESSMAX);
2842         CHECK_CALLED(Exec_SETPROGRESSPOS);
2843         CHECK_CALLED(Exec_ShellDocView_37);
2844     }
2845     if(!container_locked) {
2846         CHECK_CALLED(GetContainer);
2847         CHECK_CALLED(LockContainer);
2848         container_locked = TRUE;
2849     }
2850     CHECK_CALLED(OnChanged_READYSTATE);
2851     SET_CALLED(IsSystemMoniker); /* IE7 */
2852     SET_CALLED(Exec_ShellDocView_84);
2853     if(mon == &Moniker)
2854         CHECK_CALLED(BindToStorage);
2855     SET_CALLED(SetActiveObject); /* FIXME */
2856     if(set_clientsite) {
2857         CHECK_CALLED(Invoke_AMBIENT_SILENT);
2858         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
2859         CHECK_CALLED(Exec_ShellDocView_37);
2860     }
2861
2862     set_clientsite = container_locked = TRUE;
2863
2864     test_GetCurMoniker((IUnknown*)persist, mon, NULL);
2865
2866     IBindCtx_Release(bind);
2867
2868     test_readyState((IUnknown*)persist);
2869 }
2870
2871 #define DWL_VERBDONE  0x0001
2872 #define DWL_CSS       0x0002
2873 #define DWL_TRYCSS    0x0004
2874 #define DWL_HTTP      0x0008
2875
2876 static void test_download(DWORD flags)
2877 {
2878     HWND hwnd;
2879     MSG msg;
2880
2881     hwnd = FindWindowA("Internet Explorer_Hidden", NULL);
2882     ok(hwnd != NULL, "Could not find hidden window\n");
2883
2884     test_readyState(NULL);
2885
2886     if(flags & (DWL_VERBDONE|DWL_HTTP))
2887         SET_EXPECT(Exec_SETPROGRESSMAX);
2888     if((flags & DWL_VERBDONE) && !load_from_stream)
2889         SET_EXPECT(GetHostInfo);
2890     SET_EXPECT(SetStatusText);
2891     SET_EXPECT(Exec_SETDOWNLOADSTATE_1);
2892     SET_EXPECT(GetDropTarget);
2893     if(flags & DWL_TRYCSS)
2894         SET_EXPECT(Exec_ShellDocView_84);
2895     if(flags & DWL_CSS) {
2896         SET_EXPECT(CreateInstance);
2897         SET_EXPECT(Start);
2898         SET_EXPECT(LockRequest);
2899         SET_EXPECT(Terminate);
2900         SET_EXPECT(Protocol_Read);
2901         SET_EXPECT(UnlockRequest);
2902     }
2903     SET_EXPECT(Exec_Explorer_69);
2904     SET_EXPECT(EnableModeless_TRUE); /* IE7 */
2905     SET_EXPECT(Frame_EnableModeless_TRUE); /* IE7 */
2906     SET_EXPECT(EnableModeless_FALSE); /* IE7 */
2907     SET_EXPECT(Frame_EnableModeless_FALSE); /* IE7 */
2908     if(doc_mon != &Moniker) {
2909         SET_EXPECT(OnChanged_1012);
2910         SET_EXPECT(Exec_HTTPEQUIV);
2911         SET_EXPECT(Exec_SETTITLE);
2912     }
2913     SET_EXPECT(OnChanged_1005);
2914     SET_EXPECT(OnChanged_READYSTATE);
2915     SET_EXPECT(Exec_SETPROGRESSPOS);
2916     SET_EXPECT(Exec_SETDOWNLOADSTATE_0);
2917     SET_EXPECT(Exec_ShellDocView_103);
2918     SET_EXPECT(Exec_ShellDocView_105);
2919     SET_EXPECT(Exec_ShellDocView_140);
2920     SET_EXPECT(Exec_MSHTML_PARSECOMPLETE);
2921     SET_EXPECT(Exec_HTTPEQUIV_DONE);
2922     SET_EXPECT(SetStatusText);
2923     expect_status_text = (LPWSTR)0xdeadbeef; /* TODO */
2924
2925     while(!called_Exec_HTTPEQUIV_DONE && GetMessage(&msg, NULL, 0, 0)) {
2926         TranslateMessage(&msg);
2927         DispatchMessage(&msg);
2928     }
2929
2930     if(flags & DWL_VERBDONE)
2931         CHECK_CALLED(Exec_SETPROGRESSMAX);
2932     if(flags & DWL_HTTP)
2933         SET_CALLED(Exec_SETPROGRESSMAX);
2934     if((flags & DWL_VERBDONE) && !load_from_stream)
2935         CHECK_CALLED(GetHostInfo);
2936     CHECK_CALLED(SetStatusText);
2937     CHECK_CALLED(Exec_SETDOWNLOADSTATE_1);
2938     CHECK_CALLED(GetDropTarget);
2939     if(flags & DWL_TRYCSS)
2940         SET_CALLED(Exec_ShellDocView_84);
2941     if(flags & DWL_CSS) {
2942         CHECK_CALLED(CreateInstance);
2943         CHECK_CALLED(Start);
2944         CHECK_CALLED(LockRequest);
2945         CHECK_CALLED(Terminate);
2946         CHECK_CALLED(Protocol_Read);
2947         CHECK_CALLED(UnlockRequest);
2948     }
2949     SET_CALLED(Exec_Explorer_69);
2950     SET_CALLED(EnableModeless_TRUE); /* IE7 */
2951     SET_CALLED(Frame_EnableModeless_TRUE); /* IE7 */
2952     SET_CALLED(EnableModeless_FALSE); /* IE7 */
2953     SET_CALLED(Frame_EnableModeless_FALSE); /* IE7 */
2954     if(doc_mon != &Moniker) todo_wine {
2955         CHECK_CALLED(OnChanged_1012);
2956         CHECK_CALLED(Exec_HTTPEQUIV);
2957         CHECK_CALLED(Exec_SETTITLE);
2958     }
2959     CHECK_CALLED(OnChanged_1005);
2960     CHECK_CALLED(OnChanged_READYSTATE);
2961     CHECK_CALLED(Exec_SETPROGRESSPOS);
2962     CHECK_CALLED(Exec_SETDOWNLOADSTATE_0);
2963     SET_CALLED(Exec_ShellDocView_103);
2964     SET_CALLED(Exec_ShellDocView_105);
2965     SET_CALLED(Exec_ShellDocView_140);
2966     CHECK_CALLED(Exec_MSHTML_PARSECOMPLETE);
2967     CHECK_CALLED(Exec_HTTPEQUIV_DONE);
2968     SET_CALLED(SetStatusText);
2969
2970     load_state = LD_COMPLETE;
2971
2972     test_readyState(NULL);
2973 }
2974
2975 static void test_Persist(IUnknown *unk, IMoniker *mon)
2976 {
2977     IPersistMoniker *persist_mon;
2978     IPersistFile *persist_file;
2979     GUID guid;
2980     HRESULT hres;
2981
2982     hres = IUnknown_QueryInterface(unk, &IID_IPersistFile, (void**)&persist_file);
2983     ok(hres == S_OK, "QueryInterface(IID_IPersist) failed: %08x\n", hres);
2984     if(SUCCEEDED(hres)) {
2985         hres = IPersist_GetClassID(persist_file, NULL);
2986         ok(hres == E_INVALIDARG, "GetClassID returned: %08x, expected E_INVALIDARG\n", hres);
2987
2988         hres = IPersist_GetClassID(persist_file, &guid);
2989         ok(hres == S_OK, "GetClassID failed: %08x\n", hres);
2990         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
2991
2992         IPersist_Release(persist_file);
2993     }
2994
2995     hres = IUnknown_QueryInterface(unk, &IID_IPersistMoniker, (void**)&persist_mon);
2996     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker) failed: %08x\n", hres);
2997     if(SUCCEEDED(hres)) {
2998         hres = IPersistMoniker_GetClassID(persist_mon, NULL);
2999         ok(hres == E_INVALIDARG, "GetClassID returned: %08x, expected E_INVALIDARG\n", hres);
3000
3001         hres = IPersistMoniker_GetClassID(persist_mon, &guid);
3002         ok(hres == S_OK, "GetClassID failed: %08x\n", hres);
3003         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
3004
3005         if(load_state == LD_DOLOAD)
3006             test_Load(persist_mon, mon);
3007
3008         test_readyState(unk);
3009
3010         IPersistMoniker_Release(persist_mon);
3011     }
3012 }
3013
3014 static void test_put_href(IUnknown *unk)
3015 {
3016     IHTMLLocation *location;
3017     IHTMLDocument2 *doc;
3018     BSTR str;
3019     HRESULT hres;
3020
3021     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&doc);
3022     ok(hres == S_OK, "Could not get IHTMLDocument2 iface: %08x\n", hres);
3023
3024     location = NULL;
3025     hres = IHTMLDocument2_get_location(doc, &location);
3026     IHTMLDocument2_Release(doc);
3027     ok(hres == S_OK, "get_location failed: %08x\n", hres);
3028     ok(location != NULL, "location == NULL\n");
3029
3030     SET_EXPECT(TranslateUrl);
3031     SET_EXPECT(Navigate);
3032     str = a2bstr("about:blank");
3033     hres = IHTMLLocation_put_href(location, str);
3034     SysFreeString(str);
3035     ok(hres == S_OK, "put_href failed: %08x\n", hres);
3036     CHECK_CALLED(TranslateUrl);
3037     CHECK_CALLED(Navigate);
3038
3039     IHTMLLocation_Release(location);
3040 }
3041
3042 static const OLECMDF expect_cmds[OLECMDID_GETPRINTTEMPLATE+1] = {
3043     0,
3044     OLECMDF_SUPPORTED,                  /* OLECMDID_OPEN */
3045     OLECMDF_SUPPORTED,                  /* OLECMDID_NEW */
3046     OLECMDF_SUPPORTED,                  /* OLECMDID_SAVE */
3047     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_SAVEAS */
3048     OLECMDF_SUPPORTED,                  /* OLECMDID_SAVECOPYAS */
3049     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PRINT */
3050     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PRINTPREVIEW */
3051     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PAGESETUP */
3052     OLECMDF_SUPPORTED,                  /* OLECMDID_SPELL */
3053     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_PROPERTIES */
3054     OLECMDF_SUPPORTED,                  /* OLECMDID_CUT */
3055     OLECMDF_SUPPORTED,                  /* OLECMDID_COPY */
3056     OLECMDF_SUPPORTED,                  /* OLECMDID_PASTE */
3057     OLECMDF_SUPPORTED,                  /* OLECMDID_PASTESPECIAL */
3058     OLECMDF_SUPPORTED,                  /* OLECMDID_UNDO */
3059     OLECMDF_SUPPORTED,                  /* OLECMDID_REDO */
3060     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_SELECTALL */
3061     OLECMDF_SUPPORTED,                  /* OLECMDID_CLEARSELECTION */
3062     OLECMDF_SUPPORTED,                  /* OLECMDID_ZOOM */
3063     OLECMDF_SUPPORTED,                  /* OLECMDID_GETZOOMRANGE */
3064     0,
3065     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_REFRESH */
3066     OLECMDF_SUPPORTED|OLECMDF_ENABLED,  /* OLECMDID_STOP */
3067     0,0,0,0,0,0,
3068     OLECMDF_SUPPORTED,                  /* OLECMDID_STOPDOWNLOAD */
3069     0,0,
3070     OLECMDF_SUPPORTED,                  /* OLECMDID_DELETE */
3071     0,0,
3072     OLECMDF_SUPPORTED,                  /* OLECMDID_ENABLE_INTERACTION */
3073     OLECMDF_SUPPORTED,                  /* OLECMDID_ONUNLOAD */
3074     0,0,0,0,0,
3075     OLECMDF_SUPPORTED,                  /* OLECMDID_SHOWPAGESETUP */
3076     OLECMDF_SUPPORTED,                  /* OLECMDID_SHOWPRINT */
3077     0,0,
3078     OLECMDF_SUPPORTED,                  /* OLECMDID_CLOSE */
3079     0,0,0,
3080     OLECMDF_SUPPORTED,                  /* OLECMDID_SETPRINTTEMPLATE */
3081     OLECMDF_SUPPORTED                   /* OLECMDID_GETPRINTTEMPLATE */
3082 };
3083
3084 #define test_QueryStatus(u,cgid,cmdid,cmdf) _test_QueryStatus(__LINE__,u,cgid,cmdid,cmdf)
3085 static void _test_QueryStatus(unsigned line, IUnknown *unk, REFIID cgid, ULONG cmdid, DWORD cmdf)
3086 {
3087     IOleCommandTarget *cmdtrg;
3088     OLECMD olecmd = {cmdid, 0};
3089     HRESULT hres;
3090
3091     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3092     ok_(__FILE__,line) (hres == S_OK, "QueryInterface(IID_IOleCommandTarget failed: %08x\n", hres);
3093     if(FAILED(hres))
3094         return;
3095
3096     hres = IOleCommandTarget_QueryStatus(cmdtrg, cgid, 1, &olecmd, NULL);
3097     ok(hres == S_OK, "QueryStatus(%u) failed: %08x\n", cmdid, hres);
3098
3099     IOleCommandTarget_Release(cmdtrg);
3100
3101     ok_(__FILE__,line) (olecmd.cmdID == cmdid, "cmdID changed\n");
3102     ok_(__FILE__,line) (olecmd.cmdf == cmdf, "(%u) cmdf=%08x, expected %08x\n", cmdid, olecmd.cmdf, cmdf);
3103 }
3104
3105 static void test_MSHTML_QueryStatus(IUnknown *unk, DWORD cmdf)
3106 {
3107     if(!unk)
3108         unk = doc_unk;
3109
3110     test_QueryStatus(unk, &CGID_MSHTML, IDM_FONTNAME, cmdf);
3111     test_QueryStatus(unk, &CGID_MSHTML, IDM_FONTSIZE, cmdf);
3112     test_QueryStatus(unk, &CGID_MSHTML, IDM_SELECTALL, cmdf|OLECMDF_ENABLED);
3113     test_QueryStatus(unk, &CGID_MSHTML, IDM_BOLD, cmdf);
3114     test_QueryStatus(unk, &CGID_MSHTML, IDM_FORECOLOR, cmdf);
3115     test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYCENTER, cmdf);
3116     test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYLEFT, cmdf);
3117     test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYRIGHT, cmdf);
3118     test_QueryStatus(unk, &CGID_MSHTML, IDM_ITALIC, cmdf);
3119     test_QueryStatus(unk, &CGID_MSHTML, IDM_UNDERLINE, cmdf);
3120     test_QueryStatus(unk, &CGID_MSHTML, IDM_HORIZONTALLINE, cmdf);
3121     test_QueryStatus(unk, &CGID_MSHTML, IDM_ORDERLIST, cmdf);
3122     test_QueryStatus(unk, &CGID_MSHTML, IDM_UNORDERLIST, cmdf);
3123     test_QueryStatus(unk, &CGID_MSHTML, IDM_INDENT, cmdf);
3124     test_QueryStatus(unk, &CGID_MSHTML, IDM_OUTDENT, cmdf);
3125     test_QueryStatus(unk, &CGID_MSHTML, IDM_DELETE, cmdf);
3126 }
3127
3128 static void test_OleCommandTarget(IUnknown *unk)
3129 {
3130     IOleCommandTarget *cmdtrg;
3131     OLECMD cmds[OLECMDID_GETPRINTTEMPLATE];
3132     int i;
3133     HRESULT hres;
3134
3135     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3136     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget failed: %08x\n", hres);
3137     if(FAILED(hres))
3138         return;
3139
3140     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
3141         cmds[i].cmdID = i+1;
3142         cmds[i].cmdf = 0xf0f0;
3143     }
3144
3145     SET_EXPECT(QueryStatus_OPEN);
3146     SET_EXPECT(QueryStatus_NEW);
3147     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, sizeof(cmds)/sizeof(cmds[0]), cmds, NULL);
3148     ok(hres == S_OK, "QueryStatus failed: %08x\n", hres);
3149     CHECK_CALLED(QueryStatus_OPEN);
3150     CHECK_CALLED(QueryStatus_NEW);
3151
3152     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
3153         ok(cmds[i].cmdID == i+1, "cmds[%d].cmdID canged to %x\n", i, cmds[i].cmdID);
3154         if(i+1 == OLECMDID_FIND)
3155             continue;
3156         ok(cmds[i].cmdf == expect_cmds[i+1], "cmds[%d].cmdf=%x, expected %x\n",
3157                 i+1, cmds[i].cmdf, expect_cmds[i+1]);
3158     }
3159
3160     ok(!cmds[OLECMDID_FIND-1].cmdf || cmds[OLECMDID_FIND-1].cmdf == (OLECMDF_SUPPORTED|OLECMDF_ENABLED),
3161        "cmds[OLECMDID_FIND].cmdf=%x\n", cmds[OLECMDID_FIND-1].cmdf);
3162
3163     IOleCommandTarget_Release(cmdtrg);
3164 }
3165
3166 static void test_OleCommandTarget_fail(IUnknown *unk)
3167 {
3168     IOleCommandTarget *cmdtrg;
3169     int i;
3170     HRESULT hres;
3171
3172     OLECMD cmd[2] = {
3173         {OLECMDID_OPEN, 0xf0f0},
3174         {OLECMDID_GETPRINTTEMPLATE+1, 0xf0f0}
3175     };
3176
3177     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3178     ok(hres == S_OK, "QueryInterface(IIDIOleCommandTarget failed: %08x\n", hres);
3179     if(FAILED(hres))
3180         return;
3181
3182     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 0, NULL, NULL);
3183     ok(hres == S_OK, "QueryStatus failed: %08x\n", hres);
3184
3185     SET_EXPECT(QueryStatus_OPEN);
3186     hres = IOleCommandTarget_QueryStatus(cmdtrg, NULL, 2, cmd, NULL);
3187     CHECK_CALLED(QueryStatus_OPEN);
3188
3189     ok(hres == OLECMDERR_E_NOTSUPPORTED,
3190             "QueryStatus failed: %08x, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
3191     ok(cmd[1].cmdID == OLECMDID_GETPRINTTEMPLATE+1,
3192             "cmd[0].cmdID=%d, expected OLECMDID_GETPRINTTEMPLATE+1\n", cmd[0].cmdID);
3193     ok(cmd[1].cmdf == 0, "cmd[0].cmdf=%x, expected 0\n", cmd[0].cmdf);
3194     ok(cmd[0].cmdf == OLECMDF_SUPPORTED,
3195             "cmd[1].cmdf=%x, expected OLECMDF_SUPPORTED\n", cmd[1].cmdf);
3196
3197     hres = IOleCommandTarget_QueryStatus(cmdtrg, &IID_IHTMLDocument2, 2, cmd, NULL);
3198     ok(hres == OLECMDERR_E_UNKNOWNGROUP,
3199             "QueryStatus failed: %08x, expected OLECMDERR_E_UNKNOWNGROUP\n", hres);
3200
3201     for(i=0; i<OLECMDID_GETPRINTTEMPLATE; i++) {
3202         if(!expect_cmds[i]) {
3203             hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_UPDATECOMMANDS,
3204                     OLECMDEXECOPT_DODEFAULT, NULL, NULL);
3205             ok(hres == OLECMDERR_E_NOTSUPPORTED,
3206                     "Exec failed: %08x, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
3207         }
3208     }
3209
3210     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_GETPRINTTEMPLATE+1,
3211             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
3212     ok(hres == OLECMDERR_E_NOTSUPPORTED,
3213             "Exec failed: %08x, expected OLECMDERR_E_NOTSUPPORTED\n", hres);
3214
3215     IOleCommandTarget_Release(cmdtrg);
3216 }
3217
3218 static void test_exec_onunload(IUnknown *unk)
3219 {
3220     IOleCommandTarget *cmdtrg;
3221     VARIANT var;
3222     HRESULT hres;
3223
3224     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3225     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
3226     if(FAILED(hres))
3227         return;
3228
3229     memset(&var, 0x0a, sizeof(var));
3230     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_ONUNLOAD,
3231             OLECMDEXECOPT_DODEFAULT, NULL, &var);
3232     ok(hres == S_OK, "Exec(..., OLECMDID_ONUNLOAD, ...) failed: %08x\n", hres);
3233     ok(V_VT(&var) == VT_BOOL, "V_VT(var)=%d, expected VT_BOOL\n", V_VT(&var));
3234     ok(V_BOOL(&var) == VARIANT_TRUE, "V_BOOL(var)=%x, expected VARIANT_TRUE\n", V_BOOL(&var));
3235
3236     hres = IOleCommandTarget_Exec(cmdtrg, NULL, OLECMDID_ONUNLOAD,
3237             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
3238     ok(hres == S_OK, "Exec(..., OLECMDID_ONUNLOAD, ...) failed: %08x\n", hres);
3239
3240     IOleCommandTarget_Release(cmdtrg);
3241 }
3242
3243 static void test_exec_editmode(IUnknown *unk, BOOL loaded)
3244 {
3245     IOleCommandTarget *cmdtrg;
3246     HRESULT hres;
3247
3248     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3249     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
3250     if(FAILED(hres))
3251         return;
3252
3253     editmode = TRUE;
3254
3255     if(loaded)
3256         load_state = LD_DOLOAD;
3257
3258     if(loaded)
3259         SET_EXPECT(GetClassID);
3260     SET_EXPECT(SetStatusText);
3261     SET_EXPECT(Exec_ShellDocView_37);
3262     SET_EXPECT(GetHostInfo);
3263     if(loaded)
3264         SET_EXPECT(GetDisplayName);
3265     SET_EXPECT(Invoke_AMBIENT_SILENT);
3266     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3267     SET_EXPECT(OnChanged_READYSTATE);
3268     SET_EXPECT(IsSystemMoniker);
3269     SET_EXPECT(Exec_ShellDocView_84);
3270     if(loaded)
3271         SET_EXPECT(BindToStorage);
3272     SET_EXPECT(InPlaceUIWindow_SetActiveObject);
3273     SET_EXPECT(HideUI);
3274     SET_EXPECT(ShowUI);
3275     SET_EXPECT(InPlaceFrame_SetBorderSpace);
3276
3277     expect_status_text = NULL;
3278     readystate_set_loading = TRUE;
3279
3280     hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, IDM_EDITMODE,
3281             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
3282     ok(hres == S_OK, "Exec failed: %08x\n", hres);
3283
3284     if(loaded)
3285         CHECK_CALLED(GetClassID);
3286     CHECK_CALLED(SetStatusText);
3287     CHECK_CALLED(Exec_ShellDocView_37);
3288     CHECK_CALLED(GetHostInfo);
3289     if(loaded)
3290         CHECK_CALLED(GetDisplayName);
3291     CHECK_CALLED(Invoke_AMBIENT_SILENT);
3292     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3293     CHECK_CALLED(OnChanged_READYSTATE);
3294     SET_CALLED(IsSystemMoniker); /* IE7 */
3295     SET_CALLED(Exec_ShellDocView_84);
3296     if(loaded)
3297         CHECK_CALLED(BindToStorage);
3298     CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
3299     CHECK_CALLED(HideUI);
3300     CHECK_CALLED(ShowUI);
3301     CHECK_CALLED(InPlaceFrame_SetBorderSpace);
3302
3303     test_timer(EXPECT_UPDATEUI|EXPECT_SETTITLE);
3304
3305     IOleCommandTarget_Release(cmdtrg);
3306
3307     hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, IDM_EDITMODE,
3308             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
3309     ok(hres == S_OK, "Exec failed: %08x\n", hres);
3310 }
3311
3312 static void test_exec_fontname(IUnknown *unk, LPCWSTR name, LPCWSTR exname)
3313 {
3314    IOleCommandTarget *cmdtrg;
3315    VARIANT *in = NULL, _in, *out = NULL, _out;
3316    HRESULT hres;
3317
3318    hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3319    ok(hres == S_OK, "QueryInterface(IIDIOleM=CommandTarget failed: %08x\n", hres);
3320    if(FAILED(hres))
3321        return;
3322
3323    if(name) {
3324        in = &_in;
3325        V_VT(in) = VT_BSTR;
3326        V_BSTR(in) = SysAllocString(name);
3327    }
3328
3329    if(exname) {
3330        out = &_out;
3331        V_VT(out) = VT_I4;
3332        V_I4(out) = 0xdeadbeef;
3333    }
3334
3335    hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, IDM_FONTNAME, 0, in, out);
3336    ok(hres == S_OK, "Exec(IDM_FONTNAME) failed: %08x\n", hres);
3337
3338    if(in)
3339        VariantClear(in);
3340
3341    if(out) {
3342        ok(V_VT(out) == VT_BSTR, "V_VT(out) = %x\n", V_VT(out));
3343        if(V_VT(out) == VT_BSTR) {
3344            if(exname)
3345                ok(!lstrcmpW(V_BSTR(out), name ? name : exname),
3346                   "unexpected fontname %s\n", wine_dbgstr_w(name));
3347            else
3348                ok(V_BSTR(out) == NULL, "V_BSTR(out) != NULL\n");
3349        }
3350        VariantClear(out);
3351    }
3352
3353    IOleCommandTarget_Release(cmdtrg);
3354 }
3355
3356 static void test_exec_noargs(IUnknown *unk, DWORD cmdid)
3357 {
3358     IOleCommandTarget *cmdtrg;
3359     HRESULT hres;
3360
3361     hres = IUnknown_QueryInterface(unk, &IID_IOleCommandTarget, (void**)&cmdtrg);
3362     ok(hres == S_OK, "QueryInterface(IID_IOleCommandTarget) failed: %08x\n", hres);
3363     if(FAILED(hres))
3364         return;
3365
3366     hres = IOleCommandTarget_Exec(cmdtrg, &CGID_MSHTML, cmdid,
3367             OLECMDEXECOPT_DODEFAULT, NULL, NULL);
3368     ok(hres == S_OK, "Exec failed: %08x\n", hres);
3369
3370     IOleCommandTarget_Release(cmdtrg);
3371 }
3372
3373 static void test_IsDirty(IUnknown *unk, HRESULT exhres)
3374 {
3375     IPersistStreamInit *perinit;
3376     IPersistMoniker *permon;
3377     IPersistFile *perfile;
3378     HRESULT hres;
3379
3380     hres = IUnknown_QueryInterface(unk, &IID_IPersistStreamInit, (void**)&perinit);
3381     ok(hres == S_OK, "QueryInterface(IID_IPersistStreamInit failed: %08x\n", hres);
3382     if(SUCCEEDED(hres)) {
3383         hres = IPersistStreamInit_IsDirty(perinit);
3384         ok(hres == exhres, "IsDirty() = %08x, expected %08x\n", hres, exhres);
3385         IPersistStreamInit_Release(perinit);
3386     }
3387
3388     hres = IUnknown_QueryInterface(unk, &IID_IPersistMoniker, (void**)&permon);
3389     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker failed: %08x\n", hres);
3390     if(SUCCEEDED(hres)) {
3391         hres = IPersistMoniker_IsDirty(permon);
3392         ok(hres == exhres, "IsDirty() = %08x, expected %08x\n", hres, exhres);
3393         IPersistMoniker_Release(permon);
3394     }
3395
3396     hres = IUnknown_QueryInterface(unk, &IID_IPersistFile, (void**)&perfile);
3397     ok(hres == S_OK, "QueryInterface(IID_IPersistFile failed: %08x\n", hres);
3398     if(SUCCEEDED(hres)) {
3399         hres = IPersistFile_IsDirty(perfile);
3400         ok(hres == exhres, "IsDirty() = %08x, expected %08x\n", hres, exhres);
3401         IPersistFile_Release(perfile);
3402     }
3403 }
3404
3405 static HWND create_container_window(void)
3406 {
3407     static const WCHAR wszHTMLDocumentTest[] =
3408         {'H','T','M','L','D','o','c','u','m','e','n','t','T','e','s','t',0};
3409     static WNDCLASSEXW wndclass = {
3410         sizeof(WNDCLASSEXW),
3411         0,
3412         wnd_proc,
3413         0, 0, NULL, NULL, NULL, NULL, NULL,
3414         wszHTMLDocumentTest,
3415         NULL
3416     };
3417
3418     RegisterClassExW(&wndclass);
3419     return CreateWindowW(wszHTMLDocumentTest, wszHTMLDocumentTest,
3420             WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
3421             515, 530, NULL, NULL, NULL, NULL);
3422 }
3423
3424 static void test_DoVerb(IOleObject *oleobj)
3425 {
3426     RECT rect = {0,0,500,500};
3427     HRESULT hres;
3428
3429     if(!container_locked) {
3430         SET_EXPECT(GetContainer);
3431         SET_EXPECT(LockContainer);
3432     }
3433     SET_EXPECT(ActivateMe);
3434     expect_LockContainer_fLock = TRUE;
3435
3436     hres = IOleObject_DoVerb(oleobj, OLEIVERB_SHOW, NULL, &ClientSite, -1, container_hwnd, &rect);
3437     ok(hres == S_OK, "DoVerb failed: %08x\n", hres);
3438
3439     if(!container_locked) {
3440         CHECK_CALLED(GetContainer);
3441         CHECK_CALLED(LockContainer);
3442         container_locked = TRUE;
3443     }
3444     CHECK_CALLED(ActivateMe);
3445 }
3446
3447 #define CLIENTSITE_EXPECTPATH 0x00000001
3448 #define CLIENTSITE_SETNULL    0x00000002
3449 #define CLIENTSITE_DONTSET    0x00000004
3450
3451 static void test_ClientSite(IOleObject *oleobj, DWORD flags)
3452 {
3453     IOleClientSite *clientsite;
3454     HRESULT hres;
3455
3456     if(flags & CLIENTSITE_SETNULL) {
3457         hres = IOleObject_GetClientSite(oleobj, &clientsite);
3458         ok(clientsite == &ClientSite, "clientsite=%p, expected %p\n", clientsite, &ClientSite);
3459
3460         hres = IOleObject_SetClientSite(oleobj, NULL);
3461         ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
3462
3463         set_clientsite = FALSE;
3464     }
3465
3466     if(flags & CLIENTSITE_DONTSET)
3467         return;
3468
3469     hres = IOleObject_GetClientSite(oleobj, &clientsite);
3470     ok(hres == S_OK, "GetClientSite failed: %08x\n", hres);
3471     ok(clientsite == (set_clientsite ? &ClientSite : NULL), "GetClientSite() = %p, expected %p\n",
3472             clientsite, set_clientsite ? &ClientSite : NULL);
3473
3474     if(!set_clientsite) {
3475         SET_EXPECT(GetHostInfo);
3476         if(flags & CLIENTSITE_EXPECTPATH) {
3477             SET_EXPECT(GetOptionKeyPath);
3478             SET_EXPECT(GetOverrideKeyPath);
3479         }
3480         SET_EXPECT(GetWindow);
3481         SET_EXPECT(QueryStatus_SETPROGRESSTEXT);
3482         SET_EXPECT(Exec_SETPROGRESSMAX);
3483         SET_EXPECT(Exec_SETPROGRESSPOS);
3484         SET_EXPECT(Invoke_AMBIENT_USERMODE);
3485         SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
3486         SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3487         SET_EXPECT(Invoke_AMBIENT_SILENT);
3488         SET_EXPECT(Invoke_AMBIENT_USERAGENT);
3489         SET_EXPECT(Invoke_AMBIENT_PALETTE);
3490
3491         hres = IOleObject_SetClientSite(oleobj, &ClientSite);
3492         ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
3493
3494         CHECK_CALLED(GetHostInfo);
3495         if(flags & CLIENTSITE_EXPECTPATH) {
3496             CHECK_CALLED(GetOptionKeyPath);
3497             CHECK_CALLED(GetOverrideKeyPath);
3498         }
3499         CHECK_CALLED(GetWindow);
3500         CHECK_CALLED(QueryStatus_SETPROGRESSTEXT);
3501         CHECK_CALLED(Exec_SETPROGRESSMAX);
3502         CHECK_CALLED(Exec_SETPROGRESSPOS);
3503         CHECK_CALLED(Invoke_AMBIENT_USERMODE);
3504         CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
3505         CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED); 
3506         CHECK_CALLED(Invoke_AMBIENT_SILENT);
3507         CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
3508         CHECK_CALLED(Invoke_AMBIENT_PALETTE);
3509
3510         set_clientsite = TRUE;
3511     }
3512
3513     hres = IOleObject_SetClientSite(oleobj, &ClientSite);
3514     ok(hres == S_OK, "SetClientSite failed: %08x\n", hres);
3515
3516     hres = IOleObject_GetClientSite(oleobj, &clientsite);
3517     ok(hres == S_OK, "GetClientSite failed: %08x\n", hres);
3518     ok(clientsite == &ClientSite, "GetClientSite() = %p, expected %p\n", clientsite, &ClientSite);
3519 }
3520
3521 static void test_OnAmbientPropertyChange(IUnknown *unk)
3522 {
3523     IOleControl *control = NULL;
3524     HRESULT hres;
3525
3526     hres = IUnknown_QueryInterface(unk, &IID_IOleControl, (void**)&control);
3527     ok(hres == S_OK, "QueryInterface(IID_IOleControl failed: %08x\n", hres);
3528     if(FAILED(hres))
3529         return;
3530
3531     SET_EXPECT(Invoke_AMBIENT_USERMODE);
3532     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_USERMODE);
3533     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
3534     CHECK_CALLED(Invoke_AMBIENT_USERMODE);
3535
3536     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
3537     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_DLCONTROL);
3538     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
3539     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
3540
3541     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
3542     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3543     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_OFFLINEIFNOTCONNECTED);
3544     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
3545     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
3546     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3547
3548     SET_EXPECT(Invoke_AMBIENT_DLCONTROL);
3549     SET_EXPECT(Invoke_AMBIENT_SILENT);
3550     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_SILENT);
3551     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
3552     CHECK_CALLED(Invoke_AMBIENT_DLCONTROL);
3553     CHECK_CALLED(Invoke_AMBIENT_SILENT);
3554
3555     SET_EXPECT(Invoke_AMBIENT_USERAGENT);
3556     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_USERAGENT);
3557     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
3558     CHECK_CALLED(Invoke_AMBIENT_USERAGENT);
3559
3560     SET_EXPECT(Invoke_AMBIENT_PALETTE);
3561     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_PALETTE);
3562     ok(hres == S_OK, "OnAmbientChange failed: %08x\n", hres);
3563     CHECK_CALLED(Invoke_AMBIENT_PALETTE);
3564
3565     IOleControl_Release(control);
3566 }
3567
3568
3569
3570 static void test_OnAmbientPropertyChange2(IUnknown *unk)
3571 {
3572     IOleControl *control = NULL;
3573     HRESULT hres;
3574
3575     hres = IUnknown_QueryInterface(unk, &IID_IOleControl, (void**)&control);
3576     ok(hres == S_OK, "QueryInterface(IID_IOleControl failed: %08x\n", hres);
3577     if(FAILED(hres))
3578         return;
3579
3580     hres = IOleControl_OnAmbientPropertyChange(control, DISPID_AMBIENT_PALETTE);
3581     ok(hres == S_OK, "OnAmbientPropertyChange failed: %08x\n", hres);
3582
3583     IOleControl_Release(control);
3584 }
3585
3586 static void test_Close(IUnknown *unk, BOOL set_client)
3587 {
3588     IOleObject *oleobj = NULL;
3589     HRESULT hres;
3590
3591     hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
3592     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
3593     if(FAILED(hres))
3594         return;
3595
3596     SET_EXPECT(GetContainer);
3597     SET_EXPECT(LockContainer);
3598     expect_LockContainer_fLock = FALSE;
3599     hres = IOleObject_Close(oleobj, OLECLOSE_NOSAVE);
3600     ok(hres == S_OK, "Close failed: %08x\n", hres);
3601     CHECK_CALLED(GetContainer);
3602     CHECK_CALLED(LockContainer);
3603     container_locked = FALSE;
3604
3605     if(set_client)
3606         test_ClientSite(oleobj, CLIENTSITE_SETNULL|CLIENTSITE_DONTSET);
3607
3608     IOleObject_Release(oleobj);
3609 }
3610
3611 static void test_OnFrameWindowActivate(IUnknown *unk)
3612 {
3613     IOleInPlaceActiveObject *inplaceact;
3614     HRESULT hres;
3615
3616     hres = IUnknown_QueryInterface(unk, &IID_IOleInPlaceActiveObject, (void**)&inplaceact);
3617     ok(hres == S_OK, "QueryInterface(IID_IOleInPlaceActiveObject) failed: %08x\n", hres);
3618     if(FAILED(hres))
3619         return;
3620
3621     if(set_clientsite) {
3622         expect_OnFrameWindowActivate_fActivate = TRUE;
3623         SET_EXPECT(OnFrameWindowActivate);
3624         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
3625         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
3626         CHECK_CALLED(OnFrameWindowActivate);
3627
3628         SET_EXPECT(OnFrameWindowActivate);
3629         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
3630         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
3631         CHECK_CALLED(OnFrameWindowActivate);
3632
3633         expect_OnFrameWindowActivate_fActivate = FALSE;
3634         SET_EXPECT(OnFrameWindowActivate);
3635         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, FALSE);
3636         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
3637         CHECK_CALLED(OnFrameWindowActivate);
3638
3639         expect_OnFrameWindowActivate_fActivate = TRUE;
3640         SET_EXPECT(OnFrameWindowActivate);
3641         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
3642         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
3643         CHECK_CALLED(OnFrameWindowActivate);
3644     }else {
3645         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, FALSE);
3646         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
3647
3648         hres = IOleInPlaceActiveObject_OnFrameWindowActivate(inplaceact, TRUE);
3649         ok(hres == S_OK, "OnFrameWindowActivate failed: %08x\n", hres);
3650     }
3651
3652     IOleInPlaceActiveObject_Release(inplaceact);
3653 }
3654
3655 static void test_InPlaceDeactivate(IUnknown *unk, BOOL expect_call)
3656 {
3657     IOleInPlaceObjectWindowless *windowlessobj = NULL;
3658     HRESULT hres;
3659
3660     hres = IUnknown_QueryInterface(unk, &IID_IOleInPlaceObjectWindowless,
3661             (void**)&windowlessobj);
3662     ok(hres == S_OK, "QueryInterface(IID_IOleInPlaceObjectWindowless) failed: %08x\n", hres);
3663     if(FAILED(hres))
3664         return;
3665
3666     if(expect_call) {
3667         SET_EXPECT(OnFocus_FALSE);
3668         if(ipsex)
3669             SET_EXPECT(OnInPlaceDeactivateEx);
3670         else
3671             SET_EXPECT(OnInPlaceDeactivate);
3672     }
3673     hres = IOleInPlaceObjectWindowless_InPlaceDeactivate(windowlessobj);
3674     ok(hres == S_OK, "InPlaceDeactivate failed: %08x\n", hres);
3675     if(expect_call) {
3676         CHECK_CALLED(OnFocus_FALSE);
3677         if(ipsex)
3678             CHECK_CALLED(OnInPlaceDeactivateEx);
3679         else
3680             CHECK_CALLED(OnInPlaceDeactivate);
3681     }
3682
3683     IOleInPlaceObjectWindowless_Release(windowlessobj);
3684 }
3685
3686 static void test_Activate(IUnknown *unk, DWORD flags)
3687 {
3688     IOleObject *oleobj = NULL;
3689     IOleDocumentView *docview;
3690     GUID guid;
3691     HRESULT hres;
3692
3693     last_hwnd = hwnd;
3694
3695     if(view)
3696         IOleDocumentView_Release(view);
3697     view = NULL;
3698
3699     hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
3700     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08x\n", hres);
3701
3702     hres = IOleObject_GetUserClassID(oleobj, NULL);
3703     ok(hres == E_INVALIDARG, "GetUserClassID returned: %08x, expected E_INVALIDARG\n", hres);
3704
3705     hres = IOleObject_GetUserClassID(oleobj, &guid);
3706     ok(hres == S_OK, "GetUserClassID failed: %08x\n", hres);
3707     ok(IsEqualGUID(&guid, &CLSID_HTMLDocument), "guid != CLSID_HTMLDocument\n");
3708
3709     test_OnFrameWindowActivate(unk);
3710
3711     test_ClientSite(oleobj, flags);
3712     test_InPlaceDeactivate(unk, FALSE);
3713     test_DoVerb(oleobj);
3714
3715     if(call_UIActivate == CallUIActivate_AfterShow) {
3716         hres = IOleObject_QueryInterface(oleobj, &IID_IOleDocumentView, (void **)&docview);
3717         ok(hres == S_OK, "IOleObject_QueryInterface failed with error 0x%08x\n", hres);
3718
3719         SET_EXPECT(OnFocus_TRUE);
3720         SET_EXPECT(SetActiveObject);
3721         SET_EXPECT(ShowUI);
3722         SET_EXPECT(InPlaceUIWindow_SetActiveObject);
3723         SET_EXPECT(InPlaceFrame_SetBorderSpace);
3724         expect_status_text = NULL;
3725
3726         hres = IOleDocumentView_UIActivate(docview, TRUE);
3727         ok(hres == S_OK, "IOleDocumentView_UIActivate failed with error 0x%08x\n", hres);
3728
3729         CHECK_CALLED(OnFocus_TRUE);
3730         CHECK_CALLED(SetActiveObject);
3731         CHECK_CALLED(ShowUI);
3732         CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
3733         CHECK_CALLED(InPlaceFrame_SetBorderSpace);
3734
3735         IOleDocumentView_Release(docview);
3736     }
3737
3738     IOleObject_Release(oleobj);
3739
3740     test_OnFrameWindowActivate(unk);
3741 }
3742
3743 static void test_Window(IUnknown *unk, BOOL expect_success)
3744 {
3745     IOleInPlaceActiveObject *activeobject = NULL;
3746     HWND tmp_hwnd;
3747     HRESULT hres;
3748
3749     hres = IOleDocumentView_QueryInterface(view, &IID_IOleInPlaceActiveObject, (void**)&activeobject);
3750     ok(hres == S_OK, "Could not get IOleInPlaceActiveObject interface: %08x\n", hres);
3751     if(FAILED(hres))
3752         return;
3753
3754     hres = IOleInPlaceActiveObject_GetWindow(activeobject, &tmp_hwnd);
3755
3756     if(expect_success) {
3757         ok(hres == S_OK, "GetWindow failed: %08x\n", hres);
3758         ok(tmp_hwnd == hwnd, "tmp_hwnd=%p, expected %p\n", tmp_hwnd, hwnd);
3759     }else {
3760         ok(hres == E_FAIL, "GetWindow returned %08x, expected E_FAIL\n", hres);
3761         ok(IsWindow(hwnd), "hwnd is destroyed\n");
3762     }
3763
3764     IOleInPlaceActiveObject_Release(activeobject);
3765 }
3766
3767 static void test_CloseView(void)
3768 {
3769     IOleInPlaceSite *inplacesite = (IOleInPlaceSite*)0xff00ff00;
3770     HRESULT hres;
3771
3772     if(!view)
3773         return;
3774
3775     hres = IOleDocumentView_Show(view, FALSE);
3776     ok(hres == S_OK, "Show failed: %08x\n", hres);
3777
3778     hres = IOleDocumentView_CloseView(view, 0);
3779     ok(hres == S_OK, "CloseView failed: %08x\n", hres);
3780
3781     hres = IOleDocumentView_SetInPlaceSite(view, NULL);
3782     ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
3783
3784     hres = IOleDocumentView_GetInPlaceSite(view, &inplacesite);
3785     ok(hres == S_OK, "SetInPlaceSite failed: %08x\n", hres);
3786     ok(inplacesite == NULL, "inplacesite=%p, expected NULL\n", inplacesite);
3787 }
3788
3789 static void test_UIDeactivate(void)
3790 {
3791     HRESULT hres;
3792
3793     if(call_UIActivate == CallUIActivate_AfterShow) {
3794         SET_EXPECT(InPlaceUIWindow_SetActiveObject);
3795     }
3796     if(call_UIActivate != CallUIActivate_None) {
3797         SET_EXPECT(SetActiveObject_null);
3798         SET_EXPECT(HideUI);
3799         SET_EXPECT(OnUIDeactivate);
3800     }
3801
3802     hres = IOleDocumentView_UIActivate(view, FALSE);
3803     ok(hres == S_OK, "UIActivate failed: %08x\n", hres);
3804
3805     if(call_UIActivate != CallUIActivate_None) {
3806         CHECK_CALLED(SetActiveObject_null);
3807         CHECK_CALLED(HideUI);
3808         CHECK_CALLED(OnUIDeactivate);
3809     }
3810     if(call_UIActivate == CallUIActivate_AfterShow) {
3811         CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
3812     }
3813 }
3814
3815 static void test_Hide(void)
3816 {
3817     HRESULT hres;
3818
3819     if(!view)
3820         return;
3821
3822     hres = IOleDocumentView_Show(view, FALSE);
3823     ok(hres == S_OK, "Show failed: %08x\n", hres);
3824 }
3825
3826 static HRESULT create_document(IUnknown **unk)
3827 {
3828     IHTMLDocument5 *doc5;
3829     HRESULT hres;
3830
3831     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
3832             &IID_IUnknown, (void**)unk);
3833     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
3834     if(FAILED(hres))
3835         return hres;
3836
3837     hres = IUnknown_QueryInterface(*unk, &IID_IHTMLDocument5, (void**)&doc5);
3838     if(SUCCEEDED(hres)) {
3839         IHTMLDocument5_Release(doc5);
3840     }else {
3841         win_skip("Could not get IHTMLDocument5, probably too old IE\n");
3842         IUnknown_Release(*unk);
3843     }
3844
3845     return hres;
3846 }
3847
3848 static void test_Navigate(IUnknown *unk)
3849 {
3850     IHlinkTarget *hlink;
3851     HRESULT hres;
3852
3853     hres = IUnknown_QueryInterface(unk, &IID_IHlinkTarget, (void**)&hlink);
3854     ok(hres == S_OK, "QueryInterface(IID_IHlinkTarget) failed: %08x\n", hres);
3855
3856     SET_EXPECT(ActivateMe);
3857     hres = IHlinkTarget_Navigate(hlink, 0, NULL);
3858     ok(hres == S_OK, "Navigate failed: %08x\n", hres);
3859     CHECK_CALLED(ActivateMe);
3860
3861     IHlinkTarget_Release(hlink);
3862 }
3863
3864 static void test_external(IUnknown *unk, BOOL initialized)
3865 {
3866     IDispatch *external;
3867     IHTMLDocument2 *doc;
3868     IHTMLWindow2 *htmlwin;
3869     HRESULT hres;
3870
3871     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDocument2, (void**)&doc);
3872     ok(hres == S_OK, "QueryInterface(IID_IHTMLWindow2) failed: %08x\n", hres);
3873
3874     hres = IHTMLDocument2_get_parentWindow(doc, &htmlwin);
3875     IHTMLDocument2_Release(doc);
3876     ok(hres == S_OK, "get_parentWindow failed: %08x\n", hres);
3877
3878     if(initialized)
3879         SET_EXPECT(GetExternal);
3880     external = (void*)0xdeadbeef;
3881     hres = IHTMLWindow2_get_external(htmlwin, &external);
3882     if(initialized) {
3883         ok(hres == S_FALSE || hres == S_OK, "get_external failed: %08x\n", hres);
3884         CHECK_CALLED(GetExternal);
3885         ok(external != NULL, "external == NULL\n");
3886     }else {
3887         ok(hres == S_OK, "get_external failed: %08x\n", hres);
3888         ok(external == NULL, "external != NULL\n");
3889     }
3890
3891     IHTMLWindow2_Release(htmlwin);
3892 }
3893
3894 static void test_StreamLoad(IUnknown *unk)
3895 {
3896     IPersistStreamInit *init;
3897     HRESULT hres;
3898
3899     hres = IUnknown_QueryInterface(unk, &IID_IPersistStreamInit, (void**)&init);
3900     ok(hres == S_OK, "QueryInterface(IID_IPersistStreamInit) failed: %08x\n", hres);
3901     if(FAILED(hres))
3902         return;
3903
3904     SET_EXPECT(Invoke_AMBIENT_SILENT);
3905     SET_EXPECT(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3906     SET_EXPECT(Exec_ShellDocView_37);
3907     SET_EXPECT(OnChanged_READYSTATE);
3908     SET_EXPECT(Read);
3909     readystate_set_loading = TRUE;
3910
3911     hres = IPersistStreamInit_Load(init, &Stream);
3912     ok(hres == S_OK, "Load failed: %08x\n", hres);
3913
3914     CHECK_CALLED(Invoke_AMBIENT_SILENT);
3915     CHECK_CALLED(Invoke_AMBIENT_OFFLINEIFNOTCONNECTED);
3916     CHECK_CALLED(Exec_ShellDocView_37);
3917     CHECK_CALLED(OnChanged_READYSTATE);
3918     CHECK_CALLED(Read);
3919
3920     test_timer(EXPECT_SETTITLE);
3921     test_GetCurMoniker(unk, NULL, about_blank_url);
3922
3923     IPersistStreamInit_Release(init);
3924 }
3925
3926 static void test_QueryInterface(IUnknown *unk)
3927 {
3928     IUnknown *qi;
3929     HRESULT hres;
3930
3931     static const IID IID_UndocumentedScriptIface =
3932         {0x719c3050,0xf9d3,0x11cf,{0xa4,0x93,0x00,0x40,0x05,0x23,0xa8,0xa0}};
3933
3934     qi = (void*)0xdeadbeef;
3935     hres = IUnknown_QueryInterface(unk, &IID_IRunnableObject, (void**)&qi);
3936     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
3937     ok(qi == NULL, "qirunnable=%p, expected NULL\n", qi);
3938
3939     qi = (void*)0xdeadbeef;
3940     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&qi);
3941     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
3942     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
3943
3944     qi = (void*)0xdeadbeef;
3945     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode2, (void**)&qi);
3946     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
3947     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
3948
3949     qi = (void*)0xdeadbeef;
3950     hres = IUnknown_QueryInterface(unk, &IID_IPersistPropertyBag, (void**)&qi);
3951     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
3952     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
3953
3954     qi = (void*)0xdeadbeef;
3955     hres = IUnknown_QueryInterface(unk, &IID_UndocumentedScriptIface, (void**)&qi);
3956     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
3957     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
3958
3959     qi = (void*)0xdeadbeef;
3960     hres = IUnknown_QueryInterface(unk, &IID_IMarshal, (void**)&qi);
3961     ok(hres == E_NOINTERFACE, "QueryInterface returned %08x, expected E_NOINTERFACE\n", hres);
3962     ok(qi == NULL, "qi=%p, expected NULL\n", qi);
3963 }
3964
3965 static void init_test(enum load_state_t ls) {
3966     doc_unk = NULL;
3967     hwnd = last_hwnd = NULL;
3968     set_clientsite = FALSE;
3969     load_from_stream = FALSE;
3970     call_UIActivate = CallUIActivate_None;
3971     load_state = ls;
3972     editmode = FALSE;
3973     stream_read = 0;
3974     protocol_read = 0;
3975     ipsex = FALSE;
3976     inplace_deactivated = FALSE;
3977 }
3978
3979 static void test_HTMLDocument(BOOL do_load)
3980 {
3981     IUnknown *unk;
3982     HRESULT hres;
3983     ULONG ref;
3984
3985     trace("Testing HTMLDocument (%s)...\n", (do_load ? "load" : "no load"));
3986
3987     init_test(do_load ? LD_DOLOAD : LD_NO);
3988
3989     hres = create_document(&unk);
3990     if(FAILED(hres))
3991         return;
3992     doc_unk = unk;
3993
3994     test_QueryInterface(unk);
3995     test_IsDirty(unk, S_FALSE);
3996     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
3997     test_external(unk, FALSE);
3998     test_ConnectionPointContainer(unk);
3999     test_GetCurMoniker(unk, NULL, NULL);
4000     test_Persist(unk, &Moniker);
4001     if(!do_load)
4002         test_OnAmbientPropertyChange2(unk);
4003
4004     test_Activate(unk, CLIENTSITE_EXPECTPATH);
4005
4006     if(do_load) {
4007         test_download(DWL_CSS|DWL_TRYCSS);
4008         test_GetCurMoniker(unk, &Moniker, NULL);
4009     }
4010
4011     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4012     test_OleCommandTarget_fail(unk);
4013     test_OleCommandTarget(unk);
4014     test_OnAmbientPropertyChange(unk);
4015     test_Window(unk, TRUE);
4016     test_external(unk, TRUE);
4017
4018     test_UIDeactivate();
4019     test_OleCommandTarget(unk);
4020     test_Window(unk, TRUE);
4021     test_InPlaceDeactivate(unk, TRUE);
4022
4023     /* Calling test_OleCommandTarget here causes Segmentation Fault with native
4024      * MSHTML. It doesn't with Wine. */
4025
4026     test_Window(unk, FALSE);
4027     test_Hide();
4028     test_InPlaceDeactivate(unk, FALSE);
4029     test_CloseView();
4030     test_Close(unk, FALSE);
4031
4032     /* Activate HTMLDocument again */
4033     test_Activate(unk, CLIENTSITE_SETNULL);
4034     test_Window(unk, TRUE);
4035     test_OleCommandTarget(unk);
4036     test_UIDeactivate();
4037     test_InPlaceDeactivate(unk, TRUE);
4038     test_Close(unk, FALSE);
4039
4040     /* Activate HTMLDocument again, this time without UIActivate */
4041     call_UIActivate = CallUIActivate_None;
4042     test_Activate(unk, CLIENTSITE_SETNULL);
4043     test_Window(unk, TRUE);
4044
4045     test_UIDeactivate();
4046     test_InPlaceDeactivate(unk, TRUE);
4047     test_CloseView();
4048     test_CloseView();
4049     test_Close(unk, TRUE);
4050     test_OnAmbientPropertyChange2(unk);
4051     test_GetCurMoniker(unk, do_load ? &Moniker : NULL, NULL);
4052
4053     if(!do_load) {
4054         /* Activate HTMLDocument again, calling UIActivate after showing the window */
4055         call_UIActivate = CallUIActivate_AfterShow;
4056         test_Activate(unk, 0);
4057         test_Window(unk, TRUE);
4058         test_OleCommandTarget(unk);
4059         test_UIDeactivate();
4060         test_InPlaceDeactivate(unk, TRUE);
4061         test_Close(unk, FALSE);
4062         call_UIActivate = CallUIActivate_None;
4063     }
4064
4065     if(view)
4066         IOleDocumentView_Release(view);
4067     view = NULL;
4068
4069     ok(IsWindow(hwnd), "hwnd is destroyed\n");
4070
4071     ref = IUnknown_Release(unk);
4072     ok(ref == 0, "ref=%d, expected 0\n", ref);
4073
4074     ok(!IsWindow(hwnd), "hwnd is not destroyed\n");
4075 }
4076
4077 static void test_HTMLDocument_hlink(void)
4078 {
4079     IUnknown *unk;
4080     HRESULT hres;
4081     ULONG ref;
4082
4083     trace("Testing HTMLDocument (hlink)...\n");
4084
4085     init_test(LD_DOLOAD);
4086     ipsex = TRUE;
4087
4088     hres = create_document(&unk);
4089     if(FAILED(hres))
4090         return;
4091     doc_unk = unk;
4092
4093     test_ConnectionPointContainer(unk);
4094     test_GetCurMoniker(unk, NULL, NULL);
4095     test_Persist(unk, &Moniker);
4096     test_Navigate(unk);
4097     if(show_failed) {
4098         IUnknown_Release(unk);
4099         return;
4100     }
4101
4102     test_download(DWL_CSS|DWL_TRYCSS);
4103
4104     test_IsDirty(unk, S_FALSE);
4105     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4106
4107     test_exec_onunload(unk);
4108     test_Window(unk, TRUE);
4109     test_InPlaceDeactivate(unk, TRUE);
4110     test_Close(unk, FALSE);
4111     test_IsDirty(unk, S_FALSE);
4112     test_GetCurMoniker(unk, &Moniker, NULL);
4113
4114     if(view)
4115         IOleDocumentView_Release(view);
4116     view = NULL;
4117
4118     ref = IUnknown_Release(unk);
4119     ok(ref == 0, "ref=%d, expected 0\n", ref);
4120 }
4121
4122 static void test_HTMLDocument_http(void)
4123 {
4124     IMoniker *http_mon;
4125     IUnknown *unk;
4126     ULONG ref;
4127     HRESULT hres;
4128
4129     static const WCHAR http_urlW[] =
4130         {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
4131
4132     trace("Testing HTMLDocument (http)...\n");
4133
4134     hres = CreateURLMoniker(NULL, http_urlW, &http_mon);
4135     ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
4136
4137     init_test(LD_DOLOAD);
4138     ipsex = TRUE;
4139
4140     hres = create_document(&unk);
4141     if(FAILED(hres))
4142         return;
4143     doc_unk = unk;
4144
4145     test_ConnectionPointContainer(unk);
4146     test_GetCurMoniker(unk, NULL, NULL);
4147     test_Persist(unk, http_mon);
4148     test_Navigate(unk);
4149     if(show_failed) {
4150         IUnknown_Release(unk);
4151         return;
4152     }
4153
4154     if (winetest_interactive || ! is_ie_hardened())
4155         test_download(DWL_HTTP);
4156     else
4157         win_skip("IE running in Enhanced Security Configuration\n");
4158
4159     test_IsDirty(unk, S_FALSE);
4160     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4161
4162     test_put_href(unk);
4163
4164     test_InPlaceDeactivate(unk, TRUE);
4165     test_Close(unk, FALSE);
4166     test_IsDirty(unk, S_FALSE);
4167     test_GetCurMoniker(unk, http_mon, NULL);
4168
4169     if(view)
4170         IOleDocumentView_Release(view);
4171     view = NULL;
4172
4173     ref = IUnknown_Release(unk);
4174     ok(!ref, "ref=%d, expected 0\n", ref);
4175
4176     ref = IMoniker_Release(http_mon);
4177     ok(!ref, "ref=%d, expected 0\n", ref);
4178 }
4179
4180 static void test_HTMLDocument_StreamLoad(void)
4181 {
4182     IOleObject *oleobj;
4183     IUnknown *unk;
4184     HRESULT hres;
4185     ULONG ref;
4186
4187     trace("Testing HTMLDocument (IPersistStreamInit)...\n");
4188
4189     init_test(LD_DOLOAD);
4190     load_from_stream = TRUE;
4191
4192     hres = create_document(&unk);
4193     if(FAILED(hres))
4194         return;
4195     doc_unk = unk;
4196
4197     hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
4198     ok(hres == S_OK, "Could not get IOleObject: %08x\n", hres);
4199
4200     test_readyState(unk);
4201     test_IsDirty(unk, S_FALSE);
4202     test_ConnectionPointContainer(unk);
4203     test_ClientSite(oleobj, CLIENTSITE_EXPECTPATH);
4204     test_DoVerb(oleobj);
4205     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4206
4207     IOleObject_Release(oleobj);
4208
4209     test_GetCurMoniker(unk, NULL, NULL);
4210     test_StreamLoad(unk);
4211     test_download(DWL_VERBDONE|DWL_TRYCSS);
4212     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4213
4214     test_UIDeactivate();
4215     test_InPlaceDeactivate(unk, TRUE);
4216     test_Close(unk, FALSE);
4217     test_IsDirty(unk, S_FALSE);
4218
4219     if(view) {
4220         IOleDocumentView_Release(view);
4221         view = NULL;
4222     }
4223
4224
4225     ref = IUnknown_Release(unk);
4226     ok(ref == 0, "ref=%d, expected 0\n", ref);
4227 }
4228
4229 static void test_edit_uiactivate(IOleObject *oleobj)
4230 {
4231     IOleDocumentView *docview;
4232     HRESULT hres;
4233
4234     hres = IOleObject_QueryInterface(oleobj, &IID_IOleDocumentView, (void **)&docview);
4235     ok(hres == S_OK, "IOleObject_QueryInterface failed with error 0x%08x\n", hres);
4236
4237     SET_EXPECT(OnFocus_TRUE);
4238     SET_EXPECT(SetActiveObject);
4239     SET_EXPECT(ShowUI);
4240     SET_EXPECT(InPlaceUIWindow_SetActiveObject);
4241     SET_EXPECT(InPlaceFrame_SetBorderSpace);
4242     expect_status_text = NULL;
4243
4244     hres = IOleDocumentView_UIActivate(docview, TRUE);
4245     ok(hres == S_OK, "IOleDocumentView_UIActivate failed with error 0x%08x\n", hres);
4246
4247     CHECK_CALLED(OnFocus_TRUE);
4248     CHECK_CALLED(SetActiveObject);
4249     CHECK_CALLED(ShowUI);
4250     CHECK_CALLED(InPlaceUIWindow_SetActiveObject);
4251     CHECK_CALLED(InPlaceFrame_SetBorderSpace);
4252
4253     IOleDocumentView_Release(docview);
4254 }
4255
4256 static void test_editing_mode(BOOL do_load)
4257 {
4258     IUnknown *unk;
4259     IOleObject *oleobj;
4260     HRESULT hres;
4261     ULONG ref;
4262
4263     trace("Testing HTMLDocument (edit%s)...\n", do_load ? " load" : "");
4264
4265     init_test(do_load ? LD_DOLOAD : LD_NO);
4266     call_UIActivate = CallUIActivate_AfterShow;
4267
4268     hres = create_document(&unk);
4269     if(FAILED(hres))
4270         return;
4271     doc_unk = unk;
4272
4273     hres = IUnknown_QueryInterface(unk, &IID_IOleObject, (void**)&oleobj);
4274     ok(hres == S_OK, "Could not get IOleObject: %08x\n", hres);
4275
4276     test_readyState(unk);
4277     test_ConnectionPointContainer(unk);
4278     test_ClientSite(oleobj, CLIENTSITE_EXPECTPATH);
4279     test_DoVerb(oleobj);
4280     test_edit_uiactivate(oleobj);
4281
4282     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4283     if(do_load)
4284         test_Persist(unk, &Moniker);
4285     stream_read = protocol_read = 0;
4286     test_exec_editmode(unk, do_load);
4287     test_UIDeactivate();
4288     call_UIActivate = CallUIActivate_None;
4289     IOleObject_Release(oleobj);
4290
4291     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED);
4292     test_download(DWL_VERBDONE | (do_load ? DWL_CSS|DWL_TRYCSS : 0));
4293
4294     SET_EXPECT(SetStatusText); /* ignore race in native mshtml */
4295     test_timer(EXPECT_UPDATEUI);
4296     SET_CALLED(SetStatusText);
4297
4298     test_MSHTML_QueryStatus(unk, OLECMDF_SUPPORTED|OLECMDF_ENABLED);
4299
4300     if(!do_load) {
4301         test_exec_fontname(unk, NULL, wszTimesNewRoman);
4302         test_exec_fontname(unk, wszArial, wszTimesNewRoman);
4303         test_timer(EXPECT_UPDATEUI);
4304         test_exec_fontname(unk, NULL, wszArial);
4305
4306         test_exec_noargs(unk, IDM_JUSTIFYRIGHT);
4307         test_timer(EXPECT_UPDATEUI);
4308         test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYRIGHT,
4309                          OLECMDF_SUPPORTED|OLECMDF_ENABLED|OLECMDF_LATCHED);
4310
4311         test_exec_noargs(unk, IDM_JUSTIFYCENTER);
4312         test_timer(EXPECT_UPDATEUI);
4313         test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYRIGHT,
4314                          OLECMDF_SUPPORTED|OLECMDF_ENABLED);
4315         test_QueryStatus(unk, &CGID_MSHTML, IDM_JUSTIFYCENTER,
4316                          OLECMDF_SUPPORTED|OLECMDF_ENABLED|OLECMDF_LATCHED);
4317
4318         test_exec_noargs(unk, IDM_HORIZONTALLINE);
4319         test_timer(EXPECT_UPDATEUI);
4320         test_QueryStatus(unk, &CGID_MSHTML, IDM_HORIZONTALLINE,
4321                          OLECMDF_SUPPORTED|OLECMDF_ENABLED);
4322     }
4323
4324     test_UIDeactivate();
4325     test_InPlaceDeactivate(unk, TRUE);
4326     test_Close(unk, FALSE);
4327
4328     if(view) {
4329         IOleDocumentView_Release(view);
4330         view = NULL;
4331     }
4332
4333     ref = IUnknown_Release(unk);
4334     ok(ref == 0, "ref=%d, expected 0\n", ref);
4335 }
4336
4337 static void register_protocol(void)
4338 {
4339     IInternetSession *session;
4340     HRESULT hres;
4341
4342     static const WCHAR wsz_winetest[] = {'w','i','n','e','t','e','s','t',0};
4343
4344     hres = CoInternetGetSession(0, &session, 0);
4345     ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
4346
4347     hres = IInternetSession_RegisterNameSpace(session, &ClassFactory, &IID_NULL,
4348             wsz_winetest, 0, NULL, 0);
4349     ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
4350
4351     IInternetSession_Release(session);
4352 }
4353
4354 static void test_HTMLDoc_ISupportErrorInfo(void)
4355 {
4356     HRESULT hres;
4357     IUnknown *unk;
4358     ISupportErrorInfo *sinfo;
4359     LONG ref;
4360
4361     hres = create_document(&unk);
4362     if(FAILED(hres))
4363         return;
4364
4365     hres = IUnknown_QueryInterface(unk, &IID_ISupportErrorInfo, (void**)&sinfo);
4366     ok(hres == S_OK, "got %x\n", hres);
4367     ok(sinfo != NULL, "got %p\n", sinfo);
4368     if(sinfo)
4369     {
4370         hres = ISupportErrorInfo_InterfaceSupportsErrorInfo(sinfo, &IID_IErrorInfo);
4371         ok(hres == S_FALSE, "Expected S_OK, got %x\n", hres);
4372         IUnknown_Release(sinfo);
4373     }
4374
4375     ref = IUnknown_Release(unk);
4376     ok(ref == 0, "ref=%d, expected 0\n", ref);
4377 }
4378
4379 static void test_IPersistHistory(void)
4380 {
4381     HRESULT hres;
4382     IUnknown *unk;
4383     LONG ref;
4384     IPersistHistory *phist;
4385
4386     hres = create_document(&unk);
4387     if(FAILED(hres))
4388         return;
4389
4390     hres = IUnknown_QueryInterface(unk, &IID_IPersistHistory, (void**)&phist);
4391     ok(hres == S_OK, "QueryInterface returned %08x, expected S_OK\n", hres);
4392     if(hres == S_OK)
4393         IPersistHistory_Release(phist);
4394
4395     ref = IUnknown_Release(unk);
4396     ok(ref == 0, "ref=%d, expected 0\n", ref);
4397 }
4398
4399 START_TEST(htmldoc)
4400 {
4401     CoInitialize(NULL);
4402     container_hwnd = create_container_window();
4403     register_protocol();
4404
4405     test_HTMLDocument_hlink();
4406     if(!show_failed) {
4407         test_HTMLDocument(FALSE);
4408         test_HTMLDocument(TRUE);
4409         test_HTMLDocument_StreamLoad();
4410         test_editing_mode(FALSE);
4411         test_editing_mode(TRUE);
4412         test_HTMLDocument_http();
4413     }
4414     test_HTMLDoc_ISupportErrorInfo();
4415     test_IPersistHistory();
4416
4417     DestroyWindow(container_hwnd);
4418     CoUninitialize();
4419 }