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