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