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