[SHELL32_WINETEST] Sync with Wine Staging 1.9.14.
[reactos.git] / rostests / winetests / shell32 / ebrowser.c
1 /*
2 * Unit tests for the Explorer Browser control
3 *
4 * Copyright 2010 David Hedberg
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdio.h>
22
23 #define COBJMACROS
24 #define CONST_VTABLE
25
26 #include "shlobj.h"
27 #include "shlwapi.h"
28
29 #include "wine/test.h"
30
31 #include "initguid.h"
32 #include "mshtml.h"
33
34 /**********************************************************************
35 * Some IIDs for test_SetSite.
36 */
37 DEFINE_GUID(IID_IBrowserSettings, 0xDD1E21CC, 0xE2C7, 0x402C, 0xBF,0x05, 0x10,0x32,0x8D,0x3F,0x6B,0xAD);
38 DEFINE_GUID(IID_IShellBrowserService, 0xDFBC7E30, 0xF9E5, 0x455F, 0x88,0xF8, 0xFA,0x98,0xC1,0xE4,0x94,0xCA);
39 DEFINE_GUID(IID_IShellTaskScheduler, 0x6CCB7BE0, 0x6807, 0x11D0, 0xB8,0x10, 0x00,0xC0,0x4F,0xD7,0x06,0xEC);
40 DEFINE_GUID(IID_IBrowserWithActivationNotification,
41 0x6DB89131, 0x7B4C, 0x4E1C, 0x8B,0x01, 0x5D,0x31,0x2C,0x9C,0x73,0x88);
42 DEFINE_GUID(IID_ILayoutModifier, 0x90B4135A, 0x95BA, 0x46EA, 0x8C,0xAA, 0xE0,0x5B,0x45,0xCD,0x80,0x1E);
43 DEFINE_GUID(CLSID_Desktop, 0x00021400, 0x0000, 0x0000, 0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
44 DEFINE_GUID(IID_IFileDialogPrivate, 0xAC92FFC5, 0xF0E9, 0x455A, 0x90,0x6B, 0x4A,0x83,0xE7,0x4A,0x80,0x3B);
45 DEFINE_GUID(IID_IWebbrowserApp, 0x0002df05, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
46 DEFINE_GUID(IID_IBrowserSettings_Vista, 0xF81B80BC, 0x29D1, 0x4734, 0xB5,0x15, 0x77,0x24,0xBF,0xF1,0x60,0x01);
47 DEFINE_GUID(IID_IFolderTypeModifier, 0x04BA120E, 0xAD52, 0x4A2D, 0x98,0x07, 0x2D,0xA1,0x78,0xD0,0xC3,0xE1);
48 DEFINE_GUID(IID_IShellBrowserService_Vista, 0xF5A24314, 0x5B8B, 0x44FA, 0xBC,0x2E, 0x31,0x28,0x55,0x44,0xB5,0x20);
49 DEFINE_GUID(IID_IFileDialogPrivate_Vista, 0x2539E31C, 0x857F, 0x43C4, 0x88,0x72, 0x45,0xBD,0x6A,0x02,0x48,0x92);
50 DEFINE_GUID(SID_SMenuBandParent, 0x8C278EEC, 0x3EAB, 0x11D1, 0x8C,0xB0 ,0x00,0xC0,0x4F,0xD9,0x18,0xD0);
51 DEFINE_GUID(SID_SMenuPopup, 0xD1E7AFEB, 0x6A2E, 0x11D0, 0x8C,0x78, 0x00,0xC0,0x4F,0xD9,0x18,0xB4);
52 DEFINE_GUID(IID_IShellMenu, 0xEE1F7637, 0xE138, 0x11D1, 0x83,0x79, 0x00,0xC0,0x4F,0xD9,0x18,0xD0);
53
54 DEFINE_GUID(IID_UnknownInterface1, 0x3934E4C2, 0x8143, 0x4E4C, 0xA1,0xDC, 0x71,0x8F,0x85,0x63,0xF3,0x37);
55 DEFINE_GUID(IID_UnknownInterface2, 0x3E24A11C, 0x15B2, 0x4F71, 0xB8,0x1E, 0x00,0x8F,0x77,0x99,0x8E,0x9F);
56 DEFINE_GUID(IID_UnknownInterface3, 0xE38FE0F3, 0x3DB0, 0x47EE, 0xA3,0x14, 0x25,0xCF,0x7F,0x4B,0xF5,0x21);
57 DEFINE_GUID(IID_UnknownInterface4, 0xFAD451C2, 0xAF58, 0x4161, 0xB9,0xFF, 0x57,0xAF,0xBB,0xED,0x0A,0xD2);
58 DEFINE_GUID(IID_UnknownInterface5, 0xF80C2137, 0x5829, 0x4CE9, 0x9F,0x81, 0xA9,0x5E,0x15,0x9D,0xD8,0xD5);
59 DEFINE_GUID(IID_UnknownInterface6, 0xD7F81F62, 0x491F, 0x49BC, 0x89,0x1D, 0x56,0x65,0x08,0x5D,0xF9,0x69);
60 DEFINE_GUID(IID_UnknownInterface7, 0x68A4FDBA, 0xA48A, 0x4A86, 0xA3,0x29, 0x1B,0x69,0xB9,0xB1,0x9E,0x89);
61 DEFINE_GUID(IID_UnknownInterface8, 0xD3B1CAF5, 0xEC4F, 0x4B2E, 0xBC,0xB0, 0x60,0xD7,0x15,0xC9,0x3C,0xB2);
62 DEFINE_GUID(IID_UnknownInterface9, 0x9536CA39, 0x1ACB, 0x4AE6, 0xAD,0x27, 0x24,0x03,0xD0,0x4C,0xA2,0x8F);
63 DEFINE_GUID(IID_UnknownInterface10, 0xB722BE00, 0x4E68, 0x101B, 0xA2,0xBC, 0x00,0xAA,0x00,0x40,0x47,0x70);
64 DEFINE_GUID(IID_UnknownInterface11, 0x691ecf9f, 0x6b9c, 0x4311, 0xa1,0x7b, 0xad,0x15,0x4c,0x30,0xe9,0x1f);
65 DEFINE_GUID(IID_UnknownInterface12, 0x7e3159f5, 0x21ca, 0x4ec2, 0x8f,0xbe, 0x66,0x2d,0x08,0x2c,0xa3,0xeb);
66 DEFINE_GUID(IID_UnknownInterface13, 0xa36a3ace, 0x8332, 0x45ce, 0xaa,0x29, 0x50,0x3c,0xb7,0x6b,0x25,0x87);
67 DEFINE_GUID(IID_UnknownInterface14, 0x16770868, 0x239c, 0x445b, 0xa0,0x1d, 0xf2,0x6c,0x7f,0xbb,0xf2,0x6c);
68 DEFINE_GUID(IID_UnknownInterface15, 0x05a89298, 0x6246, 0x4c63, 0xbb,0x0d, 0x9b,0xda,0xf1,0x40,0xbf,0x3b);
69 DEFINE_GUID(IID_UnknownInterface16, 0x35094a87, 0x8bb1, 0x4237, 0x96,0xc6, 0xc4,0x17,0xee,0xbd,0xb0,0x78);
70 DEFINE_GUID(IID_UnknownInterface17, 0x3d5d8c60, 0x21e4, 0x4b03, 0x83,0xb8, 0xc7,0x3f,0x8c,0x94,0x00,0x78);
71 DEFINE_GUID(IID_UnknownInterface18, 0x1fc45c07, 0x9e35, 0x4276, 0xad,0x7f, 0x08,0x60,0x3a,0xa0,0xf6,0x0f);
72 DEFINE_GUID(IID_UnknownInterface19, 0xacd9b67a, 0xceab, 0x4c6c, 0x90,0xa1, 0xe8,0x57,0xc6,0x59,0xe3,0x9d);
73 DEFINE_GUID(IID_UnknownInterface20, 0xd0fe6f62, 0xdea4, 0x46c9, 0x9d,0xae, 0x36,0xcb,0x13,0x99,0x78,0xfa);
74
75 static HWND hwnd;
76
77 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
78 static HRESULT (WINAPI *pSHParseDisplayName)(LPCWSTR,IBindCtx*,LPITEMIDLIST*,SFGAOF,SFGAOF*);
79
80 static void init_function_pointers(void)
81 {
82 HMODULE hmod;
83
84 hmod = GetModuleHandleA("shell32.dll");
85 pSHCreateShellItem = (void*)GetProcAddress(hmod, "SHCreateShellItem");
86 pSHParseDisplayName = (void*)GetProcAddress(hmod, "SHParseDisplayName");
87 }
88
89 /*********************************************************************
90 * Some simple helpers
91 */
92 static HRESULT ebrowser_instantiate(IExplorerBrowser **peb)
93 {
94 return CoCreateInstance(&CLSID_ExplorerBrowser, NULL, CLSCTX_INPROC_SERVER,
95 &IID_IExplorerBrowser, (void**)peb);
96 }
97
98 static HRESULT ebrowser_initialize(IExplorerBrowser *peb)
99 {
100 RECT rc;
101 SetRect(&rc, 0, 0, 500, 500);
102 return IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
103 }
104
105 static HRESULT ebrowser_browse_to_desktop(IExplorerBrowser *peb)
106 {
107 LPITEMIDLIST pidl_desktop;
108 HRESULT hr;
109 SHGetSpecialFolderLocation (hwnd, CSIDL_DESKTOP, &pidl_desktop);
110 hr = IExplorerBrowser_BrowseToIDList(peb, pidl_desktop, 0);
111 ILFree(pidl_desktop);
112 return hr;
113 }
114
115 /* Process some messages */
116 static void process_msgs(void)
117 {
118 MSG msg;
119 while(PeekMessageA( &msg, NULL, 0, 0, PM_REMOVE))
120 {
121 TranslateMessage(&msg);
122 DispatchMessageA(&msg);
123 }
124 }
125
126 /*********************************************************************
127 * IExplorerBrowserEvents implementation
128 */
129 typedef struct {
130 IExplorerBrowserEvents IExplorerBrowserEvents_iface;
131 LONG ref;
132 UINT pending, created, completed, failed;
133 } IExplorerBrowserEventsImpl;
134
135 static IExplorerBrowserEventsImpl ebev;
136
137 static inline IExplorerBrowserEventsImpl *impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents *iface)
138 {
139 return CONTAINING_RECORD(iface, IExplorerBrowserEventsImpl, IExplorerBrowserEvents_iface);
140 }
141
142 static HRESULT WINAPI IExplorerBrowserEvents_fnQueryInterface(IExplorerBrowserEvents *iface,
143 REFIID riid, void **ppvObj)
144 {
145 ok(0, "Never called.\n");
146 return E_NOINTERFACE;
147 }
148
149 static ULONG WINAPI IExplorerBrowserEvents_fnAddRef(IExplorerBrowserEvents *iface)
150 {
151 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
152 return InterlockedIncrement(&This->ref);
153 }
154
155 static ULONG WINAPI IExplorerBrowserEvents_fnRelease(IExplorerBrowserEvents *iface)
156 {
157 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
158 return InterlockedDecrement(&This->ref);
159 }
160
161 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationPending(IExplorerBrowserEvents *iface,
162 PCIDLIST_ABSOLUTE pidlFolder)
163 {
164 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
165 This->pending++;
166 return S_OK;
167 }
168
169 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationComplete(IExplorerBrowserEvents *iface,
170 PCIDLIST_ABSOLUTE pidlFolder)
171 {
172 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
173 This->completed++;
174 return S_OK;
175 }
176 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationFailed(IExplorerBrowserEvents *iface,
177 PCIDLIST_ABSOLUTE pidlFolder)
178 {
179 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
180 This->failed++;
181 return S_OK;
182 }
183 static HRESULT WINAPI IExplorerBrowserEvents_fnOnViewCreated(IExplorerBrowserEvents *iface,
184 IShellView *psv)
185 {
186 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
187 This->created++;
188 return S_OK;
189 }
190
191 static const IExplorerBrowserEventsVtbl ebevents =
192 {
193 IExplorerBrowserEvents_fnQueryInterface,
194 IExplorerBrowserEvents_fnAddRef,
195 IExplorerBrowserEvents_fnRelease,
196 IExplorerBrowserEvents_fnOnNavigationPending,
197 IExplorerBrowserEvents_fnOnViewCreated,
198 IExplorerBrowserEvents_fnOnNavigationComplete,
199 IExplorerBrowserEvents_fnOnNavigationFailed
200 };
201
202 /*********************************************************************
203 * IExplorerPaneVisibility implementation
204 */
205 typedef struct
206 {
207 IExplorerPaneVisibility IExplorerPaneVisibility_iface;
208 LONG ref;
209 LONG count;
210 LONG np, cp, cp_o, cp_v, dp, pp, qp, aqp, unk; /* The panes */
211 } IExplorerPaneVisibilityImpl;
212
213 static inline IExplorerPaneVisibilityImpl *impl_from_IExplorerPaneVisibility(IExplorerPaneVisibility *iface)
214 {
215 return CONTAINING_RECORD(iface, IExplorerPaneVisibilityImpl, IExplorerPaneVisibility_iface);
216 }
217
218 static HRESULT WINAPI IExplorerPaneVisibility_fnQueryInterface(IExplorerPaneVisibility *iface,
219 REFIID riid, LPVOID *ppvObj)
220 {
221 ok(0, "unexpected, %s\n", wine_dbgstr_guid(riid));
222 *ppvObj = NULL;
223 return E_NOINTERFACE;
224 }
225
226 static ULONG WINAPI IExplorerPaneVisibility_fnAddRef(IExplorerPaneVisibility *iface)
227 {
228 IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
229 return InterlockedIncrement(&This->ref);
230 }
231
232 static ULONG WINAPI IExplorerPaneVisibility_fnRelease(IExplorerPaneVisibility *iface)
233 {
234 IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
235 ULONG ref = InterlockedDecrement(&This->ref);
236
237 if(!ref)
238 HeapFree(GetProcessHeap(), 0, This);
239
240 return ref;
241 }
242
243 static HRESULT WINAPI IExplorerPaneVisibility_fnGetPaneState(IExplorerPaneVisibility *iface,
244 REFEXPLORERPANE ep,
245 EXPLORERPANESTATE *peps)
246 {
247 IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
248 This->count++;
249
250 ok(ep != NULL, "ep is NULL.\n");
251 ok(peps != NULL, "peps is NULL.\n");
252 ok(*peps == 0, "got %d\n", *peps);
253
254 *peps = EPS_FORCE;
255 if(IsEqualGUID(&EP_NavPane, ep)) This->np++;
256 else if(IsEqualGUID(&EP_Commands, ep)) This->cp++;
257 else if(IsEqualGUID(&EP_Commands_Organize, ep)) This->cp_o++;
258 else if(IsEqualGUID(&EP_Commands_View, ep)) This->cp_v++;
259 else if(IsEqualGUID(&EP_DetailsPane, ep)) This->dp++;
260 else if(IsEqualGUID(&EP_PreviewPane, ep)) This->pp++;
261 else if(IsEqualGUID(&EP_QueryPane, ep)) This->qp++;
262 else if(IsEqualGUID(&EP_AdvQueryPane, ep)) This->aqp++;
263 else
264 {
265 trace("Unknown explorer pane: %s\n", wine_dbgstr_guid(ep));
266 This->unk++;
267 }
268
269 return S_OK;
270 }
271
272 static const IExplorerPaneVisibilityVtbl epvvt =
273 {
274 IExplorerPaneVisibility_fnQueryInterface,
275 IExplorerPaneVisibility_fnAddRef,
276 IExplorerPaneVisibility_fnRelease,
277 IExplorerPaneVisibility_fnGetPaneState
278 };
279
280 static IExplorerPaneVisibilityImpl *create_explorerpanevisibility(void)
281 {
282 IExplorerPaneVisibilityImpl *epv;
283
284 epv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IExplorerPaneVisibilityImpl));
285 epv->IExplorerPaneVisibility_iface.lpVtbl = &epvvt;
286 epv->ref = 1;
287
288 return epv;
289 }
290
291 /*********************************************************************
292 * ICommDlgBrowser3 implementation
293 */
294 typedef struct
295 {
296 ICommDlgBrowser3 ICommDlgBrowser3_iface;
297 LONG ref;
298 UINT OnDefaultCommand, OnStateChange, IncludeObject;
299 UINT Notify, GetDefaultMenuText, GetViewFlags;
300 UINT OnColumnClicked, GetCurrentFilter, OnPreviewCreated;
301 } ICommDlgBrowser3Impl;
302
303 static inline ICommDlgBrowser3Impl *impl_from_ICommDlgBrowser3(ICommDlgBrowser3 *iface)
304 {
305 return CONTAINING_RECORD(iface, ICommDlgBrowser3Impl, ICommDlgBrowser3_iface);
306 }
307
308 static HRESULT WINAPI ICommDlgBrowser3_fnQueryInterface(ICommDlgBrowser3 *iface, REFIID riid, LPVOID *ppvObj)
309 {
310 ok(0, "unexpected %s\n", wine_dbgstr_guid(riid));
311 *ppvObj = NULL;
312 return E_NOINTERFACE;
313 }
314
315 static ULONG WINAPI ICommDlgBrowser3_fnAddRef(ICommDlgBrowser3 *iface)
316 {
317 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
318 return InterlockedIncrement(&This->ref);
319 }
320
321 static ULONG WINAPI ICommDlgBrowser3_fnRelease(ICommDlgBrowser3 *iface)
322 {
323 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
324 ULONG ref = InterlockedDecrement(&This->ref);
325
326 if(!ref)
327 HeapFree(GetProcessHeap(), 0, This);
328
329 return ref;
330 }
331
332 static HRESULT WINAPI ICommDlgBrowser3_fnOnDefaultCommand(ICommDlgBrowser3* iface, IShellView *shv)
333 {
334 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
335 This->OnDefaultCommand++;
336 return E_NOTIMPL;
337 }
338
339 static HRESULT WINAPI ICommDlgBrowser3_fnOnStateChange(
340 ICommDlgBrowser3* iface,
341 IShellView *shv,
342 ULONG uChange)
343 {
344 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
345 This->OnStateChange++;
346 return E_NOTIMPL;
347 }
348
349 static HRESULT WINAPI ICommDlgBrowser3_fnIncludeObject(
350 ICommDlgBrowser3* iface,
351 IShellView *shv,
352 LPCITEMIDLIST pidl)
353 {
354 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
355 This->IncludeObject++;
356 return S_OK;
357 }
358
359 static HRESULT WINAPI ICommDlgBrowser3_fnNotify(
360 ICommDlgBrowser3* iface,
361 IShellView *ppshv,
362 DWORD dwNotifyType)
363 {
364 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
365 This->Notify++;
366 return E_NOTIMPL;
367 }
368
369 static HRESULT WINAPI ICommDlgBrowser3_fnGetDefaultMenuText(
370 ICommDlgBrowser3* iface,
371 IShellView *ppshv,
372 LPWSTR pszText,
373 int cchMax)
374 {
375 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
376 This->GetDefaultMenuText++;
377 return E_NOTIMPL;
378 }
379
380 static HRESULT WINAPI ICommDlgBrowser3_fnGetViewFlags(
381 ICommDlgBrowser3* iface,
382 DWORD *pdwFlags)
383 {
384 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
385 This->GetViewFlags++;
386 return E_NOTIMPL;
387 }
388
389 static HRESULT WINAPI ICommDlgBrowser3_fnOnColumnClicked(
390 ICommDlgBrowser3* iface,
391 IShellView *ppshv,
392 int iColumn)
393 {
394 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
395 This->OnColumnClicked++;
396 return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI ICommDlgBrowser3_fnGetCurrentFilter(
400 ICommDlgBrowser3* iface,
401 LPWSTR pszFileSpec,
402 int cchFileSpec)
403 {
404 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
405 This->GetCurrentFilter++;
406 return E_NOTIMPL;
407 }
408
409 static HRESULT WINAPI ICommDlgBrowser3_fnOnPreviewCreated(
410 ICommDlgBrowser3* iface,
411 IShellView *ppshv)
412 {
413 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
414 This->OnPreviewCreated++;
415 return E_NOTIMPL;
416 }
417
418 static const ICommDlgBrowser3Vtbl cdbvtbl =
419 {
420 ICommDlgBrowser3_fnQueryInterface,
421 ICommDlgBrowser3_fnAddRef,
422 ICommDlgBrowser3_fnRelease,
423 ICommDlgBrowser3_fnOnDefaultCommand,
424 ICommDlgBrowser3_fnOnStateChange,
425 ICommDlgBrowser3_fnIncludeObject,
426 ICommDlgBrowser3_fnNotify,
427 ICommDlgBrowser3_fnGetDefaultMenuText,
428 ICommDlgBrowser3_fnGetViewFlags,
429 ICommDlgBrowser3_fnOnColumnClicked,
430 ICommDlgBrowser3_fnGetCurrentFilter,
431 ICommDlgBrowser3_fnOnPreviewCreated
432 };
433
434 static ICommDlgBrowser3Impl *create_commdlgbrowser3(void)
435 {
436 ICommDlgBrowser3Impl *cdb;
437
438 cdb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ICommDlgBrowser3Impl));
439 cdb->ICommDlgBrowser3_iface.lpVtbl = &cdbvtbl;
440 cdb->ref = 1;
441
442 return cdb;
443 }
444
445 /*********************************************************************
446 * IServiceProvider Implementation
447 */
448 typedef struct {
449 IServiceProvider IServiceProvider_iface;
450 LONG ref;
451 struct services {
452 REFGUID service;
453 REFIID id;
454 int count;
455 void *punk;
456 } *interfaces;
457 } IServiceProviderImpl;
458
459 static inline IServiceProviderImpl *impl_from_IServiceProvider(IServiceProvider *iface)
460 {
461 return CONTAINING_RECORD(iface, IServiceProviderImpl, IServiceProvider_iface);
462 }
463
464 static HRESULT WINAPI IServiceProvider_fnQueryInterface(IServiceProvider *iface, REFIID riid, LPVOID *ppvObj)
465 {
466 *ppvObj = NULL;
467 if(IsEqualIID(riid, &IID_IServiceProvider))
468 {
469 *ppvObj = iface;
470 IServiceProvider_AddRef(iface);
471 return S_OK;
472 }
473
474 if(IsEqualIID(riid, &IID_IOleCommandTarget))
475 {
476 /* Windows Vista. */
477 return E_NOINTERFACE;
478 }
479
480 ok(0, "Unexpected interface requested, %s\n", wine_dbgstr_guid(riid));
481 return E_NOINTERFACE;
482 }
483
484 static ULONG WINAPI IServiceProvider_fnAddRef(IServiceProvider *iface)
485 {
486 IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
487 return InterlockedIncrement(&This->ref);
488 }
489
490 static ULONG WINAPI IServiceProvider_fnRelease(IServiceProvider *iface)
491 {
492 IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
493 LONG ref = InterlockedDecrement(&This->ref);
494
495 if(!ref)
496 HeapFree(GetProcessHeap(), 0, This);
497
498 return ref;
499 }
500
501 static HRESULT WINAPI IServiceProvider_fnQueryService(IServiceProvider *iface,
502 REFGUID guidService,
503 REFIID riid,
504 void **ppv)
505 {
506 IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
507 BOOL was_in_list = FALSE;
508 IUnknown *punk = NULL;
509 UINT i;
510
511 *ppv = NULL;
512 for(i = 0; This->interfaces[i].service != NULL; i++)
513 {
514 if(IsEqualGUID(This->interfaces[i].service, guidService) &&
515 IsEqualIID(This->interfaces[i].id, riid))
516 {
517 was_in_list = TRUE;
518 This->interfaces[i].count++;
519 punk = This->interfaces[i].punk;
520 break;
521 }
522 }
523
524 ok(was_in_list, "unknown service, serviceID: %s, riid: %s\n", wine_dbgstr_guid(guidService), wine_dbgstr_guid(riid));
525
526 /* Give back an interface, if any. */
527 if(punk)
528 {
529 *ppv = punk;
530 IUnknown_AddRef(punk);
531 return S_OK;
532 }
533
534 return E_NOINTERFACE;
535 }
536
537 static const IServiceProviderVtbl spvtbl =
538 {
539 IServiceProvider_fnQueryInterface,
540 IServiceProvider_fnAddRef,
541 IServiceProvider_fnRelease,
542 IServiceProvider_fnQueryService
543 };
544
545 static IServiceProviderImpl *create_serviceprovider(void)
546 {
547 IServiceProviderImpl *sp = HeapAlloc(GetProcessHeap(), 0, sizeof(IServiceProviderImpl));
548 sp->IServiceProvider_iface.lpVtbl = &spvtbl;
549 sp->ref = 1;
550 return sp;
551 }
552
553 static void test_QueryInterface(void)
554 {
555 IExplorerBrowser *peb;
556 IUnknown *punk;
557 HRESULT hr;
558 LONG lres;
559
560 hr = ebrowser_instantiate(&peb);
561 ok(hr == S_OK, "Got 0x%08x\n", hr);
562
563 #define test_qinterface(iid, exp) \
564 do { \
565 hr = IExplorerBrowser_QueryInterface(peb, &iid, (void**)&punk); \
566 ok(hr == exp, "(%s:)Expected (0x%08x), got (0x%08x)\n", \
567 #iid, exp, hr); \
568 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
569 } while(0)
570
571 test_qinterface(IID_IUnknown, S_OK);
572 test_qinterface(IID_IExplorerBrowser, S_OK);
573 test_qinterface(IID_IShellBrowser, S_OK);
574 todo_wine test_qinterface(IID_IOleWindow, S_OK);
575 test_qinterface(IID_ICommDlgBrowser, S_OK);
576 test_qinterface(IID_ICommDlgBrowser2, S_OK);
577 test_qinterface(IID_ICommDlgBrowser3, S_OK);
578 todo_wine test_qinterface(IID_IServiceProvider, S_OK);
579 test_qinterface(IID_IObjectWithSite, S_OK);
580 todo_wine test_qinterface(IID_IConnectionPointContainer, S_OK);
581 test_qinterface(IID_IOleObject, E_NOINTERFACE);
582 test_qinterface(IID_IViewObject, E_NOINTERFACE);
583 test_qinterface(IID_IViewObject2, E_NOINTERFACE);
584 test_qinterface(IID_IViewObjectEx, E_NOINTERFACE);
585 test_qinterface(IID_IConnectionPoint, E_NOINTERFACE);
586 test_qinterface(IID_IShellView, E_NOINTERFACE);
587 test_qinterface(IID_INameSpaceTreeControlEvents, E_NOINTERFACE);
588
589 #undef test_qinterface
590
591 lres = IExplorerBrowser_Release(peb);
592 ok(lres == 0, "Got %d\n", lres);
593 }
594
595 static void test_SB_misc(void)
596 {
597 IExplorerBrowser *peb;
598 IShellBrowser *psb;
599 IUnknown *punk;
600 HRESULT hr;
601 HWND retHwnd;
602 LRESULT lres;
603 LONG ref;
604
605 ebrowser_instantiate(&peb);
606 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
607 ok(hr == S_OK, "Got 0x%08x\n", hr);
608 if(FAILED(hr))
609 {
610 skip("Failed to get IShellBrowser interface.\n");
611 return;
612 }
613
614 /* Some unimplemented methods */
615 retHwnd = (HWND)0xdeadbeef;
616 hr = IShellBrowser_GetControlWindow(psb, FCW_TOOLBAR, &retHwnd);
617 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
618 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
619
620 retHwnd = (HWND)0xdeadbeef;
621 hr = IShellBrowser_GetControlWindow(psb, FCW_STATUS, &retHwnd);
622 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
623 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
624
625 retHwnd = (HWND)0xdeadbeef;
626 hr = IShellBrowser_GetControlWindow(psb, FCW_TREE, &retHwnd);
627 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
628 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
629
630 retHwnd = (HWND)0xdeadbeef;
631 hr = IShellBrowser_GetControlWindow(psb, FCW_PROGRESS, &retHwnd);
632 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
633 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
634
635 /* ::InsertMenuSB */
636 hr = IShellBrowser_InsertMenusSB(psb, NULL, NULL);
637 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
638
639 /* ::RemoveMenusSB */
640 hr = IShellBrowser_RemoveMenusSB(psb, NULL);
641 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
642
643 /* ::SetMenuSB */
644 hr = IShellBrowser_SetMenuSB(psb, NULL, NULL, NULL);
645 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
646
647 /***** Before EB::Initialize *****/
648
649 /* ::GetWindow */
650 retHwnd = (HWND)0xDEADBEEF;
651 hr = IShellBrowser_GetWindow(psb, &retHwnd);
652 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
653 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
654
655 todo_wine
656 {
657
658 /* ::SendControlMsg */
659 lres = 0xDEADBEEF;
660 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
661 ok(hr == S_OK, "got (0x%08x)\n", hr);
662 ok(lres == 0, "lres was %ld\n", lres);
663
664 lres = 0xDEADBEEF;
665 hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, TB_CHECKBUTTON,
666 FCIDM_TB_SMALLICON, TRUE, &lres);
667 ok(hr == S_OK, "got (0x%08x)\n", hr);
668 ok(lres == 0, "lres was %ld\n", lres);
669
670 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
671 ok(hr == S_OK, "got (0x%08x)\n", hr);
672
673 hr = IShellBrowser_SendControlMsg(psb, FCW_TREE, 0, 0, 0, NULL);
674 ok(hr == S_OK, "got (0x%08x)\n", hr);
675
676 hr = IShellBrowser_SendControlMsg(psb, FCW_PROGRESS, 0, 0, 0, NULL);
677 ok(hr == S_OK, "got (0x%08x)\n", hr);
678 }
679
680 /* ::QueryActiveShellView */
681 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
682 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
683
684 /* Initialize ExplorerBrowser */
685 ebrowser_initialize(peb);
686
687 /***** After EB::Initialize *****/
688
689 /* ::GetWindow */
690 hr = IShellBrowser_GetWindow(psb, &retHwnd);
691 ok(hr == S_OK, "got (0x%08x)\n", hr);
692 ok(GetParent(retHwnd) == hwnd, "The HWND returned is not our child.\n");
693
694 todo_wine
695 {
696 /* ::SendControlMsg */
697 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
698 ok(hr == S_OK, "got (0x%08x)\n", hr);
699
700 lres = 0xDEADBEEF;
701 hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, 0, 0, 0, &lres);
702 ok(hr == S_OK, "got (0x%08x)\n", hr);
703 ok(lres == 0, "lres was %ld\n", lres);
704
705 lres = 0xDEADBEEF;
706 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
707 ok(hr == S_OK, "got (0x%08x)\n", hr);
708 ok(lres == 0, "lres was %ld\n", lres);
709
710 lres = 0xDEADBEEF;
711 hr = IShellBrowser_SendControlMsg(psb, 1234, 0, 0, 0, &lres);
712 ok(hr == S_OK, "got (0x%08x)\n", hr);
713 ok(lres == 0, "lres was %ld\n", lres);
714
715 /* Returns S_OK */
716 hr = IShellBrowser_SetStatusTextSB(psb, NULL);
717 ok(hr == S_OK, "got (0x%08x)\n", hr);
718
719 hr = IShellBrowser_ContextSensitiveHelp(psb, FALSE);
720 ok(hr == S_OK, "got (0x%08x)\n", hr);
721
722 hr = IShellBrowser_EnableModelessSB(psb, TRUE);
723 ok(hr == S_OK, "got (0x%08x)\n", hr);
724
725 hr = IShellBrowser_SetToolbarItems(psb, NULL, 1, 1);
726 ok(hr == S_OK, "got (0x%08x)\n", hr);
727 }
728
729 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
730 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
731
732 IShellBrowser_Release(psb);
733 IExplorerBrowser_Destroy(peb);
734 IExplorerBrowser_Release(peb);
735
736 /* Browse to the desktop. */
737 ebrowser_instantiate(&peb);
738 ebrowser_initialize(peb);
739 IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
740
741 process_msgs();
742 hr = ebrowser_browse_to_desktop(peb);
743 ok(hr == S_OK, "got (0x%08x)\n", hr);
744 process_msgs();
745
746 /****** After Browsing *****/
747
748 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
749 ok(hr == S_OK, "got (0x%08x)\n", hr);
750 if(SUCCEEDED(hr)) IUnknown_Release(punk);
751
752 IShellBrowser_Release(psb);
753 IExplorerBrowser_Destroy(peb);
754 ref = IExplorerBrowser_Release(peb);
755 ok(ref == 0, "Got %d\n", ref);
756 }
757
758 static void test_initialization(void)
759 {
760 IExplorerBrowser *peb;
761 IShellBrowser *psb;
762 HWND eb_hwnd;
763 HRESULT hr;
764 ULONG lres;
765 LONG style;
766 RECT rc;
767
768 ebrowser_instantiate(&peb);
769
770 if(0)
771 {
772 /* Crashes on Windows 7 */
773 IExplorerBrowser_Initialize(peb, NULL, NULL, NULL);
774 IExplorerBrowser_Initialize(peb, hwnd, NULL, NULL);
775 }
776
777 ZeroMemory(&rc, sizeof(RECT));
778
779 hr = IExplorerBrowser_Initialize(peb, NULL, &rc, NULL);
780 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
781
782 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
783 ok(hr == S_OK, "got (0x%08x)\n", hr);
784
785 /* Initialize twice */
786 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
787 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
788
789 hr = IExplorerBrowser_Destroy(peb);
790 ok(hr == S_OK, "got (0x%08x)\n", hr);
791
792 /* Initialize again */
793 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
794 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
795
796 /* Destroy again */
797 hr = IExplorerBrowser_Destroy(peb);
798 ok(hr == S_OK, "got (0x%08x)\n", hr);
799 lres = IExplorerBrowser_Release(peb);
800 ok(lres == 0, "Got %d\n", lres);
801
802 /* Initialize with a few different rectangles */
803 peb = NULL;
804 ebrowser_instantiate(&peb);
805 SetRect(&rc, 50, 20, 100, 80);
806 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
807 ok(hr == S_OK, "got (0x%08x)\n", hr);
808 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
809 ok(hr == S_OK, "Got 0x%08x\n", hr);
810 if(SUCCEEDED(hr))
811 {
812 RECT eb_rc;
813 char buf[1024];
814 LONG expected_style;
815 static const RECT exp_rc = {0, 0, 48, 58};
816
817 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
818 ok(hr == S_OK, "Got 0x%08x\n", hr);
819
820 GetClientRect(eb_hwnd, &eb_rc);
821 ok(EqualRect(&eb_rc, &exp_rc), "Got client rect %s\n", wine_dbgstr_rect(&eb_rc));
822
823 GetWindowRect(eb_hwnd, &eb_rc);
824 ok(eb_rc.right - eb_rc.left == 50, "Got window width %d\n", eb_rc.right - eb_rc.left);
825 ok(eb_rc.bottom - eb_rc.top == 60, "Got window height %d\n", eb_rc.bottom - eb_rc.top);
826
827 buf[0] = '\0';
828 GetClassNameA(eb_hwnd, buf, 1024);
829 ok(!lstrcmpA(buf, "ExplorerBrowserControl"), "Unexpected classname %s\n", buf);
830
831 expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER;
832 style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
833 todo_wine ok(style == expected_style, "Got style 0x%08x, expected 0x%08x\n", style, expected_style);
834
835 expected_style = WS_EX_CONTROLPARENT;
836 style = GetWindowLongPtrW(eb_hwnd, GWL_EXSTYLE);
837 ok(style == expected_style, "Got exstyle 0x%08x, expected 0x%08x\n", style, expected_style);
838
839 ok(GetParent(eb_hwnd) == hwnd, "GetParent returns %p\n", GetParent(eb_hwnd));
840
841 /* ::Destroy() destroys the window. */
842 ok(IsWindow(eb_hwnd), "eb_hwnd invalid.\n");
843 IExplorerBrowser_Destroy(peb);
844 ok(!IsWindow(eb_hwnd), "eb_hwnd valid.\n");
845
846 IShellBrowser_Release(psb);
847 lres = IExplorerBrowser_Release(peb);
848 ok(lres == 0, "Got refcount %d\n", lres);
849 }
850 else
851 {
852 skip("Skipping some tests.\n");
853
854 IExplorerBrowser_Destroy(peb);
855 lres = IExplorerBrowser_Release(peb);
856 ok(lres == 0, "Got refcount %d\n", lres);
857 }
858
859 /* check window style with EBO_NOBORDER */
860 ebrowser_instantiate(&peb);
861 hr = IExplorerBrowser_SetOptions(peb, EBO_NOBORDER);
862 ok(hr == S_OK, "got 0x%08x\n", hr);
863 SetRect(&rc, 50, 20, 100, 80);
864
865 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
866 ok(hr == S_OK, "got (0x%08x)\n", hr);
867
868 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
869 ok(hr == S_OK, "Got 0x%08x\n", hr);
870
871 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
872 ok(hr == S_OK, "Got 0x%08x\n", hr);
873
874 style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
875 ok(!(style & WS_BORDER) || broken(style & WS_BORDER) /* before win8 */, "got style 0x%08x\n", style);
876
877 IShellBrowser_Release(psb);
878 IExplorerBrowser_Destroy(peb);
879 IExplorerBrowser_Release(peb);
880
881 /* empty rectangle */
882 ebrowser_instantiate(&peb);
883 SetRectEmpty(&rc);
884 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
885 ok(hr == S_OK, "got (0x%08x)\n", hr);
886 IExplorerBrowser_Destroy(peb);
887 lres = IExplorerBrowser_Release(peb);
888 ok(lres == 0, "Got refcount %d\n", lres);
889
890 ebrowser_instantiate(&peb);
891 SetRect(&rc, -1, -1, 1, 1);
892 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
893 ok(hr == S_OK, "got (0x%08x)\n", hr);
894 IExplorerBrowser_Destroy(peb);
895 lres = IExplorerBrowser_Release(peb);
896 ok(lres == 0, "Got refcount %d\n", lres);
897
898 ebrowser_instantiate(&peb);
899 SetRect(&rc, 10, 10, 5, 5);
900 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
901 ok(hr == S_OK, "got (0x%08x)\n", hr);
902 IExplorerBrowser_Destroy(peb);
903 lres = IExplorerBrowser_Release(peb);
904 ok(lres == 0, "Got refcount %d\n", lres);
905
906 ebrowser_instantiate(&peb);
907 SetRect(&rc, 10, 10, 5, 5);
908 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
909 ok(hr == S_OK, "got (0x%08x)\n", hr);
910 IExplorerBrowser_Destroy(peb);
911 lres = IExplorerBrowser_Release(peb);
912 ok(lres == 0, "Got refcount %d\n", lres);
913 }
914
915 static void test_SetSite(void)
916 {
917 IExplorerBrowser *peb;
918 IServiceProviderImpl *spimpl = create_serviceprovider();
919 ICommDlgBrowser3Impl *cdbimpl = create_commdlgbrowser3();
920 IExplorerPaneVisibilityImpl *epvimpl = create_explorerpanevisibility();
921 IObjectWithSite *pow;
922 HRESULT hr;
923 LONG ref;
924 UINT i;
925 struct services expected[] = {
926 /* Win 7 */
927 { &SID_STopLevelBrowser, &IID_ICommDlgBrowser2, 0, cdbimpl },
928 { &SID_STopLevelBrowser, &IID_IShellBrowserService, 0, NULL },
929 { &SID_STopLevelBrowser, &IID_IShellBrowser, 0, NULL },
930 { &SID_STopLevelBrowser, &IID_UnknownInterface8, 0, NULL },
931 { &SID_STopLevelBrowser, &IID_IConnectionPointContainer, 0, NULL },
932 { &SID_STopLevelBrowser, &IID_IProfferService, 0, NULL },
933 { &SID_STopLevelBrowser, &IID_UnknownInterface9, 0, NULL },
934 { &SID_ExplorerPaneVisibility, &IID_IExplorerPaneVisibility, 0, epvimpl },
935 { &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser2, 0, cdbimpl },
936 { &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser3, 0, cdbimpl },
937 { &IID_IFileDialogPrivate, &IID_IFileDialogPrivate, 0, NULL },
938 { &IID_IFileDialogPrivate, &IID_IFileDialog, 0, NULL },
939 { &IID_IShellTaskScheduler, &IID_IShellTaskScheduler, 0, NULL },
940 { &IID_IShellTaskScheduler, &IID_UnknownInterface2, 0, NULL },
941 { &IID_IWebbrowserApp, &IID_IConnectionPointContainer, 0, NULL },
942 { &IID_IFolderView, &IID_IFolderView, 0, NULL },
943 { &IID_ILayoutModifier, &IID_ILayoutModifier, 0, NULL },
944 { &IID_IBrowserSettings, &IID_IBrowserSettings, 0, NULL },
945 { &CLSID_Desktop, &IID_IUnknown, 0, NULL },
946 { &IID_UnknownInterface1, &IID_UnknownInterface1, 0, NULL },
947 { &IID_UnknownInterface3, &IID_UnknownInterface3, 0, NULL },
948 { &IID_UnknownInterface4, &IID_IUnknown, 0, NULL },
949 { &IID_UnknownInterface6, &IID_UnknownInterface7, 0, NULL },
950 { &IID_IBrowserWithActivationNotification, &IID_IBrowserWithActivationNotification, 0, NULL },
951 /* Win 8 */
952 { &IID_ICommDlgBrowser, &IID_UnknownInterface11, 0, NULL },
953 { &IID_ICommDlgBrowser, &IID_UnknownInterface12, 0, NULL },
954 { &IID_ICommDlgBrowser, &IID_UnknownInterface20, 0, NULL },
955 { &IID_UnknownInterface13, &IID_IUnknown, 0, NULL },
956 { &IID_UnknownInterface13, &IID_UnknownInterface13, 0, NULL },
957 { &IID_UnknownInterface13, &IID_UnknownInterface18, 0, NULL },
958 { &IID_UnknownInterface14, &IID_UnknownInterface14, 0, NULL },
959 { &IID_UnknownInterface15, &IID_UnknownInterface15, 0, NULL },
960 { &IID_UnknownInterface16, &IID_UnknownInterface16, 0, NULL },
961 { &IID_UnknownInterface17, &IID_UnknownInterface17, 0, NULL },
962 { &IID_UnknownInterface17, &IID_UnknownInterface19, 0, NULL },
963
964 /* Other services requested in Vista, Windows 2008 but not in Windows 7 */
965 { &IID_IBrowserSettings_Vista, &IID_IBrowserSettings_Vista, 0, NULL },
966 { &IID_IFolderTypeModifier, &IID_IFolderTypeModifier, 0, NULL },
967 { &SID_STopLevelBrowser, &IID_IShellBrowserService_Vista, 0, NULL },
968 { &IID_UnknownInterface5, &IID_UnknownInterface5, 0, NULL },
969 { &IID_ICommDlgBrowser, &IID_ICommDlgBrowser, 0, cdbimpl },
970 { &IID_IFileDialogPrivate_Vista,&IID_IFileDialogPrivate_Vista, 0, NULL},
971 { &IID_IFileDialogPrivate_Vista,&IID_IFileDialog, 0, NULL},
972 { &IID_UnknownInterface10, &IID_IHTMLDocument2, 0, NULL},
973 { &SID_SMenuBandParent, &IID_IOleCommandTarget, 0, NULL},
974 { &SID_SMenuBandParent, &IID_IShellMenu, 0, NULL},
975 { &SID_STopLevelBrowser, &IID_IOleWindow, 0, NULL},
976 { &SID_SMenuPopup, &IID_IOleCommandTarget, 0, NULL},
977 { NULL }
978 };
979
980 ebrowser_instantiate(&peb);
981 IExplorerBrowser_SetOptions(peb, EBO_SHOWFRAMES);
982
983 hr = IExplorerBrowser_QueryInterface(peb, &IID_IObjectWithSite, (void**)&pow);
984 ok(hr == S_OK, "Got 0x%08x\n", hr);
985 if(SUCCEEDED(hr))
986 {
987 spimpl->interfaces = expected;
988
989 hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
990 ok(hr == S_OK, "Got 0x%08x\n", hr);
991
992 if(FAILED(hr))
993 IObjectWithSite_Release(pow);
994 }
995
996 if(FAILED(hr))
997 {
998 skip("Failed to set site.\n");
999
1000 IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1001 ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
1002 IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
1003 IExplorerBrowser_Destroy(peb);
1004 ref = IExplorerBrowser_Release(peb);
1005 ok(ref == 0, "Got ref %d\n", ref);
1006
1007 return;
1008 }
1009
1010 ShowWindow(hwnd, TRUE);
1011 ebrowser_initialize(peb);
1012 ebrowser_browse_to_desktop(peb);
1013
1014 for(i = 0; i < 10; i++)
1015 {
1016 Sleep(100);
1017 process_msgs();
1018 }
1019 ShowWindow(hwnd, FALSE);
1020
1021 /* ICommDlgBrowser3 */
1022 ok(!cdbimpl->OnDefaultCommand, "Got %d\n", cdbimpl->OnDefaultCommand);
1023 todo_wine ok(cdbimpl->OnStateChange, "Got %d\n", cdbimpl->OnStateChange);
1024 ok(cdbimpl->IncludeObject, "Got %d\n", cdbimpl->IncludeObject);
1025 ok(!cdbimpl->Notify, "Got %d\n", cdbimpl->Notify);
1026 ok(!cdbimpl->GetDefaultMenuText, "Got %d\n", cdbimpl->GetDefaultMenuText);
1027 todo_wine ok(cdbimpl->GetViewFlags, "Got %d\n", cdbimpl->GetViewFlags);
1028 ok(!cdbimpl->OnColumnClicked, "Got %d\n", cdbimpl->OnColumnClicked);
1029 ok(!cdbimpl->GetCurrentFilter, "Got %d\n", cdbimpl->GetCurrentFilter);
1030 todo_wine ok(cdbimpl->OnPreviewCreated, "Got %d\n", cdbimpl->OnPreviewCreated);
1031
1032 /* IExplorerPaneVisibility */
1033 ok(epvimpl->np, "Got %d\n", epvimpl->np);
1034 todo_wine ok(epvimpl->cp, "Got %d\n", epvimpl->cp);
1035 todo_wine ok(epvimpl->cp_o, "Got %d\n", epvimpl->cp_o);
1036 todo_wine ok(epvimpl->cp_v, "Got %d\n", epvimpl->cp_v);
1037 todo_wine ok(epvimpl->dp, "Got %d\n", epvimpl->dp);
1038 todo_wine ok(epvimpl->pp, "Got %d\n", epvimpl->pp);
1039 ok(!epvimpl->qp, "Got %d\n", epvimpl->qp);
1040 ok(!epvimpl->aqp, "Got %d\n", epvimpl->aqp);
1041 ok(!epvimpl->unk, "Got %d\n", epvimpl->unk);
1042
1043 if(0)
1044 {
1045 for(i = 0; expected[i].service != NULL; i++)
1046 if(!expected[i].count) trace("count %d was 0.\n", i);
1047 }
1048
1049 /* Test when IServiceProvider is released. */
1050 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1051 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1052 ok(ref == 2, "Got ref %d\n", ref);
1053
1054 hr = IObjectWithSite_SetSite(pow, NULL);
1055 ok(hr == S_OK, "Got 0x%08x\n", hr);
1056
1057 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1058 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1059 ok(ref == 1, "Got ref %d\n", ref);
1060
1061 hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
1062 ok(hr == S_OK, "Got 0x%08x\n", hr);
1063
1064 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1065 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1066 ok(ref == 2, "Got ref %d\n", ref);
1067
1068 IExplorerBrowser_Destroy(peb);
1069
1070 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1071 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1072 ok(ref == 2, "Got ref %d\n", ref);
1073
1074 IObjectWithSite_Release(pow);
1075 ref = IExplorerBrowser_Release(peb);
1076 ok(ref == 0, "Got ref %d\n", ref);
1077
1078 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1079 ok(ref == 0, "Got ref %d\n", ref);
1080
1081 ref = ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
1082 ok(ref == 0, "Got ref %d\n", ref);
1083 ref = IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
1084 ok(ref == 0, "Got ref %d\n", ref);
1085 }
1086
1087 static void test_basics(void)
1088 {
1089 IExplorerBrowser *peb;
1090 IShellBrowser *psb;
1091 FOLDERSETTINGS fs;
1092 ULONG lres;
1093 DWORD flags;
1094 HDWP hdwp;
1095 RECT rc;
1096 HRESULT hr;
1097 static const WCHAR winetest[] = {'W','i','n','e','T','e','s','t',0};
1098
1099 ebrowser_instantiate(&peb);
1100 ebrowser_initialize(peb);
1101
1102 /* SetRect */
1103 SetRectEmpty(&rc);
1104 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1105 ok(hr == S_OK, "got (0x%08x)\n", hr);
1106
1107 SetRect(&rc, 100, 100, 10, 10);
1108 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1109 ok(hr == S_OK, "got (0x%08x)\n", hr);
1110
1111 /* SetRect with DeferWindowPos */
1112 SetRect(&rc, 0, 0, 10, 10);
1113 hdwp = BeginDeferWindowPos(1);
1114 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1115 ok(hr == S_OK, "got (0x%08x)\n", hr);
1116 lres = EndDeferWindowPos(hdwp);
1117 ok(lres, "EndDeferWindowPos failed.\n");
1118
1119 hdwp = NULL;
1120 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1121 ok(hr == S_OK, "got (0x%08x)\n", hr);
1122 ok(hdwp == NULL, "got %p\n", hdwp);
1123 lres = EndDeferWindowPos(hdwp);
1124 ok(!lres, "EndDeferWindowPos succeeded unexpectedly.\n");
1125
1126 /* Test positioning */
1127 SetRect(&rc, 10, 20, 50, 50);
1128 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1129 ok(hr == S_OK, "got (0x%08x)\n", hr);
1130 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1131 ok(hr == S_OK, "Got 0x%08x\n", hr);
1132 if(SUCCEEDED(hr))
1133 {
1134 HWND eb_hwnd;
1135 RECT eb_rc;
1136 static const RECT exp_rc = {11, 21, 49, 49};
1137 static const RECT exp_rc2 = {11, 21, 49, 24};
1138
1139 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
1140 ok(hr == S_OK, "Got 0x%08x\n", hr);
1141
1142 GetClientRect(eb_hwnd, &eb_rc);
1143 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1144 ok(EqualRect(&eb_rc, &exp_rc), "Got rect %s\n", wine_dbgstr_rect(&eb_rc));
1145
1146 /* Try resizing with invalid hdwp */
1147 rc.bottom = 25;
1148 hdwp = (HDWP)0xdeadbeef;
1149 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1150 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1151 GetClientRect(eb_hwnd, &eb_rc);
1152 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1153 ok(EqualRect(&eb_rc, &exp_rc), "Got rect %s\n", wine_dbgstr_rect(&eb_rc));
1154
1155 hdwp = NULL;
1156 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1157 ok(hr == S_OK, "Got 0x%08x\n", hr);
1158 GetClientRect(eb_hwnd, &eb_rc);
1159 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1160 ok(EqualRect(&eb_rc, &exp_rc2), "Got rect %s\n", wine_dbgstr_rect(&eb_rc));
1161
1162 IShellBrowser_Release(psb);
1163 }
1164
1165 IExplorerBrowser_Destroy(peb);
1166 IExplorerBrowser_Release(peb);
1167
1168 /* GetOptions/SetOptions*/
1169 ebrowser_instantiate(&peb);
1170
1171 if(0) {
1172 /* Crashes on Windows 7 */
1173 IExplorerBrowser_GetOptions(peb, NULL);
1174 }
1175
1176 hr = IExplorerBrowser_GetOptions(peb, &flags);
1177 ok(hr == S_OK, "got (0x%08x)\n", hr);
1178 ok(flags == 0, "got (0x%08x)\n", flags);
1179
1180 /* Settings preserved through Initialize. */
1181 hr = IExplorerBrowser_SetOptions(peb, 0xDEADBEEF);
1182 ok(hr == S_OK, "got (0x%08x)\n", hr);
1183
1184 ebrowser_initialize(peb);
1185
1186 hr = IExplorerBrowser_GetOptions(peb, &flags);
1187 ok(flags == 0xDEADBEEF, "got (0x%08x)\n", flags);
1188 ok(hr == S_OK, "got (0x%08x)\n", hr);
1189
1190 IExplorerBrowser_Destroy(peb);
1191 IExplorerBrowser_Release(peb);
1192
1193 ebrowser_instantiate(&peb);
1194 ebrowser_initialize(peb);
1195
1196 /* SetFolderSettings */
1197 hr = IExplorerBrowser_SetFolderSettings(peb, NULL);
1198 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1199 fs.ViewMode = 0; fs.fFlags = 0;
1200 hr = IExplorerBrowser_SetFolderSettings(peb, &fs);
1201 todo_wine ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1202
1203 /* SetPropertyBag */
1204 hr = IExplorerBrowser_SetPropertyBag(peb, NULL);
1205 ok(hr == E_INVALIDARG, "Got 0x%08x\n", hr);
1206 hr = IExplorerBrowser_SetPropertyBag(peb, winetest);
1207 ok(hr == S_OK, "Got 0x%08x\n", hr);
1208
1209 /* TODO: Test after browsing somewhere. */
1210
1211 IExplorerBrowser_Destroy(peb);
1212 lres = IExplorerBrowser_Release(peb);
1213 ok(lres == 0, "Got %d\n", lres);
1214 }
1215
1216 static void test_Advise(void)
1217 {
1218 IExplorerBrowser *peb;
1219 IExplorerBrowserEvents *pebe;
1220 DWORD cookies[10];
1221 HRESULT hr;
1222 UINT i, ref;
1223
1224 /* Set up our IExplorerBrowserEvents implementation */
1225 ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1226 pebe = &ebev.IExplorerBrowserEvents_iface;
1227
1228 ebrowser_instantiate(&peb);
1229
1230 if(0)
1231 {
1232 /* Crashes on Windows 7 */
1233 IExplorerBrowser_Advise(peb, pebe, NULL);
1234 IExplorerBrowser_Advise(peb, NULL, &cookies[0]);
1235 }
1236
1237 /* Using Unadvise with a cookie that has yet to be given out
1238 * results in E_INVALIDARG */
1239 hr = IExplorerBrowser_Unadvise(peb, 11);
1240 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1241
1242 /* Add some before initialization */
1243 for(i = 0; i < 5; i++)
1244 {
1245 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1246 ok(hr == S_OK, "got (0x%08x)\n", hr);
1247 }
1248
1249 ebrowser_initialize(peb);
1250
1251 /* Add some after initialization */
1252 for(i = 5; i < 10; i++)
1253 {
1254 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1255 ok(hr == S_OK, "got (0x%08x)\n", hr);
1256 }
1257
1258 ok(ebev.ref == 10, "Got %d\n", ebev.ref);
1259
1260 ebev.completed = 0;
1261 ebrowser_browse_to_desktop(peb);
1262 process_msgs();
1263 ok(ebev.completed == 10, "Got %d\n", ebev.completed);
1264
1265 /* Remove a bunch somewhere in the middle */
1266 for(i = 4; i < 8; i++)
1267 {
1268 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1269 ok(hr == S_OK, "got (0x%08x)\n", hr);
1270 }
1271
1272 ebev.completed = 0;
1273 ebrowser_browse_to_desktop(peb);
1274 process_msgs();
1275 ok(ebev.completed == 6, "Got %d\n", ebev.completed);
1276
1277 if(0)
1278 {
1279 /* Using unadvise with a previously unadvised cookie results
1280 * in a crash. */
1281 IExplorerBrowser_Unadvise(peb, cookies[5]);
1282 }
1283
1284 /* Remove the rest. */
1285 for(i = 0; i < 10; i++)
1286 {
1287 if(i<4||i>7)
1288 {
1289 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1290 ok(hr == S_OK, "%d: got (0x%08x)\n", i, hr);
1291 }
1292 }
1293
1294 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
1295
1296 ebev.completed = 0;
1297 ebrowser_browse_to_desktop(peb);
1298 process_msgs();
1299 ok(ebev.completed == 0, "Got %d\n", ebev.completed);
1300
1301 /* ::Destroy implies ::Unadvise. */
1302 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[0]);
1303 ok(hr == S_OK, "Got 0x%08x\n", hr);
1304 ok(ebev.ref == 1, "Got %d\n", ebev.ref);
1305
1306 hr = IExplorerBrowser_Destroy(peb);
1307 ok(hr == S_OK, "Got 0x%08x\n", hr);
1308 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
1309
1310 ref = IExplorerBrowser_Release(peb);
1311 ok(!ref, "Got %d\n", ref);
1312 }
1313
1314 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
1315 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
1316 {
1317 size_t iLen;
1318
1319 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
1320 return NULL;
1321
1322 if (iLen)
1323 {
1324 lpszPath += iLen;
1325 if (lpszPath[-1] != '\\')
1326 {
1327 *lpszPath++ = '\\';
1328 *lpszPath = '\0';
1329 }
1330 }
1331 return lpszPath;
1332 }
1333
1334 static void test_browse_pidl_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
1335 LPITEMIDLIST pidl, UINT uFlags,
1336 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
1337 const char *file, int line)
1338 {
1339 HRESULT hr;
1340 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
1341
1342 hr = IExplorerBrowser_BrowseToIDList(peb, pidl, uFlags);
1343 ok_(file, line) (hr == hr_exp, "BrowseToIDList returned 0x%08x\n", hr);
1344 process_msgs();
1345
1346 ok_(file, line)
1347 (ebev->pending == pending && ebev->created == created &&
1348 ebev->failed == failed && ebev->completed == completed,
1349 "Events occurred: %d, %d, %d, %d\n",
1350 ebev->pending, ebev->created, ebev->failed, ebev->completed);
1351 }
1352 #define test_browse_pidl(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
1353 test_browse_pidl_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
1354
1355 static void test_browse_pidl_sb_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
1356 LPITEMIDLIST pidl, UINT uFlags,
1357 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
1358 const char *file, int line)
1359 {
1360 IShellBrowser *psb;
1361 HRESULT hr;
1362
1363 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1364 ok_(file, line) (hr == S_OK, "QueryInterface returned 0x%08x\n", hr);
1365 if(SUCCEEDED(hr))
1366 {
1367 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
1368
1369 hr = IShellBrowser_BrowseObject(psb, pidl, uFlags);
1370 ok_(file, line) (hr == hr_exp, "BrowseObject returned 0x%08x\n", hr);
1371 process_msgs();
1372
1373 ok_(file, line)
1374 (ebev->pending == pending && ebev->created == created &&
1375 ebev->failed == failed && ebev->completed == completed,
1376 "Events occurred: %d, %d, %d, %d\n",
1377 ebev->pending, ebev->created, ebev->failed, ebev->completed);
1378
1379 IShellBrowser_Release(psb);
1380 }
1381 }
1382 #define test_browse_pidl_sb(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
1383 test_browse_pidl_sb_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
1384
1385 static void test_navigation(void)
1386 {
1387 IExplorerBrowser *peb, *peb2;
1388 IFolderView *pfv;
1389 IShellItem *psi;
1390 IShellFolder *psf;
1391 LPITEMIDLIST pidl_current, pidl_child;
1392 DWORD cookie, cookie2;
1393 HRESULT hr;
1394 LONG lres;
1395 WCHAR current_path[MAX_PATH];
1396 WCHAR child_path[MAX_PATH];
1397 static const WCHAR testfolderW[] =
1398 {'w','i','n','e','t','e','s','t','f','o','l','d','e','r','\0'};
1399
1400 ok(pSHParseDisplayName != NULL, "pSHParseDisplayName unexpectedly missing.\n");
1401 ok(pSHCreateShellItem != NULL, "pSHCreateShellItem unexpectedly missing.\n");
1402
1403 GetCurrentDirectoryW(MAX_PATH, current_path);
1404 if(!current_path[0])
1405 {
1406 skip("Failed to create test-directory.\n");
1407 return;
1408 }
1409
1410 lstrcpyW(child_path, current_path);
1411 myPathAddBackslashW(child_path);
1412 lstrcatW(child_path, testfolderW);
1413
1414 CreateDirectoryW(child_path, NULL);
1415
1416 pSHParseDisplayName(current_path, NULL, &pidl_current, 0, NULL);
1417 pSHParseDisplayName(child_path, NULL, &pidl_child, 0, NULL);
1418
1419 ebrowser_instantiate(&peb);
1420 ebrowser_initialize(peb);
1421
1422 ebrowser_instantiate(&peb2);
1423 ebrowser_initialize(peb2);
1424
1425 /* Set up our IExplorerBrowserEvents implementation */
1426 ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1427
1428 IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1429 IExplorerBrowser_Advise(peb2, &ebev.IExplorerBrowserEvents_iface, &cookie2);
1430
1431 /* These should all fail */
1432 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1433 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1434 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
1435 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
1436 test_browse_pidl(peb, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1437 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1438 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1439 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1440 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
1441 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
1442 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1443 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1444
1445 /* "The first browse is synchronous" */
1446 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
1447 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
1448
1449 /* Navigate empty history */
1450 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
1451 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
1452 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
1453 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
1454
1455 /* Navigate history */
1456 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
1457 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
1458 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
1459 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
1460 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
1461 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
1462 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1463 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1464
1465 /* Relative navigation */
1466 test_browse_pidl(peb, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1467 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1468
1469 hr = IExplorerBrowser_GetCurrentView(peb, &IID_IFolderView, (void**)&pfv);
1470 ok(hr == S_OK, "Got 0x%08x\n", hr);
1471 if(SUCCEEDED(hr))
1472 {
1473 LPITEMIDLIST pidl_relative;
1474
1475 hr = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1476 ok(hr == S_OK, "Got 0x%08x\n", hr);
1477 hr = IShellFolder_ParseDisplayName(psf, NULL, NULL, (LPWSTR)testfolderW,
1478 NULL, &pidl_relative, NULL);
1479 ok(hr == S_OK, "Got 0x%08x\n", hr);
1480
1481 /* Browsing to another location here before using the
1482 * pidl_relative would make ExplorerBrowser in Windows 7 show a
1483 * not-available dialog. Also, passing a relative pidl without
1484 * specifying SBSP_RELATIVE makes it look for the pidl on the
1485 * desktop
1486 */
1487
1488 test_browse_pidl(peb, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
1489 test_browse_pidl_sb(peb2, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
1490
1491 ILFree(pidl_relative);
1492 IShellFolder_Release(psf);
1493 IFolderView_Release(pfv);
1494 }
1495
1496 /* misc **/
1497 test_browse_pidl(peb, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1498 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1499 test_browse_pidl(peb, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
1500 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
1501 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
1502 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
1503 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
1504 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
1505
1506 test_browse_pidl(peb, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
1507 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
1508 test_browse_pidl(peb, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
1509 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
1510
1511 /* SBSP_NEWBROWSER will return E_INVALIDARG, claims MSDN, but in
1512 * reality it works as one would expect (Windows 7 only?).
1513 */
1514 if(0)
1515 {
1516 IExplorerBrowser_BrowseToIDList(peb, NULL, SBSP_NEWBROWSER);
1517 }
1518
1519 hr = IExplorerBrowser_Unadvise(peb, cookie);
1520 ok(hr == S_OK, "Got 0x%08x\n", hr);
1521 IExplorerBrowser_Destroy(peb);
1522 process_msgs();
1523 hr = IExplorerBrowser_Unadvise(peb2, cookie2);
1524 ok(hr == S_OK, "Got 0x%08x\n", hr);
1525 IExplorerBrowser_Destroy(peb2);
1526 process_msgs();
1527
1528 /* Attempt browsing after destroyed */
1529 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
1530 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
1531
1532 lres = IExplorerBrowser_Release(peb);
1533 ok(lres == 0, "Got lres %d\n", lres);
1534 lres = IExplorerBrowser_Release(peb2);
1535 ok(lres == 0, "Got lres %d\n", lres);
1536
1537 /******************************************/
1538 /* Test some options that affect browsing */
1539
1540 ebrowser_instantiate(&peb);
1541 hr = IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1542 ok(hr == S_OK, "Got 0x%08x\n", hr);
1543 hr = IExplorerBrowser_SetOptions(peb, EBO_NAVIGATEONCE);
1544 ok(hr == S_OK, "got (0x%08x)\n", hr);
1545 ebrowser_initialize(peb);
1546
1547 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 1, 0, 1);
1548 test_browse_pidl(peb, &ebev, pidl_current, 0, E_FAIL, 0, 0, 0, 0);
1549
1550 hr = IExplorerBrowser_SetOptions(peb, 0);
1551 ok(hr == S_OK, "got (0x%08x)\n", hr);
1552
1553 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1554 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1555
1556 /* Difference in behavior lies where? */
1557 hr = IExplorerBrowser_SetOptions(peb, EBO_ALWAYSNAVIGATE);
1558 ok(hr == S_OK, "got (0x%08x)\n", hr);
1559
1560 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1561 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1562
1563 hr = IExplorerBrowser_Unadvise(peb, cookie);
1564 ok(hr == S_OK, "Got 0x%08x\n", hr);
1565
1566 IExplorerBrowser_Destroy(peb);
1567 lres = IExplorerBrowser_Release(peb);
1568 ok(lres == 0, "Got lres %d\n", lres);
1569
1570 /* BrowseToObject tests */
1571 ebrowser_instantiate(&peb);
1572 ebrowser_initialize(peb);
1573
1574 /* Browse to the desktop by passing an IShellFolder */
1575 hr = SHGetDesktopFolder(&psf);
1576 ok(hr == S_OK, "Got 0x%08x\n", hr);
1577 if(SUCCEEDED(hr))
1578 {
1579 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1580 ok(hr == S_OK, "got (0x%08x)\n", hr);
1581 if(hr == S_OK) process_msgs();
1582
1583 IShellFolder_Release(psf);
1584 }
1585
1586 /* Browse to the current directory by passing a ShellItem */
1587 hr = pSHCreateShellItem(NULL, NULL, pidl_current, &psi);
1588 ok(hr == S_OK, "Got 0x%08x\n", hr);
1589 if(SUCCEEDED(hr))
1590 {
1591 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psi, SBSP_DEFBROWSER);
1592 ok(hr == S_OK, "got (0x%08x)\n", hr);
1593 process_msgs();
1594
1595 IShellItem_Release(psi);
1596 }
1597
1598 IExplorerBrowser_Destroy(peb);
1599 lres = IExplorerBrowser_Release(peb);
1600 ok(lres == 0, "Got lres %d\n", lres);
1601
1602 /* Cleanup */
1603 RemoveDirectoryW(child_path);
1604 ILFree(pidl_current);
1605 ILFree(pidl_child);
1606 }
1607
1608 static void test_GetCurrentView(void)
1609 {
1610 IExplorerBrowser *peb;
1611 IUnknown *punk;
1612 HRESULT hr;
1613
1614 /* GetCurrentView */
1615 ebrowser_instantiate(&peb);
1616
1617 if(0)
1618 {
1619 /* Crashes under Windows 7 */
1620 IExplorerBrowser_GetCurrentView(peb, NULL, NULL);
1621 }
1622 hr = IExplorerBrowser_GetCurrentView(peb, NULL, (void**)&punk);
1623 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1624
1625 #define test_gcv(iid, exp) \
1626 do { \
1627 hr = IExplorerBrowser_GetCurrentView(peb, &iid, (void**)&punk); \
1628 ok(hr == exp, "(%s:)Expected (0x%08x), got: (0x%08x)\n", \
1629 #iid ,exp, hr); \
1630 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
1631 } while(0)
1632
1633 test_gcv(IID_IUnknown, E_FAIL);
1634 test_gcv(IID_IUnknown, E_FAIL);
1635 test_gcv(IID_IShellView, E_FAIL);
1636 test_gcv(IID_IShellView2, E_FAIL);
1637 test_gcv(IID_IFolderView, E_FAIL);
1638 test_gcv(IID_IPersistFolder, E_FAIL);
1639 test_gcv(IID_IPersistFolder2, E_FAIL);
1640 test_gcv(IID_ICommDlgBrowser, E_FAIL);
1641 test_gcv(IID_ICommDlgBrowser2, E_FAIL);
1642 test_gcv(IID_ICommDlgBrowser3, E_FAIL);
1643
1644 ebrowser_initialize(peb);
1645 ebrowser_browse_to_desktop(peb);
1646
1647 test_gcv(IID_IUnknown, S_OK);
1648 test_gcv(IID_IUnknown, S_OK);
1649 test_gcv(IID_IShellView, S_OK);
1650 test_gcv(IID_IShellView2, S_OK);
1651 test_gcv(IID_IFolderView, S_OK);
1652 todo_wine test_gcv(IID_IPersistFolder, S_OK);
1653 test_gcv(IID_IPersistFolder2, E_NOINTERFACE);
1654 test_gcv(IID_ICommDlgBrowser, E_NOINTERFACE);
1655 test_gcv(IID_ICommDlgBrowser2, E_NOINTERFACE);
1656 test_gcv(IID_ICommDlgBrowser3, E_NOINTERFACE);
1657
1658 #undef test_gcv
1659
1660 IExplorerBrowser_Destroy(peb);
1661 IExplorerBrowser_Release(peb);
1662 }
1663
1664 static void test_InputObject(void)
1665 {
1666 IExplorerBrowser *peb;
1667 IShellFolder *psf;
1668 IInputObject *pio;
1669 HRESULT hr;
1670 RECT rc;
1671 UINT i;
1672 WPARAM supported_key_accels_mode1[] = {
1673 VK_BACK, VK_TAB, VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
1674 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
1675 VK_F5, VK_F6, VK_F10, 0 };
1676 WPARAM supported_key_accels_mode2[] = {
1677 VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
1678 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
1679 VK_F10, 0 };
1680 WPARAM *key_accels;
1681 MSG msg_a = {
1682 hwnd,
1683 WM_KEYDOWN,
1684 VK_F5, 0,
1685 GetTickCount(),
1686 {5, 2}
1687 };
1688
1689 ebrowser_instantiate(&peb);
1690 hr = IExplorerBrowser_QueryInterface(peb, &IID_IInputObject, (void**)&pio);
1691 ok(hr == S_OK, "Got 0x%08x\n", hr);
1692 if(FAILED(hr))
1693 {
1694 win_skip("IInputObject not supported.\n");
1695 return;
1696 }
1697
1698 /* Before initializing */
1699 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1700 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1701
1702 hr = IInputObject_HasFocusIO(pio);
1703 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1704
1705 hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1706 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1707
1708 hr = IInputObject_HasFocusIO(pio);
1709 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1710
1711 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1712 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1713
1714 SetRect(&rc, 0, 0, 100, 100);
1715 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
1716 ok(hr == S_OK, "Got 0x%08x\n", hr);
1717
1718 hr = IInputObject_HasFocusIO(pio);
1719 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1720
1721 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1722 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1723
1724 /* Browse to the desktop */
1725 SHGetDesktopFolder(&psf);
1726 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1727 ok(hr == S_OK, "Got 0x%08x\n", hr);
1728 IShellFolder_Release(psf);
1729
1730 hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1731 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1732
1733 hr = IInputObject_HasFocusIO(pio);
1734 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1735
1736 hr = IInputObject_UIActivateIO(pio, FALSE, &msg_a);
1737 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1738
1739 hr = IInputObject_HasFocusIO(pio);
1740 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1741
1742 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1743 if(hr == S_OK)
1744 key_accels = supported_key_accels_mode1;
1745 else
1746 key_accels = supported_key_accels_mode2;
1747
1748 for(i = 0; i < 0x100; i++)
1749 {
1750 BOOL found = FALSE;
1751 UINT j;
1752 for(j = 0; key_accels[j] != 0; j++)
1753 if(key_accels[j] == i)
1754 {
1755 found = TRUE;
1756 break;
1757 }
1758
1759 msg_a.wParam = i;
1760 process_msgs();
1761 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1762 todo_wine ok(hr == (found ? S_OK : S_FALSE), "Got 0x%08x (%04x)\n", hr, i);
1763 if(i == VK_F5)
1764 Sleep(1000); /* Needed for w2k8 (64bit) */
1765 }
1766
1767 process_msgs();
1768
1769 IInputObject_Release(pio);
1770 IExplorerBrowser_Destroy(peb);
1771 IExplorerBrowser_Release(peb);
1772 }
1773
1774 static BOOL test_instantiate_control(void)
1775 {
1776 IExplorerBrowser *peb;
1777 HRESULT hr;
1778
1779 hr = ebrowser_instantiate(&peb);
1780 ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got (0x%08x)\n", hr);
1781 if(FAILED(hr))
1782 return FALSE;
1783
1784 IExplorerBrowser_Release(peb);
1785 return TRUE;
1786 }
1787
1788 static void setup_window(void)
1789 {
1790 WNDCLASSW wc;
1791 static const WCHAR ebtestW[] = {'e','b','t','e','s','t',0};
1792
1793 ZeroMemory(&wc, sizeof(WNDCLASSW));
1794 wc.lpfnWndProc = DefWindowProcW;
1795 wc.lpszClassName = ebtestW;
1796 RegisterClassW(&wc);
1797 hwnd = CreateWindowExW(0, ebtestW, NULL, 0,
1798 0, 0, 500, 500,
1799 NULL, 0, 0, NULL);
1800 ok(hwnd != NULL, "Failed to create window for tests.\n");
1801 }
1802
1803 START_TEST(ebrowser)
1804 {
1805 OleInitialize(NULL);
1806
1807 if(!test_instantiate_control())
1808 {
1809 win_skip("No ExplorerBrowser control..\n");
1810 OleUninitialize();
1811 return;
1812 }
1813
1814 setup_window();
1815 init_function_pointers();
1816
1817 test_QueryInterface();
1818 test_SB_misc();
1819 test_initialization();
1820 test_basics();
1821 test_Advise();
1822 test_navigation();
1823 test_GetCurrentView();
1824 test_SetSite();
1825 test_InputObject();
1826
1827 DestroyWindow(hwnd);
1828 OleUninitialize();
1829 }