ebrowser.c 55.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 *    Unit tests for the Explorer Browser control
 *
 * Copyright 2010 David Hedberg
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <stdio.h>

#define COBJMACROS
24
#define CONST_VTABLE
25 26

#include "shlobj.h"
27
#include "shlwapi.h"
28 29 30

#include "wine/test.h"

31 32 33
#include "initguid.h"
#include "mshtml.h"

34 35
static HWND hwnd;

36 37 38 39 40 41 42 43 44 45
static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);

static void init_function_pointers(void)
{
    HMODULE hmod;

    hmod = GetModuleHandleA("shell32.dll");
    pSHCreateShellItem = (void*)GetProcAddress(hmod, "SHCreateShellItem");
}

46 47 48 49 50 51 52 53 54
/*********************************************************************
 * Some simple helpers
 */
static HRESULT ebrowser_instantiate(IExplorerBrowser **peb)
{
    return CoCreateInstance(&CLSID_ExplorerBrowser, NULL, CLSCTX_INPROC_SERVER,
                            &IID_IExplorerBrowser, (void**)peb);
}

55 56 57
static HRESULT ebrowser_initialize(IExplorerBrowser *peb)
{
    RECT rc;
58
    SetRect(&rc, 0, 0, 500, 500);
59 60 61
    return IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
}

62 63 64
static HRESULT ebrowser_browse_to_desktop(IExplorerBrowser *peb)
{
    LPITEMIDLIST pidl_desktop;
65
    HRESULT hr;
66
    SHGetSpecialFolderLocation (hwnd, CSIDL_DESKTOP, &pidl_desktop);
67 68 69
    hr = IExplorerBrowser_BrowseToIDList(peb, pidl_desktop, 0);
    ILFree(pidl_desktop);
    return hr;
70 71
}

72 73 74 75
/* Process some messages */
static void process_msgs(void)
{
    MSG msg;
76
    while(PeekMessageA( &msg, NULL, 0, 0, PM_REMOVE))
77 78
    {
        TranslateMessage(&msg);
79
        DispatchMessageA(&msg);
80 81 82
    }
}

83 84 85 86
/*********************************************************************
 * IExplorerBrowserEvents implementation
 */
typedef struct {
87
    IExplorerBrowserEvents IExplorerBrowserEvents_iface;
88 89 90 91 92 93
    LONG ref;
    UINT pending, created, completed, failed;
} IExplorerBrowserEventsImpl;

static IExplorerBrowserEventsImpl ebev;

94 95 96 97 98
static inline IExplorerBrowserEventsImpl *impl_from_IExplorerBrowserEvents(IExplorerBrowserEvents *iface)
{
    return CONTAINING_RECORD(iface, IExplorerBrowserEventsImpl, IExplorerBrowserEvents_iface);
}

99 100 101 102 103 104 105 106 107
static HRESULT WINAPI IExplorerBrowserEvents_fnQueryInterface(IExplorerBrowserEvents *iface,
                                                              REFIID riid, void **ppvObj)
{
    ok(0, "Never called.\n");
    return E_NOINTERFACE;
}

static ULONG WINAPI IExplorerBrowserEvents_fnAddRef(IExplorerBrowserEvents *iface)
{
108
    IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
109 110 111 112 113
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI IExplorerBrowserEvents_fnRelease(IExplorerBrowserEvents *iface)
{
114
    IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
115 116 117 118 119 120
    return InterlockedDecrement(&This->ref);
}

static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationPending(IExplorerBrowserEvents *iface,
                                                                   PCIDLIST_ABSOLUTE pidlFolder)
{
121
    IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
122 123 124 125 126 127 128
    This->pending++;
    return S_OK;
}

static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationComplete(IExplorerBrowserEvents *iface,
                                                                    PCIDLIST_ABSOLUTE pidlFolder)
{
129
    IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
130 131 132 133 134 135
    This->completed++;
    return S_OK;
}
static HRESULT WINAPI IExplorerBrowserEvents_fnOnNavigationFailed(IExplorerBrowserEvents *iface,
                                                                  PCIDLIST_ABSOLUTE pidlFolder)
{
136
    IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
137 138 139 140 141 142
    This->failed++;
    return S_OK;
}
static HRESULT WINAPI IExplorerBrowserEvents_fnOnViewCreated(IExplorerBrowserEvents *iface,
                                                             IShellView *psv)
{
143
    IExplorerBrowserEventsImpl *This = impl_from_IExplorerBrowserEvents(iface);
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    This->created++;
    return S_OK;
}

static const IExplorerBrowserEventsVtbl ebevents =
{
    IExplorerBrowserEvents_fnQueryInterface,
    IExplorerBrowserEvents_fnAddRef,
    IExplorerBrowserEvents_fnRelease,
    IExplorerBrowserEvents_fnOnNavigationPending,
    IExplorerBrowserEvents_fnOnViewCreated,
    IExplorerBrowserEvents_fnOnNavigationComplete,
    IExplorerBrowserEvents_fnOnNavigationFailed
};

159 160 161 162 163
/*********************************************************************
 * IExplorerPaneVisibility implementation
 */
typedef struct
{
164
    IExplorerPaneVisibility IExplorerPaneVisibility_iface;
165 166 167 168 169
    LONG ref;
    LONG count;
    LONG np, cp, cp_o, cp_v, dp, pp, qp, aqp, unk; /* The panes */
} IExplorerPaneVisibilityImpl;

170 171 172 173 174
static inline IExplorerPaneVisibilityImpl *impl_from_IExplorerPaneVisibility(IExplorerPaneVisibility *iface)
{
    return CONTAINING_RECORD(iface, IExplorerPaneVisibilityImpl, IExplorerPaneVisibility_iface);
}

175 176 177
static HRESULT WINAPI IExplorerPaneVisibility_fnQueryInterface(IExplorerPaneVisibility *iface,
                                                               REFIID riid, LPVOID *ppvObj)
{
178
    ok(0, "unexpected, %s\n", wine_dbgstr_guid(riid));
179 180 181 182 183 184
    *ppvObj = NULL;
    return E_NOINTERFACE;
}

static ULONG WINAPI IExplorerPaneVisibility_fnAddRef(IExplorerPaneVisibility *iface)
{
185
    IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
186 187 188 189 190
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI IExplorerPaneVisibility_fnRelease(IExplorerPaneVisibility *iface)
{
191
    IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
192 193 194
    ULONG ref = InterlockedDecrement(&This->ref);

    if(!ref)
195
        free(This);
196 197 198 199 200 201 202 203

    return ref;
}

static HRESULT WINAPI IExplorerPaneVisibility_fnGetPaneState(IExplorerPaneVisibility *iface,
                                                             REFEXPLORERPANE ep,
                                                             EXPLORERPANESTATE *peps)
{
204
    IExplorerPaneVisibilityImpl *This = impl_from_IExplorerPaneVisibility(iface);
205 206 207 208
    This->count++;

    ok(ep != NULL, "ep is NULL.\n");
    ok(peps != NULL, "peps is NULL.\n");
209
    ok(*peps == 0, "got %ld\n", *peps);
210 211 212 213 214 215 216 217 218 219 220 221

    *peps = EPS_FORCE;
    if(IsEqualGUID(&EP_NavPane, ep))                 This->np++;
    else if(IsEqualGUID(&EP_Commands, ep))           This->cp++;
    else if(IsEqualGUID(&EP_Commands_Organize, ep))  This->cp_o++;
    else if(IsEqualGUID(&EP_Commands_View, ep))      This->cp_v++;
    else if(IsEqualGUID(&EP_DetailsPane, ep))        This->dp++;
    else if(IsEqualGUID(&EP_PreviewPane, ep))        This->pp++;
    else if(IsEqualGUID(&EP_QueryPane, ep))          This->qp++;
    else if(IsEqualGUID(&EP_AdvQueryPane, ep))       This->aqp++;
    else
    {
222
        trace("Unknown explorer pane: %s\n", wine_dbgstr_guid(ep));
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
        This->unk++;
    }

    return S_OK;
}

static const IExplorerPaneVisibilityVtbl epvvt =
{
    IExplorerPaneVisibility_fnQueryInterface,
    IExplorerPaneVisibility_fnAddRef,
    IExplorerPaneVisibility_fnRelease,
    IExplorerPaneVisibility_fnGetPaneState
};

static IExplorerPaneVisibilityImpl *create_explorerpanevisibility(void)
{
    IExplorerPaneVisibilityImpl *epv;

241
    epv = calloc(1, sizeof(*epv));
242
    epv->IExplorerPaneVisibility_iface.lpVtbl = &epvvt;
243 244 245 246 247
    epv->ref = 1;

    return epv;
}

248 249 250 251 252
/*********************************************************************
 * ICommDlgBrowser3 implementation
 */
typedef struct
{
253
    ICommDlgBrowser3 ICommDlgBrowser3_iface;
254 255 256 257 258 259
    LONG ref;
    UINT OnDefaultCommand, OnStateChange, IncludeObject;
    UINT Notify, GetDefaultMenuText, GetViewFlags;
    UINT OnColumnClicked, GetCurrentFilter, OnPreviewCreated;
} ICommDlgBrowser3Impl;

260 261 262 263 264
static inline ICommDlgBrowser3Impl *impl_from_ICommDlgBrowser3(ICommDlgBrowser3 *iface)
{
    return CONTAINING_RECORD(iface, ICommDlgBrowser3Impl, ICommDlgBrowser3_iface);
}

265 266
static HRESULT WINAPI ICommDlgBrowser3_fnQueryInterface(ICommDlgBrowser3 *iface, REFIID riid, LPVOID *ppvObj)
{
267
    ok(0, "unexpected %s\n", wine_dbgstr_guid(riid));
268 269 270 271 272 273
    *ppvObj = NULL;
    return E_NOINTERFACE;
}

static ULONG WINAPI ICommDlgBrowser3_fnAddRef(ICommDlgBrowser3 *iface)
{
274
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
275 276 277 278 279
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI ICommDlgBrowser3_fnRelease(ICommDlgBrowser3 *iface)
{
280
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
281 282 283
    ULONG ref = InterlockedDecrement(&This->ref);

    if(!ref)
284
        free(This);
285 286 287 288 289 290

    return ref;
}

static HRESULT WINAPI ICommDlgBrowser3_fnOnDefaultCommand(ICommDlgBrowser3* iface, IShellView *shv)
{
291
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
292 293 294 295 296 297 298 299 300
    This->OnDefaultCommand++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnOnStateChange(
    ICommDlgBrowser3* iface,
    IShellView *shv,
    ULONG uChange)
{
301
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
302 303 304 305 306 307 308 309 310
    This->OnStateChange++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnIncludeObject(
    ICommDlgBrowser3* iface,
    IShellView *shv,
    LPCITEMIDLIST pidl)
{
311
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
312 313 314 315 316 317 318 319 320
    This->IncludeObject++;
    return S_OK;
}

static HRESULT WINAPI ICommDlgBrowser3_fnNotify(
    ICommDlgBrowser3* iface,
    IShellView *ppshv,
    DWORD dwNotifyType)
{
321
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
322 323 324 325 326 327 328 329 330 331
    This->Notify++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnGetDefaultMenuText(
    ICommDlgBrowser3* iface,
    IShellView *ppshv,
    LPWSTR pszText,
    int cchMax)
{
332
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
333 334 335 336 337 338 339 340
    This->GetDefaultMenuText++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnGetViewFlags(
    ICommDlgBrowser3* iface,
    DWORD *pdwFlags)
{
341
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
342 343 344 345 346 347 348 349 350
    This->GetViewFlags++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnOnColumnClicked(
    ICommDlgBrowser3* iface,
    IShellView *ppshv,
    int iColumn)
{
351
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
352 353 354 355 356 357 358 359 360
    This->OnColumnClicked++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnGetCurrentFilter(
    ICommDlgBrowser3* iface,
    LPWSTR pszFileSpec,
    int cchFileSpec)
{
361
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
362 363 364 365 366 367 368 369
    This->GetCurrentFilter++;
    return E_NOTIMPL;
}

static HRESULT WINAPI ICommDlgBrowser3_fnOnPreviewCreated(
    ICommDlgBrowser3* iface,
    IShellView *ppshv)
{
370
    ICommDlgBrowser3Impl *This = impl_from_ICommDlgBrowser3(iface);
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
    This->OnPreviewCreated++;
    return E_NOTIMPL;
}

static const ICommDlgBrowser3Vtbl cdbvtbl =
{
    ICommDlgBrowser3_fnQueryInterface,
    ICommDlgBrowser3_fnAddRef,
    ICommDlgBrowser3_fnRelease,
    ICommDlgBrowser3_fnOnDefaultCommand,
    ICommDlgBrowser3_fnOnStateChange,
    ICommDlgBrowser3_fnIncludeObject,
    ICommDlgBrowser3_fnNotify,
    ICommDlgBrowser3_fnGetDefaultMenuText,
    ICommDlgBrowser3_fnGetViewFlags,
    ICommDlgBrowser3_fnOnColumnClicked,
    ICommDlgBrowser3_fnGetCurrentFilter,
    ICommDlgBrowser3_fnOnPreviewCreated
};

391
static ICommDlgBrowser3Impl *create_commdlgbrowser3(void)
392 393 394
{
    ICommDlgBrowser3Impl *cdb;

395
    cdb = calloc(1, sizeof(*cdb));
396
    cdb->ICommDlgBrowser3_iface.lpVtbl = &cdbvtbl;
397 398 399 400 401
    cdb->ref = 1;

    return cdb;
}

402 403 404 405
/*********************************************************************
 * IServiceProvider Implementation
 */
typedef struct {
406
    IServiceProvider IServiceProvider_iface;
407 408 409 410 411 412 413 414
    LONG ref;
    struct services {
        REFGUID service;
        REFIID id;
        void *punk;
    } *interfaces;
} IServiceProviderImpl;

415 416 417 418 419
static inline IServiceProviderImpl *impl_from_IServiceProvider(IServiceProvider *iface)
{
    return CONTAINING_RECORD(iface, IServiceProviderImpl, IServiceProvider_iface);
}

420 421 422 423 424 425
static HRESULT WINAPI IServiceProvider_fnQueryInterface(IServiceProvider *iface, REFIID riid, LPVOID *ppvObj)
{
    *ppvObj = NULL;
    if(IsEqualIID(riid, &IID_IServiceProvider))
    {
        *ppvObj = iface;
426
        IServiceProvider_AddRef(iface);
427 428 429 430 431 432 433 434 435
        return S_OK;
    }

    if(IsEqualIID(riid, &IID_IOleCommandTarget))
    {
        /* Windows Vista. */
        return E_NOINTERFACE;
    }

436
    ok(0, "Unexpected interface requested, %s\n", wine_dbgstr_guid(riid));
437 438 439 440 441
    return E_NOINTERFACE;
}

static ULONG WINAPI IServiceProvider_fnAddRef(IServiceProvider *iface)
{
442
    IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
443 444 445 446 447
    return InterlockedIncrement(&This->ref);
}

static ULONG WINAPI IServiceProvider_fnRelease(IServiceProvider *iface)
{
448
    IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
449 450 451
    LONG ref = InterlockedDecrement(&This->ref);

    if(!ref)
452
        free(This);
453 454 455 456 457 458 459 460 461

    return ref;
}

static HRESULT WINAPI IServiceProvider_fnQueryService(IServiceProvider *iface,
                                                      REFGUID guidService,
                                                      REFIID riid,
                                                      void **ppv)
{
462
    IServiceProviderImpl *This = impl_from_IServiceProvider(iface);
463 464
    UINT i;

465 466 467
    if (winetest_debug > 1)
            trace("QueryService(service %s, iid %s)\n", debugstr_guid(guidService), debugstr_guid(riid));

468 469 470 471 472
    for(i = 0; This->interfaces[i].service != NULL; i++)
    {
        if(IsEqualGUID(This->interfaces[i].service, guidService) &&
           IsEqualIID(This->interfaces[i].id, riid))
        {
473 474 475
            *ppv = This->interfaces[i].punk;
            IUnknown_AddRef((IUnknown *)*ppv);
            return S_OK;
476 477 478
        }
    }

479
    *ppv = NULL;
480 481 482 483 484 485 486 487 488 489 490 491 492
    return E_NOINTERFACE;
}

static const IServiceProviderVtbl spvtbl =
{
    IServiceProvider_fnQueryInterface,
    IServiceProvider_fnAddRef,
    IServiceProvider_fnRelease,
    IServiceProvider_fnQueryService
};

static IServiceProviderImpl *create_serviceprovider(void)
{
493
    IServiceProviderImpl *sp = malloc(sizeof(*sp));
494
    sp->IServiceProvider_iface.lpVtbl = &spvtbl;
495 496 497 498
    sp->ref = 1;
    return sp;
}

499 500 501 502 503 504 505 506
static void test_QueryInterface(void)
{
    IExplorerBrowser *peb;
    IUnknown *punk;
    HRESULT hr;
    LONG lres;

    hr = ebrowser_instantiate(&peb);
507
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
508 509 510 511

#define test_qinterface(iid, exp)                                       \
    do {                                                                \
        hr = IExplorerBrowser_QueryInterface(peb, &iid, (void**)&punk); \
512
        ok(hr == exp, "(%s:)Expected (0x%08lx), got (0x%08lx)\n",         \
513 514 515 516 517 518
           #iid, exp, hr);                                              \
        if(SUCCEEDED(hr)) IUnknown_Release(punk);                       \
    } while(0)

    test_qinterface(IID_IUnknown, S_OK);
    test_qinterface(IID_IExplorerBrowser, S_OK);
519
    test_qinterface(IID_IShellBrowser, S_OK);
520
    test_qinterface(IID_IOleWindow, S_OK);
521 522 523
    test_qinterface(IID_ICommDlgBrowser, S_OK);
    test_qinterface(IID_ICommDlgBrowser2, S_OK);
    test_qinterface(IID_ICommDlgBrowser3, S_OK);
524
    todo_wine test_qinterface(IID_IServiceProvider, S_OK);
525
    test_qinterface(IID_IObjectWithSite, S_OK);
526 527 528 529 530 531 532 533 534 535 536 537
    todo_wine test_qinterface(IID_IConnectionPointContainer, S_OK);
    test_qinterface(IID_IOleObject, E_NOINTERFACE);
    test_qinterface(IID_IViewObject, E_NOINTERFACE);
    test_qinterface(IID_IViewObject2, E_NOINTERFACE);
    test_qinterface(IID_IViewObjectEx, E_NOINTERFACE);
    test_qinterface(IID_IConnectionPoint, E_NOINTERFACE);
    test_qinterface(IID_IShellView, E_NOINTERFACE);
    test_qinterface(IID_INameSpaceTreeControlEvents, E_NOINTERFACE);

#undef test_qinterface

    lres = IExplorerBrowser_Release(peb);
538
    ok(lres == 0, "Got %ld\n", lres);
539 540
}

541 542 543 544
static void test_SB_misc(void)
{
    IExplorerBrowser *peb;
    IShellBrowser *psb;
545
    IUnknown *punk;
546 547
    HRESULT hr;
    HWND retHwnd;
548 549
    LRESULT lres;
    LONG ref;
550 551 552

    ebrowser_instantiate(&peb);
    hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
553
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
554 555 556 557 558 559 560
    if(FAILED(hr))
    {
        skip("Failed to get IShellBrowser interface.\n");
        return;
    }

    /* Some unimplemented methods */
561
    retHwnd = (HWND)0xdeadbeef;
562
    hr = IShellBrowser_GetControlWindow(psb, FCW_TOOLBAR, &retHwnd);
563
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
564
    ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
565

566
    retHwnd = (HWND)0xdeadbeef;
567
    hr = IShellBrowser_GetControlWindow(psb, FCW_STATUS, &retHwnd);
568
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
569
    ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
570

571
    retHwnd = (HWND)0xdeadbeef;
572
    hr = IShellBrowser_GetControlWindow(psb, FCW_TREE, &retHwnd);
573
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
574
    ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
575

576
    retHwnd = (HWND)0xdeadbeef;
577
    hr = IShellBrowser_GetControlWindow(psb, FCW_PROGRESS, &retHwnd);
578
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
579
    ok(retHwnd == NULL || broken(retHwnd == (HWND)0xdeadbeef), "got %p\n", retHwnd);
580 581 582

    /* ::InsertMenuSB */
    hr = IShellBrowser_InsertMenusSB(psb, NULL, NULL);
583
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
584 585 586

    /* ::RemoveMenusSB */
    hr = IShellBrowser_RemoveMenusSB(psb, NULL);
587
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
588 589 590

    /* ::SetMenuSB */
    hr = IShellBrowser_SetMenuSB(psb, NULL, NULL, NULL);
591
    ok(hr == E_NOTIMPL, "got (0x%08lx)\n", hr);
592

593 594 595 596 597
    /***** Before EB::Initialize *****/

    /* ::GetWindow */
    retHwnd = (HWND)0xDEADBEEF;
    hr = IShellBrowser_GetWindow(psb, &retHwnd);
598
    ok(hr == E_FAIL, "got (0x%08lx)\n", hr);
599 600 601 602 603 604 605 606
    ok(retHwnd == (HWND)0xDEADBEEF, "HWND overwritten\n");

    todo_wine
    {

        /* ::SendControlMsg */
        lres = 0xDEADBEEF;
        hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
607 608
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
        ok(lres == 0, "lres was %Id\n", lres);
609 610 611 612

        lres = 0xDEADBEEF;
        hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, TB_CHECKBUTTON,
                                          FCIDM_TB_SMALLICON, TRUE, &lres);
613 614
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
        ok(lres == 0, "lres was %Id\n", lres);
615 616

        hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
617
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
618 619

        hr = IShellBrowser_SendControlMsg(psb, FCW_TREE, 0, 0, 0, NULL);
620
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
621 622

        hr = IShellBrowser_SendControlMsg(psb, FCW_PROGRESS, 0, 0, 0, NULL);
623
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
624 625 626 627
    }

    /* ::QueryActiveShellView */
    hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
628
    ok(hr == E_FAIL, "got (0x%08lx)\n", hr);
629 630 631 632 633 634 635 636

    /* Initialize ExplorerBrowser */
    ebrowser_initialize(peb);

    /***** After EB::Initialize *****/

    /* ::GetWindow */
    hr = IShellBrowser_GetWindow(psb, &retHwnd);
637
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
638 639 640 641 642 643
    ok(GetParent(retHwnd) == hwnd, "The HWND returned is not our child.\n");

    todo_wine
    {
        /* ::SendControlMsg */
        hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, NULL);
644
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
645 646 647

        lres = 0xDEADBEEF;
        hr = IShellBrowser_SendControlMsg(psb, FCW_TOOLBAR, 0, 0, 0, &lres);
648 649
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
        ok(lres == 0, "lres was %Id\n", lres);
650 651 652

        lres = 0xDEADBEEF;
        hr = IShellBrowser_SendControlMsg(psb, FCW_STATUS, 0, 0, 0, &lres);
653 654
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
        ok(lres == 0, "lres was %Id\n", lres);
655 656 657

        lres = 0xDEADBEEF;
        hr = IShellBrowser_SendControlMsg(psb, 1234, 0, 0, 0, &lres);
658 659
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
        ok(lres == 0, "lres was %Id\n", lres);
660 661 662

        /* Returns S_OK */
        hr = IShellBrowser_SetStatusTextSB(psb, NULL);
663
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
664 665

        hr = IShellBrowser_ContextSensitiveHelp(psb, FALSE);
666
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
667 668

        hr = IShellBrowser_EnableModelessSB(psb, TRUE);
669
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
670 671

        hr = IShellBrowser_SetToolbarItems(psb, NULL, 1, 1);
672
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
673 674 675
    }

    hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
676
    ok(hr == E_FAIL, "got (0x%08lx)\n", hr);
677

678 679 680 681 682 683 684 685 686 687 688
    IShellBrowser_Release(psb);
    IExplorerBrowser_Destroy(peb);
    IExplorerBrowser_Release(peb);

    /* Browse to the desktop. */
    ebrowser_instantiate(&peb);
    ebrowser_initialize(peb);
    IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);

    process_msgs();
    hr = ebrowser_browse_to_desktop(peb);
689
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
690 691 692 693 694
    process_msgs();

    /****** After Browsing *****/

    hr = IShellBrowser_QueryActiveShellView(psb, (IShellView**)&punk);
695
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
696 697
    if(SUCCEEDED(hr)) IUnknown_Release(punk);

698
    IShellBrowser_Release(psb);
699 700
    IExplorerBrowser_Destroy(peb);
    ref = IExplorerBrowser_Release(peb);
701
    ok(ref == 0, "Got %ld\n", ref);
702 703
}

704 705 706 707
static void test_initialization(void)
{
    IExplorerBrowser *peb;
    IShellBrowser *psb;
708
    HWND eb_hwnd;
709 710
    HRESULT hr;
    ULONG lres;
711
    LONG style;
712 713 714 715 716 717 718
    RECT rc;

    ebrowser_instantiate(&peb);

    if(0)
    {
        /* Crashes on Windows 7 */
719 720
        IExplorerBrowser_Initialize(peb, NULL, NULL, NULL);
        IExplorerBrowser_Initialize(peb, hwnd, NULL, NULL);
721 722 723 724 725
    }

    ZeroMemory(&rc, sizeof(RECT));

    hr = IExplorerBrowser_Initialize(peb, NULL, &rc, NULL);
726
    ok(hr == E_INVALIDARG, "got (0x%08lx)\n", hr);
727 728

    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
729
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
730 731 732

    /* Initialize twice */
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
733
    ok(hr == E_UNEXPECTED, "got (0x%08lx)\n", hr);
734 735

    hr = IExplorerBrowser_Destroy(peb);
736
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
737 738 739

    /* Initialize again */
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
740
    ok(hr == E_UNEXPECTED, "got (0x%08lx)\n", hr);
741 742 743

    /* Destroy again */
    hr = IExplorerBrowser_Destroy(peb);
744
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
745
    lres = IExplorerBrowser_Release(peb);
746
    ok(lres == 0, "Got %ld\n", lres);
747 748 749 750

    /* Initialize with a few different rectangles */
    peb = NULL;
    ebrowser_instantiate(&peb);
751
    SetRect(&rc, 50, 20, 100, 80);
752
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
753
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
754
    hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
755
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
756 757 758 759
    if(SUCCEEDED(hr))
    {
        RECT eb_rc;
        char buf[1024];
760
        LONG expected_style;
761 762 763
        static const RECT exp_rc = {0, 0, 48, 58};

        hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
764
        ok(hr == S_OK, "Got 0x%08lx\n", hr);
765 766

        GetClientRect(eb_hwnd, &eb_rc);
767
        ok(EqualRect(&eb_rc, &exp_rc), "Got client rect %s\n", wine_dbgstr_rect(&eb_rc));
768 769

        GetWindowRect(eb_hwnd, &eb_rc);
770 771
        ok(eb_rc.right - eb_rc.left == 50, "Got window width %ld\n", eb_rc.right - eb_rc.left);
        ok(eb_rc.bottom - eb_rc.top == 60, "Got window height %ld\n", eb_rc.bottom - eb_rc.top);
772 773 774 775 776 777 778

        buf[0] = '\0';
        GetClassNameA(eb_hwnd, buf, 1024);
        ok(!lstrcmpA(buf, "ExplorerBrowserControl"), "Unexpected classname %s\n", buf);

        expected_style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_BORDER;
        style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
779
        todo_wine ok(style == expected_style, "Got style 0x%08lx, expected 0x%08lx\n", style, expected_style);
780 781 782

        expected_style = WS_EX_CONTROLPARENT;
        style = GetWindowLongPtrW(eb_hwnd, GWL_EXSTYLE);
783
        ok(style == expected_style, "Got exstyle 0x%08lx, expected 0x%08lx\n", style, expected_style);
784 785 786 787 788 789 790 791 792 793

        ok(GetParent(eb_hwnd) == hwnd, "GetParent returns %p\n", GetParent(eb_hwnd));

        /* ::Destroy() destroys the window. */
        ok(IsWindow(eb_hwnd), "eb_hwnd invalid.\n");
        IExplorerBrowser_Destroy(peb);
        ok(!IsWindow(eb_hwnd), "eb_hwnd valid.\n");

        IShellBrowser_Release(psb);
        lres = IExplorerBrowser_Release(peb);
794
        ok(lres == 0, "Got refcount %ld\n", lres);
795 796 797 798 799 800 801
    }
    else
    {
        skip("Skipping some tests.\n");

        IExplorerBrowser_Destroy(peb);
        lres = IExplorerBrowser_Release(peb);
802
        ok(lres == 0, "Got refcount %ld\n", lres);
803 804
    }

805 806 807
    /* check window style with EBO_NOBORDER */
    ebrowser_instantiate(&peb);
    hr = IExplorerBrowser_SetOptions(peb, EBO_NOBORDER);
808
    ok(hr == S_OK, "got 0x%08lx\n", hr);
809
    SetRect(&rc, 50, 20, 100, 80);
810 811

    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
812
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
813 814

    hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
815
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
816 817

    hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
818
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
819 820

    style = GetWindowLongPtrW(eb_hwnd, GWL_STYLE);
821
    ok(!(style & WS_BORDER) || broken(style & WS_BORDER) /* before win8 */, "got style 0x%08lx\n", style);
822 823 824 825 826 827

    IShellBrowser_Release(psb);
    IExplorerBrowser_Destroy(peb);
    IExplorerBrowser_Release(peb);

    /* empty rectangle */
828
    ebrowser_instantiate(&peb);
829
    SetRectEmpty(&rc);
830
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
831
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
832 833
    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
834
    ok(lres == 0, "Got refcount %ld\n", lres);
835 836

    ebrowser_instantiate(&peb);
837
    SetRect(&rc, -1, -1, 1, 1);
838
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
839
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
840 841
    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
842
    ok(lres == 0, "Got refcount %ld\n", lres);
843 844

    ebrowser_instantiate(&peb);
845
    SetRect(&rc, 10, 10, 5, 5);
846
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
847
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
848 849
    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
850
    ok(lres == 0, "Got refcount %ld\n", lres);
851 852

    ebrowser_instantiate(&peb);
853
    SetRect(&rc, 10, 10, 5, 5);
854
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
855
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
856 857
    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
858
    ok(lres == 0, "Got refcount %ld\n", lres);
859 860
}

861 862 863 864
static void test_SetSite(void)
{
    IExplorerBrowser *peb;
    IServiceProviderImpl *spimpl = create_serviceprovider();
865
    ICommDlgBrowser3Impl *cdbimpl = create_commdlgbrowser3();
866
    IExplorerPaneVisibilityImpl *epvimpl = create_explorerpanevisibility();
867 868 869 870
    IObjectWithSite *pow;
    HRESULT hr;
    LONG ref;
    UINT i;
871 872 873 874 875 876 877 878
    struct services expected[] =
    {
        {&SID_STopLevelBrowser,        &IID_ICommDlgBrowser2,          cdbimpl},
        {&SID_ExplorerPaneVisibility,  &IID_IExplorerPaneVisibility,   epvimpl},
        {&SID_SExplorerBrowserFrame,   &IID_ICommDlgBrowser2,          cdbimpl},
        {&SID_SExplorerBrowserFrame,   &IID_ICommDlgBrowser3,          cdbimpl},
        {&IID_ICommDlgBrowser,         &IID_ICommDlgBrowser,           cdbimpl},
        {NULL}
879 880 881 882 883 884
    };

    ebrowser_instantiate(&peb);
    IExplorerBrowser_SetOptions(peb, EBO_SHOWFRAMES);

    hr = IExplorerBrowser_QueryInterface(peb, &IID_IObjectWithSite, (void**)&pow);
885
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
886 887 888 889
    if(SUCCEEDED(hr))
    {
        spimpl->interfaces = expected;

890
        hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
891
        ok(hr == S_OK, "Got 0x%08lx\n", hr);
892 893 894 895 896 897 898 899 900

        if(FAILED(hr))
            IObjectWithSite_Release(pow);
    }

    if(FAILED(hr))
    {
        skip("Failed to set site.\n");

901 902 903
        IServiceProvider_Release(&spimpl->IServiceProvider_iface);
        ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
        IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
904 905
        IExplorerBrowser_Destroy(peb);
        ref = IExplorerBrowser_Release(peb);
906
        ok(ref == 0, "Got ref %ld\n", ref);
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921

        return;
    }

    ShowWindow(hwnd, TRUE);
    ebrowser_initialize(peb);
    ebrowser_browse_to_desktop(peb);

    for(i = 0; i < 10; i++)
    {
        Sleep(100);
        process_msgs();
    }
    ShowWindow(hwnd, FALSE);

922 923 924 925 926 927 928 929 930 931 932
    /* ICommDlgBrowser3 */
    ok(!cdbimpl->OnDefaultCommand, "Got %d\n", cdbimpl->OnDefaultCommand);
    todo_wine ok(cdbimpl->OnStateChange, "Got %d\n", cdbimpl->OnStateChange);
    ok(cdbimpl->IncludeObject, "Got %d\n", cdbimpl->IncludeObject);
    ok(!cdbimpl->Notify, "Got %d\n", cdbimpl->Notify);
    ok(!cdbimpl->GetDefaultMenuText, "Got %d\n", cdbimpl->GetDefaultMenuText);
    todo_wine ok(cdbimpl->GetViewFlags, "Got %d\n", cdbimpl->GetViewFlags);
    ok(!cdbimpl->OnColumnClicked, "Got %d\n", cdbimpl->OnColumnClicked);
    ok(!cdbimpl->GetCurrentFilter, "Got %d\n", cdbimpl->GetCurrentFilter);
    todo_wine ok(cdbimpl->OnPreviewCreated, "Got %d\n", cdbimpl->OnPreviewCreated);

933
    /* IExplorerPaneVisibility */
934 935 936 937 938 939 940 941 942
    ok(epvimpl->np, "Got %ld\n", epvimpl->np);
    todo_wine ok(epvimpl->cp, "Got %ld\n", epvimpl->cp);
    todo_wine ok(epvimpl->cp_o, "Got %ld\n", epvimpl->cp_o);
    todo_wine ok(epvimpl->cp_v, "Got %ld\n", epvimpl->cp_v);
    todo_wine ok(epvimpl->dp, "Got %ld\n", epvimpl->dp);
    todo_wine ok(epvimpl->pp, "Got %ld\n", epvimpl->pp);
    ok(!epvimpl->qp, "Got %ld\n", epvimpl->qp);
    ok(!epvimpl->aqp, "Got %ld\n", epvimpl->aqp);
    ok(!epvimpl->unk, "Got %ld\n", epvimpl->unk);
943

944
    /* Test when IServiceProvider is released. */
945 946
    IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
    ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
947
    ok(ref == 2, "Got ref %ld\n", ref);
948 949

    hr = IObjectWithSite_SetSite(pow, NULL);
950
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
951

952 953
    IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
    ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
954
    ok(ref == 1, "Got ref %ld\n", ref);
955

956
    hr = IObjectWithSite_SetSite(pow, (IUnknown*)&spimpl->IServiceProvider_iface);
957
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
958

959 960
    IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
    ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
961
    ok(ref == 2, "Got ref %ld\n", ref);
962 963 964

    IExplorerBrowser_Destroy(peb);

965 966
    IServiceProvider_AddRef(&spimpl->IServiceProvider_iface);
    ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
967
    ok(ref == 2, "Got ref %ld\n", ref);
968 969 970

    IObjectWithSite_Release(pow);
    ref = IExplorerBrowser_Release(peb);
971
    ok(ref == 0, "Got ref %ld\n", ref);
972

973
    ref = IServiceProvider_Release(&spimpl->IServiceProvider_iface);
974
    ok(ref == 0, "Got ref %ld\n", ref);
975

976
    ref = ICommDlgBrowser3_Release(&cdbimpl->ICommDlgBrowser3_iface);
977
    ok(ref == 0, "Got ref %ld\n", ref);
978
    ref = IExplorerPaneVisibility_Release(&epvimpl->IExplorerPaneVisibility_iface);
979
    ok(ref == 0, "Got ref %ld\n", ref);
980 981
}

982 983 984 985
static void test_basics(void)
{
    IExplorerBrowser *peb;
    IShellBrowser *psb;
986
    FOLDERSETTINGS fs;
987
    ULONG lres;
988
    EXPLORER_BROWSER_OPTIONS flags;
989 990 991
    HDWP hdwp;
    RECT rc;
    HRESULT hr;
992
    static const WCHAR winetest[] = {'W','i','n','e','T','e','s','t',0};
993 994 995 996 997

    ebrowser_instantiate(&peb);
    ebrowser_initialize(peb);

    /* SetRect */
998
    SetRectEmpty(&rc);
999
    hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1000
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1001

1002
    SetRect(&rc, 100, 100, 10, 10);
1003
    hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1004
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1005 1006

    /* SetRect with DeferWindowPos */
1007
    SetRect(&rc, 0, 0, 10, 10);
1008 1009
    hdwp = BeginDeferWindowPos(1);
    hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1010
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1011 1012 1013 1014 1015
    lres = EndDeferWindowPos(hdwp);
    ok(lres, "EndDeferWindowPos failed.\n");

    hdwp = NULL;
    hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1016
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1017 1018 1019 1020 1021
    ok(hdwp == NULL, "got %p\n", hdwp);
    lres = EndDeferWindowPos(hdwp);
    ok(!lres, "EndDeferWindowPos succeeded unexpectedly.\n");

    /* Test positioning */
1022
    SetRect(&rc, 10, 20, 50, 50);
1023
    hr = IExplorerBrowser_SetRect(peb, NULL, rc);
1024
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1025
    hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1026
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1027 1028 1029 1030 1031
    if(SUCCEEDED(hr))
    {
        HWND eb_hwnd;
        RECT eb_rc;
        static const RECT exp_rc = {11, 21, 49, 49};
1032
        static const RECT exp_rc2 = {11, 21, 49, 24};
1033 1034

        hr = IShellBrowser_GetWindow(psb, &eb_hwnd);
1035
        ok(hr == S_OK, "Got 0x%08lx\n", hr);
1036 1037 1038

        GetClientRect(eb_hwnd, &eb_rc);
        MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1039
        ok(EqualRect(&eb_rc, &exp_rc), "Got rect %s\n", wine_dbgstr_rect(&eb_rc));
1040

1041 1042 1043 1044
        /* Try resizing with invalid hdwp */
        rc.bottom = 25;
        hdwp = (HDWP)0xdeadbeef;
        hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1045
        ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1046 1047
        GetClientRect(eb_hwnd, &eb_rc);
        MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1048
        ok(EqualRect(&eb_rc, &exp_rc), "Got rect %s\n", wine_dbgstr_rect(&eb_rc));
1049 1050 1051

        hdwp = NULL;
        hr = IExplorerBrowser_SetRect(peb, &hdwp, rc);
1052
        ok(hr == S_OK, "Got 0x%08lx\n", hr);
1053 1054
        GetClientRect(eb_hwnd, &eb_rc);
        MapWindowPoints(eb_hwnd, hwnd, (POINT*)&eb_rc, 2);
1055
        ok(EqualRect(&eb_rc, &exp_rc2), "Got rect %s\n", wine_dbgstr_rect(&eb_rc));
1056

1057 1058 1059
        IShellBrowser_Release(psb);
    }

1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071
    IExplorerBrowser_Destroy(peb);
    IExplorerBrowser_Release(peb);

    /* GetOptions/SetOptions*/
    ebrowser_instantiate(&peb);

    if(0) {
        /* Crashes on Windows 7 */
        IExplorerBrowser_GetOptions(peb, NULL);
    }

    hr = IExplorerBrowser_GetOptions(peb, &flags);
1072
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1073 1074 1075 1076
    ok(flags == 0, "got (0x%08x)\n", flags);

    /* Settings preserved through Initialize. */
    hr = IExplorerBrowser_SetOptions(peb, 0xDEADBEEF);
1077
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1078 1079 1080 1081 1082

    ebrowser_initialize(peb);

    hr = IExplorerBrowser_GetOptions(peb, &flags);
    ok(flags == 0xDEADBEEF, "got (0x%08x)\n", flags);
1083
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1084

1085 1086 1087 1088 1089 1090 1091 1092
    IExplorerBrowser_Destroy(peb);
    IExplorerBrowser_Release(peb);

    ebrowser_instantiate(&peb);
    ebrowser_initialize(peb);

    /* SetFolderSettings */
    hr = IExplorerBrowser_SetFolderSettings(peb, NULL);
1093
    ok(hr == E_INVALIDARG, "got (0x%08lx)\n", hr);
1094 1095
    fs.ViewMode = 0; fs.fFlags = 0;
    hr = IExplorerBrowser_SetFolderSettings(peb, &fs);
1096
    todo_wine ok(hr == E_INVALIDARG, "got (0x%08lx)\n", hr);
1097

1098 1099
    /* SetPropertyBag */
    hr = IExplorerBrowser_SetPropertyBag(peb, NULL);
1100
    ok(hr == E_INVALIDARG, "Got 0x%08lx\n", hr);
1101
    hr = IExplorerBrowser_SetPropertyBag(peb, winetest);
1102
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1103

1104 1105
    /* TODO: Test after browsing somewhere. */

1106 1107
    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
1108
    ok(lres == 0, "Got %ld\n", lres);
1109 1110
}

1111 1112 1113 1114 1115 1116 1117 1118 1119
static void test_Advise(void)
{
    IExplorerBrowser *peb;
    IExplorerBrowserEvents *pebe;
    DWORD cookies[10];
    HRESULT hr;
    UINT i, ref;

    /* Set up our IExplorerBrowserEvents implementation */
1120 1121
    ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
    pebe = &ebev.IExplorerBrowserEvents_iface;
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134

    ebrowser_instantiate(&peb);

    if(0)
    {
        /* Crashes on Windows 7 */
        IExplorerBrowser_Advise(peb, pebe, NULL);
        IExplorerBrowser_Advise(peb, NULL, &cookies[0]);
    }

    /* Using Unadvise with a cookie that has yet to be given out
     * results in E_INVALIDARG */
    hr = IExplorerBrowser_Unadvise(peb, 11);
1135
    ok(hr == E_INVALIDARG, "got (0x%08lx)\n", hr);
1136 1137 1138 1139 1140

    /* Add some before initialization */
    for(i = 0; i < 5; i++)
    {
        hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1141
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
1142 1143 1144 1145 1146 1147 1148 1149
    }

    ebrowser_initialize(peb);

    /* Add some after initialization */
    for(i = 5; i < 10; i++)
    {
        hr = IExplorerBrowser_Advise(peb, pebe, &cookies[i]);
1150
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
1151 1152
    }

1153
    ok(ebev.ref == 10, "Got %ld\n", ebev.ref);
1154

1155 1156 1157 1158 1159
    ebev.completed = 0;
    ebrowser_browse_to_desktop(peb);
    process_msgs();
    ok(ebev.completed == 10, "Got %d\n", ebev.completed);

1160 1161 1162 1163
    /* Remove a bunch somewhere in the middle */
    for(i = 4; i < 8; i++)
    {
        hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1164
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
1165 1166
    }

1167 1168 1169 1170 1171
    ebev.completed = 0;
    ebrowser_browse_to_desktop(peb);
    process_msgs();
    ok(ebev.completed == 6, "Got %d\n", ebev.completed);

1172 1173 1174 1175
    if(0)
    {
        /* Using unadvise with a previously unadvised cookie results
         * in a crash. */
1176
        IExplorerBrowser_Unadvise(peb, cookies[5]);
1177 1178 1179 1180 1181 1182 1183 1184
    }

    /* Remove the rest. */
    for(i = 0; i < 10; i++)
    {
        if(i<4||i>7)
        {
            hr = IExplorerBrowser_Unadvise(peb, cookies[i]);
1185
            ok(hr == S_OK, "%d: got (0x%08lx)\n", i, hr);
1186 1187 1188
        }
    }

1189
    ok(ebev.ref == 0, "Got %ld\n", ebev.ref);
1190

1191 1192 1193 1194 1195
    ebev.completed = 0;
    ebrowser_browse_to_desktop(peb);
    process_msgs();
    ok(ebev.completed == 0, "Got %d\n", ebev.completed);

1196 1197
    /* ::Destroy implies ::Unadvise. */
    hr = IExplorerBrowser_Advise(peb, pebe, &cookies[0]);
1198 1199
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
    ok(ebev.ref == 1, "Got %ld\n", ebev.ref);
1200 1201

    hr = IExplorerBrowser_Destroy(peb);
1202 1203
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
    ok(ebev.ref == 0, "Got %ld\n", ebev.ref);
1204 1205

    ref = IExplorerBrowser_Release(peb);
1206
    ok(!ref, "Got %d\n", ref);
1207 1208
}

1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
/* Based on PathAddBackslashW from dlls/shlwapi/path.c */
static LPWSTR myPathAddBackslashW( LPWSTR lpszPath )
{
  size_t iLen;

  if (!lpszPath || (iLen = lstrlenW(lpszPath)) >= MAX_PATH)
    return NULL;

  if (iLen)
  {
    lpszPath += iLen;
    if (lpszPath[-1] != '\\')
    {
      *lpszPath++ = '\\';
      *lpszPath = '\0';
    }
  }
  return lpszPath;
}

static void test_browse_pidl_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
                              LPITEMIDLIST pidl, UINT uFlags,
                              HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
                              const char *file, int line)
{
    HRESULT hr;
    ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;

    hr = IExplorerBrowser_BrowseToIDList(peb, pidl, uFlags);
1238
    ok_(file, line) (hr == hr_exp, "BrowseToIDList returned 0x%08lx\n", hr);
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
    process_msgs();

    ok_(file, line)
        (ebev->pending == pending && ebev->created == created &&
         ebev->failed == failed && ebev->completed == completed,
         "Events occurred: %d, %d, %d, %d\n",
         ebev->pending, ebev->created, ebev->failed, ebev->completed);
}
#define test_browse_pidl(peb, ebev, pidl, uFlags, hr, p, cr, f, co)     \
    test_browse_pidl_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)

static void test_browse_pidl_sb_(IExplorerBrowser *peb, IExplorerBrowserEventsImpl *ebev,
                                 LPITEMIDLIST pidl, UINT uFlags,
                                 HRESULT hr_exp, UINT pending, UINT created, UINT failed, UINT completed,
                                 const char *file, int line)
{
    IShellBrowser *psb;
    HRESULT hr;

    hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
1259
    ok_(file, line) (hr == S_OK, "QueryInterface returned 0x%08lx\n", hr);
1260 1261 1262 1263 1264
    if(SUCCEEDED(hr))
    {
        ebev->completed = ebev->created = ebev->pending = ebev->failed = 0;

        hr = IShellBrowser_BrowseObject(psb, pidl, uFlags);
1265
        ok_(file, line) (hr == hr_exp, "BrowseObject returned 0x%08lx\n", hr);
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
        process_msgs();

        ok_(file, line)
            (ebev->pending == pending && ebev->created == created &&
             ebev->failed == failed && ebev->completed == completed,
             "Events occurred: %d, %d, %d, %d\n",
             ebev->pending, ebev->created, ebev->failed, ebev->completed);

        IShellBrowser_Release(psb);
    }
}
#define test_browse_pidl_sb(peb, ebev, pidl, uFlags, hr, p, cr, f, co)  \
    test_browse_pidl_sb_(peb, ebev, pidl, uFlags, hr, p, cr, f, co, __FILE__, __LINE__)

static void test_navigation(void)
{
    IExplorerBrowser *peb, *peb2;
    IFolderView *pfv;
1284
    IShellItem *psi;
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
    IShellFolder *psf;
    LPITEMIDLIST pidl_current, pidl_child;
    DWORD cookie, cookie2;
    HRESULT hr;
    LONG lres;
    WCHAR current_path[MAX_PATH];
    WCHAR child_path[MAX_PATH];
    static const WCHAR testfolderW[] =
        {'w','i','n','e','t','e','s','t','f','o','l','d','e','r','\0'};

    ok(pSHCreateShellItem != NULL, "pSHCreateShellItem unexpectedly missing.\n");

    GetCurrentDirectoryW(MAX_PATH, current_path);
1298
    if(!current_path[0])
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309
    {
        skip("Failed to create test-directory.\n");
        return;
    }

    lstrcpyW(child_path, current_path);
    myPathAddBackslashW(child_path);
    lstrcatW(child_path, testfolderW);

    CreateDirectoryW(child_path, NULL);

1310
    hr = SHParseDisplayName(current_path, NULL, &pidl_current, 0, NULL);
1311
    ok(hr == S_OK, "Failed to parse a path, hr %#lx.\n", hr);
1312
    hr = SHParseDisplayName(child_path, NULL, &pidl_child, 0, NULL);
1313
    ok(hr == S_OK, "Failed to parse a path, hr %#lx.\n", hr);
1314 1315 1316 1317 1318 1319 1320 1321

    ebrowser_instantiate(&peb);
    ebrowser_initialize(peb);

    ebrowser_instantiate(&peb2);
    ebrowser_initialize(peb2);

    /* Set up our IExplorerBrowserEvents implementation */
1322
    ebev.IExplorerBrowserEvents_iface.lpVtbl = &ebevents;
1323

1324 1325
    IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
    IExplorerBrowser_Advise(peb2, &ebev.IExplorerBrowserEvents_iface, &cookie2);
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335

    /* These should all fail */
    test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE | SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, E_INVALIDARG, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_RELATIVE, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, E_FAIL, 0, 0, 0, 0);
1336 1337 1338 1339
    test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, E_FAIL, 0, 0, 0, 0);
1340 1341 1342 1343 1344

    /* "The first browse is synchronous" */
    test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, S_OK, 1, 1, 0, 1);

1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360
    /* Navigate empty history */
    test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 0, 0, 0, 0);

    /* Navigate history */
    test_browse_pidl(peb, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_PARENT, S_OK, 1, 1, 0, 1);
    test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEBACK, S_OK, 1, 1, 0, 1);
    test_browse_pidl(peb, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_NAVIGATEFORWARD, S_OK, 1, 1, 0, 1);
    test_browse_pidl(peb, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, 0, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);

1361
    /* Relative navigation */
1362 1363
    test_browse_pidl(peb, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_ABSOLUTE, S_OK, 1, 0, 0, 1);
1364 1365

    hr = IExplorerBrowser_GetCurrentView(peb, &IID_IFolderView, (void**)&pfv);
1366
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1367 1368 1369 1370 1371
    if(SUCCEEDED(hr))
    {
        LPITEMIDLIST pidl_relative;

        hr = IFolderView_GetFolder(pfv, &IID_IShellFolder, (void**)&psf);
1372
        ok(hr == S_OK, "Got 0x%08lx\n", hr);
1373 1374
        hr = IShellFolder_ParseDisplayName(psf, NULL, NULL, (LPWSTR)testfolderW,
                                           NULL, &pidl_relative, NULL);
1375
        ok(hr == S_OK, "Got 0x%08lx\n", hr);
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387

        /* Browsing to another location here before using the
         * pidl_relative would make ExplorerBrowser in Windows 7 show a
         * not-available dialog. Also, passing a relative pidl without
         * specifying SBSP_RELATIVE makes it look for the pidl on the
         * desktop
         */

        test_browse_pidl(peb, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);
        test_browse_pidl_sb(peb2, &ebev, pidl_relative, SBSP_RELATIVE, S_OK, 1, 1, 0, 1);

        ILFree(pidl_relative);
1388
        IShellFolder_Release(psf);
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415
        IFolderView_Release(pfv);
    }

    /* misc **/
    test_browse_pidl(peb, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_ABSOLUTE, S_OK, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, NULL, SBSP_DEFBROWSER, S_OK, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 1, 0, 1);
    test_browse_pidl(peb, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_SAMEBROWSER, S_OK, 1, 0, 0, 1);

    test_browse_pidl(peb, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_EXPLOREMODE, E_INVALIDARG, 0, 0, 0, 0);
    test_browse_pidl(peb, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);
    test_browse_pidl_sb(peb2, &ebev, pidl_current, SBSP_OPENMODE, S_OK, 1, 0, 0, 1);

    /* SBSP_NEWBROWSER will return E_INVALIDARG, claims MSDN, but in
     * reality it works as one would expect (Windows 7 only?).
     */
    if(0)
    {
        IExplorerBrowser_BrowseToIDList(peb, NULL, SBSP_NEWBROWSER);
    }

    hr = IExplorerBrowser_Unadvise(peb, cookie);
1416
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1417 1418 1419
    IExplorerBrowser_Destroy(peb);
    process_msgs();
    hr = IExplorerBrowser_Unadvise(peb2, cookie2);
1420
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1421 1422 1423 1424 1425 1426 1427 1428
    IExplorerBrowser_Destroy(peb2);
    process_msgs();

    /* Attempt browsing after destroyed */
    test_browse_pidl(peb, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);
    test_browse_pidl_sb(peb2, &ebev, pidl_child, SBSP_ABSOLUTE, HRESULT_FROM_WIN32(ERROR_BUSY), 0, 0, 0, 0);

    lres = IExplorerBrowser_Release(peb);
1429
    ok(lres == 0, "Got lres %ld\n", lres);
1430
    lres = IExplorerBrowser_Release(peb2);
1431
    ok(lres == 0, "Got lres %ld\n", lres);
1432 1433 1434 1435 1436

    /******************************************/
    /* Test some options that affect browsing */

    ebrowser_instantiate(&peb);
1437
    hr = IExplorerBrowser_Advise(peb, &ebev.IExplorerBrowserEvents_iface, &cookie);
1438
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1439
    hr = IExplorerBrowser_SetOptions(peb, EBO_NAVIGATEONCE);
1440
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1441 1442 1443 1444 1445 1446
    ebrowser_initialize(peb);

    test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 1, 0, 1);
    test_browse_pidl(peb, &ebev, pidl_current, 0, E_FAIL, 0, 0, 0, 0);

    hr = IExplorerBrowser_SetOptions(peb, 0);
1447
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1448 1449 1450 1451 1452 1453

    test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
    test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);

    /* Difference in behavior lies where? */
    hr = IExplorerBrowser_SetOptions(peb, EBO_ALWAYSNAVIGATE);
1454
    ok(hr == S_OK, "got (0x%08lx)\n", hr);
1455 1456 1457 1458 1459

    test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);
    test_browse_pidl(peb, &ebev, pidl_current, 0, S_OK, 1, 0, 0, 1);

    hr = IExplorerBrowser_Unadvise(peb, cookie);
1460
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1461 1462 1463

    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
1464
    ok(lres == 0, "Got lres %ld\n", lres);
1465

1466 1467 1468 1469 1470 1471
    /* BrowseToObject tests */
    ebrowser_instantiate(&peb);
    ebrowser_initialize(peb);

    /* Browse to the desktop by passing an IShellFolder */
    hr = SHGetDesktopFolder(&psf);
1472
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1473 1474 1475
    if(SUCCEEDED(hr))
    {
        hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1476
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
1477 1478 1479 1480 1481 1482 1483
        if(hr == S_OK) process_msgs();

        IShellFolder_Release(psf);
    }

    /* Browse to the current directory by passing a ShellItem */
    hr = pSHCreateShellItem(NULL, NULL, pidl_current, &psi);
1484
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1485 1486 1487
    if(SUCCEEDED(hr))
    {
        hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psi, SBSP_DEFBROWSER);
1488
        ok(hr == S_OK, "got (0x%08lx)\n", hr);
1489 1490 1491 1492 1493 1494 1495
        process_msgs();

        IShellItem_Release(psi);
    }

    IExplorerBrowser_Destroy(peb);
    lres = IExplorerBrowser_Release(peb);
1496
    ok(lres == 0, "Got lres %ld\n", lres);
1497

1498 1499 1500 1501 1502 1503
    /* Cleanup */
    RemoveDirectoryW(child_path);
    ILFree(pidl_current);
    ILFree(pidl_child);
}

1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
static void test_GetCurrentView(void)
{
    IExplorerBrowser *peb;
    IUnknown *punk;
    HRESULT hr;

    /* GetCurrentView */
    ebrowser_instantiate(&peb);

    if(0)
    {
        /* Crashes under Windows 7 */
1516
        IExplorerBrowser_GetCurrentView(peb, NULL, NULL);
1517 1518
    }
    hr = IExplorerBrowser_GetCurrentView(peb, NULL, (void**)&punk);
1519
    ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1520 1521 1522 1523

#define test_gcv(iid, exp)                                              \
    do {                                                                \
        hr = IExplorerBrowser_GetCurrentView(peb, &iid, (void**)&punk); \
1524
        ok(hr == exp, "(%s:)Expected (0x%08lx), got: (0x%08lx)\n",        \
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
           #iid ,exp, hr);                                              \
        if(SUCCEEDED(hr)) IUnknown_Release(punk);                       \
    } while(0)

    test_gcv(IID_IUnknown, E_FAIL);
    test_gcv(IID_IUnknown, E_FAIL);
    test_gcv(IID_IShellView, E_FAIL);
    test_gcv(IID_IShellView2, E_FAIL);
    test_gcv(IID_IFolderView, E_FAIL);
    test_gcv(IID_IPersistFolder, E_FAIL);
    test_gcv(IID_IPersistFolder2, E_FAIL);
    test_gcv(IID_ICommDlgBrowser, E_FAIL);
    test_gcv(IID_ICommDlgBrowser2, E_FAIL);
    test_gcv(IID_ICommDlgBrowser3, E_FAIL);

    ebrowser_initialize(peb);
    ebrowser_browse_to_desktop(peb);

    test_gcv(IID_IUnknown, S_OK);
    test_gcv(IID_IUnknown, S_OK);
    test_gcv(IID_IShellView, S_OK);
    test_gcv(IID_IShellView2, S_OK);
    test_gcv(IID_IFolderView, S_OK);
    todo_wine test_gcv(IID_IPersistFolder, S_OK);
    test_gcv(IID_IPersistFolder2, E_NOINTERFACE);
    test_gcv(IID_ICommDlgBrowser, E_NOINTERFACE);
    test_gcv(IID_ICommDlgBrowser2, E_NOINTERFACE);
    test_gcv(IID_ICommDlgBrowser3, E_NOINTERFACE);

#undef test_gcv

    IExplorerBrowser_Destroy(peb);
    IExplorerBrowser_Release(peb);
}

1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
static void test_InputObject(void)
{
    IExplorerBrowser *peb;
    IShellFolder *psf;
    IInputObject *pio;
    HRESULT hr;
    RECT rc;
    UINT i;
    WPARAM supported_key_accels_mode1[] = {
        VK_BACK, VK_TAB, VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
        VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
        VK_F5, VK_F6, VK_F10, 0 };
    WPARAM supported_key_accels_mode2[] = {
        VK_RETURN, VK_PRIOR, VK_NEXT, VK_END, VK_HOME,
        VK_LEFT, VK_UP, VK_RIGHT, VK_DOWN, VK_DELETE, VK_F1, VK_F2,
        VK_F10, 0 };
    WPARAM *key_accels;
    MSG msg_a = {
        hwnd,
        WM_KEYDOWN,
        VK_F5, 0,
        GetTickCount(),
        {5, 2}
    };

    ebrowser_instantiate(&peb);
    hr = IExplorerBrowser_QueryInterface(peb, &IID_IInputObject, (void**)&pio);
1587
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1588 1589 1590 1591 1592 1593 1594 1595
    if(FAILED(hr))
    {
        win_skip("IInputObject not supported.\n");
        return;
    }

    /* Before initializing */
    hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1596
    todo_wine ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1597 1598

    hr = IInputObject_HasFocusIO(pio);
1599
    todo_wine ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1600 1601

    hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1602
    todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
1603 1604

    hr = IInputObject_HasFocusIO(pio);
1605
    todo_wine ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1606 1607

    hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1608
    todo_wine ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1609

1610
    SetRect(&rc, 0, 0, 100, 100);
1611
    hr = IExplorerBrowser_Initialize(peb, hwnd, &rc, NULL);
1612
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1613 1614

    hr = IInputObject_HasFocusIO(pio);
1615
    todo_wine ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1616 1617

    hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1618
    todo_wine ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
1619 1620 1621 1622

    /* Browse to the desktop */
    SHGetDesktopFolder(&psf);
    hr = IExplorerBrowser_BrowseToObject(peb, (IUnknown*)psf, SBSP_DEFBROWSER);
1623
    ok(hr == S_OK, "Got 0x%08lx\n", hr);
1624 1625 1626
    IShellFolder_Release(psf);

    hr = IInputObject_UIActivateIO(pio, TRUE, &msg_a);
1627
    todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
1628 1629

    hr = IInputObject_HasFocusIO(pio);
1630
    todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
1631 1632

    hr = IInputObject_UIActivateIO(pio, FALSE, &msg_a);
1633
    todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
1634 1635

    hr = IInputObject_HasFocusIO(pio);
1636
    todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657

    hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
    if(hr == S_OK)
        key_accels = supported_key_accels_mode1;
    else
        key_accels = supported_key_accels_mode2;

    for(i = 0; i < 0x100; i++)
    {
        BOOL found = FALSE;
        UINT j;
        for(j = 0; key_accels[j] != 0; j++)
            if(key_accels[j] == i)
            {
                found = TRUE;
                break;
            }

        msg_a.wParam = i;
        process_msgs();
        hr = IInputObject_TranslateAcceleratorIO(pio, &msg_a);
1658
        todo_wine ok(hr == (found ? S_OK : S_FALSE), "Got 0x%08lx (%04x)\n", hr, i);
1659 1660
        if(i == VK_F5)
            Sleep(1000); /* Needed for w2k8 (64bit) */
1661 1662 1663 1664 1665 1666 1667 1668 1669
    }

    process_msgs();

    IInputObject_Release(pio);
    IExplorerBrowser_Destroy(peb);
    IExplorerBrowser_Release(peb);
}

1670 1671 1672 1673 1674 1675
static BOOL test_instantiate_control(void)
{
    IExplorerBrowser *peb;
    HRESULT hr;

    hr = ebrowser_instantiate(&peb);
1676
    ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got (0x%08lx)\n", hr);
1677 1678 1679 1680 1681 1682 1683
    if(FAILED(hr))
        return FALSE;

    IExplorerBrowser_Release(peb);
    return TRUE;
}

1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
static void setup_window(void)
{
    WNDCLASSW wc;
    static const WCHAR ebtestW[] = {'e','b','t','e','s','t',0};

    ZeroMemory(&wc, sizeof(WNDCLASSW));
    wc.lpfnWndProc      = DefWindowProcW;
    wc.lpszClassName    = ebtestW;
    RegisterClassW(&wc);
    hwnd = CreateWindowExW(0, ebtestW, NULL, 0,
                           0, 0, 500, 500,
                           NULL, 0, 0, NULL);
    ok(hwnd != NULL, "Failed to create window for tests.\n");
}

1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
START_TEST(ebrowser)
{
    OleInitialize(NULL);

    if(!test_instantiate_control())
    {
        win_skip("No ExplorerBrowser control..\n");
        OleUninitialize();
        return;
    }

1710
    setup_window();
1711
    init_function_pointers();
1712

1713
    test_QueryInterface();
1714
    test_SB_misc();
1715
    test_initialization();
1716
    test_basics();
1717
    test_Advise();
1718
    test_navigation();
1719
    test_GetCurrentView();
1720
    test_SetSite();
1721
    test_InputObject();
1722

1723
    DestroyWindow(hwnd);
1724 1725
    OleUninitialize();
}