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