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