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