shell32/tests: Add some tests related to the shellview created by ExplorerBrowser.
[wine.git] / dlls / shell32 / tests / ebrowser.c
blob8fa8b9ad09d8de081b848b585e2d399c6e698a1d
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
25 #include "shlobj.h"
27 #include "wine/test.h"
29 static HWND hwnd;
31 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
32 static HRESULT (WINAPI *pSHParseDisplayName)(LPCWSTR,IBindCtx*,LPITEMIDLIST*,SFGAOF,SFGAOF*);
34 static void init_function_pointers(void)
36 HMODULE hmod;
38 hmod = GetModuleHandleA("shell32.dll");
39 pSHCreateShellItem = (void*)GetProcAddress(hmod, "SHCreateShellItem");
40 pSHParseDisplayName = (void*)GetProcAddress(hmod, "SHParseDisplayName");
43 /*********************************************************************
44 * Some simple helpers
46 static HRESULT ebrowser_instantiate(IExplorerBrowser **peb)
48 return CoCreateInstance(&CLSID_ExplorerBrowser, NULL, CLSCTX_INPROC_SERVER,
49 &IID_IExplorerBrowser, (void**)peb);
52 static HRESULT ebrowser_initialize(IExplorerBrowser *peb)
54 RECT rc;
55 rc.top = rc.left = 0; rc.bottom = rc.right = 500;
56 return IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
59 static HRESULT ebrowser_browse_to_desktop(IExplorerBrowser *peb)
61 LPITEMIDLIST pidl_desktop;
62 SHGetSpecialFolderLocation (hwnd, CSIDL_DESKTOP, &pidl_desktop);
63 return IExplorerBrowser_BrowseToIDList(peb, pidl_desktop, 0);
66 /* Process some messages */
67 static void process_msgs(void)
69 MSG msg;
70 while(PeekMessage( &msg, NULL, 0, 0, PM_REMOVE))
72 TranslateMessage(&msg);
73 DispatchMessage(&msg);
77 /*********************************************************************
78 * IExplorerBrowserEvents implementation
80 typedef struct {
81 const IExplorerBrowserEventsVtbl *lpVtbl;
82 LONG ref;
83 UINT pending, created, completed, failed;
84 } IExplorerBrowserEventsImpl;
86 static IExplorerBrowserEventsImpl ebev;
88 static HRESULT WINAPI IExplorerBrowserEvents_fnQueryInterface(IExplorerBrowserEvents *iface,
89 REFIID riid, void **ppvObj)
91 ok(0, "Never called.\n");
92 return E_NOINTERFACE;
95 static ULONG WINAPI IExplorerBrowserEvents_fnAddRef(IExplorerBrowserEvents *iface)
97 IExplorerBrowserEventsImpl *This = (IExplorerBrowserEventsImpl*)iface;
98 return InterlockedIncrement(&This->ref);
101 static ULONG WINAPI IExplorerBrowserEvents_fnRelease(IExplorerBrowserEvents *iface)
103 IExplorerBrowserEventsImpl *This = (IExplorerBrowserEventsImpl*)iface;
104 return InterlockedDecrement(&This->ref);
107 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationPending(IExplorerBrowserEvents *iface,
108 PCIDLIST_ABSOLUTE pidlFolder)
110 IExplorerBrowserEventsImpl *This = (IExplorerBrowserEventsImpl*)iface;
111 This->pending++;
112 return S_OK;
115 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationComplete(IExplorerBrowserEvents *iface,
116 PCIDLIST_ABSOLUTE pidlFolder)
118 IExplorerBrowserEventsImpl *This = (IExplorerBrowserEventsImpl*)iface;
119 This->completed++;
120 return S_OK;
122 static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationFailed(IExplorerBrowserEvents *iface,
123 PCIDLIST_ABSOLUTE pidlFolder)
125 IExplorerBrowserEventsImpl *This = (IExplorerBrowserEventsImpl*)iface;
126 This->failed++;
127 return S_OK;
129 static HRESULT WINAPI IExplorerBrowserEvents_fnOnViewCreated(IExplorerBrowserEvents *iface,
130 IShellView *psv)
132 IExplorerBrowserEventsImpl *This = (IExplorerBrowserEventsImpl*)iface;
133 This->created++;
134 return S_OK;
137 static const IExplorerBrowserEventsVtbl ebevents =
139 IExplorerBrowserEvents_fnQueryInterface,
140 IExplorerBrowserEvents_fnAddRef,
141 IExplorerBrowserEvents_fnRelease,
142 IExplorerBrowserEvents_fnOnNavigationPending,
143 IExplorerBrowserEvents_fnOnViewCreated,
144 IExplorerBrowserEvents_fnOnNavigationComplete,
145 IExplorerBrowserEvents_fnOnNavigationFailed
148 static void test_QueryInterface(void)
150 IExplorerBrowser *peb;
151 IUnknown *punk;
152 HRESULT hr;
153 LONG lres;
155 hr = ebrowser_instantiate(&peb);
156 ok(hr == S_OK, "Got 0x%08x\n", hr);
158 #define test_qinterface(iid, exp) \
159 do { \
160 hr = IExplorerBrowser_QueryInterface(peb, &iid, (void**)&punk); \
161 ok(hr == exp, "(%s:)Expected (0x%08x), got (0x%08x)\n", \
162 #iid, exp, hr); \
163 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
164 } while(0)
166 test_qinterface(IID_IUnknown, S_OK);
167 test_qinterface(IID_IExplorerBrowser, S_OK);
168 test_qinterface(IID_IShellBrowser, S_OK);
169 todo_wine test_qinterface(IID_IOleWindow, S_OK);
170 todo_wine test_qinterface(IID_ICommDlgBrowser, S_OK);
171 todo_wine test_qinterface(IID_ICommDlgBrowser2, S_OK);
172 todo_wine test_qinterface(IID_ICommDlgBrowser3, S_OK);
173 todo_wine test_qinterface(IID_IServiceProvider, S_OK);
174 todo_wine test_qinterface(IID_IObjectWithSite, S_OK);
175 todo_wine test_qinterface(IID_IConnectionPointContainer, S_OK);
176 test_qinterface(IID_IOleObject, E_NOINTERFACE);
177 test_qinterface(IID_IViewObject, E_NOINTERFACE);
178 test_qinterface(IID_IViewObject2, E_NOINTERFACE);
179 test_qinterface(IID_IViewObjectEx, E_NOINTERFACE);
180 test_qinterface(IID_IConnectionPoint, E_NOINTERFACE);
181 test_qinterface(IID_IShellView, E_NOINTERFACE);
182 test_qinterface(IID_INameSpaceTreeControlEvents, E_NOINTERFACE);
184 #undef test_qinterface
186 lres = IExplorerBrowser_Release(peb);
187 ok(lres == 0, "Got %d\n", lres);
190 static void test_SB_misc(void)
192 IExplorerBrowser *peb;
193 IShellBrowser *psb;
194 IUnknown *punk;
195 HRESULT hr;
196 HWND retHwnd;
197 LRESULT lres;
198 LONG ref;
200 ebrowser_instantiate(&peb);
201 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
202 ok(hr == S_OK, "Got 0x%08x\n", hr);
203 if(FAILED(hr))
205 skip("Failed to get IShellBrowser interface.\n");
206 return;
209 /* Some unimplemented methods */
210 retHwnd = (HWND)0xDEADBEEF;
211 hr = IShellBrowser_GetControlWindow(psb, FCW_TOOLBAR, &retHwnd);
212 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
213 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
215 hr = IShellBrowser_GetControlWindow(psb, FCW_STATUS, &retHwnd);
216 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
217 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
219 hr = IShellBrowser_GetControlWindow(psb, FCW_TREE, &retHwnd);
220 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
221 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
223 hr = IShellBrowser_GetControlWindow(psb, FCW_PROGRESS, &retHwnd);
224 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
225 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
227 /* ::InsertMenuSB */
228 hr = IShellBrowser_InsertMenusSB(psb, NULL, NULL);
229 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
231 /* ::RemoveMenusSB */
232 hr = IShellBrowser_RemoveMenusSB(psb, NULL);
233 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
235 /* ::SetMenuSB */
236 hr = IShellBrowser_SetMenuSB(psb, NULL, NULL, NULL);
237 ok(hr == E_NOTIMPL, "got (0x%08x)\n", hr);
239 /***** Before EB::Initialize *****/
241 /* ::GetWindow */
242 retHwnd = (HWND)0xDEADBEEF;
243 hr = IShellBrowser_GetWindow(psb, &retHwnd);
244 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
245 ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");
247 todo_wine
250 /* ::SendControlMsg */
251 lres = 0xDEADBEEF;
252 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
253 ok(hr == S_OK, "got (0x%08x)\n", hr);
254 ok(lres == 0, "lres was %ld\n", lres);
256 lres = 0xDEADBEEF;
257 hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, TB_CHECKBUTTON,
258 FCIDM_TB_SMALLICON, TRUE, &lres);
259 ok(hr == S_OK, "got (0x%08x)\n", hr);
260 ok(lres == 0, "lres was %ld\n", lres);
262 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
263 ok(hr == S_OK, "got (0x%08x)\n", hr);
265 hr = IShellBrowser_SendControlMsg(psb, FCW_TREE, 0, 0, 0, NULL);
266 ok(hr == S_OK, "got (0x%08x)\n", hr);
268 hr = IShellBrowser_SendControlMsg(psb, FCW_PROGRESS, 0, 0, 0, NULL);
269 ok(hr == S_OK, "got (0x%08x)\n", hr);
272 /* ::QueryActiveShellView */
273 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
274 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
276 /* Initialize ExplorerBrowser */
277 ebrowser_initialize(peb);
279 /***** After EB::Initialize *****/
281 /* ::GetWindow */
282 hr = IShellBrowser_GetWindow(psb, &retHwnd);
283 ok(hr == S_OK, "got (0x%08x)\n", hr);
284 ok(GetParent(retHwnd) == hwnd, "The HWND returned is not our child.\n");
286 todo_wine
288 /* ::SendControlMsg */
289 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
290 ok(hr == S_OK, "got (0x%08x)\n", hr);
292 lres = 0xDEADBEEF;
293 hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, 0, 0, 0, &lres);
294 ok(hr == S_OK, "got (0x%08x)\n", hr);
295 ok(lres == 0, "lres was %ld\n", lres);
297 lres = 0xDEADBEEF;
298 hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
299 ok(hr == S_OK, "got (0x%08x)\n", hr);
300 ok(lres == 0, "lres was %ld\n", lres);
302 lres = 0xDEADBEEF;
303 hr = IShellBrowser_SendControlMsg(psb, 1234, 0, 0, 0, &lres);
304 ok(hr == S_OK, "got (0x%08x)\n", hr);
305 ok(lres == 0, "lres was %ld\n", lres);
307 /* Returns S_OK */
308 hr = IShellBrowser_SetStatusTextSB(psb, NULL);
309 ok(hr == S_OK, "got (0x%08x)\n", hr);
311 hr = IShellBrowser_ContextSensitiveHelp(psb, FALSE);
312 ok(hr == S_OK, "got (0x%08x)\n", hr);
314 hr = IShellBrowser_EnableModelessSB(psb, TRUE);
315 ok(hr == S_OK, "got (0x%08x)\n", hr);
317 hr = IShellBrowser_SetToolbarItems(psb, NULL, 1, 1);
318 ok(hr == S_OK, "got (0x%08x)\n", hr);
321 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
322 ok(hr == E_FAIL, "got (0x%08x)\n", hr);
324 IShellBrowser_Release(psb);
325 IExplorerBrowser_Destroy(peb);
326 IExplorerBrowser_Release(peb);
328 /* Browse to the desktop. */
329 ebrowser_instantiate(&peb);
330 ebrowser_initialize(peb);
331 IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
333 process_msgs();
334 hr = ebrowser_browse_to_desktop(peb);
335 ok(hr == S_OK, "got (0x%08x)\n", hr);
336 process_msgs();
338 /****** After Browsing *****/
340 hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
341 ok(hr == S_OK, "got (0x%08x)\n", hr);
342 if(SUCCEEDED(hr)) IUnknown_Release(punk);
344 IShellBrowser_Release(psb);
345 IExplorerBrowser_Destroy(peb);
346 ref = IExplorerBrowser_Release(peb);
347 ok(ref == 0, "Got %d\n", ref);
350 static void test_initialization(void)
352 IExplorerBrowser *peb;
353 IShellBrowser *psb;
354 HRESULT hr;
355 ULONG lres;
356 RECT rc;
358 ebrowser_instantiate(&peb);
360 if(0)
362 /* Crashes on Windows 7 */
363 hr = IExplorerBrowser_Initialize(peb, NULL, NULL, NULL);
364 hr = IExplorerBrowser_Initialize(peb, hwnd, NULL, NULL);
367 ZeroMemory(&rc, sizeof(RECT));
369 hr = IExplorerBrowser_Initialize(peb, NULL, &rc, NULL);
370 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
372 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
373 ok(hr == S_OK, "got (0x%08x)\n", hr);
375 /* Initialize twice */
376 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
377 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
379 hr = IExplorerBrowser_Destroy(peb);
380 ok(hr == S_OK, "got (0x%08x)\n", hr);
382 /* Initialize again */
383 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
384 ok(hr == E_UNEXPECTED, "got (0x%08x)\n", hr);
386 /* Destroy again */
387 hr = IExplorerBrowser_Destroy(peb);
388 ok(hr == S_OK, "got (0x%08x)\n", hr);
389 lres = IExplorerBrowser_Release(peb);
390 ok(lres == 0, "Got %d\n", lres);
392 /* Initialize with a few different rectangles */
393 peb = NULL;
394 ebrowser_instantiate(&peb);
395 rc.left = 50; rc.top = 20; rc.right = 100; rc.bottom = 80;
396 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
397 ok(hr == S_OK, "got (0x%08x)\n", hr);
398 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
399 ok(hr == S_OK, "Got 0x%08x\n", hr);
400 if(SUCCEEDED(hr))
402 HWND eb_hwnd;
403 RECT eb_rc;
404 char buf[1024];
405 LONG style, expected_style;
406 static const RECT exp_rc = {0, 0, 48, 58};
408 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
409 ok(hr == S_OK, "Got 0x%08x\n", hr);
411 GetClientRect(eb_hwnd, &eb_rc);
412 ok(EqualRect(&eb_rc, &exp_rc), "Got client rect (%d, %d)-(%d, %d)\n",
413 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
415 GetWindowRect(eb_hwnd, &eb_rc);
416 ok(eb_rc.right - eb_rc.left == 50, "Got window width %d\n", eb_rc.right - eb_rc.left);
417 ok(eb_rc.bottom - eb_rc.top == 60, "Got window height %d\n", eb_rc.bottom - eb_rc.top);
419 buf[0] = '\0';
420 GetClassNameA(eb_hwnd, buf, 1024);
421 ok(!lstrcmpA(buf, "ExplorerBrowserControl"), "Unexpected classname %s\n", buf);
423 expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER;
424 style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
425 todo_wine ok(style == expected_style, "Got style 0x%08x, expected 0x%08x\n", style, expected_style);
427 expected_style = WS_EX_CONTROLPARENT;
428 style = GetWindowLongPtrW(eb_hwnd, GWL_EXSTYLE);
429 ok(style == expected_style, "Got exstyle 0x%08x, expected 0x%08x\n", style, expected_style);
431 ok(GetParent(eb_hwnd) == hwnd, "GetParent returns %p\n", GetParent(eb_hwnd));
433 /* ::Destroy() destroys the window. */
434 ok(IsWindow(eb_hwnd), "eb_hwnd invalid.\n");
435 IExplorerBrowser_Destroy(peb);
436 ok(!IsWindow(eb_hwnd), "eb_hwnd valid.\n");
438 IShellBrowser_Release(psb);
439 lres = IExplorerBrowser_Release(peb);
440 ok(lres == 0, "Got refcount %d\n", lres);
442 else
444 skip("Skipping some tests.\n");
446 IExplorerBrowser_Destroy(peb);
447 lres = IExplorerBrowser_Release(peb);
448 ok(lres == 0, "Got refcount %d\n", lres);
451 ebrowser_instantiate(&peb);
452 rc.left = 0; rc.top = 0; rc.right = 0; rc.bottom = 0;
453 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
454 ok(hr == S_OK, "got (0x%08x)\n", hr);
455 IExplorerBrowser_Destroy(peb);
456 lres = IExplorerBrowser_Release(peb);
457 ok(lres == 0, "Got refcount %d\n", lres);
459 ebrowser_instantiate(&peb);
460 rc.left = -1; rc.top = -1; rc.right = 1; rc.bottom = 1;
461 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
462 ok(hr == S_OK, "got (0x%08x)\n", hr);
463 IExplorerBrowser_Destroy(peb);
464 lres = IExplorerBrowser_Release(peb);
465 ok(lres == 0, "Got refcount %d\n", lres);
467 ebrowser_instantiate(&peb);
468 rc.left = 10; rc.top = 10; rc.right = 5; rc.bottom = 5;
469 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
470 ok(hr == S_OK, "got (0x%08x)\n", hr);
471 IExplorerBrowser_Destroy(peb);
472 lres = IExplorerBrowser_Release(peb);
473 ok(lres == 0, "Got refcount %d\n", lres);
475 ebrowser_instantiate(&peb);
476 rc.left = 10; rc.top = 10; rc.right = 5; rc.bottom = 5;
477 hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
478 ok(hr == S_OK, "got (0x%08x)\n", hr);
479 IExplorerBrowser_Destroy(peb);
480 lres = IExplorerBrowser_Release(peb);
481 ok(lres == 0, "Got refcount %d\n", lres);
484 static void test_basics(void)
486 IExplorerBrowser *peb;
487 IShellBrowser *psb;
488 FOLDERSETTINGS fs;
489 ULONG lres;
490 DWORD flags;
491 HDWP hdwp;
492 RECT rc;
493 HRESULT hr;
495 ebrowser_instantiate(&peb);
496 ebrowser_initialize(peb);
498 /* SetRect */
499 rc.left = 0; rc.top = 0; rc.right = 0; rc.bottom = 0;
500 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
501 ok(hr == S_OK, "got (0x%08x)\n", hr);
503 rc.left = 100; rc.top = 100; rc.right = 10; rc.bottom = 10;
504 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
505 ok(hr == S_OK, "got (0x%08x)\n", hr);
507 /* SetRect with DeferWindowPos */
508 rc.left = rc.top = 0; rc.right = rc.bottom = 10;
509 hdwp = BeginDeferWindowPos(1);
510 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
511 ok(hr == S_OK, "got (0x%08x)\n", hr);
512 lres = EndDeferWindowPos(hdwp);
513 ok(lres, "EndDeferWindowPos failed.\n");
515 hdwp = NULL;
516 hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
517 ok(hr == S_OK, "got (0x%08x)\n", hr);
518 ok(hdwp == NULL, "got %p\n", hdwp);
519 lres = EndDeferWindowPos(hdwp);
520 ok(!lres, "EndDeferWindowPos succeeded unexpectedly.\n");
522 /* Test positioning */
523 rc.left = 10; rc.top = 20; rc.right = 50; rc.bottom = 50;
524 hr = IExplorerBrowser_SetRect(peb, NULL, rc);
525 ok(hr == S_OK, "got (0x%08x)\n", hr);
526 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
527 ok(hr == S_OK, "Got 0x%08x\n", hr);
528 if(SUCCEEDED(hr))
530 HWND eb_hwnd;
531 RECT eb_rc;
532 static const RECT exp_rc = {11, 21, 49, 49};
534 hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
535 ok(hr == S_OK, "Got 0x%08x\n", hr);
537 GetClientRect(eb_hwnd, &eb_rc);
538 MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
539 ok(EqualRect(&eb_rc, &exp_rc), "Got rect (%d, %d) - (%d, %d)\n",
540 eb_rc.left, eb_rc.top, eb_rc.right, eb_rc.bottom);
542 IShellBrowser_Release(psb);
545 IExplorerBrowser_Destroy(peb);
546 IExplorerBrowser_Release(peb);
548 /* GetOptions/SetOptions*/
549 ebrowser_instantiate(&peb);
551 if(0) {
552 /* Crashes on Windows 7 */
553 IExplorerBrowser_GetOptions(peb, NULL);
556 hr = IExplorerBrowser_GetOptions(peb, &flags);
557 ok(hr == S_OK, "got (0x%08x)\n", hr);
558 ok(flags == 0, "got (0x%08x)\n", flags);
560 /* Settings preserved through Initialize. */
561 hr = IExplorerBrowser_SetOptions(peb, 0xDEADBEEF);
562 ok(hr == S_OK, "got (0x%08x)\n", hr);
564 ebrowser_initialize(peb);
566 hr = IExplorerBrowser_GetOptions(peb, &flags);
567 ok(flags == 0xDEADBEEF, "got (0x%08x)\n", flags);
568 ok(hr == S_OK, "got (0x%08x)\n", hr);
570 IExplorerBrowser_Destroy(peb);
571 IExplorerBrowser_Release(peb);
573 ebrowser_instantiate(&peb);
574 ebrowser_initialize(peb);
576 /* SetFolderSettings */
577 hr = IExplorerBrowser_SetFolderSettings(peb, NULL);
578 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
579 fs.ViewMode = 0; fs.fFlags = 0;
580 hr = IExplorerBrowser_SetFolderSettings(peb, &fs);
581 todo_wine ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
583 /* TODO: Test after browsing somewhere. */
585 IExplorerBrowser_Destroy(peb);
586 lres = IExplorerBrowser_Release(peb);
587 ok(lres == 0, "Got %d\n", lres);
590 static void test_Advise(void)
592 IExplorerBrowser *peb;
593 IExplorerBrowserEvents *pebe;
594 DWORD cookies[10];
595 HRESULT hr;
596 UINT i, ref;
598 /* Set up our IExplorerBrowserEvents implementation */
599 ebev.lpVtbl = &ebevents;
600 pebe = (IExplorerBrowserEvents*) &ebev;
602 ebrowser_instantiate(&peb);
604 if(0)
606 /* Crashes on Windows 7 */
607 IExplorerBrowser_Advise(peb, pebe, NULL);
608 IExplorerBrowser_Advise(peb, NULL, &cookies[0]);
611 /* Using Unadvise with a cookie that has yet to be given out
612 * results in E_INVALIDARG */
613 hr = IExplorerBrowser_Unadvise(peb, 11);
614 ok(hr == E_INVALIDARG, "got (0x%08x)\n", hr);
616 /* Add some before initialization */
617 for(i = 0; i < 5; i++)
619 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
620 ok(hr == S_OK, "got (0x%08x)\n", hr);
623 ebrowser_initialize(peb);
625 /* Add some after initialization */
626 for(i = 5; i < 10; i++)
628 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
629 ok(hr == S_OK, "got (0x%08x)\n", hr);
632 ok(ebev.ref == 10, "Got %d\n", ebev.ref);
634 /* Remove a bunch somewhere in the middle */
635 for(i = 4; i < 8; i++)
637 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
638 ok(hr == S_OK, "got (0x%08x)\n", hr);
641 if(0)
643 /* Using unadvise with a previously unadvised cookie results
644 * in a crash. */
645 hr = IExplorerBrowser_Unadvise(peb, cookies[5]);
648 /* Remove the rest. */
649 for(i = 0; i < 10; i++)
651 if(i<4||i>7)
653 hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
654 ok(hr == S_OK, "%d: got (0x%08x)\n", i, hr);
658 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
660 /* ::Destroy implies ::Unadvise. */
661 hr = IExplorerBrowser_Advise(peb, pebe, &cookies[0]);
662 ok(hr == S_OK, "Got 0x%08x\n", hr);
663 ok(ebev.ref == 1, "Got %d\n", ebev.ref);
665 hr = IExplorerBrowser_Destroy(peb);
666 ok(hr == S_OK, "Got 0x%08x\n", hr);
667 ok(ebev.ref == 0, "Got %d\n", ebev.ref);
669 ref = IExplorerBrowser_Release(peb);
670 ok(!ref, "Got %d", ref);
673 /* Based on PathAddBackslashW from dlls/shlwapi/path.c */
674 static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
676 size_t iLen;
678 if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
679 return NULL;
681 if (iLen)
683 lpszPath += iLen;
684 if (lpszPath[-1] != '\\')
686 *lpszPath++ = '\\';
687 *lpszPath = '\0';
690 return lpszPath;
693 static void test_browse_pidl_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
694 LPITEMIDLIST pidl, UINT uFlags,
695 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
696 const char *file, int line)
698 HRESULT hr;
699 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
701 hr = IExplorerBrowser_BrowseToIDList(peb, pidl, uFlags);
702 ok_(file, line) (hr == hr_exp, "BrowseToIDList returned 0x%08x\n", hr);
703 process_msgs();
705 ok_(file, line)
706 (ebev->pending == pending && ebev->created == created &&
707 ebev->failed == failed && ebev->completed == completed,
708 "Events occurred: %d, %d, %d, %d\n",
709 ebev->pending, ebev->created, ebev->failed, ebev->completed);
711 #define test_browse_pidl(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
712 test_browse_pidl_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
714 static void test_browse_pidl_sb_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
715 LPITEMIDLIST pidl, UINT uFlags,
716 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
717 const char *file, int line)
719 IShellBrowser *psb;
720 HRESULT hr;
722 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
723 ok_(file, line) (hr == S_OK, "QueryInterface returned 0x%08x\n", hr);
724 if(SUCCEEDED(hr))
726 ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;
728 hr = IShellBrowser_BrowseObject(psb, pidl, uFlags);
729 ok_(file, line) (hr == hr_exp, "BrowseObject returned 0x%08x\n", hr);
730 process_msgs();
732 ok_(file, line)
733 (ebev->pending == pending && ebev->created == created &&
734 ebev->failed == failed && ebev->completed == completed,
735 "Events occurred: %d, %d, %d, %d\n",
736 ebev->pending, ebev->created, ebev->failed, ebev->completed);
738 IShellBrowser_Release(psb);
741 #define test_browse_pidl_sb(peb, ebev, pidl, uFlags, hr, p, cr, f, co) \
742 test_browse_pidl_sb_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)
744 static void test_navigation(void)
746 IExplorerBrowser *peb, *peb2;
747 IFolderView *pfv;
748 IShellFolder *psf;
749 LPITEMIDLIST pidl_current, pidl_child;
750 DWORD cookie, cookie2;
751 HRESULT hr;
752 LONG lres;
753 WCHAR current_path[MAX_PATH];
754 WCHAR child_path[MAX_PATH];
755 static const WCHAR testfolderW[] =
756 {'w','i','n','e','t','e','s','t','f','o','l','d','e','r','\0'};
758 ok(pSHParseDisplayName != NULL, "pSHParseDisplayName unexpectedly missing.\n");
759 ok(pSHCreateShellItem != NULL, "pSHCreateShellItem unexpectedly missing.\n");
761 GetCurrentDirectoryW(MAX_PATH, current_path);
762 if(!lstrlenW(current_path))
764 skip("Failed to create test-directory.\n");
765 return;
768 lstrcpyW(child_path, current_path);
769 myPathAddBackslashW(child_path);
770 lstrcatW(child_path, testfolderW);
772 CreateDirectoryW(child_path, NULL);
774 pSHParseDisplayName(current_path, NULL, &pidl_current, 0, NULL);
775 pSHParseDisplayName(child_path, NULL, &pidl_child, 0, NULL);
777 ebrowser_instantiate(&peb);
778 ebrowser_initialize(peb);
780 ebrowser_instantiate(&peb2);
781 ebrowser_initialize(peb2);
783 /* Set up our IExplorerBrowserEvents implementation */
784 ebev.lpVtbl = &ebevents;
786 IExplorerBrowser_Advise(peb, (IExplorerBrowserEvents*)&ebev, &cookie);
787 IExplorerBrowser_Advise(peb2, (IExplorerBrowserEvents*)&ebev, &cookie2);
789 /* These should all fail */
790 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
791 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
792 test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
793 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
794 test_browse_pidl(peb, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
795 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
796 test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
797 test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
799 /* "The first browse is synchronous" */
800 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
801 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
803 /* Relative navigation */
804 test_browse_pidl(peb, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
805 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
807 hr = IExplorerBrowser_GetCurrentView(peb, &IID_IFolderView, (void**)&pfv);
808 ok(hr == S_OK, "Got 0x%08x\n", hr);
809 if(SUCCEEDED(hr))
811 LPITEMIDLIST pidl_relative;
813 hr = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
814 ok(hr == S_OK, "Got 0x%08x\n", hr);
815 hr = IShellFolder_ParseDisplayName(psf, NULL, NULL, (LPWSTR)testfolderW,
816 NULL, &pidl_relative, NULL);
817 ok(hr == S_OK, "Got 0x%08x\n", hr);
819 /* Browsing to another location here before using the
820 * pidl_relative would make ExplorerBrowser in Windows 7 show a
821 * not-available dialog. Also, passing a relative pidl without
822 * specifying SBSP_RELATIVE makes it look for the pidl on the
823 * desktop
826 test_browse_pidl(peb, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
827 test_browse_pidl_sb(peb2, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
829 ILFree(pidl_relative);
830 /* IShellFolder_Release(psf); */
831 IFolderView_Release(pfv);
834 /* misc **/
835 test_browse_pidl(peb, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
836 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
837 test_browse_pidl(peb, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
838 test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
839 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
840 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
841 test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
842 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
844 test_browse_pidl(peb, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
845 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
846 test_browse_pidl(peb, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
847 test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
849 /* SBSP_NEWBROWSER will return E_INVALIDARG, claims MSDN, but in
850 * reality it works as one would expect (Windows 7 only?).
852 if(0)
854 IExplorerBrowser_BrowseToIDList(peb, NULL, SBSP_NEWBROWSER);
857 hr = IExplorerBrowser_Unadvise(peb, cookie);
858 ok(hr == S_OK, "Got 0x%08x\n", hr);
859 IExplorerBrowser_Destroy(peb);
860 process_msgs();
861 hr = IExplorerBrowser_Unadvise(peb2, cookie2);
862 ok(hr == S_OK, "Got 0x%08x\n", hr);
863 IExplorerBrowser_Destroy(peb2);
864 process_msgs();
866 /* Attempt browsing after destroyed */
867 test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
868 test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
870 lres = IExplorerBrowser_Release(peb);
871 ok(lres == 0, "Got lres %d\n", lres);
872 lres = IExplorerBrowser_Release(peb2);
873 ok(lres == 0, "Got lres %d\n", lres);
875 /******************************************/
876 /* Test some options that affect browsing */
878 ebrowser_instantiate(&peb);
879 hr = IExplorerBrowser_Advise(peb, (IExplorerBrowserEvents*)&ebev, &cookie);
880 ok(hr == S_OK, "Got 0x%08x\n", hr);
881 hr = IExplorerBrowser_SetOptions(peb, EBO_NAVIGATEONCE);
882 ok(hr == S_OK, "got (0x%08x)\n", hr);
883 ebrowser_initialize(peb);
885 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 1, 0, 1);
886 test_browse_pidl(peb, &ebev, pidl_current, 0, E_FAIL, 0, 0, 0, 0);
888 hr = IExplorerBrowser_SetOptions(peb, 0);
889 ok(hr == S_OK, "got (0x%08x)\n", hr);
891 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
892 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
894 /* Difference in behavior lies where? */
895 hr = IExplorerBrowser_SetOptions(peb, EBO_ALWAYSNAVIGATE);
896 ok(hr == S_OK, "got (0x%08x)\n", hr);
898 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
899 test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
901 hr = IExplorerBrowser_Unadvise(peb, cookie);
902 ok(hr == S_OK, "Got 0x%08x\n", hr);
904 IExplorerBrowser_Destroy(peb);
905 lres = IExplorerBrowser_Release(peb);
906 ok(lres == 0, "Got lres %d\n", lres);
908 /* Cleanup */
909 RemoveDirectoryW(child_path);
910 ILFree(pidl_current);
911 ILFree(pidl_child);
914 static void test_GetCurrentView(void)
916 IExplorerBrowser *peb;
917 IUnknown *punk;
918 HRESULT hr;
920 /* GetCurrentView */
921 ebrowser_instantiate(&peb);
923 if(0)
925 /* Crashes under Windows 7 */
926 hr = IExplorerBrowser_GetCurrentView(peb, NULL, NULL);
928 hr = IExplorerBrowser_GetCurrentView(peb, NULL, (void**)&punk);
929 ok(hr == E_FAIL, "Got 0x%08x\n", hr);
931 #define test_gcv(iid, exp) \
932 do { \
933 hr = IExplorerBrowser_GetCurrentView(peb, &iid, (void**)&punk); \
934 ok(hr == exp, "(%s:)Expected (0x%08x), got: (0x%08x)\n", \
935 #iid ,exp, hr); \
936 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
937 } while(0)
939 test_gcv(IID_IUnknown, E_FAIL);
940 test_gcv(IID_IUnknown, E_FAIL);
941 test_gcv(IID_IShellView, E_FAIL);
942 test_gcv(IID_IShellView2, E_FAIL);
943 test_gcv(IID_IFolderView, E_FAIL);
944 test_gcv(IID_IPersistFolder, E_FAIL);
945 test_gcv(IID_IPersistFolder2, E_FAIL);
946 test_gcv(IID_ICommDlgBrowser, E_FAIL);
947 test_gcv(IID_ICommDlgBrowser2, E_FAIL);
948 test_gcv(IID_ICommDlgBrowser3, E_FAIL);
950 ebrowser_initialize(peb);
951 ebrowser_browse_to_desktop(peb);
953 test_gcv(IID_IUnknown, S_OK);
954 test_gcv(IID_IUnknown, S_OK);
955 test_gcv(IID_IShellView, S_OK);
956 test_gcv(IID_IShellView2, S_OK);
957 test_gcv(IID_IFolderView, S_OK);
958 todo_wine test_gcv(IID_IPersistFolder, S_OK);
959 test_gcv(IID_IPersistFolder2, E_NOINTERFACE);
960 test_gcv(IID_ICommDlgBrowser, E_NOINTERFACE);
961 test_gcv(IID_ICommDlgBrowser2, E_NOINTERFACE);
962 test_gcv(IID_ICommDlgBrowser3, E_NOINTERFACE);
964 #undef test_gcv
966 IExplorerBrowser_Destroy(peb);
967 IExplorerBrowser_Release(peb);
970 static BOOL test_instantiate_control(void)
972 IExplorerBrowser *peb;
973 HRESULT hr;
975 hr = ebrowser_instantiate(&peb);
976 ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got (0x%08x)\n", hr);
977 if(FAILED(hr))
978 return FALSE;
980 IExplorerBrowser_Release(peb);
981 return TRUE;
984 static void setup_window(void)
986 WNDCLASSW wc;
987 static const WCHAR ebtestW[] = {'e','b','t','e','s','t',0};
989 ZeroMemory(&wc, sizeof(WNDCLASSW));
990 wc.lpfnWndProc = DefWindowProcW;
991 wc.lpszClassName = ebtestW;
992 RegisterClassW(&wc);
993 hwnd = CreateWindowExW(0, ebtestW, NULL, 0,
994 0, 0, 500, 500,
995 NULL, 0, 0, NULL);
996 ok(hwnd != NULL, "Failed to create window for tests.\n");
999 START_TEST(ebrowser)
1001 OleInitialize(NULL);
1003 if(!test_instantiate_control())
1005 win_skip("No ExplorerBrowser control..\n");
1006 OleUninitialize();
1007 return;
1010 setup_window();
1011 init_function_pointers();
1013 test_QueryInterface();
1014 test_SB_misc();
1015 test_initialization();
1016 test_basics();
1017 test_Advise();
1018 test_navigation();
1019 test_GetCurrentView();
1021 DestroyWindow(hwnd);
1022 OleUninitialize();