57f52c9ec22d15d05b453619936cdcc52a396896
[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 (%d, %d)-(%d, %d)\n",
822 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
823
824 GetWindowRect(eb_hwnd, &eb_rc);
825 ok(eb_rc.right - eb_rc.left == 50, "Got window width %d\n", eb_rc.right - eb_rc.left);
826 ok(eb_rc.bottom - eb_rc.top == 60, "Got window height %d\n", eb_rc.bottom - eb_rc.top);
827
828 buf[0] = '\0';
829 GetClassNameA(eb_hwnd, buf, 1024);
830 ok(!lstrcmpA(buf, "ExplorerBrowserControl"), "Unexpected classname %s\n", buf);
831
832 expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER;
833 style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
834 todo_wine ok(style == expected_style, "Got style 0x%08x, expected 0x%08x\n", style, expected_style);
835
836 expected_style = WS_EX_CONTROLPARENT;
837 style = GetWindowLongPtrW(eb_hwnd, GWL_EXSTYLE);
838 ok(style == expected_style, "Got exstyle 0x%08x, expected 0x%08x\n", style, expected_style);
839
840 ok(GetParent(eb_hwnd) == hwnd, "GetParent returns %p\n", GetParent(eb_hwnd));
841
842 /* ::Destroy() destroys the window. */
843 ok(IsWindow(eb_hwnd), "eb_hwnd invalid.\n");
844 IExplorerBrowser_Destroy(peb);
845 ok(!IsWindow(eb_hwnd), "eb_hwnd valid.\n");
846
847 IShellBrowser_Release(psb);
848 lres = IExplorerBrowser_Release(peb);
849 ok(lres == 0, "Got refcount %d\n", lres);
850 }
851 else
852 {
853 skip("Skipping some tests.\n");
854
855 IExplorerBrowser_Destroy(peb);
856 lres = IExplorerBrowser_Release(peb);
857 ok(lres == 0, "Got refcount %d\n", lres);
858 }
859
860 /* check window style with EBO_NOBORDER */
861 ebrowser_instantiate(&peb);
862 hr = IExplorerBrowser_SetOptions(peb, EBO_NOBORDER);
863 ok(hr == S_OK, "got 0x%08x\n", hr);
864 SetRect(&rc, 50, 20, 100, 80);
865
866 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
867 ok(hr == S_OK, "got (0x%08x)\n", hr);
868
869 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
870 ok(hr == S_OK, "Got 0x%08x\n", hr);
871
872 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
873 ok(hr == S_OK, "Got 0x%08x\n", hr);
874
875 style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
876 ok(!(style & WS_BORDER) || broken(style & WS_BORDER) /* before win8 */, "got style 0x%08x\n", style);
877
878 IShellBrowser_Release(psb);
879 IExplorerBrowser_Destroy(peb);
880 IExplorerBrowser_Release(peb);
881
882 /* empty rectangle */
883 ebrowser_instantiate(&peb);
884 SetRectEmpty(&rc);
885 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
886 ok(hr == S_OK, "got (0x%08x)\n", hr);
887 IExplorerBrowser_Destroy(peb);
888 lres = IExplorerBrowser_Release(peb);
889 ok(lres == 0, "Got refcount %d\n", lres);
890
891 ebrowser_instantiate(&peb);
892 SetRect(&rc, -1, -1, 1, 1);
893 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
894 ok(hr == S_OK, "got (0x%08x)\n", hr);
895 IExplorerBrowser_Destroy(peb);
896 lres = IExplorerBrowser_Release(peb);
897 ok(lres == 0, "Got refcount %d\n", lres);
898
899 ebrowser_instantiate(&peb);
900 SetRect(&rc, 10, 10, 5, 5);
901 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
902 ok(hr == S_OK, "got (0x%08x)\n", hr);
903 IExplorerBrowser_Destroy(peb);
904 lres = IExplorerBrowser_Release(peb);
905 ok(lres == 0, "Got refcount %d\n", lres);
906
907 ebrowser_instantiate(&peb);
908 SetRect(&rc, 10, 10, 5, 5);
909 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
910 ok(hr == S_OK, "got (0x%08x)\n", hr);
911 IExplorerBrowser_Destroy(peb);
912 lres = IExplorerBrowser_Release(peb);
913 ok(lres == 0, "Got refcount %d\n", lres);
914 }
915
916 static void test_SetSite(void)
917 {
918 IExplorerBrowser *peb;
919 IServiceProviderImpl *spimpl = create_serviceprovider();
920 ICommDlgBrowser3Impl *cdbimpl = create_commdlgbrowser3();
921 IExplorerPaneVisibilityImpl *epvimpl = create_explorerpanevisibility();
922 IObjectWithSite *pow;
923 HRESULT hr;
924 LONG ref;
925 UINT i;
926 struct services expected[] = {
927 /* Win 7 */
928 { &SID_STopLevelBrowser, &IID_ICommDlgBrowser2, 0, cdbimpl },
929 { &SID_STopLevelBrowser, &IID_IShellBrowserService, 0, NULL },
930 { &SID_STopLevelBrowser, &IID_IShellBrowser, 0, NULL },
931 { &SID_STopLevelBrowser, &IID_UnknownInterface8, 0, NULL },
932 { &SID_STopLevelBrowser, &IID_IConnectionPointContainer, 0, NULL },
933 { &SID_STopLevelBrowser, &IID_IProfferService, 0, NULL },
934 { &SID_STopLevelBrowser, &IID_UnknownInterface9, 0, NULL },
935 { &SID_ExplorerPaneVisibility, &IID_IExplorerPaneVisibility, 0, epvimpl },
936 { &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser2, 0, cdbimpl },
937 { &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser3, 0, cdbimpl },
938 { &IID_IFileDialogPrivate, &IID_IFileDialogPrivate, 0, NULL },
939 { &IID_IFileDialogPrivate, &IID_IFileDialog, 0, NULL },
940 { &IID_IShellTaskScheduler, &IID_IShellTaskScheduler, 0, NULL },
941 { &IID_IShellTaskScheduler, &IID_UnknownInterface2, 0, NULL },
942 { &IID_IWebbrowserApp, &IID_IConnectionPointContainer, 0, NULL },
943 { &IID_IFolderView, &IID_IFolderView, 0, NULL },
944 { &IID_ILayoutModifier, &IID_ILayoutModifier, 0, NULL },
945 { &IID_IBrowserSettings, &IID_IBrowserSettings, 0, NULL },
946 { &CLSID_Desktop, &IID_IUnknown, 0, NULL },
947 { &IID_UnknownInterface1, &IID_UnknownInterface1, 0, NULL },
948 { &IID_UnknownInterface3, &IID_UnknownInterface3, 0, NULL },
949 { &IID_UnknownInterface4, &IID_IUnknown, 0, NULL },
950 { &IID_UnknownInterface6, &IID_UnknownInterface7, 0, NULL },
951 { &IID_IBrowserWithActivationNotification, &IID_IBrowserWithActivationNotification, 0, NULL },
952 /* Win 8 */
953 { &IID_ICommDlgBrowser, &IID_UnknownInterface11, 0, NULL },
954 { &IID_ICommDlgBrowser, &IID_UnknownInterface12, 0, NULL },
955 { &IID_ICommDlgBrowser, &IID_UnknownInterface20, 0, NULL },
956 { &IID_UnknownInterface13, &IID_IUnknown, 0, NULL },
957 { &IID_UnknownInterface13, &IID_UnknownInterface13, 0, NULL },
958 { &IID_UnknownInterface13, &IID_UnknownInterface18, 0, NULL },
959 { &IID_UnknownInterface14, &IID_UnknownInterface14, 0, NULL },
960 { &IID_UnknownInterface15, &IID_UnknownInterface15, 0, NULL },
961 { &IID_UnknownInterface16, &IID_UnknownInterface16, 0, NULL },
962 { &IID_UnknownInterface17, &IID_UnknownInterface17, 0, NULL },
963 { &IID_UnknownInterface17, &IID_UnknownInterface19, 0, NULL },
964
965 /* Other services requested in Vista, Windows 2008 but not in Windows 7 */
966 { &IID_IBrowserSettings_Vista, &IID_IBrowserSettings_Vista, 0, NULL },
967 { &IID_IFolderTypeModifier, &IID_IFolderTypeModifier, 0, NULL },
968 { &SID_STopLevelBrowser, &IID_IShellBrowserService_Vista, 0, NULL },
969 { &IID_UnknownInterface5, &IID_UnknownInterface5, 0, NULL },
970 { &IID_ICommDlgBrowser, &IID_ICommDlgBrowser, 0, cdbimpl },
971 { &IID_IFileDialogPrivate_Vista,&IID_IFileDialogPrivate_Vista, 0, NULL},
972 { &IID_IFileDialogPrivate_Vista,&IID_IFileDialog, 0, NULL},
973 { &IID_UnknownInterface10, &IID_IHTMLDocument2, 0, NULL},
974 { &SID_SMenuBandParent, &IID_IOleCommandTarget, 0, NULL},
975 { &SID_SMenuBandParent, &IID_IShellMenu, 0, NULL},
976 { &SID_STopLevelBrowser, &IID_IOleWindow, 0, NULL},
977 { &SID_SMenuPopup, &IID_IOleCommandTarget, 0, NULL},
978 { NULL }
979 };
980
981 ebrowser_instantiate(&peb);
982 IExplorerBrowser_SetOptions(peb, EBO_SHOWFRAMES);
983
984 hr = IExplorerBrowser_QueryInterface(peb, &IID_IObjectWithSite, (void**)&pow);
985 ok(hr == S_OK, "Got 0x%08x\n", hr);
986 if(SUCCEEDED(hr))
987 {
988 spimpl->interfaces = expected;
989
990 hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
991 ok(hr == S_OK, "Got 0x%08x\n", hr);
992
993 if(FAILED(hr))
994 IObjectWithSite_Release(pow);
995 }
996
997 if(FAILED(hr))
998 {
999 skip("Failed to set site.\n");
1000
1001 IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1002 ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
1003 IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
1004 IExplorerBrowser_Destroy(peb);
1005 ref = IExplorerBrowser_Release(peb);
1006 ok(ref == 0, "Got ref %d\n", ref);
1007
1008 return;
1009 }
1010
1011 ShowWindow(hwnd, TRUE);
1012 ebrowser_initialize(peb);
1013 ebrowser_browse_to_desktop(peb);
1014
1015 for(i = 0; i < 10; i++)
1016 {
1017 Sleep(100);
1018 process_msgs();
1019 }
1020 ShowWindow(hwnd, FALSE);
1021
1022 /* ICommDlgBrowser3 */
1023 ok(!cdbimpl->OnDefaultCommand, "Got %d\n", cdbimpl->OnDefaultCommand);
1024 todo_wine ok(cdbimpl->OnStateChange, "Got %d\n", cdbimpl->OnStateChange);
1025 ok(cdbimpl->IncludeObject, "Got %d\n", cdbimpl->IncludeObject);
1026 ok(!cdbimpl->Notify, "Got %d\n", cdbimpl->Notify);
1027 ok(!cdbimpl->GetDefaultMenuText, "Got %d\n", cdbimpl->GetDefaultMenuText);
1028 todo_wine ok(cdbimpl->GetViewFlags, "Got %d\n", cdbimpl->GetViewFlags);
1029 ok(!cdbimpl->OnColumnClicked, "Got %d\n", cdbimpl->OnColumnClicked);
1030 ok(!cdbimpl->GetCurrentFilter, "Got %d\n", cdbimpl->GetCurrentFilter);
1031 todo_wine ok(cdbimpl->OnPreviewCreated, "Got %d\n", cdbimpl->OnPreviewCreated);
1032
1033 /* IExplorerPaneVisibility */
1034 ok(epvimpl->np, "Got %d\n", epvimpl->np);
1035 todo_wine ok(epvimpl->cp, "Got %d\n", epvimpl->cp);
1036 todo_wine ok(epvimpl->cp_o, "Got %d\n", epvimpl->cp_o);
1037 todo_wine ok(epvimpl->cp_v, "Got %d\n", epvimpl->cp_v);
1038 todo_wine ok(epvimpl->dp, "Got %d\n", epvimpl->dp);
1039 todo_wine ok(epvimpl->pp, "Got %d\n", epvimpl->pp);
1040 ok(!epvimpl->qp, "Got %d\n", epvimpl->qp);
1041 ok(!epvimpl->aqp, "Got %d\n", epvimpl->aqp);
1042 ok(!epvimpl->unk, "Got %d\n", epvimpl->unk);
1043
1044 if(0)
1045 {
1046 for(i = 0; expected[i].service != NULL; i++)
1047 if(!expected[i].count) trace("count %d was 0.\n", i);
1048 }
1049
1050 /* Test when IServiceProvider is released. */
1051 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1052 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1053 ok(ref == 2, "Got ref %d\n", ref);
1054
1055 hr = IObjectWithSite_SetSite(pow, NULL);
1056 ok(hr == S_OK, "Got 0x%08x\n", hr);
1057
1058 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1059 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1060 ok(ref == 1, "Got ref %d\n", ref);
1061
1062 hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
1063 ok(hr == S_OK, "Got 0x%08x\n", hr);
1064
1065 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1066 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1067 ok(ref == 2, "Got ref %d\n", ref);
1068
1069 IExplorerBrowser_Destroy(peb);
1070
1071 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1072 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1073 ok(ref == 2, "Got ref %d\n", ref);
1074
1075 IObjectWithSite_Release(pow);
1076 ref = IExplorerBrowser_Release(peb);
1077 ok(ref == 0, "Got ref %d\n", ref);
1078
1079 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1080 ok(ref == 0, "Got ref %d\n", ref);
1081
1082 ref = ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
1083 ok(ref == 0, "Got ref %d\n", ref);
1084 ref = IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
1085 ok(ref == 0, "Got ref %d\n", ref);
1086 }
1087
1088 static void test_basics(void)
1089 {
1090 IExplorerBrowser *peb;
1091 IShellBrowser *psb;
1092 FOLDERSETTINGS fs;
1093 ULONG lres;
1094 DWORD flags;
1095 HDWP hdwp;
1096 RECT rc;
1097 HRESULT hr;
1098 static const WCHAR winetest[] = {'W','i','n','e','T','e','s','t',0};
1099
1100 ebrowser_instantiate(&peb);
1101 ebrowser_initialize(peb);
1102
1103 /* SetRect */
1104 SetRectEmpty(&rc);
1105 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1106 ok(hr == S_OK, "got (0x%08x)\n", hr);
1107
1108 SetRect(&rc, 100, 100, 10, 10);
1109 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1110 ok(hr == S_OK, "got (0x%08x)\n", hr);
1111
1112 /* SetRect with DeferWindowPos */
1113 SetRect(&rc, 0, 0, 10, 10);
1114 hdwp = BeginDeferWindowPos(1);
1115 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1116 ok(hr == S_OK, "got (0x%08x)\n", hr);
1117 lres = EndDeferWindowPos(hdwp);
1118 ok(lres, "EndDeferWindowPos failed.\n");
1119
1120 hdwp = NULL;
1121 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1122 ok(hr == S_OK, "got (0x%08x)\n", hr);
1123 ok(hdwp == NULL, "got %p\n", hdwp);
1124 lres = EndDeferWindowPos(hdwp);
1125 ok(!lres, "EndDeferWindowPos succeeded unexpectedly.\n");
1126
1127 /* Test positioning */
1128 SetRect(&rc, 10, 20, 50, 50);
1129 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1130 ok(hr == S_OK, "got (0x%08x)\n", hr);
1131 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1132 ok(hr == S_OK, "Got 0x%08x\n", hr);
1133 if(SUCCEEDED(hr))
1134 {
1135 HWND eb_hwnd;
1136 RECT eb_rc;
1137 static const RECT exp_rc = {11, 21, 49, 49};
1138 static const RECT exp_rc2 = {11, 21, 49, 24};
1139
1140 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
1141 ok(hr == S_OK, "Got 0x%08x\n", hr);
1142
1143 GetClientRect(eb_hwnd, &eb_rc);
1144 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1145 ok(EqualRect(&eb_rc, &exp_rc), "Got rect (%d, %d) - (%d, %d)\n",
1146 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
1147
1148 /* Try resizing with invalid hdwp */
1149 rc.bottom = 25;
1150 hdwp = (HDWP)0xdeadbeef;
1151 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1152 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1153 GetClientRect(eb_hwnd, &eb_rc);
1154 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1155 ok(EqualRect(&eb_rc, &exp_rc), "Got rect (%d, %d) - (%d, %d)\n",
1156 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
1157
1158 hdwp = NULL;
1159 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1160 ok(hr == S_OK, "Got 0x%08x\n", hr);
1161 GetClientRect(eb_hwnd, &eb_rc);
1162 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1163 ok(EqualRect(&eb_rc, &exp_rc2), "Got rect (%d, %d) - (%d, %d)\n",
1164 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
1165
1166 IShellBrowser_Release(psb);
1167 }
1168
1169 IExplorerBrowser_Destroy(peb);
1170 IExplorerBrowser_Release(peb);
1171
1172 /* GetOptions/SetOptions*/
1173 ebrowser_instantiate(&peb);
1174
1175 if(0) {
1176 /* Crashes on Windows 7 */
1177 IExplorerBrowser_GetOptions(peb, NULL);
1178 }
1179
1180 hr = IExplorerBrowser_GetOptions(peb, &flags);
1181 ok(hr == S_OK, "got (0x%08x)\n", hr);
1182 ok(flags == 0, "got (0x%08x)\n", flags);
1183
1184 /* Settings preserved through Initialize. */
1185 hr = IExplorerBrowser_SetOptions(peb, 0xDEADBEEF);
1186 ok(hr == S_OK, "got (0x%08x)\n", hr);
1187
1188 ebrowser_initialize(peb);
1189
1190 hr = IExplorerBrowser_GetOptions(peb, &flags);
1191 ok(flags == 0xDEADBEEF, "got (0x%08x)\n", flags);
1192 ok(hr == S_OK, "got (0x%08x)\n", hr);
1193
1194 IExplorerBrowser_Destroy(peb);
1195 IExplorerBrowser_Release(peb);
1196
1197 ebrowser_instantiate(&peb);
1198 ebrowser_initialize(peb);
1199
1200 /* SetFolderSettings */
1201 hr = IExplorerBrowser_SetFolderSettings(peb, NULL);
1202 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1203 fs.ViewMode = 0; fs.fFlags = 0;
1204 hr = IExplorerBrowser_SetFolderSettings(peb, &fs);
1205 todo_wine ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1206
1207 /* SetPropertyBag */
1208 hr = IExplorerBrowser_SetPropertyBag(peb, NULL);
1209 ok(hr == E_INVALIDARG, "Got 0x%08x\n", hr);
1210 hr = IExplorerBrowser_SetPropertyBag(peb, winetest);
1211 ok(hr == S_OK, "Got 0x%08x\n", hr);
1212
1213 /* TODO: Test after browsing somewhere. */
1214
1215 IExplorerBrowser_Destroy(peb);
1216 lres = IExplorerBrowser_Release(peb);
1217 ok(lres == 0, "Got %d\n", lres);
1218 }
1219
1220 static void test_Advise(void)
1221 {
1222 IExplorerBrowser *peb;
1223 IExplorerBrowserEvents *pebe;
1224 DWORD cookies[10];
1225 HRESULT hr;
1226 UINT i, ref;
1227
1228 /* Set up our IExplorerBrowserEvents implementation */
1229 ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1230 pebe = &ebev.IExplorerBrowserEvents_iface;
1231
1232 ebrowser_instantiate(&peb);
1233
1234 if(0)
1235 {
1236 /* Crashes on Windows 7 */
1237 IExplorerBrowser_Advise(peb, pebe, NULL);
1238 IExplorerBrowser_Advise(peb, NULL, &cookies[0]);
1239 }
1240
1241 /* Using Unadvise with a cookie that has yet to be given out
1242 * results in E_INVALIDARG */
1243 hr = IExplorerBrowser_Unadvise(peb, 11);
1244 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1245
1246 /* Add some before initialization */
1247 for(i = 0; i < 5; i++)
1248 {
1249 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1250 ok(hr == S_OK, "got (0x%08x)\n", hr);
1251 }
1252
1253 ebrowser_initialize(peb);
1254
1255 /* Add some after initialization */
1256 for(i = 5; i < 10; i++)
1257 {
1258 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1259 ok(hr == S_OK, "got (0x%08x)\n", hr);
1260 }
1261
1262 ok(ebev.ref == 10, "Got %d\n", ebev.ref);
1263
1264 ebev.completed = 0;
1265 ebrowser_browse_to_desktop(peb);
1266 process_msgs();
1267 ok(ebev.completed == 10, "Got %d\n", ebev.completed);
1268
1269 /* Remove a bunch somewhere in the middle */
1270 for(i = 4; i < 8; i++)
1271 {
1272 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1273 ok(hr == S_OK, "got (0x%08x)\n", hr);
1274 }
1275
1276 ebev.completed = 0;
1277 ebrowser_browse_to_desktop(peb);
1278 process_msgs();
1279 ok(ebev.completed == 6, "Got %d\n", ebev.completed);
1280
1281 if(0)
1282 {
1283 /* Using unadvise with a previously unadvised cookie results
1284 * in a crash. */
1285 IExplorerBrowser_Unadvise(peb, cookies[5]);
1286 }
1287
1288 /* Remove the rest. */
1289 for(i = 0; i < 10; i++)
1290 {
1291 if(i<4||i>7)
1292 {
1293 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1294 ok(hr == S_OK, "%d: got (0x%08x)\n", i, hr);
1295 }
1296 }
1297
1298 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
1299
1300 ebev.completed = 0;
1301 ebrowser_browse_to_desktop(peb);
1302 process_msgs();
1303 ok(ebev.completed == 0, "Got %d\n", ebev.completed);
1304
1305 /* ::Destroy implies ::Unadvise. */
1306 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[0]);
1307 ok(hr == S_OK, "Got 0x%08x\n", hr);
1308 ok(ebev.ref == 1, "Got %d\n", ebev.ref);
1309
1310 hr = IExplorerBrowser_Destroy(peb);
1311 ok(hr == S_OK, "Got 0x%08x\n", hr);
1312 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
1313
1314 ref = IExplorerBrowser_Release(peb);
1315 ok(!ref, "Got %d\n", ref);
1316 }
1317
1318 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
1319 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
1320 {
1321 size_t iLen;
1322
1323 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
1324 return NULL;
1325
1326 if (iLen)
1327 {
1328 lpszPath += iLen;
1329 if (lpszPath[-1] != '\\')
1330 {
1331 *lpszPath++ = '\\';
1332 *lpszPath = '\0';
1333 }
1334 }
1335 return lpszPath;
1336 }
1337
1338 static void test_browse_pidl_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
1339 LPITEMIDLIST pidl, UINT uFlags,
1340 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
1341 const char *file, int line)
1342 {
1343 HRESULT hr;
1344 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
1345
1346 hr = IExplorerBrowser_BrowseToIDList(peb, pidl, uFlags);
1347 ok_(file, line) (hr == hr_exp, "BrowseToIDList returned 0x%08x\n", hr);
1348 process_msgs();
1349
1350 ok_(file, line)
1351 (ebev->pending == pending && ebev->created == created &&
1352 ebev->failed == failed && ebev->completed == completed,
1353 "Events occurred: %d, %d, %d, %d\n",
1354 ebev->pending, ebev->created, ebev->failed, ebev->completed);
1355 }
1356 #define test_browse_pidl(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
1357 test_browse_pidl_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
1358
1359 static void test_browse_pidl_sb_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
1360 LPITEMIDLIST pidl, UINT uFlags,
1361 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
1362 const char *file, int line)
1363 {
1364 IShellBrowser *psb;
1365 HRESULT hr;
1366
1367 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1368 ok_(file, line) (hr == S_OK, "QueryInterface returned 0x%08x\n", hr);
1369 if(SUCCEEDED(hr))
1370 {
1371 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
1372
1373 hr = IShellBrowser_BrowseObject(psb, pidl, uFlags);
1374 ok_(file, line) (hr == hr_exp, "BrowseObject returned 0x%08x\n", hr);
1375 process_msgs();
1376
1377 ok_(file, line)
1378 (ebev->pending == pending && ebev->created == created &&
1379 ebev->failed == failed && ebev->completed == completed,
1380 "Events occurred: %d, %d, %d, %d\n",
1381 ebev->pending, ebev->created, ebev->failed, ebev->completed);
1382
1383 IShellBrowser_Release(psb);
1384 }
1385 }
1386 #define test_browse_pidl_sb(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
1387 test_browse_pidl_sb_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
1388
1389 static void test_navigation(void)
1390 {
1391 IExplorerBrowser *peb, *peb2;
1392 IFolderView *pfv;
1393 IShellItem *psi;
1394 IShellFolder *psf;
1395 LPITEMIDLIST pidl_current, pidl_child;
1396 DWORD cookie, cookie2;
1397 HRESULT hr;
1398 LONG lres;
1399 WCHAR current_path[MAX_PATH];
1400 WCHAR child_path[MAX_PATH];
1401 static const WCHAR testfolderW[] =
1402 {'w','i','n','e','t','e','s','t','f','o','l','d','e','r','\0'};
1403
1404 ok(pSHParseDisplayName != NULL, "pSHParseDisplayName unexpectedly missing.\n");
1405 ok(pSHCreateShellItem != NULL, "pSHCreateShellItem unexpectedly missing.\n");
1406
1407 GetCurrentDirectoryW(MAX_PATH, current_path);
1408 if(!current_path[0])
1409 {
1410 skip("Failed to create test-directory.\n");
1411 return;
1412 }
1413
1414 lstrcpyW(child_path, current_path);
1415 myPathAddBackslashW(child_path);
1416 lstrcatW(child_path, testfolderW);
1417
1418 CreateDirectoryW(child_path, NULL);
1419
1420 pSHParseDisplayName(current_path, NULL, &pidl_current, 0, NULL);
1421 pSHParseDisplayName(child_path, NULL, &pidl_child, 0, NULL);
1422
1423 ebrowser_instantiate(&peb);
1424 ebrowser_initialize(peb);
1425
1426 ebrowser_instantiate(&peb2);
1427 ebrowser_initialize(peb2);
1428
1429 /* Set up our IExplorerBrowserEvents implementation */
1430 ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1431
1432 IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1433 IExplorerBrowser_Advise(peb2, &ebev.IExplorerBrowserEvents_iface, &cookie2);
1434
1435 /* These should all fail */
1436 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1437 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1438 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
1439 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
1440 test_browse_pidl(peb, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1441 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1442 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1443 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1444 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
1445 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
1446 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1447 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1448
1449 /* "The first browse is synchronous" */
1450 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
1451 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
1452
1453 /* Navigate empty history */
1454 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
1455 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
1456 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
1457 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
1458
1459 /* Navigate history */
1460 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
1461 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
1462 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
1463 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
1464 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
1465 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
1466 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1467 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1468
1469 /* Relative navigation */
1470 test_browse_pidl(peb, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1471 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1472
1473 hr = IExplorerBrowser_GetCurrentView(peb, &IID_IFolderView, (void**)&pfv);
1474 ok(hr == S_OK, "Got 0x%08x\n", hr);
1475 if(SUCCEEDED(hr))
1476 {
1477 LPITEMIDLIST pidl_relative;
1478
1479 hr = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1480 ok(hr == S_OK, "Got 0x%08x\n", hr);
1481 hr = IShellFolder_ParseDisplayName(psf, NULL, NULL, (LPWSTR)testfolderW,
1482 NULL, &pidl_relative, NULL);
1483 ok(hr == S_OK, "Got 0x%08x\n", hr);
1484
1485 /* Browsing to another location here before using the
1486 * pidl_relative would make ExplorerBrowser in Windows 7 show a
1487 * not-available dialog. Also, passing a relative pidl without
1488 * specifying SBSP_RELATIVE makes it look for the pidl on the
1489 * desktop
1490 */
1491
1492 test_browse_pidl(peb, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
1493 test_browse_pidl_sb(peb2, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
1494
1495 ILFree(pidl_relative);
1496 IShellFolder_Release(psf);
1497 IFolderView_Release(pfv);
1498 }
1499
1500 /* misc **/
1501 test_browse_pidl(peb, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1502 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1503 test_browse_pidl(peb, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
1504 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
1505 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
1506 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
1507 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
1508 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
1509
1510 test_browse_pidl(peb, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
1511 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
1512 test_browse_pidl(peb, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
1513 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
1514
1515 /* SBSP_NEWBROWSER will return E_INVALIDARG, claims MSDN, but in
1516 * reality it works as one would expect (Windows 7 only?).
1517 */
1518 if(0)
1519 {
1520 IExplorerBrowser_BrowseToIDList(peb, NULL, SBSP_NEWBROWSER);
1521 }
1522
1523 hr = IExplorerBrowser_Unadvise(peb, cookie);
1524 ok(hr == S_OK, "Got 0x%08x\n", hr);
1525 IExplorerBrowser_Destroy(peb);
1526 process_msgs();
1527 hr = IExplorerBrowser_Unadvise(peb2, cookie2);
1528 ok(hr == S_OK, "Got 0x%08x\n", hr);
1529 IExplorerBrowser_Destroy(peb2);
1530 process_msgs();
1531
1532 /* Attempt browsing after destroyed */
1533 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
1534 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
1535
1536 lres = IExplorerBrowser_Release(peb);
1537 ok(lres == 0, "Got lres %d\n", lres);
1538 lres = IExplorerBrowser_Release(peb2);
1539 ok(lres == 0, "Got lres %d\n", lres);
1540
1541 /******************************************/
1542 /* Test some options that affect browsing */
1543
1544 ebrowser_instantiate(&peb);
1545 hr = IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1546 ok(hr == S_OK, "Got 0x%08x\n", hr);
1547 hr = IExplorerBrowser_SetOptions(peb, EBO_NAVIGATEONCE);
1548 ok(hr == S_OK, "got (0x%08x)\n", hr);
1549 ebrowser_initialize(peb);
1550
1551 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 1, 0, 1);
1552 test_browse_pidl(peb, &ebev, pidl_current, 0, E_FAIL, 0, 0, 0, 0);
1553
1554 hr = IExplorerBrowser_SetOptions(peb, 0);
1555 ok(hr == S_OK, "got (0x%08x)\n", hr);
1556
1557 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1558 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1559
1560 /* Difference in behavior lies where? */
1561 hr = IExplorerBrowser_SetOptions(peb, EBO_ALWAYSNAVIGATE);
1562 ok(hr == S_OK, "got (0x%08x)\n", hr);
1563
1564 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1565 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1566
1567 hr = IExplorerBrowser_Unadvise(peb, cookie);
1568 ok(hr == S_OK, "Got 0x%08x\n", hr);
1569
1570 IExplorerBrowser_Destroy(peb);
1571 lres = IExplorerBrowser_Release(peb);
1572 ok(lres == 0, "Got lres %d\n", lres);
1573
1574 /* BrowseToObject tests */
1575 ebrowser_instantiate(&peb);
1576 ebrowser_initialize(peb);
1577
1578 /* Browse to the desktop by passing an IShellFolder */
1579 hr = SHGetDesktopFolder(&psf);
1580 ok(hr == S_OK, "Got 0x%08x\n", hr);
1581 if(SUCCEEDED(hr))
1582 {
1583 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1584 ok(hr == S_OK, "got (0x%08x)\n", hr);
1585 if(hr == S_OK) process_msgs();
1586
1587 IShellFolder_Release(psf);
1588 }
1589
1590 /* Browse to the current directory by passing a ShellItem */
1591 hr = pSHCreateShellItem(NULL, NULL, pidl_current, &psi);
1592 ok(hr == S_OK, "Got 0x%08x\n", hr);
1593 if(SUCCEEDED(hr))
1594 {
1595 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psi, SBSP_DEFBROWSER);
1596 ok(hr == S_OK, "got (0x%08x)\n", hr);
1597 process_msgs();
1598
1599 IShellItem_Release(psi);
1600 }
1601
1602 IExplorerBrowser_Destroy(peb);
1603 lres = IExplorerBrowser_Release(peb);
1604 ok(lres == 0, "Got lres %d\n", lres);
1605
1606 /* Cleanup */
1607 RemoveDirectoryW(child_path);
1608 ILFree(pidl_current);
1609 ILFree(pidl_child);
1610 }
1611
1612 static void test_GetCurrentView(void)
1613 {
1614 IExplorerBrowser *peb;
1615 IUnknown *punk;
1616 HRESULT hr;
1617
1618 /* GetCurrentView */
1619 ebrowser_instantiate(&peb);
1620
1621 if(0)
1622 {
1623 /* Crashes under Windows 7 */
1624 IExplorerBrowser_GetCurrentView(peb, NULL, NULL);
1625 }
1626 hr = IExplorerBrowser_GetCurrentView(peb, NULL, (void**)&punk);
1627 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1628
1629 #define test_gcv(iid, exp) \
1630 do { \
1631 hr = IExplorerBrowser_GetCurrentView(peb, &iid, (void**)&punk); \
1632 ok(hr == exp, "(%s:)Expected (0x%08x), got: (0x%08x)\n", \
1633 #iid ,exp, hr); \
1634 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
1635 } while(0)
1636
1637 test_gcv(IID_IUnknown, E_FAIL);
1638 test_gcv(IID_IUnknown, E_FAIL);
1639 test_gcv(IID_IShellView, E_FAIL);
1640 test_gcv(IID_IShellView2, E_FAIL);
1641 test_gcv(IID_IFolderView, E_FAIL);
1642 test_gcv(IID_IPersistFolder, E_FAIL);
1643 test_gcv(IID_IPersistFolder2, E_FAIL);
1644 test_gcv(IID_ICommDlgBrowser, E_FAIL);
1645 test_gcv(IID_ICommDlgBrowser2, E_FAIL);
1646 test_gcv(IID_ICommDlgBrowser3, E_FAIL);
1647
1648 ebrowser_initialize(peb);
1649 ebrowser_browse_to_desktop(peb);
1650
1651 test_gcv(IID_IUnknown, S_OK);
1652 test_gcv(IID_IUnknown, S_OK);
1653 test_gcv(IID_IShellView, S_OK);
1654 test_gcv(IID_IShellView2, S_OK);
1655 test_gcv(IID_IFolderView, S_OK);
1656 todo_wine test_gcv(IID_IPersistFolder, S_OK);
1657 test_gcv(IID_IPersistFolder2, E_NOINTERFACE);
1658 test_gcv(IID_ICommDlgBrowser, E_NOINTERFACE);
1659 test_gcv(IID_ICommDlgBrowser2, E_NOINTERFACE);
1660 test_gcv(IID_ICommDlgBrowser3, E_NOINTERFACE);
1661
1662 #undef test_gcv
1663
1664 IExplorerBrowser_Destroy(peb);
1665 IExplorerBrowser_Release(peb);
1666 }
1667
1668 static void test_InputObject(void)
1669 {
1670 IExplorerBrowser *peb;
1671 IShellFolder *psf;
1672 IInputObject *pio;
1673 HRESULT hr;
1674 RECT rc;
1675 UINT i;
1676 WPARAM supported_key_accels_mode1[] = {
1677 VK_BACK, VK_TAB, 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_F5, VK_F6, VK_F10, 0 };
1680 WPARAM supported_key_accels_mode2[] = {
1681 VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
1682 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
1683 VK_F10, 0 };
1684 WPARAM *key_accels;
1685 MSG msg_a = {
1686 hwnd,
1687 WM_KEYDOWN,
1688 VK_F5, 0,
1689 GetTickCount(),
1690 {5, 2}
1691 };
1692
1693 ebrowser_instantiate(&peb);
1694 hr = IExplorerBrowser_QueryInterface(peb, &IID_IInputObject, (void**)&pio);
1695 ok(hr == S_OK, "Got 0x%08x\n", hr);
1696 if(FAILED(hr))
1697 {
1698 win_skip("IInputObject not supported.\n");
1699 return;
1700 }
1701
1702 /* Before initializing */
1703 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1704 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1705
1706 hr = IInputObject_HasFocusIO(pio);
1707 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1708
1709 hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1710 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1711
1712 hr = IInputObject_HasFocusIO(pio);
1713 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1714
1715 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1716 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1717
1718 SetRect(&rc, 0, 0, 100, 100);
1719 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
1720 ok(hr == S_OK, "Got 0x%08x\n", hr);
1721
1722 hr = IInputObject_HasFocusIO(pio);
1723 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1724
1725 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1726 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1727
1728 /* Browse to the desktop */
1729 SHGetDesktopFolder(&psf);
1730 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1731 ok(hr == S_OK, "Got 0x%08x\n", hr);
1732 IShellFolder_Release(psf);
1733
1734 hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1735 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1736
1737 hr = IInputObject_HasFocusIO(pio);
1738 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1739
1740 hr = IInputObject_UIActivateIO(pio, FALSE, &msg_a);
1741 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1742
1743 hr = IInputObject_HasFocusIO(pio);
1744 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1745
1746 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1747 if(hr == S_OK)
1748 key_accels = supported_key_accels_mode1;
1749 else
1750 key_accels = supported_key_accels_mode2;
1751
1752 for(i = 0; i < 0x100; i++)
1753 {
1754 BOOL found = FALSE;
1755 UINT j;
1756 for(j = 0; key_accels[j] != 0; j++)
1757 if(key_accels[j] == i)
1758 {
1759 found = TRUE;
1760 break;
1761 }
1762
1763 msg_a.wParam = i;
1764 process_msgs();
1765 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1766 todo_wine ok(hr == (found ? S_OK : S_FALSE), "Got 0x%08x (%04x)\n", hr, i);
1767 if(i == VK_F5)
1768 Sleep(1000); /* Needed for w2k8 (64bit) */
1769 }
1770
1771 process_msgs();
1772
1773 IInputObject_Release(pio);
1774 IExplorerBrowser_Destroy(peb);
1775 IExplorerBrowser_Release(peb);
1776 }
1777
1778 static BOOL test_instantiate_control(void)
1779 {
1780 IExplorerBrowser *peb;
1781 HRESULT hr;
1782
1783 hr = ebrowser_instantiate(&peb);
1784 ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got (0x%08x)\n", hr);
1785 if(FAILED(hr))
1786 return FALSE;
1787
1788 IExplorerBrowser_Release(peb);
1789 return TRUE;
1790 }
1791
1792 static void setup_window(void)
1793 {
1794 WNDCLASSW wc;
1795 static const WCHAR ebtestW[] = {'e','b','t','e','s','t',0};
1796
1797 ZeroMemory(&wc, sizeof(WNDCLASSW));
1798 wc.lpfnWndProc = DefWindowProcW;
1799 wc.lpszClassName = ebtestW;
1800 RegisterClassW(&wc);
1801 hwnd = CreateWindowExW(0, ebtestW, NULL, 0,
1802 0, 0, 500, 500,
1803 NULL, 0, 0, NULL);
1804 ok(hwnd != NULL, "Failed to create window for tests.\n");
1805 }
1806
1807 START_TEST(ebrowser)
1808 {
1809 OleInitialize(NULL);
1810
1811 if(!test_instantiate_control())
1812 {
1813 win_skip("No ExplorerBrowser control..\n");
1814 OleUninitialize();
1815 return;
1816 }
1817
1818 setup_window();
1819 init_function_pointers();
1820
1821 test_QueryInterface();
1822 test_SB_misc();
1823 test_initialization();
1824 test_basics();
1825 test_Advise();
1826 test_navigation();
1827 test_GetCurrentView();
1828 test_SetSite();
1829 test_InputObject();
1830
1831 DestroyWindow(hwnd);
1832 OleUninitialize();
1833 }