Release 1.6-rc2.
[wine/testsucceed.git] / dlls / shell32 / tests / ebrowser.c
blobc56dffba6c1c3521b26dc5098b48a5ff8f5c2f8c
1 /*
2 * Unit tests for the Explorer Browser control
4 * Copyright 2010 David Hedberg
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.
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.
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
21 #include <stdio.h>
23 #define COBJMACROS
24 #define CONST_VTABLE
26 #include "shlobj.h"
27 #include "shlwapi.h"
29 #include "wine/test.h"
31 #include "initguid.h"
32 #include "mshtml.h"
34 /**********************************************************************
35 * Some IIDs for test_SetSite.
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);
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, 0xa36a3ace, 0x8332, 0x45ce, 0xaa,0x29, 0x50,0x3c,0xb7,0x6b,0x25,0x87);
71 DEFINE_GUID(IID_UnknownInterface18, 0x3d5d8c60, 0x21e4, 0x4b03, 0x83,0xb8, 0xc7,0x3f,0x8c,0x94,0x00,0x78);
73 static HWND hwnd;
75 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
76 static HRESULT (WINAPI *pSHParseDisplayName)(LPCWSTR,IBindCtx*,LPITEMIDLIST*,SFGAOF,SFGAOF*);
78 static void init_function_pointers(void)
80 HMODULE hmod;
82 hmod = GetModuleHandleA("shell32.dll");
83 pSHCreateShellItem = (void*)GetProcAddress(hmod, "SHCreateShellItem");
84 pSHParseDisplayName = (void*)GetProcAddress(hmod, "SHParseDisplayName");
87 /*********************************************************************
88 * Some simple helpers
90 static HRESULT ebrowser_instantiate(IExplorerBrowser **peb)
92 return CoCreateInstance(&CLSID_ExplorerBrowser, NULL, CLSCTX_INPROC_SERVER,
93 &IID_IExplorerBrowser, (void**)peb);
96 static HRESULT ebrowser_initialize(IExplorerBrowser *peb)
98 RECT rc;
99 rc.top = rc.left = 0; rc.bottom = rc.right = 500;
100 return IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
103 static HRESULT ebrowser_browse_to_desktop(IExplorerBrowser *peb)
105 LPITEMIDLIST pidl_desktop;
106 HRESULT hr;
107 SHGetSpecialFolderLocation (hwnd, CSIDL_DESKTOP, &pidl_desktop);
108 hr = IExplorerBrowser_BrowseToIDList(peb, pidl_desktop, 0);
109 ILFree(pidl_desktop);
110 return hr;
113 /* Process some messages */
114 static void process_msgs(void)
116 MSG msg;
117 while(PeekMessage( &msg, NULL, 0, 0, PM_REMOVE))
119 TranslateMessage(&msg);
120 DispatchMessage(&msg);
124 static const char *debugstr_guid(REFIID riid)
126 static char buf[50];
128 if(!riid)
129 return "(null)";
131 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
132 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
133 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
134 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
136 return buf;
139 /*********************************************************************
140 * IExplorerBrowserEvents implementation
142 typedef struct {
143 IExplorerBrowserEvents IExplorerBrowserEvents_iface;
144 LONG ref;
145 UINT pending, created, completed, failed;
146 } IExplorerBrowserEventsImpl;
148 static IExplorerBrowserEventsImpl ebev;
150 static inline IExplorerBrowserEventsImpl *impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents *iface)
152 return CONTAINING_RECORD(iface, IExplorerBrowserEventsImpl, IExplorerBrowserEvents_iface);
155 static HRESULT WINAPI IExplorerBrowserEvents_fnQueryInterface(IExplorerBrowserEvents *iface,
156 REFIID riid, void **ppvObj)
158 ok(0, "Never called.\n");
159 return E_NOINTERFACE;
162 static ULONG WINAPI IExplorerBrowserEvents_fnAddRef(IExplorerBrowserEvents *iface)
164 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
165 return InterlockedIncrement(&This->ref);
168 static ULONG WINAPI IExplorerBrowserEvents_fnRelease(IExplorerBrowserEvents *iface)
170 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
171 return InterlockedDecrement(&This->ref);
174 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationPending(IExplorerBrowserEvents *iface,
175 PCIDLIST_ABSOLUTE pidlFolder)
177 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
178 This->pending++;
179 return S_OK;
182 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationComplete(IExplorerBrowserEvents *iface,
183 PCIDLIST_ABSOLUTE pidlFolder)
185 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
186 This->completed++;
187 return S_OK;
189 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationFailed(IExplorerBrowserEvents *iface,
190 PCIDLIST_ABSOLUTE pidlFolder)
192 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
193 This->failed++;
194 return S_OK;
196 static HRESULT WINAPI IExplorerBrowserEvents_fnOnViewCreated(IExplorerBrowserEvents *iface,
197 IShellView *psv)
199 IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
200 This->created++;
201 return S_OK;
204 static const IExplorerBrowserEventsVtbl ebevents =
206 IExplorerBrowserEvents_fnQueryInterface,
207 IExplorerBrowserEvents_fnAddRef,
208 IExplorerBrowserEvents_fnRelease,
209 IExplorerBrowserEvents_fnOnNavigationPending,
210 IExplorerBrowserEvents_fnOnViewCreated,
211 IExplorerBrowserEvents_fnOnNavigationComplete,
212 IExplorerBrowserEvents_fnOnNavigationFailed
215 /*********************************************************************
216 * IExplorerPaneVisibility implementation
218 typedef struct
220 IExplorerPaneVisibility IExplorerPaneVisibility_iface;
221 LONG ref;
222 LONG count;
223 LONG np, cp, cp_o, cp_v, dp, pp, qp, aqp, unk; /* The panes */
224 } IExplorerPaneVisibilityImpl;
226 static inline IExplorerPaneVisibilityImpl *impl_from_IExplorerPaneVisibility(IExplorerPaneVisibility *iface)
228 return CONTAINING_RECORD(iface, IExplorerPaneVisibilityImpl, IExplorerPaneVisibility_iface);
231 static HRESULT WINAPI IExplorerPaneVisibility_fnQueryInterface(IExplorerPaneVisibility *iface,
232 REFIID riid, LPVOID *ppvObj)
234 ok(0, "unexpected, %s\n", debugstr_guid(riid));
235 *ppvObj = NULL;
236 return E_NOINTERFACE;
239 static ULONG WINAPI IExplorerPaneVisibility_fnAddRef(IExplorerPaneVisibility *iface)
241 IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
242 return InterlockedIncrement(&This->ref);
245 static ULONG WINAPI IExplorerPaneVisibility_fnRelease(IExplorerPaneVisibility *iface)
247 IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
248 ULONG ref = InterlockedDecrement(&This->ref);
250 if(!ref)
251 HeapFree(GetProcessHeap(), 0, This);
253 return ref;
256 static HRESULT WINAPI IExplorerPaneVisibility_fnGetPaneState(IExplorerPaneVisibility *iface,
257 REFEXPLORERPANE ep,
258 EXPLORERPANESTATE *peps)
260 IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
261 This->count++;
263 ok(ep != NULL, "ep is NULL.\n");
264 ok(peps != NULL, "peps is NULL.\n");
265 ok(*peps == 0, "got %d\n", *peps);
267 *peps = EPS_FORCE;
268 if(IsEqualGUID(&EP_NavPane, ep)) This->np++;
269 else if(IsEqualGUID(&EP_Commands, ep)) This->cp++;
270 else if(IsEqualGUID(&EP_Commands_Organize, ep)) This->cp_o++;
271 else if(IsEqualGUID(&EP_Commands_View, ep)) This->cp_v++;
272 else if(IsEqualGUID(&EP_DetailsPane, ep)) This->dp++;
273 else if(IsEqualGUID(&EP_PreviewPane, ep)) This->pp++;
274 else if(IsEqualGUID(&EP_QueryPane, ep)) This->qp++;
275 else if(IsEqualGUID(&EP_AdvQueryPane, ep)) This->aqp++;
276 else
278 trace("Unknown explorer pane: %s\n", debugstr_guid(ep));
279 This->unk++;
282 return S_OK;
285 static const IExplorerPaneVisibilityVtbl epvvt =
287 IExplorerPaneVisibility_fnQueryInterface,
288 IExplorerPaneVisibility_fnAddRef,
289 IExplorerPaneVisibility_fnRelease,
290 IExplorerPaneVisibility_fnGetPaneState
293 static IExplorerPaneVisibilityImpl *create_explorerpanevisibility(void)
295 IExplorerPaneVisibilityImpl *epv;
297 epv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IExplorerPaneVisibilityImpl));
298 epv->IExplorerPaneVisibility_iface.lpVtbl = &epvvt;
299 epv->ref = 1;
301 return epv;
304 /*********************************************************************
305 * ICommDlgBrowser3 implementation
307 typedef struct
309 ICommDlgBrowser3 ICommDlgBrowser3_iface;
310 LONG ref;
311 UINT OnDefaultCommand, OnStateChange, IncludeObject;
312 UINT Notify, GetDefaultMenuText, GetViewFlags;
313 UINT OnColumnClicked, GetCurrentFilter, OnPreviewCreated;
314 } ICommDlgBrowser3Impl;
316 static inline ICommDlgBrowser3Impl *impl_from_ICommDlgBrowser3(ICommDlgBrowser3 *iface)
318 return CONTAINING_RECORD(iface, ICommDlgBrowser3Impl, ICommDlgBrowser3_iface);
321 static HRESULT WINAPI ICommDlgBrowser3_fnQueryInterface(ICommDlgBrowser3 *iface, REFIID riid, LPVOID *ppvObj)
323 ok(0, "unexpected %s\n", debugstr_guid(riid));
324 *ppvObj = NULL;
325 return E_NOINTERFACE;
328 static ULONG WINAPI ICommDlgBrowser3_fnAddRef(ICommDlgBrowser3 *iface)
330 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
331 return InterlockedIncrement(&This->ref);
334 static ULONG WINAPI ICommDlgBrowser3_fnRelease(ICommDlgBrowser3 *iface)
336 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
337 ULONG ref = InterlockedDecrement(&This->ref);
339 if(!ref)
340 HeapFree(GetProcessHeap(), 0, This);
342 return ref;
345 static HRESULT WINAPI ICommDlgBrowser3_fnOnDefaultCommand(ICommDlgBrowser3* iface, IShellView *shv)
347 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
348 This->OnDefaultCommand++;
349 return E_NOTIMPL;
352 static HRESULT WINAPI ICommDlgBrowser3_fnOnStateChange(
353 ICommDlgBrowser3* iface,
354 IShellView *shv,
355 ULONG uChange)
357 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
358 This->OnStateChange++;
359 return E_NOTIMPL;
362 static HRESULT WINAPI ICommDlgBrowser3_fnIncludeObject(
363 ICommDlgBrowser3* iface,
364 IShellView *shv,
365 LPCITEMIDLIST pidl)
367 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
368 This->IncludeObject++;
369 return S_OK;
372 static HRESULT WINAPI ICommDlgBrowser3_fnNotify(
373 ICommDlgBrowser3* iface,
374 IShellView *ppshv,
375 DWORD dwNotifyType)
377 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
378 This->Notify++;
379 return E_NOTIMPL;
382 static HRESULT WINAPI ICommDlgBrowser3_fnGetDefaultMenuText(
383 ICommDlgBrowser3* iface,
384 IShellView *ppshv,
385 LPWSTR pszText,
386 int cchMax)
388 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
389 This->GetDefaultMenuText++;
390 return E_NOTIMPL;
393 static HRESULT WINAPI ICommDlgBrowser3_fnGetViewFlags(
394 ICommDlgBrowser3* iface,
395 DWORD *pdwFlags)
397 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
398 This->GetViewFlags++;
399 return E_NOTIMPL;
402 static HRESULT WINAPI ICommDlgBrowser3_fnOnColumnClicked(
403 ICommDlgBrowser3* iface,
404 IShellView *ppshv,
405 int iColumn)
407 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
408 This->OnColumnClicked++;
409 return E_NOTIMPL;
412 static HRESULT WINAPI ICommDlgBrowser3_fnGetCurrentFilter(
413 ICommDlgBrowser3* iface,
414 LPWSTR pszFileSpec,
415 int cchFileSpec)
417 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
418 This->GetCurrentFilter++;
419 return E_NOTIMPL;
422 static HRESULT WINAPI ICommDlgBrowser3_fnOnPreviewCreated(
423 ICommDlgBrowser3* iface,
424 IShellView *ppshv)
426 ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
427 This->OnPreviewCreated++;
428 return E_NOTIMPL;
431 static const ICommDlgBrowser3Vtbl cdbvtbl =
433 ICommDlgBrowser3_fnQueryInterface,
434 ICommDlgBrowser3_fnAddRef,
435 ICommDlgBrowser3_fnRelease,
436 ICommDlgBrowser3_fnOnDefaultCommand,
437 ICommDlgBrowser3_fnOnStateChange,
438 ICommDlgBrowser3_fnIncludeObject,
439 ICommDlgBrowser3_fnNotify,
440 ICommDlgBrowser3_fnGetDefaultMenuText,
441 ICommDlgBrowser3_fnGetViewFlags,
442 ICommDlgBrowser3_fnOnColumnClicked,
443 ICommDlgBrowser3_fnGetCurrentFilter,
444 ICommDlgBrowser3_fnOnPreviewCreated
447 static ICommDlgBrowser3Impl *create_commdlgbrowser3(void)
449 ICommDlgBrowser3Impl *cdb;
451 cdb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ICommDlgBrowser3Impl));
452 cdb->ICommDlgBrowser3_iface.lpVtbl = &cdbvtbl;
453 cdb->ref = 1;
455 return cdb;
458 /*********************************************************************
459 * IServiceProvider Implementation
461 typedef struct {
462 IServiceProvider IServiceProvider_iface;
463 LONG ref;
464 struct services {
465 REFGUID service;
466 REFIID id;
467 int count;
468 void *punk;
469 } *interfaces;
470 } IServiceProviderImpl;
472 static inline IServiceProviderImpl *impl_from_IServiceProvider(IServiceProvider *iface)
474 return CONTAINING_RECORD(iface, IServiceProviderImpl, IServiceProvider_iface);
477 static HRESULT WINAPI IServiceProvider_fnQueryInterface(IServiceProvider *iface, REFIID riid, LPVOID *ppvObj)
479 *ppvObj = NULL;
480 if(IsEqualIID(riid, &IID_IServiceProvider))
482 *ppvObj = iface;
483 IServiceProvider_AddRef(iface);
484 return S_OK;
487 if(IsEqualIID(riid, &IID_IOleCommandTarget))
489 /* Windows Vista. */
490 return E_NOINTERFACE;
493 ok(0, "Unexpected interface requested, %s\n", debugstr_guid(riid));
494 return E_NOINTERFACE;
497 static ULONG WINAPI IServiceProvider_fnAddRef(IServiceProvider *iface)
499 IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
500 return InterlockedIncrement(&This->ref);
503 static ULONG WINAPI IServiceProvider_fnRelease(IServiceProvider *iface)
505 IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
506 LONG ref = InterlockedDecrement(&This->ref);
508 if(!ref)
509 HeapFree(GetProcessHeap(), 0, This);
511 return ref;
514 static HRESULT WINAPI IServiceProvider_fnQueryService(IServiceProvider *iface,
515 REFGUID guidService,
516 REFIID riid,
517 void **ppv)
519 IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
520 BOOL was_in_list = FALSE;
521 IUnknown *punk = NULL;
522 UINT i;
524 *ppv = NULL;
525 for(i = 0; This->interfaces[i].service != NULL; i++)
527 if(IsEqualGUID(This->interfaces[i].service, guidService) &&
528 IsEqualIID(This->interfaces[i].id, riid))
530 was_in_list = TRUE;
531 This->interfaces[i].count++;
532 punk = This->interfaces[i].punk;
533 break;
537 ok(was_in_list, "unknown service, serviceID: %s, riid: %s\n", debugstr_guid(guidService), debugstr_guid(riid));
539 /* Give back an interface, if any. */
540 if(punk)
542 *ppv = punk;
543 IUnknown_AddRef(punk);
544 return S_OK;
547 return E_NOINTERFACE;
550 static const IServiceProviderVtbl spvtbl =
552 IServiceProvider_fnQueryInterface,
553 IServiceProvider_fnAddRef,
554 IServiceProvider_fnRelease,
555 IServiceProvider_fnQueryService
558 static IServiceProviderImpl *create_serviceprovider(void)
560 IServiceProviderImpl *sp = HeapAlloc(GetProcessHeap(), 0, sizeof(IServiceProviderImpl));
561 sp->IServiceProvider_iface.lpVtbl = &spvtbl;
562 sp->ref = 1;
563 return sp;
566 static void test_QueryInterface(void)
568 IExplorerBrowser *peb;
569 IUnknown *punk;
570 HRESULT hr;
571 LONG lres;
573 hr = ebrowser_instantiate(&peb);
574 ok(hr == S_OK, "Got 0x%08x\n", hr);
576 #define test_qinterface(iid, exp) \
577 do { \
578 hr = IExplorerBrowser_QueryInterface(peb, &iid, (void**)&punk); \
579 ok(hr == exp, "(%s:)Expected (0x%08x), got (0x%08x)\n", \
580 #iid, exp, hr); \
581 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
582 } while(0)
584 test_qinterface(IID_IUnknown, S_OK);
585 test_qinterface(IID_IExplorerBrowser, S_OK);
586 test_qinterface(IID_IShellBrowser, S_OK);
587 todo_wine test_qinterface(IID_IOleWindow, S_OK);
588 test_qinterface(IID_ICommDlgBrowser, S_OK);
589 test_qinterface(IID_ICommDlgBrowser2, S_OK);
590 test_qinterface(IID_ICommDlgBrowser3, S_OK);
591 todo_wine test_qinterface(IID_IServiceProvider, S_OK);
592 test_qinterface(IID_IObjectWithSite, S_OK);
593 todo_wine test_qinterface(IID_IConnectionPointContainer, S_OK);
594 test_qinterface(IID_IOleObject, E_NOINTERFACE);
595 test_qinterface(IID_IViewObject, E_NOINTERFACE);
596 test_qinterface(IID_IViewObject2, E_NOINTERFACE);
597 test_qinterface(IID_IViewObjectEx, E_NOINTERFACE);
598 test_qinterface(IID_IConnectionPoint, E_NOINTERFACE);
599 test_qinterface(IID_IShellView, E_NOINTERFACE);
600 test_qinterface(IID_INameSpaceTreeControlEvents, E_NOINTERFACE);
602 #undef test_qinterface
604 lres = IExplorerBrowser_Release(peb);
605 ok(lres == 0, "Got %d\n", lres);
608 static void test_SB_misc(void)
610 IExplorerBrowser *peb;
611 IShellBrowser *psb;
612 IUnknown *punk;
613 HRESULT hr;
614 HWND retHwnd;
615 LRESULT lres;
616 LONG ref;
618 ebrowser_instantiate(&peb);
619 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
620 ok(hr == S_OK, "Got 0x%08x\n", hr);
621 if(FAILED(hr))
623 skip("Failed to get IShellBrowser interface.\n");
624 return;
627 /* Some unimplemented methods */
628 retHwnd = (HWND)0xdeadbeef;
629 hr = IShellBrowser_GetControlWindow(psb, FCW_TOOLBAR, &retHwnd);
630 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
631 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
633 retHwnd = (HWND)0xdeadbeef;
634 hr = IShellBrowser_GetControlWindow(psb, FCW_STATUS, &retHwnd);
635 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
636 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
638 retHwnd = (HWND)0xdeadbeef;
639 hr = IShellBrowser_GetControlWindow(psb, FCW_TREE, &retHwnd);
640 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
641 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
643 retHwnd = (HWND)0xdeadbeef;
644 hr = IShellBrowser_GetControlWindow(psb, FCW_PROGRESS, &retHwnd);
645 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
646 ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
648 /* ::InsertMenuSB */
649 hr = IShellBrowser_InsertMenusSB(psb, NULL, NULL);
650 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
652 /* ::RemoveMenusSB */
653 hr = IShellBrowser_RemoveMenusSB(psb, NULL);
654 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
656 /* ::SetMenuSB */
657 hr = IShellBrowser_SetMenuSB(psb, NULL, NULL, NULL);
658 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
660 /***** Before EB::Initialize *****/
662 /* ::GetWindow */
663 retHwnd = (HWND)0xDEADBEEF;
664 hr = IShellBrowser_GetWindow(psb, &retHwnd);
665 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
666 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
668 todo_wine
671 /* ::SendControlMsg */
672 lres = 0xDEADBEEF;
673 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
674 ok(hr == S_OK, "got (0x%08x)\n", hr);
675 ok(lres == 0, "lres was %ld\n", lres);
677 lres = 0xDEADBEEF;
678 hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, TB_CHECKBUTTON,
679 FCIDM_TB_SMALLICON, TRUE, &lres);
680 ok(hr == S_OK, "got (0x%08x)\n", hr);
681 ok(lres == 0, "lres was %ld\n", lres);
683 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
684 ok(hr == S_OK, "got (0x%08x)\n", hr);
686 hr = IShellBrowser_SendControlMsg(psb, FCW_TREE, 0, 0, 0, NULL);
687 ok(hr == S_OK, "got (0x%08x)\n", hr);
689 hr = IShellBrowser_SendControlMsg(psb, FCW_PROGRESS, 0, 0, 0, NULL);
690 ok(hr == S_OK, "got (0x%08x)\n", hr);
693 /* ::QueryActiveShellView */
694 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
695 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
697 /* Initialize ExplorerBrowser */
698 ebrowser_initialize(peb);
700 /***** After EB::Initialize *****/
702 /* ::GetWindow */
703 hr = IShellBrowser_GetWindow(psb, &retHwnd);
704 ok(hr == S_OK, "got (0x%08x)\n", hr);
705 ok(GetParent(retHwnd) == hwnd, "The HWND returned is not our child.\n");
707 todo_wine
709 /* ::SendControlMsg */
710 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
711 ok(hr == S_OK, "got (0x%08x)\n", hr);
713 lres = 0xDEADBEEF;
714 hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, 0, 0, 0, &lres);
715 ok(hr == S_OK, "got (0x%08x)\n", hr);
716 ok(lres == 0, "lres was %ld\n", lres);
718 lres = 0xDEADBEEF;
719 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
720 ok(hr == S_OK, "got (0x%08x)\n", hr);
721 ok(lres == 0, "lres was %ld\n", lres);
723 lres = 0xDEADBEEF;
724 hr = IShellBrowser_SendControlMsg(psb, 1234, 0, 0, 0, &lres);
725 ok(hr == S_OK, "got (0x%08x)\n", hr);
726 ok(lres == 0, "lres was %ld\n", lres);
728 /* Returns S_OK */
729 hr = IShellBrowser_SetStatusTextSB(psb, NULL);
730 ok(hr == S_OK, "got (0x%08x)\n", hr);
732 hr = IShellBrowser_ContextSensitiveHelp(psb, FALSE);
733 ok(hr == S_OK, "got (0x%08x)\n", hr);
735 hr = IShellBrowser_EnableModelessSB(psb, TRUE);
736 ok(hr == S_OK, "got (0x%08x)\n", hr);
738 hr = IShellBrowser_SetToolbarItems(psb, NULL, 1, 1);
739 ok(hr == S_OK, "got (0x%08x)\n", hr);
742 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
743 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
745 IShellBrowser_Release(psb);
746 IExplorerBrowser_Destroy(peb);
747 IExplorerBrowser_Release(peb);
749 /* Browse to the desktop. */
750 ebrowser_instantiate(&peb);
751 ebrowser_initialize(peb);
752 IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
754 process_msgs();
755 hr = ebrowser_browse_to_desktop(peb);
756 ok(hr == S_OK, "got (0x%08x)\n", hr);
757 process_msgs();
759 /****** After Browsing *****/
761 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
762 ok(hr == S_OK, "got (0x%08x)\n", hr);
763 if(SUCCEEDED(hr)) IUnknown_Release(punk);
765 IShellBrowser_Release(psb);
766 IExplorerBrowser_Destroy(peb);
767 ref = IExplorerBrowser_Release(peb);
768 ok(ref == 0, "Got %d\n", ref);
771 static void test_initialization(void)
773 IExplorerBrowser *peb;
774 IShellBrowser *psb;
775 HRESULT hr;
776 ULONG lres;
777 RECT rc;
779 ebrowser_instantiate(&peb);
781 if(0)
783 /* Crashes on Windows 7 */
784 IExplorerBrowser_Initialize(peb, NULL, NULL, NULL);
785 IExplorerBrowser_Initialize(peb, hwnd, NULL, NULL);
788 ZeroMemory(&rc, sizeof(RECT));
790 hr = IExplorerBrowser_Initialize(peb, NULL, &rc, NULL);
791 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
793 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
794 ok(hr == S_OK, "got (0x%08x)\n", hr);
796 /* Initialize twice */
797 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
798 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
800 hr = IExplorerBrowser_Destroy(peb);
801 ok(hr == S_OK, "got (0x%08x)\n", hr);
803 /* Initialize again */
804 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
805 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
807 /* Destroy again */
808 hr = IExplorerBrowser_Destroy(peb);
809 ok(hr == S_OK, "got (0x%08x)\n", hr);
810 lres = IExplorerBrowser_Release(peb);
811 ok(lres == 0, "Got %d\n", lres);
813 /* Initialize with a few different rectangles */
814 peb = NULL;
815 ebrowser_instantiate(&peb);
816 rc.left = 50; rc.top = 20; rc.right = 100; rc.bottom = 80;
817 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
818 ok(hr == S_OK, "got (0x%08x)\n", hr);
819 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
820 ok(hr == S_OK, "Got 0x%08x\n", hr);
821 if(SUCCEEDED(hr))
823 HWND eb_hwnd;
824 RECT eb_rc;
825 char buf[1024];
826 LONG style, expected_style;
827 static const RECT exp_rc = {0, 0, 48, 58};
829 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
830 ok(hr == S_OK, "Got 0x%08x\n", hr);
832 GetClientRect(eb_hwnd, &eb_rc);
833 ok(EqualRect(&eb_rc, &exp_rc), "Got client rect (%d, %d)-(%d, %d)\n",
834 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
836 GetWindowRect(eb_hwnd, &eb_rc);
837 ok(eb_rc.right - eb_rc.left == 50, "Got window width %d\n", eb_rc.right - eb_rc.left);
838 ok(eb_rc.bottom - eb_rc.top == 60, "Got window height %d\n", eb_rc.bottom - eb_rc.top);
840 buf[0] = '\0';
841 GetClassNameA(eb_hwnd, buf, 1024);
842 ok(!lstrcmpA(buf, "ExplorerBrowserControl"), "Unexpected classname %s\n", buf);
844 expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER;
845 style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
846 todo_wine ok(style == expected_style, "Got style 0x%08x, expected 0x%08x\n", style, expected_style);
848 expected_style = WS_EX_CONTROLPARENT;
849 style = GetWindowLongPtrW(eb_hwnd, GWL_EXSTYLE);
850 ok(style == expected_style, "Got exstyle 0x%08x, expected 0x%08x\n", style, expected_style);
852 ok(GetParent(eb_hwnd) == hwnd, "GetParent returns %p\n", GetParent(eb_hwnd));
854 /* ::Destroy() destroys the window. */
855 ok(IsWindow(eb_hwnd), "eb_hwnd invalid.\n");
856 IExplorerBrowser_Destroy(peb);
857 ok(!IsWindow(eb_hwnd), "eb_hwnd valid.\n");
859 IShellBrowser_Release(psb);
860 lres = IExplorerBrowser_Release(peb);
861 ok(lres == 0, "Got refcount %d\n", lres);
863 else
865 skip("Skipping some tests.\n");
867 IExplorerBrowser_Destroy(peb);
868 lres = IExplorerBrowser_Release(peb);
869 ok(lres == 0, "Got refcount %d\n", lres);
872 ebrowser_instantiate(&peb);
873 rc.left = 0; rc.top = 0; rc.right = 0; rc.bottom = 0;
874 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
875 ok(hr == S_OK, "got (0x%08x)\n", hr);
876 IExplorerBrowser_Destroy(peb);
877 lres = IExplorerBrowser_Release(peb);
878 ok(lres == 0, "Got refcount %d\n", lres);
880 ebrowser_instantiate(&peb);
881 rc.left = -1; rc.top = -1; rc.right = 1; rc.bottom = 1;
882 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
883 ok(hr == S_OK, "got (0x%08x)\n", hr);
884 IExplorerBrowser_Destroy(peb);
885 lres = IExplorerBrowser_Release(peb);
886 ok(lres == 0, "Got refcount %d\n", lres);
888 ebrowser_instantiate(&peb);
889 rc.left = 10; rc.top = 10; rc.right = 5; rc.bottom = 5;
890 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
891 ok(hr == S_OK, "got (0x%08x)\n", hr);
892 IExplorerBrowser_Destroy(peb);
893 lres = IExplorerBrowser_Release(peb);
894 ok(lres == 0, "Got refcount %d\n", lres);
896 ebrowser_instantiate(&peb);
897 rc.left = 10; rc.top = 10; rc.right = 5; rc.bottom = 5;
898 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
899 ok(hr == S_OK, "got (0x%08x)\n", hr);
900 IExplorerBrowser_Destroy(peb);
901 lres = IExplorerBrowser_Release(peb);
902 ok(lres == 0, "Got refcount %d\n", lres);
905 static void test_SetSite(void)
907 IExplorerBrowser *peb;
908 IServiceProviderImpl *spimpl = create_serviceprovider();
909 ICommDlgBrowser3Impl *cdbimpl = create_commdlgbrowser3();
910 IExplorerPaneVisibilityImpl *epvimpl = create_explorerpanevisibility();
911 IObjectWithSite *pow;
912 HRESULT hr;
913 LONG ref;
914 UINT i;
915 struct services expected[] = {
916 /* Win 7 */
917 { &SID_STopLevelBrowser, &IID_ICommDlgBrowser2, 0, cdbimpl },
918 { &SID_STopLevelBrowser, &IID_IShellBrowserService, 0, NULL },
919 { &SID_STopLevelBrowser, &IID_IShellBrowser, 0, NULL },
920 { &SID_STopLevelBrowser, &IID_UnknownInterface8, 0, NULL },
921 { &SID_STopLevelBrowser, &IID_IConnectionPointContainer, 0, NULL },
922 { &SID_STopLevelBrowser, &IID_IProfferService, 0, NULL },
923 { &SID_STopLevelBrowser, &IID_UnknownInterface9, 0, NULL },
924 { &SID_ExplorerPaneVisibility, &IID_IExplorerPaneVisibility, 0, epvimpl },
925 { &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser2, 0, cdbimpl },
926 { &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser3, 0, cdbimpl },
927 { &IID_IFileDialogPrivate, &IID_IFileDialogPrivate, 0, NULL },
928 { &IID_IFileDialogPrivate, &IID_IFileDialog, 0, NULL },
929 { &IID_IShellTaskScheduler, &IID_IShellTaskScheduler, 0, NULL },
930 { &IID_IShellTaskScheduler, &IID_UnknownInterface2, 0, NULL },
931 { &IID_IWebbrowserApp, &IID_IConnectionPointContainer, 0, NULL },
932 { &IID_IFolderView, &IID_IFolderView, 0, NULL },
933 { &IID_ILayoutModifier, &IID_ILayoutModifier, 0, NULL },
934 { &IID_IBrowserSettings, &IID_IBrowserSettings, 0, NULL },
935 { &CLSID_Desktop, &IID_IUnknown, 0, NULL },
936 { &IID_UnknownInterface1, &IID_UnknownInterface1, 0, NULL },
937 { &IID_UnknownInterface3, &IID_UnknownInterface3, 0, NULL },
938 { &IID_UnknownInterface4, &IID_IUnknown, 0, NULL },
939 { &IID_UnknownInterface6, &IID_UnknownInterface7, 0, NULL },
940 { &IID_IBrowserWithActivationNotification, &IID_IBrowserWithActivationNotification, 0, NULL },
941 /* Win 8 */
942 { &IID_ICommDlgBrowser, &IID_UnknownInterface11, 0, NULL },
943 { &IID_ICommDlgBrowser, &IID_UnknownInterface12, 0, NULL },
944 { &IID_UnknownInterface13, &IID_IUnknown, 0, NULL },
945 { &IID_UnknownInterface14, &IID_UnknownInterface14, 0, NULL },
946 { &IID_UnknownInterface15, &IID_UnknownInterface15, 0, NULL },
947 { &IID_UnknownInterface16, &IID_UnknownInterface16, 0, NULL },
948 { &IID_UnknownInterface17, &IID_UnknownInterface17, 0, NULL },
949 { &IID_UnknownInterface18, &IID_UnknownInterface18, 0, NULL },
951 /* Other services requested in Vista, Windows 2008 but not in Windows 7 */
952 { &IID_IBrowserSettings_Vista, &IID_IBrowserSettings_Vista, 0, NULL },
953 { &IID_IFolderTypeModifier, &IID_IFolderTypeModifier, 0, NULL },
954 { &SID_STopLevelBrowser, &IID_IShellBrowserService_Vista, 0, NULL },
955 { &IID_UnknownInterface5, &IID_UnknownInterface5, 0, NULL },
956 { &IID_ICommDlgBrowser, &IID_ICommDlgBrowser, 0, cdbimpl },
957 { &IID_IFileDialogPrivate_Vista,&IID_IFileDialogPrivate_Vista, 0, NULL},
958 { &IID_IFileDialogPrivate_Vista,&IID_IFileDialog, 0, NULL},
959 { &IID_UnknownInterface10, &IID_IHTMLDocument2, 0, NULL},
960 { &SID_SMenuBandParent, &IID_IOleCommandTarget, 0, NULL},
961 { &SID_SMenuBandParent, &IID_IShellMenu, 0, NULL},
962 { &SID_STopLevelBrowser, &IID_IOleWindow, 0, NULL},
963 { &SID_SMenuPopup, &IID_IOleCommandTarget, 0, NULL},
964 { NULL }
967 ebrowser_instantiate(&peb);
968 IExplorerBrowser_SetOptions(peb, EBO_SHOWFRAMES);
970 hr = IExplorerBrowser_QueryInterface(peb, &IID_IObjectWithSite, (void**)&pow);
971 ok(hr == S_OK, "Got 0x%08x\n", hr);
972 if(SUCCEEDED(hr))
974 spimpl->interfaces = expected;
976 hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
977 ok(hr == S_OK, "Got 0x%08x\n", hr);
979 if(FAILED(hr))
980 IObjectWithSite_Release(pow);
983 if(FAILED(hr))
985 skip("Failed to set site.\n");
987 IServiceProvider_Release(&spimpl->IServiceProvider_iface);
988 ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
989 IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
990 IExplorerBrowser_Destroy(peb);
991 ref = IExplorerBrowser_Release(peb);
992 ok(ref == 0, "Got ref %d\n", ref);
994 return;
997 ShowWindow(hwnd, TRUE);
998 ebrowser_initialize(peb);
999 ebrowser_browse_to_desktop(peb);
1001 for(i = 0; i < 10; i++)
1003 Sleep(100);
1004 process_msgs();
1006 ShowWindow(hwnd, FALSE);
1008 /* ICommDlgBrowser3 */
1009 ok(!cdbimpl->OnDefaultCommand, "Got %d\n", cdbimpl->OnDefaultCommand);
1010 todo_wine ok(cdbimpl->OnStateChange, "Got %d\n", cdbimpl->OnStateChange);
1011 ok(cdbimpl->IncludeObject, "Got %d\n", cdbimpl->IncludeObject);
1012 ok(!cdbimpl->Notify, "Got %d\n", cdbimpl->Notify);
1013 ok(!cdbimpl->GetDefaultMenuText, "Got %d\n", cdbimpl->GetDefaultMenuText);
1014 todo_wine ok(cdbimpl->GetViewFlags, "Got %d\n", cdbimpl->GetViewFlags);
1015 ok(!cdbimpl->OnColumnClicked, "Got %d\n", cdbimpl->OnColumnClicked);
1016 ok(!cdbimpl->GetCurrentFilter, "Got %d\n", cdbimpl->GetCurrentFilter);
1017 todo_wine ok(cdbimpl->OnPreviewCreated, "Got %d\n", cdbimpl->OnPreviewCreated);
1019 /* IExplorerPaneVisibility */
1020 ok(epvimpl->np, "Got %d\n", epvimpl->np);
1021 todo_wine ok(epvimpl->cp, "Got %d\n", epvimpl->cp);
1022 todo_wine ok(epvimpl->cp_o, "Got %d\n", epvimpl->cp_o);
1023 todo_wine ok(epvimpl->cp_v, "Got %d\n", epvimpl->cp_v);
1024 todo_wine ok(epvimpl->dp, "Got %d\n", epvimpl->dp);
1025 todo_wine ok(epvimpl->pp, "Got %d\n", epvimpl->pp);
1026 ok(!epvimpl->qp, "Got %d\n", epvimpl->qp);
1027 ok(!epvimpl->aqp, "Got %d\n", epvimpl->aqp);
1028 ok(!epvimpl->unk, "Got %d\n", epvimpl->unk);
1030 if(0)
1032 for(i = 0; expected[i].service != NULL; i++)
1033 if(!expected[i].count) trace("count %d was 0.\n", i);
1036 /* Test when IServiceProvider is released. */
1037 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1038 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1039 ok(ref == 2, "Got ref %d\n", ref);
1041 hr = IObjectWithSite_SetSite(pow, NULL);
1042 ok(hr == S_OK, "Got 0x%08x\n", hr);
1044 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1045 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1046 ok(ref == 1, "Got ref %d\n", ref);
1048 hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
1049 ok(hr == S_OK, "Got 0x%08x\n", hr);
1051 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1052 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1053 ok(ref == 2, "Got ref %d\n", ref);
1055 IExplorerBrowser_Destroy(peb);
1057 IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
1058 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1059 ok(ref == 2, "Got ref %d\n", ref);
1061 IObjectWithSite_Release(pow);
1062 ref = IExplorerBrowser_Release(peb);
1063 ok(ref == 0, "Got ref %d\n", ref);
1065 ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
1066 ok(ref == 0, "Got ref %d\n", ref);
1068 ref = ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
1069 ok(ref == 0, "Got ref %d\n", ref);
1070 ref = IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
1071 ok(ref == 0, "Got ref %d\n", ref);
1074 static void test_basics(void)
1076 IExplorerBrowser *peb;
1077 IShellBrowser *psb;
1078 FOLDERSETTINGS fs;
1079 ULONG lres;
1080 DWORD flags;
1081 HDWP hdwp;
1082 RECT rc;
1083 HRESULT hr;
1084 static const WCHAR winetest[] = {'W','i','n','e','T','e','s','t',0};
1086 ebrowser_instantiate(&peb);
1087 ebrowser_initialize(peb);
1089 /* SetRect */
1090 rc.left = 0; rc.top = 0; rc.right = 0; rc.bottom = 0;
1091 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1092 ok(hr == S_OK, "got (0x%08x)\n", hr);
1094 rc.left = 100; rc.top = 100; rc.right = 10; rc.bottom = 10;
1095 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1096 ok(hr == S_OK, "got (0x%08x)\n", hr);
1098 /* SetRect with DeferWindowPos */
1099 rc.left = rc.top = 0; rc.right = rc.bottom = 10;
1100 hdwp = BeginDeferWindowPos(1);
1101 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1102 ok(hr == S_OK, "got (0x%08x)\n", hr);
1103 lres = EndDeferWindowPos(hdwp);
1104 ok(lres, "EndDeferWindowPos failed.\n");
1106 hdwp = NULL;
1107 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1108 ok(hr == S_OK, "got (0x%08x)\n", hr);
1109 ok(hdwp == NULL, "got %p\n", hdwp);
1110 lres = EndDeferWindowPos(hdwp);
1111 ok(!lres, "EndDeferWindowPos succeeded unexpectedly.\n");
1113 /* Test positioning */
1114 rc.left = 10; rc.top = 20; rc.right = 50; rc.bottom = 50;
1115 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1116 ok(hr == S_OK, "got (0x%08x)\n", hr);
1117 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1118 ok(hr == S_OK, "Got 0x%08x\n", hr);
1119 if(SUCCEEDED(hr))
1121 HWND eb_hwnd;
1122 RECT eb_rc;
1123 static const RECT exp_rc = {11, 21, 49, 49};
1124 static const RECT exp_rc2 = {11, 21, 49, 24};
1126 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
1127 ok(hr == S_OK, "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);
1134 /* Try resizing with invalid hdwp */
1135 rc.bottom = 25;
1136 hdwp = (HDWP)0xdeadbeef;
1137 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1138 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1139 GetClientRect(eb_hwnd, &eb_rc);
1140 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1141 ok(EqualRect(&eb_rc, &exp_rc), "Got rect (%d, %d) - (%d, %d)\n",
1142 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
1144 hdwp = NULL;
1145 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1146 ok(hr == S_OK, "Got 0x%08x\n", hr);
1147 GetClientRect(eb_hwnd, &eb_rc);
1148 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1149 ok(EqualRect(&eb_rc, &exp_rc2), "Got rect (%d, %d) - (%d, %d)\n",
1150 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
1152 IShellBrowser_Release(psb);
1155 IExplorerBrowser_Destroy(peb);
1156 IExplorerBrowser_Release(peb);
1158 /* GetOptions/SetOptions*/
1159 ebrowser_instantiate(&peb);
1161 if(0) {
1162 /* Crashes on Windows 7 */
1163 IExplorerBrowser_GetOptions(peb, NULL);
1166 hr = IExplorerBrowser_GetOptions(peb, &flags);
1167 ok(hr == S_OK, "got (0x%08x)\n", hr);
1168 ok(flags == 0, "got (0x%08x)\n", flags);
1170 /* Settings preserved through Initialize. */
1171 hr = IExplorerBrowser_SetOptions(peb, 0xDEADBEEF);
1172 ok(hr == S_OK, "got (0x%08x)\n", hr);
1174 ebrowser_initialize(peb);
1176 hr = IExplorerBrowser_GetOptions(peb, &flags);
1177 ok(flags == 0xDEADBEEF, "got (0x%08x)\n", flags);
1178 ok(hr == S_OK, "got (0x%08x)\n", hr);
1180 IExplorerBrowser_Destroy(peb);
1181 IExplorerBrowser_Release(peb);
1183 ebrowser_instantiate(&peb);
1184 ebrowser_initialize(peb);
1186 /* SetFolderSettings */
1187 hr = IExplorerBrowser_SetFolderSettings(peb, NULL);
1188 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1189 fs.ViewMode = 0; fs.fFlags = 0;
1190 hr = IExplorerBrowser_SetFolderSettings(peb, &fs);
1191 todo_wine ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1193 /* SetPropertyBag */
1194 hr = IExplorerBrowser_SetPropertyBag(peb, NULL);
1195 ok(hr == E_INVALIDARG, "Got 0x%08x\n", hr);
1196 hr = IExplorerBrowser_SetPropertyBag(peb, winetest);
1197 ok(hr == S_OK, "Got 0x%08x\n", hr);
1199 /* TODO: Test after browsing somewhere. */
1201 IExplorerBrowser_Destroy(peb);
1202 lres = IExplorerBrowser_Release(peb);
1203 ok(lres == 0, "Got %d\n", lres);
1206 static void test_Advise(void)
1208 IExplorerBrowser *peb;
1209 IExplorerBrowserEvents *pebe;
1210 DWORD cookies[10];
1211 HRESULT hr;
1212 UINT i, ref;
1214 /* Set up our IExplorerBrowserEvents implementation */
1215 ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1216 pebe = &ebev.IExplorerBrowserEvents_iface;
1218 ebrowser_instantiate(&peb);
1220 if(0)
1222 /* Crashes on Windows 7 */
1223 IExplorerBrowser_Advise(peb, pebe, NULL);
1224 IExplorerBrowser_Advise(peb, NULL, &cookies[0]);
1227 /* Using Unadvise with a cookie that has yet to be given out
1228 * results in E_INVALIDARG */
1229 hr = IExplorerBrowser_Unadvise(peb, 11);
1230 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
1232 /* Add some before initialization */
1233 for(i = 0; i < 5; i++)
1235 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1236 ok(hr == S_OK, "got (0x%08x)\n", hr);
1239 ebrowser_initialize(peb);
1241 /* Add some after initialization */
1242 for(i = 5; i < 10; i++)
1244 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1245 ok(hr == S_OK, "got (0x%08x)\n", hr);
1248 ok(ebev.ref == 10, "Got %d\n", ebev.ref);
1250 ebev.completed = 0;
1251 ebrowser_browse_to_desktop(peb);
1252 process_msgs();
1253 ok(ebev.completed == 10, "Got %d\n", ebev.completed);
1255 /* Remove a bunch somewhere in the middle */
1256 for(i = 4; i < 8; i++)
1258 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1259 ok(hr == S_OK, "got (0x%08x)\n", hr);
1262 ebev.completed = 0;
1263 ebrowser_browse_to_desktop(peb);
1264 process_msgs();
1265 ok(ebev.completed == 6, "Got %d\n", ebev.completed);
1267 if(0)
1269 /* Using unadvise with a previously unadvised cookie results
1270 * in a crash. */
1271 IExplorerBrowser_Unadvise(peb, cookies[5]);
1274 /* Remove the rest. */
1275 for(i = 0; i < 10; i++)
1277 if(i<4||i>7)
1279 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1280 ok(hr == S_OK, "%d: got (0x%08x)\n", i, hr);
1284 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
1286 ebev.completed = 0;
1287 ebrowser_browse_to_desktop(peb);
1288 process_msgs();
1289 ok(ebev.completed == 0, "Got %d\n", ebev.completed);
1291 /* ::Destroy implies ::Unadvise. */
1292 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[0]);
1293 ok(hr == S_OK, "Got 0x%08x\n", hr);
1294 ok(ebev.ref == 1, "Got %d\n", ebev.ref);
1296 hr = IExplorerBrowser_Destroy(peb);
1297 ok(hr == S_OK, "Got 0x%08x\n", hr);
1298 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
1300 ref = IExplorerBrowser_Release(peb);
1301 ok(!ref, "Got %d\n", ref);
1304 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
1305 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
1307 size_t iLen;
1309 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
1310 return NULL;
1312 if (iLen)
1314 lpszPath += iLen;
1315 if (lpszPath[-1] != '\\')
1317 *lpszPath++ = '\\';
1318 *lpszPath = '\0';
1321 return lpszPath;
1324 static void test_browse_pidl_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
1325 LPITEMIDLIST pidl, UINT uFlags,
1326 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
1327 const char *file, int line)
1329 HRESULT hr;
1330 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
1332 hr = IExplorerBrowser_BrowseToIDList(peb, pidl, uFlags);
1333 ok_(file, line) (hr == hr_exp, "BrowseToIDList returned 0x%08x\n", hr);
1334 process_msgs();
1336 ok_(file, line)
1337 (ebev->pending == pending && ebev->created == created &&
1338 ebev->failed == failed && ebev->completed == completed,
1339 "Events occurred: %d, %d, %d, %d\n",
1340 ebev->pending, ebev->created, ebev->failed, ebev->completed);
1342 #define test_browse_pidl(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
1343 test_browse_pidl_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
1345 static void test_browse_pidl_sb_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
1346 LPITEMIDLIST pidl, UINT uFlags,
1347 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
1348 const char *file, int line)
1350 IShellBrowser *psb;
1351 HRESULT hr;
1353 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1354 ok_(file, line) (hr == S_OK, "QueryInterface returned 0x%08x\n", hr);
1355 if(SUCCEEDED(hr))
1357 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
1359 hr = IShellBrowser_BrowseObject(psb, pidl, uFlags);
1360 ok_(file, line) (hr == hr_exp, "BrowseObject returned 0x%08x\n", hr);
1361 process_msgs();
1363 ok_(file, line)
1364 (ebev->pending == pending && ebev->created == created &&
1365 ebev->failed == failed && ebev->completed == completed,
1366 "Events occurred: %d, %d, %d, %d\n",
1367 ebev->pending, ebev->created, ebev->failed, ebev->completed);
1369 IShellBrowser_Release(psb);
1372 #define test_browse_pidl_sb(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
1373 test_browse_pidl_sb_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
1375 static void test_navigation(void)
1377 IExplorerBrowser *peb, *peb2;
1378 IFolderView *pfv;
1379 IShellItem *psi;
1380 IShellFolder *psf;
1381 LPITEMIDLIST pidl_current, pidl_child;
1382 DWORD cookie, cookie2;
1383 HRESULT hr;
1384 LONG lres;
1385 WCHAR current_path[MAX_PATH];
1386 WCHAR child_path[MAX_PATH];
1387 static const WCHAR testfolderW[] =
1388 {'w','i','n','e','t','e','s','t','f','o','l','d','e','r','\0'};
1390 ok(pSHParseDisplayName != NULL, "pSHParseDisplayName unexpectedly missing.\n");
1391 ok(pSHCreateShellItem != NULL, "pSHCreateShellItem unexpectedly missing.\n");
1393 GetCurrentDirectoryW(MAX_PATH, current_path);
1394 if(!lstrlenW(current_path))
1396 skip("Failed to create test-directory.\n");
1397 return;
1400 lstrcpyW(child_path, current_path);
1401 myPathAddBackslashW(child_path);
1402 lstrcatW(child_path, testfolderW);
1404 CreateDirectoryW(child_path, NULL);
1406 pSHParseDisplayName(current_path, NULL, &pidl_current, 0, NULL);
1407 pSHParseDisplayName(child_path, NULL, &pidl_child, 0, NULL);
1409 ebrowser_instantiate(&peb);
1410 ebrowser_initialize(peb);
1412 ebrowser_instantiate(&peb2);
1413 ebrowser_initialize(peb2);
1415 /* Set up our IExplorerBrowserEvents implementation */
1416 ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1418 IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1419 IExplorerBrowser_Advise(peb2, &ebev.IExplorerBrowserEvents_iface, &cookie2);
1421 /* These should all fail */
1422 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1423 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1424 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
1425 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
1426 test_browse_pidl(peb, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1427 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
1428 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1429 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1430 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
1431 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
1432 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1433 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1435 /* "The first browse is synchronous" */
1436 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
1437 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
1439 /* Navigate empty history */
1440 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
1441 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
1442 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
1443 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
1445 /* Navigate history */
1446 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
1447 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
1448 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
1449 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
1450 test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
1451 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
1452 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1453 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1455 /* Relative navigation */
1456 test_browse_pidl(peb, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1457 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1459 hr = IExplorerBrowser_GetCurrentView(peb, &IID_IFolderView, (void**)&pfv);
1460 ok(hr == S_OK, "Got 0x%08x\n", hr);
1461 if(SUCCEEDED(hr))
1463 LPITEMIDLIST pidl_relative;
1465 hr = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1466 ok(hr == S_OK, "Got 0x%08x\n", hr);
1467 hr = IShellFolder_ParseDisplayName(psf, NULL, NULL, (LPWSTR)testfolderW,
1468 NULL, &pidl_relative, NULL);
1469 ok(hr == S_OK, "Got 0x%08x\n", hr);
1471 /* Browsing to another location here before using the
1472 * pidl_relative would make ExplorerBrowser in Windows 7 show a
1473 * not-available dialog. Also, passing a relative pidl without
1474 * specifying SBSP_RELATIVE makes it look for the pidl on the
1475 * desktop
1478 test_browse_pidl(peb, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
1479 test_browse_pidl_sb(peb2, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
1481 ILFree(pidl_relative);
1482 /* IShellFolder_Release(psf); */
1483 IFolderView_Release(pfv);
1486 /* misc **/
1487 test_browse_pidl(peb, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1488 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
1489 test_browse_pidl(peb, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
1490 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
1491 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
1492 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
1493 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
1494 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
1496 test_browse_pidl(peb, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
1497 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
1498 test_browse_pidl(peb, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
1499 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
1501 /* SBSP_NEWBROWSER will return E_INVALIDARG, claims MSDN, but in
1502 * reality it works as one would expect (Windows 7 only?).
1504 if(0)
1506 IExplorerBrowser_BrowseToIDList(peb, NULL, SBSP_NEWBROWSER);
1509 hr = IExplorerBrowser_Unadvise(peb, cookie);
1510 ok(hr == S_OK, "Got 0x%08x\n", hr);
1511 IExplorerBrowser_Destroy(peb);
1512 process_msgs();
1513 hr = IExplorerBrowser_Unadvise(peb2, cookie2);
1514 ok(hr == S_OK, "Got 0x%08x\n", hr);
1515 IExplorerBrowser_Destroy(peb2);
1516 process_msgs();
1518 /* Attempt browsing after destroyed */
1519 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
1520 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
1522 lres = IExplorerBrowser_Release(peb);
1523 ok(lres == 0, "Got lres %d\n", lres);
1524 lres = IExplorerBrowser_Release(peb2);
1525 ok(lres == 0, "Got lres %d\n", lres);
1527 /******************************************/
1528 /* Test some options that affect browsing */
1530 ebrowser_instantiate(&peb);
1531 hr = IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1532 ok(hr == S_OK, "Got 0x%08x\n", hr);
1533 hr = IExplorerBrowser_SetOptions(peb, EBO_NAVIGATEONCE);
1534 ok(hr == S_OK, "got (0x%08x)\n", hr);
1535 ebrowser_initialize(peb);
1537 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 1, 0, 1);
1538 test_browse_pidl(peb, &ebev, pidl_current, 0, E_FAIL, 0, 0, 0, 0);
1540 hr = IExplorerBrowser_SetOptions(peb, 0);
1541 ok(hr == S_OK, "got (0x%08x)\n", hr);
1543 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1544 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1546 /* Difference in behavior lies where? */
1547 hr = IExplorerBrowser_SetOptions(peb, EBO_ALWAYSNAVIGATE);
1548 ok(hr == S_OK, "got (0x%08x)\n", hr);
1550 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1551 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
1553 hr = IExplorerBrowser_Unadvise(peb, cookie);
1554 ok(hr == S_OK, "Got 0x%08x\n", hr);
1556 IExplorerBrowser_Destroy(peb);
1557 lres = IExplorerBrowser_Release(peb);
1558 ok(lres == 0, "Got lres %d\n", lres);
1560 /* BrowseToObject tests */
1561 ebrowser_instantiate(&peb);
1562 ebrowser_initialize(peb);
1564 /* Browse to the desktop by passing an IShellFolder */
1565 hr = SHGetDesktopFolder(&psf);
1566 ok(hr == S_OK, "Got 0x%08x\n", hr);
1567 if(SUCCEEDED(hr))
1569 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1570 ok(hr == S_OK, "got (0x%08x)\n", hr);
1571 if(hr == S_OK) process_msgs();
1573 IShellFolder_Release(psf);
1576 /* Browse to the current directory by passing a ShellItem */
1577 hr = pSHCreateShellItem(NULL, NULL, pidl_current, &psi);
1578 ok(hr == S_OK, "Got 0x%08x\n", hr);
1579 if(SUCCEEDED(hr))
1581 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psi, SBSP_DEFBROWSER);
1582 ok(hr == S_OK, "got (0x%08x)\n", hr);
1583 process_msgs();
1585 IShellItem_Release(psi);
1588 IExplorerBrowser_Destroy(peb);
1589 lres = IExplorerBrowser_Release(peb);
1590 ok(lres == 0, "Got lres %d\n", lres);
1592 /* Cleanup */
1593 RemoveDirectoryW(child_path);
1594 ILFree(pidl_current);
1595 ILFree(pidl_child);
1598 static void test_GetCurrentView(void)
1600 IExplorerBrowser *peb;
1601 IUnknown *punk;
1602 HRESULT hr;
1604 /* GetCurrentView */
1605 ebrowser_instantiate(&peb);
1607 if(0)
1609 /* Crashes under Windows 7 */
1610 IExplorerBrowser_GetCurrentView(peb, NULL, NULL);
1612 hr = IExplorerBrowser_GetCurrentView(peb, NULL, (void**)&punk);
1613 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1615 #define test_gcv(iid, exp) \
1616 do { \
1617 hr = IExplorerBrowser_GetCurrentView(peb, &iid, (void**)&punk); \
1618 ok(hr == exp, "(%s:)Expected (0x%08x), got: (0x%08x)\n", \
1619 #iid ,exp, hr); \
1620 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
1621 } while(0)
1623 test_gcv(IID_IUnknown, E_FAIL);
1624 test_gcv(IID_IUnknown, E_FAIL);
1625 test_gcv(IID_IShellView, E_FAIL);
1626 test_gcv(IID_IShellView2, E_FAIL);
1627 test_gcv(IID_IFolderView, E_FAIL);
1628 test_gcv(IID_IPersistFolder, E_FAIL);
1629 test_gcv(IID_IPersistFolder2, E_FAIL);
1630 test_gcv(IID_ICommDlgBrowser, E_FAIL);
1631 test_gcv(IID_ICommDlgBrowser2, E_FAIL);
1632 test_gcv(IID_ICommDlgBrowser3, E_FAIL);
1634 ebrowser_initialize(peb);
1635 ebrowser_browse_to_desktop(peb);
1637 test_gcv(IID_IUnknown, S_OK);
1638 test_gcv(IID_IUnknown, S_OK);
1639 test_gcv(IID_IShellView, S_OK);
1640 test_gcv(IID_IShellView2, S_OK);
1641 test_gcv(IID_IFolderView, S_OK);
1642 todo_wine test_gcv(IID_IPersistFolder, S_OK);
1643 test_gcv(IID_IPersistFolder2, E_NOINTERFACE);
1644 test_gcv(IID_ICommDlgBrowser, E_NOINTERFACE);
1645 test_gcv(IID_ICommDlgBrowser2, E_NOINTERFACE);
1646 test_gcv(IID_ICommDlgBrowser3, E_NOINTERFACE);
1648 #undef test_gcv
1650 IExplorerBrowser_Destroy(peb);
1651 IExplorerBrowser_Release(peb);
1654 static void test_InputObject(void)
1656 IExplorerBrowser *peb;
1657 IShellFolder *psf;
1658 IInputObject *pio;
1659 HRESULT hr;
1660 RECT rc;
1661 UINT i;
1662 WPARAM supported_key_accels_mode1[] = {
1663 VK_BACK, VK_TAB, VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
1664 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
1665 VK_F5, VK_F6, VK_F10, 0 };
1666 WPARAM supported_key_accels_mode2[] = {
1667 VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
1668 VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
1669 VK_F10, 0 };
1670 WPARAM *key_accels;
1671 MSG msg_a = {
1672 hwnd,
1673 WM_KEYDOWN,
1674 VK_F5, 0,
1675 GetTickCount(),
1676 {5, 2}
1679 ebrowser_instantiate(&peb);
1680 hr = IExplorerBrowser_QueryInterface(peb, &IID_IInputObject, (void**)&pio);
1681 ok(hr == S_OK, "Got 0x%08x\n", hr);
1682 if(FAILED(hr))
1684 win_skip("IInputObject not supported.\n");
1685 return;
1688 /* Before initializing */
1689 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1690 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1692 hr = IInputObject_HasFocusIO(pio);
1693 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1695 hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1696 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1698 hr = IInputObject_HasFocusIO(pio);
1699 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1701 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1702 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1704 rc.left = 0; rc.top = 0; rc.right = 100; rc.bottom = 100;
1705 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
1706 ok(hr == S_OK, "Got 0x%08x\n", hr);
1708 hr = IInputObject_HasFocusIO(pio);
1709 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1711 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1712 todo_wine ok(hr == E_FAIL, "Got 0x%08x\n", hr);
1714 /* Browse to the desktop */
1715 SHGetDesktopFolder(&psf);
1716 hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1717 ok(hr == S_OK, "Got 0x%08x\n", hr);
1718 IShellFolder_Release(psf);
1720 hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1721 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1723 hr = IInputObject_HasFocusIO(pio);
1724 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1726 hr = IInputObject_UIActivateIO(pio, FALSE, &msg_a);
1727 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1729 hr = IInputObject_HasFocusIO(pio);
1730 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
1732 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1733 if(hr == S_OK)
1734 key_accels = supported_key_accels_mode1;
1735 else
1736 key_accels = supported_key_accels_mode2;
1738 for(i = 0; i < 0x100; i++)
1740 BOOL found = FALSE;
1741 UINT j;
1742 for(j = 0; key_accels[j] != 0; j++)
1743 if(key_accels[j] == i)
1745 found = TRUE;
1746 break;
1749 msg_a.wParam = i;
1750 process_msgs();
1751 hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1752 todo_wine ok(hr == (found ? S_OK : S_FALSE), "Got 0x%08x (%04x)\n", hr, i);
1753 if(i == VK_F5)
1754 Sleep(1000); /* Needed for w2k8 (64bit) */
1757 process_msgs();
1759 IInputObject_Release(pio);
1760 IExplorerBrowser_Destroy(peb);
1761 IExplorerBrowser_Release(peb);
1764 static BOOL test_instantiate_control(void)
1766 IExplorerBrowser *peb;
1767 HRESULT hr;
1769 hr = ebrowser_instantiate(&peb);
1770 ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got (0x%08x)\n", hr);
1771 if(FAILED(hr))
1772 return FALSE;
1774 IExplorerBrowser_Release(peb);
1775 return TRUE;
1778 static void setup_window(void)
1780 WNDCLASSW wc;
1781 static const WCHAR ebtestW[] = {'e','b','t','e','s','t',0};
1783 ZeroMemory(&wc, sizeof(WNDCLASSW));
1784 wc.lpfnWndProc = DefWindowProcW;
1785 wc.lpszClassName = ebtestW;
1786 RegisterClassW(&wc);
1787 hwnd = CreateWindowExW(0, ebtestW, NULL, 0,
1788 0, 0, 500, 500,
1789 NULL, 0, 0, NULL);
1790 ok(hwnd != NULL, "Failed to create window for tests.\n");
1793 START_TEST(ebrowser)
1795 OleInitialize(NULL);
1797 if(!test_instantiate_control())
1799 win_skip("No ExplorerBrowser control..\n");
1800 OleUninitialize();
1801 return;
1804 setup_window();
1805 init_function_pointers();
1807 test_QueryInterface();
1808 test_SB_misc();
1809 test_initialization();
1810 test_basics();
1811 test_Advise();
1812 test_navigation();
1813 test_GetCurrentView();
1814 test_SetSite();
1815 test_InputObject();
1817 DestroyWindow(hwnd);
1818 OleUninitialize();