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