url.c 105 KB
Newer Older
1 2 3 4
/*
 * UrlMon URL tests
 *
 * Copyright 2004 Kevin Koltzau
5
 * Copyright 2004-2007 Jacek Caban for CodeWeavers
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * 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
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22
 */

#include <stdarg.h>
23
#include <stdio.h>
24 25

#define COBJMACROS
Jacek Caban's avatar
Jacek Caban committed
26
#define NONAMELESSUNION
27
#define CONST_VTABLE
28

29 30
#include "windef.h"
#include "winbase.h"
31
#include "initguid.h"
32
#include "urlmon.h"
33
#include "wininet.h"
34
#include "mshtml.h"
35 36 37

#include "wine/test.h"

38 39 40 41
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
DEFINE_GUID(CLSID_IdentityUnmarshal,0x0000001b,0x0000,0x0000,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46);
DEFINE_GUID(IID_IBindStatusCallbackHolder,0x79eac9cc,0xbaf9,0x11ce,0x8c,0x82,0x00,0xaa,0x00,0x4b,0xa9,0x0b);

Jacek Caban's avatar
Jacek Caban committed
42 43 44 45
#define DEFINE_EXPECT(func) \
    static BOOL expect_ ## func = FALSE, called_ ## func = FALSE

#define SET_EXPECT(func) \
Jacek Caban's avatar
Jacek Caban committed
46
    do { called_ ## func = FALSE; expect_ ## func = TRUE; } while(0)
Jacek Caban's avatar
Jacek Caban committed
47

48
#define CHECK_EXPECT2(func) \
49
    do { \
50
        ok(expect_ ##func, "unexpected call " #func "\n"); \
51 52
        called_ ## func = TRUE; \
    }while(0)
Jacek Caban's avatar
Jacek Caban committed
53

54
#define CHECK_EXPECT(func) \
55
    do { \
56 57
        CHECK_EXPECT2(func); \
        expect_ ## func = FALSE; \
58
    }while(0)
Jacek Caban's avatar
Jacek Caban committed
59 60

#define CHECK_CALLED(func) \
61 62 63 64
    do { \
        ok(called_ ## func, "expected " #func "\n"); \
        expect_ ## func = called_ ## func = FALSE; \
    }while(0)
Jacek Caban's avatar
Jacek Caban committed
65

66 67 68 69 70 71
#define CHECK_NOT_CALLED(func) \
    do { \
        ok(!called_ ## func, "unexpected " #func "\n"); \
        expect_ ## func = called_ ## func = FALSE; \
    }while(0)

72 73 74 75 76 77
#define CHECK_CALLED_BROKEN(func) \
    do { \
        ok(called_ ## func || broken(!called_ ## func), "expected " #func "\n"); \
        expect_ ## func = called_ ## func = FALSE; \
    }while(0)

78 79 80 81 82
#define CLEAR_CALLED(func) \
    expect_ ## func = called_ ## func = FALSE

DEFINE_EXPECT(QueryInterface_IServiceProvider);
DEFINE_EXPECT(QueryInterface_IHttpNegotiate);
83
DEFINE_EXPECT(QueryInterface_IBindStatusCallback);
84
DEFINE_EXPECT(QueryInterface_IBindStatusCallbackEx);
85 86 87 88
DEFINE_EXPECT(QueryInterface_IBindStatusCallbackHolder);
DEFINE_EXPECT(QueryInterface_IInternetBindInfo);
DEFINE_EXPECT(QueryInterface_IAuthenticate);
DEFINE_EXPECT(QueryInterface_IInternetProtocol);
89
DEFINE_EXPECT(QueryInterface_IWindowForBindingUI);
90 91
DEFINE_EXPECT(QueryService_IAuthenticate);
DEFINE_EXPECT(QueryService_IInternetProtocol);
92
DEFINE_EXPECT(QueryService_IInternetBindInfo);
93
DEFINE_EXPECT(QueryService_IWindowForBindingUI);
94 95
DEFINE_EXPECT(BeginningTransaction);
DEFINE_EXPECT(OnResponse);
96
DEFINE_EXPECT(QueryInterface_IHttpNegotiate2);
97
DEFINE_EXPECT(GetRootSecurityId);
Jacek Caban's avatar
Jacek Caban committed
98
DEFINE_EXPECT(GetBindInfo);
99
DEFINE_EXPECT(GetBindInfoEx);
Jacek Caban's avatar
Jacek Caban committed
100 101 102 103 104 105 106 107
DEFINE_EXPECT(OnStartBinding);
DEFINE_EXPECT(OnProgress_FINDINGRESOURCE);
DEFINE_EXPECT(OnProgress_CONNECTING);
DEFINE_EXPECT(OnProgress_SENDINGREQUEST);
DEFINE_EXPECT(OnProgress_MIMETYPEAVAILABLE);
DEFINE_EXPECT(OnProgress_BEGINDOWNLOADDATA);
DEFINE_EXPECT(OnProgress_DOWNLOADINGDATA);
DEFINE_EXPECT(OnProgress_ENDDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
108
DEFINE_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
Jacek Caban's avatar
Jacek Caban committed
109 110
DEFINE_EXPECT(OnStopBinding);
DEFINE_EXPECT(OnDataAvailable);
111
DEFINE_EXPECT(OnObjectAvailable);
Jacek Caban's avatar
Jacek Caban committed
112 113 114 115 116 117 118 119 120 121 122 123
DEFINE_EXPECT(Obj_OnStartBinding);
DEFINE_EXPECT(Obj_OnStopBinding);
DEFINE_EXPECT(Obj_GetBindInfo);
DEFINE_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
DEFINE_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
DEFINE_EXPECT(Obj_OnProgress_SENDINGREQUEST);
DEFINE_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
DEFINE_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
DEFINE_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
DEFINE_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
DEFINE_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
DEFINE_EXPECT(Obj_OnProgress_CONNECTING);
Jacek Caban's avatar
Jacek Caban committed
124
DEFINE_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
125 126 127 128 129
DEFINE_EXPECT(Start);
DEFINE_EXPECT(Read);
DEFINE_EXPECT(LockRequest);
DEFINE_EXPECT(Terminate);
DEFINE_EXPECT(UnlockRequest);
130
DEFINE_EXPECT(Continue);
Jacek Caban's avatar
Jacek Caban committed
131 132 133 134
DEFINE_EXPECT(CreateInstance);
DEFINE_EXPECT(Load);
DEFINE_EXPECT(PutProperty_MIMETYPEPROP);
DEFINE_EXPECT(PutProperty_CLASSIDPROP);
135
DEFINE_EXPECT(SetPriority);
Jacek Caban's avatar
Jacek Caban committed
136

137 138
static const WCHAR TEST_URL_1[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','\0'};
static const WCHAR TEST_PART_URL_1[] = {'/','t','e','s','t','/','\0'};
139

140 141
static const WCHAR WINE_ABOUT_URL[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.',
                                       'o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
142 143 144 145
static const WCHAR SHORT_RESPONSE_URL[] =
        {'h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.',
         'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
         'p','o','s','t','t','e','s','t','.','p','h','p',0};
146
static const WCHAR ABOUT_BLANK[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
147
static WCHAR INDEX_HTML[MAX_PATH];
148 149
static const WCHAR ITS_URL[] =
    {'i','t','s',':','t','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
150 151
static const WCHAR MK_URL[] = {'m','k',':','@','M','S','I','T','S','t','o','r','e',':',
    't','e','s','t','.','c','h','m',':',':','/','b','l','a','n','k','.','h','t','m','l',0};
152 153 154
static const WCHAR https_urlW[] =
    {'h','t','t','p','s',':','/','/','w','w','w','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',
     '/','t','e','s','t','.','h','t','m','l',0};
155 156 157
static const WCHAR ftp_urlW[] = {'f','t','p',':','/','/','f','t','p','.','w','i','n','e','h','q','.','o','r','g',
    '/','p','u','b','/','o','t','h','e','r','/',
    'w','i','n','e','l','o','g','o','.','x','c','f','.','t','a','r','.','b','z','2',0};
158

159

160 161
static const WCHAR wszTextHtml[] = {'t','e','x','t','/','h','t','m','l',0};

162
static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
163

164 165 166 167
static const WCHAR wszWineHQSite[] =
    {'w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
static const WCHAR wszWineHQIP[] =
    {'2','0','9','.','3','2','.','1','4','1','.','3',0};
168
static const CHAR wszIndexHtmlA[] = "index.html";
169
static const WCHAR wszIndexHtml[] = {'i','n','d','e','x','.','h','t','m','l',0};
Jacek Caban's avatar
Jacek Caban committed
170
static const WCHAR cache_fileW[] = {'c',':','\\','c','a','c','h','e','.','h','t','m',0};
171
static const CHAR dwl_htmlA[] = "dwl.html";
172
static const WCHAR dwl_htmlW[] = {'d','w','l','.','h','t','m','l',0};
Jacek Caban's avatar
Jacek Caban committed
173
static const WCHAR emptyW[] = {0};
174

Jacek Caban's avatar
Jacek Caban committed
175
static BOOL stopped_binding = FALSE, stopped_obj_binding = FALSE, emulate_protocol = FALSE,
176
    data_available = FALSE, http_is_first = TRUE, bind_to_object = FALSE, filedwl_api;
Jacek Caban's avatar
Jacek Caban committed
177
static DWORD read = 0, bindf = 0, prot_state = 0, thread_id, tymed;
178
static CHAR mime_type[512];
179
static IInternetProtocolSink *protocol_sink = NULL;
180
static IBinding *current_binding;
181
static HANDLE complete_event, complete_event2;
Jacek Caban's avatar
Jacek Caban committed
182
static HRESULT binding_hres;
183
static BOOL have_IHttpNegotiate2, use_bscex;
184

185
static LPCWSTR urls[] = {
186
    WINE_ABOUT_URL,
187
    ABOUT_BLANK,
188
    INDEX_HTML,
189
    ITS_URL,
190
    MK_URL,
191 192
    https_urlW,
    ftp_urlW
193 194
};

195 196
static WCHAR file_url[INTERNET_MAX_URL_LENGTH];

197 198
static enum {
    HTTP_TEST,
199
    ABOUT_TEST,
200
    FILE_TEST,
201
    ITS_TEST,
202
    MK_TEST,
203 204
    HTTPS_TEST,
    FTP_TEST
205
} test_protocol;
206

207 208 209 210 211 212
static enum {
    BEFORE_DOWNLOAD,
    DOWNLOADING,
    END_DOWNLOAD
} download_state;

213 214 215 216 217 218 219 220 221 222 223 224
static const char *debugstr_guid(REFIID riid)
{
    static char buf[50];

    sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
            riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
            riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
            riid->Data4[5], riid->Data4[6], riid->Data4[7]);

    return buf;
}

225 226 227 228 229
static BOOL is_urlmon_protocol(int prot)
{
    return prot == FILE_TEST || prot == HTTP_TEST || prot == HTTPS_TEST || prot == FTP_TEST || prot == MK_TEST;
}

230 231 232 233 234 235 236
static void test_CreateURLMoniker(LPCWSTR url1, LPCWSTR url2)
{
    HRESULT hr;
    IMoniker *mon1 = NULL;
    IMoniker *mon2 = NULL;

    hr = CreateURLMoniker(NULL, url1, &mon1);
237
    ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
238 239
    if(SUCCEEDED(hr)) {
        hr = CreateURLMoniker(mon1, url2, &mon2);
240
        ok(SUCCEEDED(hr), "failed to create moniker: 0x%08x\n", hr);
241 242 243 244 245
    }
    if(mon1) IMoniker_Release(mon1);
    if(mon2) IMoniker_Release(mon2);
}

246
static void test_create(void)
247 248 249 250
{
    test_CreateURLMoniker(TEST_URL_1, TEST_PART_URL_1);
}

251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
static HRESULT WINAPI Priority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
{
    ok(0, "unexpected call\n");
    return E_NOINTERFACE;
}

static ULONG WINAPI Priority_AddRef(IInternetPriority *iface)
{
    return 2;
}

static ULONG WINAPI Priority_Release(IInternetPriority *iface)
{
    return 1;
}

static HRESULT WINAPI Priority_SetPriority(IInternetPriority *iface, LONG nPriority)
{
    CHECK_EXPECT(SetPriority);
    ok(!nPriority, "nPriority = %d\n", nPriority);
    return S_OK;
}

static HRESULT WINAPI Priority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static const IInternetPriorityVtbl InternetPriorityVtbl = {
    Priority_QueryInterface,
    Priority_AddRef,
    Priority_Release,
    Priority_SetPriority,
    Priority_GetPriority
};

static IInternetPriority InternetPriority = { &InternetPriorityVtbl };

290 291
static HRESULT WINAPI Protocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
{
292 293
    *ppv = NULL;

294 295 296 297 298
    if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IInternetProtocol, riid)) {
        *ppv = iface;
        return S_OK;
    }

299 300 301 302 303 304 305 306 307 308 309 310
    if(IsEqualGUID(&IID_IInternetPriority, riid)) {
        if(!is_urlmon_protocol(test_protocol))
            return E_NOINTERFACE;

        *ppv = &InternetPriority;
        return S_OK;
    }

    if(IsEqualGUID(&IID_IInternetProtocolEx, riid))
        return E_NOINTERFACE; /* TODO */

    ok(0, "unexpected call %s\n", debugstr_guid(riid));
311 312 313 314 315 316 317 318 319 320 321 322 323
    return E_NOINTERFACE;
}

static ULONG WINAPI Protocol_AddRef(IInternetProtocol *iface)
{
    return 2;
}

static ULONG WINAPI Protocol_Release(IInternetProtocol *iface)
{
    return 1;
}

324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
static void test_switch_fail(void)
{
    IInternetProtocolSink *binding_sink;
    PROTOCOLDATA protocoldata;
    HRESULT hres;

    static BOOL tested_switch_fail;

    if(tested_switch_fail)
        return;

    tested_switch_fail = TRUE;

    hres = IBinding_QueryInterface(current_binding, &IID_IInternetProtocolSink, (void**)&binding_sink);
    ok(hres == S_OK, "Could not get IInternetProtocolSink iface: %08x\n", hres);
    if(SUCCEEDED(hres)) {
        hres = IInternetProtocolSink_Switch(binding_sink, &protocoldata);
        ok(hres == E_FAIL, "Switch failed: %08x, expected E_FAIL\n", hres);
        IInternetProtocolSink_Release(binding_sink);
    }
}

346 347 348 349 350
static DWORD WINAPI thread_proc(PVOID arg)
{
    PROTOCOLDATA protocoldata;
    HRESULT hres;

Jacek Caban's avatar
Jacek Caban committed
351 352 353 354
    if(bind_to_object)
        SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
    else
        SET_EXPECT(OnProgress_FINDINGRESOURCE);
355 356 357 358
    hres = IInternetProtocolSink_ReportProgress(protocol_sink,
            BINDSTATUS_FINDINGRESOURCE, wszWineHQSite);
    ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
    WaitForSingleObject(complete_event, INFINITE);
Jacek Caban's avatar
Jacek Caban committed
359 360 361 362
    if(bind_to_object)
        CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
    else
        CHECK_CALLED(OnProgress_FINDINGRESOURCE);
363

Jacek Caban's avatar
Jacek Caban committed
364 365 366 367
    if(bind_to_object)
        SET_EXPECT(Obj_OnProgress_CONNECTING);
    else
        SET_EXPECT(OnProgress_CONNECTING);
368 369 370 371
    hres = IInternetProtocolSink_ReportProgress(protocol_sink,
            BINDSTATUS_CONNECTING, wszWineHQIP);
    ok(hres == S_OK, "ReportProgress failed: %08x\n", hres);
    WaitForSingleObject(complete_event, INFINITE);
Jacek Caban's avatar
Jacek Caban committed
372 373 374 375
    if(bind_to_object)
        CHECK_CALLED(Obj_OnProgress_CONNECTING);
    else
        CHECK_CALLED(OnProgress_CONNECTING);
376

Jacek Caban's avatar
Jacek Caban committed
377 378 379 380
    if(bind_to_object)
        SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
    else
        SET_EXPECT(OnProgress_SENDINGREQUEST);
381 382
    hres = IInternetProtocolSink_ReportProgress(protocol_sink,
            BINDSTATUS_SENDINGREQUEST, NULL);
Jacek Caban's avatar
Jacek Caban committed
383
    ok(hres == S_OK, "ReportProxgress failed: %08x\n", hres);
384
    WaitForSingleObject(complete_event, INFINITE);
Jacek Caban's avatar
Jacek Caban committed
385 386 387 388
    if(bind_to_object)
        CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
    else
        CHECK_CALLED(OnProgress_SENDINGREQUEST);
389

390 391
    test_switch_fail();

392 393 394 395 396
    SET_EXPECT(Continue);
    prot_state = 1;
    hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
    ok(hres == S_OK, "Switch failed: %08x\n", hres);
    WaitForSingleObject(complete_event, INFINITE);
Jacek Caban's avatar
Jacek Caban committed
397

398 399
    CHECK_CALLED(Continue);
    CHECK_CALLED(Read);
Jacek Caban's avatar
Jacek Caban committed
400 401 402 403 404 405 406
    if(bind_to_object) {
        CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
        CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
        CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
        CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
        CHECK_CALLED(CreateInstance);
        CHECK_CALLED(PutProperty_MIMETYPEPROP);
407
        CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
Jacek Caban's avatar
Jacek Caban committed
408 409 410 411 412 413 414 415 416 417
        CHECK_CALLED(Load);
        CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
        CHECK_CALLED(OnObjectAvailable);
        CHECK_CALLED(Obj_OnStopBinding);
    }else {
        CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
        CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
        CHECK_CALLED(LockRequest);
        CHECK_CALLED(OnDataAvailable);
    }
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449

    SET_EXPECT(Continue);
    prot_state = 2;
    hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
    ok(hres == S_OK, "Switch failed: %08x\n", hres);
    WaitForSingleObject(complete_event, INFINITE);
    CHECK_CALLED(Continue);
    CHECK_CALLED(Read);
    CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
    CHECK_CALLED(OnDataAvailable);

    SET_EXPECT(Continue);
    prot_state = 2;
    hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
    ok(hres == S_OK, "Switch failed: %08x\n", hres);
    WaitForSingleObject(complete_event, INFINITE);
    CHECK_CALLED(Continue);
    CHECK_CALLED(Read);
    CHECK_CALLED(OnProgress_DOWNLOADINGDATA);
    CHECK_CALLED(OnDataAvailable);

    SET_EXPECT(Continue);
    prot_state = 3;
    hres = IInternetProtocolSink_Switch(protocol_sink, &protocoldata);
    ok(hres == S_OK, "Switch failed: %08x\n", hres);
    WaitForSingleObject(complete_event, INFINITE);
    CHECK_CALLED(Continue);
    CHECK_CALLED(Read);
    CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
    CHECK_CALLED(OnDataAvailable);
    CHECK_CALLED(OnStopBinding);

Jacek Caban's avatar
Jacek Caban committed
450
    SET_EXPECT(Read);
451

Jacek Caban's avatar
Jacek Caban committed
452
    SetEvent(complete_event2);
453 454 455
    return 0;
}

456 457
static HRESULT WINAPI Protocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
        IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
458
        DWORD grfPI, HANDLE_PTR dwReserved)
459
{
Jacek Caban's avatar
Jacek Caban committed
460
    BINDINFO bindinfo;
461
    DWORD bindf, bscf = BSCF_FIRSTDATANOTIFICATION | BSCF_LASTDATANOTIFICATION;
462 463
    HRESULT hres;

Jacek Caban's avatar
Jacek Caban committed
464 465 466
    static const STGMEDIUM stgmed_zero = {0};
    static const SECURITY_ATTRIBUTES sa_zero = {0};

467 468 469 470
    CHECK_EXPECT(Start);

    read = 0;

471
    if(!filedwl_api) /* FIXME */
472
        ok(szUrl && !lstrcmpW(szUrl, urls[test_protocol]), "wrong url %s\n", wine_dbgstr_w(szUrl));
473 474
    ok(pOIProtSink != NULL, "pOIProtSink == NULL\n");
    ok(pOIBindInfo != NULL, "pOIBindInfo == NULL\n");
475
    ok(grfPI == 0, "grfPI=%d, expected 0\n", grfPI);
476
    ok(dwReserved == 0, "dwReserved=%lx, expected 0\n", dwReserved);
477

478
    if(!filedwl_api && binding_hres != S_OK) {
Jacek Caban's avatar
Jacek Caban committed
479 480 481 482 483 484 485 486 487 488
        SET_EXPECT(OnStopBinding);
        SET_EXPECT(Terminate);
        hres = IInternetProtocolSink_ReportResult(pOIProtSink, binding_hres, 0, NULL);
        ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
        CHECK_CALLED(OnStopBinding);
        CHECK_CALLED(Terminate);

        return S_OK;
    }

489 490 491
    memset(&bindinfo, 0, sizeof(bindinfo));
    bindinfo.cbSize = sizeof(bindinfo);
    hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &bindf, &bindinfo);
492
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
493

494 495
    if(filedwl_api) {
        ok(bindf == (BINDF_PULLDATA|BINDF_FROMURLMON|BINDF_NEEDFILE), "bindf=%08x\n", bindf);
496
    }else if(tymed == TYMED_ISTREAM && is_urlmon_protocol(test_protocol)) {
497 498
        ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
                     |BINDF_FROMURLMON),
499
           "bindf=%08x\n", bindf);
500
    }else {
501 502
        ok(bindf == (BINDF_ASYNCHRONOUS|BINDF_ASYNCSTORAGE|BINDF_PULLDATA
                     |BINDF_FROMURLMON|BINDF_NEEDFILE),
503
           "bindf=%08x\n", bindf);
504 505
    }

Jacek Caban's avatar
Jacek Caban committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519
    ok(bindinfo.cbSize == sizeof(bindinfo), "bindinfo.cbSize = %d\n", bindinfo.cbSize);
    ok(!bindinfo.szExtraInfo, "bindinfo.szExtraInfo = %p\n", bindinfo.szExtraInfo);
    ok(!memcmp(&bindinfo.stgmedData, &stgmed_zero, sizeof(STGMEDIUM)), "wrong stgmedData\n");
    ok(!bindinfo.grfBindInfoF, "bindinfo.grfBindInfoF = %d\n", bindinfo.grfBindInfoF);
    ok(!bindinfo.dwBindVerb, "bindinfo.dwBindVerb = %d\n", bindinfo.dwBindVerb);
    ok(!bindinfo.szCustomVerb, "bindinfo.szCustomVerb = %p\n", bindinfo.szCustomVerb);
    ok(!bindinfo.cbstgmedData, "bindinfo.cbstgmedData = %d\n", bindinfo.cbstgmedData);
    ok(bindinfo.dwOptions == (bind_to_object ? 0x100000 : 0), "bindinfo.dwOptions = %x\n", bindinfo.dwOptions);
    ok(!bindinfo.dwOptionsFlags, "bindinfo.dwOptionsFlags = %d\n", bindinfo.dwOptionsFlags);
    ok(!bindinfo.dwCodePage, "bindinfo.dwCodePage = %d\n", bindinfo.dwCodePage);
    ok(!memcmp(&bindinfo.securityAttributes, &sa_zero, sizeof(sa_zero)), "wrong bindinfo.securityAttributes\n");
    ok(IsEqualGUID(&bindinfo.iid, &IID_NULL), "wrong bindinfo.iid\n");
    ok(!bindinfo.pUnk, "bindinfo.pUnk = %p\n", bindinfo.pUnk);
    ok(!bindinfo.dwReserved, "bindinfo.dwReserved = %d\n", bindinfo.dwReserved);
520

521 522 523 524 525 526 527 528 529
    switch(test_protocol) {
    case MK_TEST:
        hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
                BINDSTATUS_DIRECTBIND, NULL);
        ok(hres == S_OK,
           "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);

    case FILE_TEST:
    case ITS_TEST:
Jacek Caban's avatar
Jacek Caban committed
530 531 532 533
        if(bind_to_object)
            SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
        else
            SET_EXPECT(OnProgress_SENDINGREQUEST);
534
        hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
Jacek Caban's avatar
Jacek Caban committed
535
                BINDSTATUS_SENDINGREQUEST, emptyW);
536
        ok(hres == S_OK,
537
           "ReportProgress(BINDSTATUS_SENDINGREQUEST) failed: %08x\n", hres);
Jacek Caban's avatar
Jacek Caban committed
538 539 540 541
        if(bind_to_object)
            CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
        else
            CHECK_CALLED(OnProgress_SENDINGREQUEST);
542 543
    default:
        break;
544
    }
545

546
    if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
547 548 549 550 551 552 553
        IServiceProvider *service_provider;
        IHttpNegotiate *http_negotiate;
        IHttpNegotiate2 *http_negotiate2;
        LPWSTR ua = (LPWSTR)0xdeadbeef, accept_mimes[256];
        LPWSTR additional_headers = (LPWSTR)0xdeadbeef;
        BYTE sec_id[100];
        DWORD fetched = 256, size = 100;
554
        DWORD tid;
555 556 557 558 559 560 561

        static const WCHAR wszMimes[] = {'*','/','*',0};

        SET_EXPECT(QueryInterface_IInternetBindInfo);
        SET_EXPECT(QueryService_IInternetBindInfo);
        hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_USER_AGENT,
                                               &ua, 1, &fetched);
562 563 564
        CLEAR_CALLED(QueryInterface_IInternetBindInfo); /* IE <8 */
        CLEAR_CALLED(QueryService_IInternetBindInfo); /* IE <8 */

565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
        ok(hres == E_NOINTERFACE,
           "GetBindString(BINDSTRING_USER_AGETNT) failed: %08x\n", hres);
        ok(fetched == 256, "fetched = %d, expected 254\n", fetched);
        ok(ua == (LPWSTR)0xdeadbeef, "ua =  %p\n", ua);

        hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
                                               accept_mimes, 256, &fetched);
        ok(hres == S_OK,
           "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);
        ok(fetched == 1, "fetched = %d, expected 1\n", fetched);
        ok(!lstrcmpW(wszMimes, accept_mimes[0]), "unexpected mimes\n");

        hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
                                               NULL, 256, &fetched);
        ok(hres == E_INVALIDARG,
           "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);

        hres = IInternetBindInfo_GetBindString(pOIBindInfo, BINDSTRING_ACCEPT_MIMES,
                                               accept_mimes, 256, NULL);
        ok(hres == E_INVALIDARG,
           "GetBindString(BINDSTRING_ACCEPT_MIMES) failed: %08x\n", hres);

        hres = IInternetBindInfo_QueryInterface(pOIBindInfo, &IID_IServiceProvider,
                                                (void**)&service_provider);
        ok(hres == S_OK, "QueryInterface failed: %08x\n", hres);

        SET_EXPECT(QueryInterface_IHttpNegotiate);
        hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
                &IID_IHttpNegotiate, (void**)&http_negotiate);
594
        CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
595 596 597
        ok(hres == S_OK, "QueryService failed: %08x\n", hres);

        SET_EXPECT(BeginningTransaction);
598
        SET_EXPECT(QueryInterface_IHttpNegotiate);
599 600
        hres = IHttpNegotiate_BeginningTransaction(http_negotiate, urls[test_protocol],
                                                   NULL, 0, &additional_headers);
601
        CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
602 603 604 605 606 607 608 609
        CHECK_CALLED(BeginningTransaction);
        IHttpNegotiate_Release(http_negotiate);
        ok(hres == S_OK, "BeginningTransction failed: %08x\n", hres);
        ok(additional_headers == NULL, "additional_headers=%p\n", additional_headers);

        SET_EXPECT(QueryInterface_IHttpNegotiate2);
        hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate2,
                &IID_IHttpNegotiate2, (void**)&http_negotiate2);
610
        CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
611 612 613
        ok(hres == S_OK, "QueryService failed: %08x\n", hres);

        size = 512;
614
        SET_EXPECT(QueryInterface_IHttpNegotiate2);
615 616
        SET_EXPECT(GetRootSecurityId);
        hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, sec_id, &size, 0);
617
        CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2);
618 619 620 621 622 623 624 625 626
        CHECK_CALLED(GetRootSecurityId);
        IHttpNegotiate2_Release(http_negotiate2);
        ok(hres == E_FAIL, "GetRootSecurityId failed: %08x, expected E_FAIL\n", hres);
        ok(size == 13, "size=%d\n", size);

        IServiceProvider_Release(service_provider);

        IInternetProtocolSink_AddRef(pOIProtSink);
        protocol_sink = pOIProtSink;
627
        CreateThread(NULL, 0, thread_proc, NULL, 0, &tid);
628 629 630 631

        return S_OK;
    }

632
    if(test_protocol == FILE_TEST) {
633
        hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
634
                BINDSTATUS_CACHEFILENAMEAVAILABLE, file_url+8);
635
        ok(hres == S_OK,
636
           "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
637

Jacek Caban's avatar
Jacek Caban committed
638 639 640 641
        if(bind_to_object)
            SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
        else
            SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
642 643 644
        hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
                BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE, wszTextHtml);
        ok(hres == S_OK,
645
           "ReportProgress(BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE) failed: %08x\n", hres);
Jacek Caban's avatar
Jacek Caban committed
646 647 648 649
        if(bind_to_object)
            CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
        else
            CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
650 651 652 653
    }else {
        hres = IInternetProtocolSink_ReportProgress(pOIProtSink,
                BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
        ok(hres == S_OK,
654
           "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);
655 656 657 658
    }

    if(test_protocol == ABOUT_TEST)
        bscf |= BSCF_DATAFULLYAVAILABLE;
659 660
    if(test_protocol == ITS_TEST)
        bscf = BSCF_FIRSTDATANOTIFICATION|BSCF_DATAFULLYAVAILABLE;
661 662

    SET_EXPECT(Read);
Jacek Caban's avatar
Jacek Caban committed
663 664 665 666
    if(bind_to_object) {
        if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
            SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
        SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
667 668
        if(test_protocol == FILE_TEST)
            SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
Jacek Caban's avatar
Jacek Caban committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682
        SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
        SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
        SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
        SET_EXPECT(CreateInstance);
        SET_EXPECT(PutProperty_MIMETYPEPROP);
        SET_EXPECT(PutProperty_CLASSIDPROP);
        SET_EXPECT(Load);
        SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
        SET_EXPECT(OnObjectAvailable);
        SET_EXPECT(Obj_OnStopBinding);
    }else {
        if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
            SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
        SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
683 684
        if(test_protocol == FILE_TEST)
            SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
Jacek Caban's avatar
Jacek Caban committed
685 686
        SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
        SET_EXPECT(LockRequest);
687 688
        if(!filedwl_api)
            SET_EXPECT(OnDataAvailable);
Jacek Caban's avatar
Jacek Caban committed
689 690
        SET_EXPECT(OnStopBinding);
    }
691

692
    hres = IInternetProtocolSink_ReportData(pOIProtSink, bscf, 13, 13);
693
    ok(hres == S_OK, "ReportData failed: %08x\n", hres);
694

695
    CHECK_CALLED(Read);
Jacek Caban's avatar
Jacek Caban committed
696 697 698 699
    if(bind_to_object) {
        if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
            CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
        CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
700 701
        if(test_protocol == FILE_TEST)
            CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
Jacek Caban's avatar
Jacek Caban committed
702 703 704 705 706
        CHECK_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
        CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
        CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
        CHECK_CALLED(CreateInstance);
        CHECK_CALLED(PutProperty_MIMETYPEPROP);
707
        CHECK_CALLED_BROKEN(PutProperty_CLASSIDPROP);
Jacek Caban's avatar
Jacek Caban committed
708 709 710 711 712 713 714 715
        CHECK_CALLED(Load);
        CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
        CHECK_CALLED(OnObjectAvailable);
        CHECK_CALLED(Obj_OnStopBinding);
    }else {
        if(test_protocol != FILE_TEST && test_protocol != MK_TEST)
            CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
        CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
716 717
        if(test_protocol == FILE_TEST)
            CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
Jacek Caban's avatar
Jacek Caban committed
718 719
        CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
        CHECK_CALLED(LockRequest);
720 721
        if(!filedwl_api)
            CHECK_CALLED(OnDataAvailable);
Jacek Caban's avatar
Jacek Caban committed
722 723
        CHECK_CALLED(OnStopBinding);
    }
724

725 726 727 728 729 730 731
    if(test_protocol == ITS_TEST) {
        SET_EXPECT(Read);
        hres = IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_BEGINDOWNLOADDATA, NULL);
        ok(hres == S_OK, "ReportProgress(BINDSTATUS_BEGINDOWNLOADDATA) failed: %08x\n", hres);
        CHECK_CALLED(Read);
    }

732 733
    SET_EXPECT(Terminate);
    hres = IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
734
    ok(hres == S_OK, "ReportResult failed: %08x\n", hres);
735
    CHECK_CALLED(Terminate);
736 737 738 739 740 741 742

    return S_OK;
}

static HRESULT WINAPI Protocol_Continue(IInternetProtocol *iface,
        PROTOCOLDATA *pProtocolData)
{
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
    DWORD bscf = 0;
    HRESULT hres;

    CHECK_EXPECT(Continue);

    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

    ok(pProtocolData != NULL, "pProtocolData == NULL\n");
    if(!pProtocolData)
        return S_OK;

    switch(prot_state) {
    case 1: {
        IServiceProvider *service_provider;
        IHttpNegotiate *http_negotiate;
        static WCHAR header[] = {'?',0};

        hres = IInternetProtocolSink_QueryInterface(protocol_sink, &IID_IServiceProvider,
                                                    (void**)&service_provider);
        ok(hres == S_OK, "Could not get IServiceProvicder\n");

        hres = IServiceProvider_QueryService(service_provider, &IID_IHttpNegotiate,
                                             &IID_IHttpNegotiate, (void**)&http_negotiate);
        ok(hres == S_OK, "Could not get IHttpNegotiate\n");

768
        SET_EXPECT(QueryInterface_IHttpNegotiate);
769 770
        SET_EXPECT(OnResponse);
        hres = IHttpNegotiate_OnResponse(http_negotiate, 200, header, NULL, NULL);
771
        CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate);
772 773 774 775
        CHECK_CALLED(OnResponse);
        IHttpNegotiate_Release(http_negotiate);
        ok(hres == S_OK, "OnResponse failed: %08x\n", hres);

776 777 778 779 780
        if(test_protocol == HTTPS_TEST) {
            hres = IInternetProtocolSink_ReportProgress(protocol_sink, BINDSTATUS_ACCEPTRANGES, NULL);
            ok(hres == S_OK, "ReportProgress(BINDSTATUS_ACCEPTRANGES) failed: %08x\n", hres);
        }

781 782 783 784 785
        hres = IInternetProtocolSink_ReportProgress(protocol_sink,
                BINDSTATUS_MIMETYPEAVAILABLE, wszTextHtml);
        ok(hres == S_OK,
           "ReportProgress(BINDSTATUS_MIMETYPEAVAILABLE) failed: %08x\n", hres);

Jacek Caban's avatar
Jacek Caban committed
786 787 788 789 790 791 792
        if(tymed == TYMED_FILE) {
            hres = IInternetProtocolSink_ReportProgress(protocol_sink,
                    BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_fileW);
            ok(hres == S_OK,
                   "ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE) failed: %08x\n", hres);
        }

793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
        bscf |= BSCF_FIRSTDATANOTIFICATION;
        break;
    }
    case 2:
    case 3:
        bscf = BSCF_INTERMEDIATEDATANOTIFICATION;
        break;
    }

    hres = IInternetProtocolSink_ReportData(protocol_sink, bscf, 100, 400);
    ok(hres == S_OK, "ReportData failed: %08x\n", hres);

    SET_EXPECT(Read);
    switch(prot_state) {
    case 1:
Jacek Caban's avatar
Jacek Caban committed
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
        if(bind_to_object) {
            SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
            SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
            SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
            SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
            SET_EXPECT(CreateInstance);
            SET_EXPECT(PutProperty_MIMETYPEPROP);
            SET_EXPECT(PutProperty_CLASSIDPROP);
            SET_EXPECT(Load);
            SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
            SET_EXPECT(OnObjectAvailable);
            SET_EXPECT(Obj_OnStopBinding);
        }else {
            SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
            SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
            SET_EXPECT(LockRequest);
        }
825 826 827 828 829 830 831 832
        break;
    case 2:
        SET_EXPECT(OnProgress_DOWNLOADINGDATA);
        break;
    case 3:
        SET_EXPECT(OnProgress_DOWNLOADINGDATA);
        SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
    }
Jacek Caban's avatar
Jacek Caban committed
833 834
    if(!bind_to_object || prot_state >= 2)
        SET_EXPECT(OnDataAvailable);
835 836 837 838
    if(prot_state == 3)
        SET_EXPECT(OnStopBinding);

    return S_OK;
839 840 841 842 843 844 845 846 847 848 849 850
}

static HRESULT WINAPI Protocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
        DWORD dwOptions)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI Protocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
{
    CHECK_EXPECT(Terminate);
851

852
    ok(dwOptions == 0, "dwOptions=%d, expected 0\n", dwOptions);
853 854 855 856 857 858

    if(protocol_sink) {
        IInternetProtocolSink_Release(protocol_sink);
        protocol_sink = NULL;
    }

859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
    return S_OK;
}

static HRESULT WINAPI Protocol_Suspend(IInternetProtocol *iface)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI Protocol_Resume(IInternetProtocol *iface)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI Protocol_Read(IInternetProtocol *iface, void *pv,
        ULONG cb, ULONG *pcbRead)
{
    static const char data[] = "<HTML></HTML>";

    CHECK_EXPECT2(Read);

881
    if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
        HRESULT hres;

        static BOOL pending = TRUE;

        pending = !pending;

        switch(prot_state) {
        case 1:
        case 2:
            if(pending) {
                *pcbRead = 10;
                memset(pv, '?', 10);
                return E_PENDING;
            }else {
                memset(pv, '?', cb);
                *pcbRead = cb;
                read++;
                return S_OK;
            }
        case 3:
            prot_state++;

            *pcbRead = 0;

            hres = IInternetProtocolSink_ReportData(protocol_sink,
                    BSCF_LASTDATANOTIFICATION|BSCF_INTERMEDIATEDATANOTIFICATION, 2000, 2000);
            ok(hres == S_OK, "ReportData failed: %08x\n", hres);

            hres = IInternetProtocolSink_ReportResult(protocol_sink, S_OK, 0, NULL);
            ok(hres == S_OK, "ReportResult failed: %08x\n", hres);

            return S_FALSE;
        case 4:
            *pcbRead = 0;
            return S_FALSE;
        }
    }

920 921 922 923 924 925 926 927 928
    if(read) {
        *pcbRead = 0;
        return S_FALSE;
    }

    ok(pv != NULL, "pv == NULL\n");
    ok(cb != 0, "cb == 0\n");
    ok(pcbRead != NULL, "pcbRead == NULL\n");
    if(pcbRead) {
929
        ok(*pcbRead == 0, "*pcbRead=%d, expected 0\n", *pcbRead);
930
        read += *pcbRead = sizeof(data)-1;
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
    }
    if(pv)
        memcpy(pv, data, sizeof(data));

    return S_OK;
}

static HRESULT WINAPI Protocol_Seek(IInternetProtocol *iface,
        LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI Protocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
{
    CHECK_EXPECT(LockRequest);
    return S_OK;
}

static HRESULT WINAPI Protocol_UnlockRequest(IInternetProtocol *iface)
{
    CHECK_EXPECT(UnlockRequest);
    return S_OK;
}

static const IInternetProtocolVtbl ProtocolVtbl = {
    Protocol_QueryInterface,
    Protocol_AddRef,
    Protocol_Release,
    Protocol_Start,
    Protocol_Continue,
    Protocol_Abort,
    Protocol_Terminate,
    Protocol_Suspend,
    Protocol_Resume,
    Protocol_Read,
    Protocol_Seek,
    Protocol_LockRequest,
    Protocol_UnlockRequest
};

static IInternetProtocol Protocol = { &ProtocolVtbl };

975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002
static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv)
{
    if(IsEqualGUID(&IID_IUnknown, riid)
            || IsEqualGUID(&IID_IHttpNegotiate, riid)
            || IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
        *ppv = iface;
        return S_OK;
    }

    ok(0, "unexpected call\n");
    return E_NOINTERFACE;
}

static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
{
    return 2;
}

static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
{
    return 1;
}

static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL,
        LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
{
    CHECK_EXPECT(BeginningTransaction);

1003 1004
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
    ok(!lstrcmpW(szURL, urls[test_protocol]), "szURL != urls[test_protocol]\n");
    ok(!dwReserved, "dwReserved=%d, expected 0\n", dwReserved);
    ok(pszAdditionalHeaders != NULL, "pszAdditionalHeaders == NULL\n");
    if(pszAdditionalHeaders)
        ok(*pszAdditionalHeaders == NULL, "*pszAdditionalHeaders != NULL\n");

    return S_OK;
}

static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
        LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders)
{
    CHECK_EXPECT(OnResponse);

1019 1020
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
    ok(dwResponseCode == 200, "dwResponseCode=%d, expected 200\n", dwResponseCode);
    ok(szResponseHeaders != NULL, "szResponseHeaders == NULL\n");
    ok(szRequestHeaders == NULL, "szRequestHeaders != NULL\n");
    /* Note: in protocol.c tests, OnResponse pszAdditionalRequestHeaders _is_ NULL */
    ok(pszAdditionalRequestHeaders != NULL, "pszAdditionalHeaders == NULL\n");
    if(pszAdditionalRequestHeaders)
        ok(*pszAdditionalRequestHeaders == NULL, "*pszAdditionalHeaders != NULL\n");

    return S_OK;
}

static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
        BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
{
    static const BYTE sec_id[] = {'h','t','t','p',':','t','e','s','t',1,0,0,0};

    CHECK_EXPECT(GetRootSecurityId);

1039 1040
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1041 1042 1043 1044
    ok(!dwReserved, "dwReserved=%ld, expected 0\n", dwReserved);
    ok(pbSecurityId != NULL, "pbSecurityId == NULL\n");
    ok(pcbSecurityId != NULL, "pcbSecurityId == NULL\n");

1045 1046 1047
    if(pbSecurityId == (void*)0xdeadbeef)
        return E_NOTIMPL;

1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
    if(pcbSecurityId) {
        ok(*pcbSecurityId == 512, "*pcbSecurityId=%d, expected 512\n", *pcbSecurityId);
        *pcbSecurityId = sizeof(sec_id);
    }

    if(pbSecurityId)
        memcpy(pbSecurityId, sec_id, sizeof(sec_id));

    return E_FAIL;
}

static IHttpNegotiate2Vtbl HttpNegotiateVtbl = {
    HttpNegotiate_QueryInterface,
    HttpNegotiate_AddRef,
    HttpNegotiate_Release,
    HttpNegotiate_BeginningTransaction,
    HttpNegotiate_OnResponse,
    HttpNegotiate_GetRootSecurityId
};

static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiateVtbl };

1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv)
{
    ok(0, "unexpected call\n");
    return E_NOINTERFACE;
}

static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
{
    return 2;
}

static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
{
    return 1;
}

static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
        REFGUID guidService, REFIID riid, void **ppv)
{
    if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
        CHECK_EXPECT(QueryService_IAuthenticate);
        return E_NOTIMPL;
    }

    if(IsEqualGUID(&IID_IInternetProtocol, guidService)) {
        CHECK_EXPECT2(QueryService_IInternetProtocol);
        return E_NOTIMPL;
    }

1099 1100 1101 1102 1103
    if(IsEqualGUID(&IID_IInternetBindInfo, guidService)) {
        CHECK_EXPECT(QueryService_IInternetBindInfo);
        return E_NOTIMPL;
    }

1104 1105 1106 1107 1108
    if(IsEqualGUID(&IID_IWindowForBindingUI, guidService)) {
        CHECK_EXPECT(QueryService_IWindowForBindingUI);
        return E_NOTIMPL;
    }

1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
    ok(0, "unexpected service %s\n", debugstr_guid(guidService));
    return E_NOINTERFACE;
}

static IServiceProviderVtbl ServiceProviderVtbl = {
    ServiceProvider_QueryInterface,
    ServiceProvider_AddRef,
    ServiceProvider_Release,
    ServiceProvider_QueryService
};

static IServiceProvider ServiceProvider = { &ServiceProviderVtbl };

1122
static IBindStatusCallbackEx objbsc;
Jacek Caban's avatar
Jacek Caban committed
1123

1124
static HRESULT WINAPI statusclb_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv)
1125
{
1126 1127
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

Jacek Caban's avatar
Jacek Caban committed
1128
    if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
1129
        CHECK_EXPECT2(QueryInterface_IInternetProtocol);
Jacek Caban's avatar
Jacek Caban committed
1130 1131 1132 1133 1134 1135
        if(emulate_protocol) {
            *ppv = &Protocol;
            return S_OK;
        }else {
            return E_NOINTERFACE;
        }
1136
    }
1137 1138
    else if (IsEqualGUID(&IID_IServiceProvider, riid))
    {
1139 1140 1141
        CHECK_EXPECT2(QueryInterface_IServiceProvider);
        *ppv = &ServiceProvider;
        return S_OK;
1142 1143 1144
    }
    else if (IsEqualGUID(&IID_IHttpNegotiate, riid))
    {
1145
        CHECK_EXPECT2(QueryInterface_IHttpNegotiate);
1146 1147
        *ppv = &HttpNegotiate;
        return S_OK;
1148 1149 1150 1151
    }
    else if (IsEqualGUID(&IID_IHttpNegotiate2, riid))
    {
        CHECK_EXPECT(QueryInterface_IHttpNegotiate2);
1152 1153
        *ppv = &HttpNegotiate;
        return S_OK;
1154
    }
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
    else if (IsEqualGUID(&IID_IAuthenticate, riid))
    {
        CHECK_EXPECT(QueryInterface_IAuthenticate);
        return E_NOINTERFACE;
    }
    else if(IsEqualGUID(&IID_IBindStatusCallback, riid))
    {
        CHECK_EXPECT2(QueryInterface_IBindStatusCallback);
        *ppv = iface;
        return S_OK;
    }
    else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid))
    {
        CHECK_EXPECT2(QueryInterface_IBindStatusCallbackHolder);
        return E_NOINTERFACE;
    }
1171 1172 1173 1174 1175 1176 1177 1178
    else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid))
    {
        CHECK_EXPECT(QueryInterface_IBindStatusCallbackEx);
        if(!use_bscex)
            return E_NOINTERFACE;
        *ppv = iface;
        return S_OK;
    }
1179 1180 1181
    else if(IsEqualGUID(&IID_IInternetBindInfo, riid))
    {
        /* TODO */
1182
        CHECK_EXPECT2(QueryInterface_IInternetBindInfo);
1183
    }
1184 1185 1186 1187 1188
    else if(IsEqualGUID(&IID_IWindowForBindingUI, riid))
    {
        CHECK_EXPECT2(QueryInterface_IWindowForBindingUI);
        return E_NOINTERFACE;
    }
1189 1190 1191 1192
    else
    {
        ok(0, "unexpected interface %s\n", debugstr_guid(riid));
    }
1193

1194 1195 1196
    return E_NOINTERFACE;
}

1197
static ULONG WINAPI statusclb_AddRef(IBindStatusCallbackEx *iface)
1198
{
Jacek Caban's avatar
Jacek Caban committed
1199
    return 2;
1200 1201
}

1202
static ULONG WINAPI statusclb_Release(IBindStatusCallbackEx *iface)
1203
{
Jacek Caban's avatar
Jacek Caban committed
1204
    return 1;
1205 1206
}

1207
static HRESULT WINAPI statusclb_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved,
Jacek Caban's avatar
Jacek Caban committed
1208
        IBinding *pib)
1209
{
Jacek Caban's avatar
Jacek Caban committed
1210
    IWinInetHttpInfo *http_info;
1211 1212
    HRESULT hres;
    IMoniker *mon;
1213

Jacek Caban's avatar
Jacek Caban committed
1214 1215 1216 1217
    if(iface == &objbsc)
        CHECK_EXPECT(Obj_OnStartBinding);
    else
        CHECK_EXPECT(OnStartBinding);
Jacek Caban's avatar
Jacek Caban committed
1218

1219 1220
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1221
    ok(pib != NULL, "pib should not be NULL\n");
1222 1223 1224 1225
    ok(dwReserved == 0xff, "dwReserved=%x\n", dwReserved);

    if(pib == (void*)0xdeadbeef)
        return S_OK;
1226

1227 1228
    current_binding = pib;

1229 1230 1231 1232 1233
    hres = IBinding_QueryInterface(pib, &IID_IMoniker, (void**)&mon);
    ok(hres == E_NOINTERFACE, "IBinding should not have IMoniker interface\n");
    if(SUCCEEDED(hres))
        IMoniker_Release(mon);

Jacek Caban's avatar
Jacek Caban committed
1234 1235 1236
    hres = IBinding_QueryInterface(pib, &IID_IWinInetHttpInfo, (void**)&http_info);
    ok(hres == E_NOINTERFACE, "Could not get IID_IWinInetHttpInfo: %08x\n", hres);

1237
    return S_OK;
1238 1239
}

1240
static HRESULT WINAPI statusclb_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
1241
{
Jacek Caban's avatar
Jacek Caban committed
1242
    ok(0, "unexpected call\n");
1243 1244 1245
    return E_NOTIMPL;
}

1246
static HRESULT WINAPI statusclb_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
1247
{
Jacek Caban's avatar
Jacek Caban committed
1248
    ok(0, "unexpected call\n");
1249 1250 1251
    return E_NOTIMPL;
}

1252
static HRESULT WINAPI statusclb_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
Jacek Caban's avatar
Jacek Caban committed
1253
        ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
1254
{
1255 1256
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

Jacek Caban's avatar
Jacek Caban committed
1257 1258
    switch(ulStatusCode) {
    case BINDSTATUS_FINDINGRESOURCE:
Jacek Caban's avatar
Jacek Caban committed
1259 1260
        if(iface == &objbsc)
            CHECK_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
1261 1262
        else if(test_protocol == FTP_TEST)
            todo_wine CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
Jacek Caban's avatar
Jacek Caban committed
1263 1264
        else
            CHECK_EXPECT(OnProgress_FINDINGRESOURCE);
1265 1266
        if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
            SetEvent(complete_event);
Jacek Caban's avatar
Jacek Caban committed
1267 1268
        break;
    case BINDSTATUS_CONNECTING:
Jacek Caban's avatar
Jacek Caban committed
1269 1270
        if(iface == &objbsc)
            CHECK_EXPECT(Obj_OnProgress_CONNECTING);
1271 1272
        else if(test_protocol == FTP_TEST)
            todo_wine CHECK_EXPECT(OnProgress_CONNECTING);
Jacek Caban's avatar
Jacek Caban committed
1273 1274
        else
            CHECK_EXPECT(OnProgress_CONNECTING);
1275 1276
        if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
            SetEvent(complete_event);
Jacek Caban's avatar
Jacek Caban committed
1277 1278
        break;
    case BINDSTATUS_SENDINGREQUEST:
Jacek Caban's avatar
Jacek Caban committed
1279 1280
        if(iface == &objbsc)
            CHECK_EXPECT(Obj_OnProgress_SENDINGREQUEST);
1281 1282
        else if(test_protocol == FTP_TEST)
            CHECK_EXPECT2(OnProgress_SENDINGREQUEST);
Jacek Caban's avatar
Jacek Caban committed
1283 1284
        else
            CHECK_EXPECT(OnProgress_SENDINGREQUEST);
1285 1286
        if((bindf & BINDF_ASYNCHRONOUS) && emulate_protocol)
            SetEvent(complete_event);
Jacek Caban's avatar
Jacek Caban committed
1287 1288
        break;
    case BINDSTATUS_MIMETYPEAVAILABLE:
Jacek Caban's avatar
Jacek Caban committed
1289 1290 1291 1292 1293 1294 1295
        if(iface == &objbsc)
            CHECK_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
        else
            CHECK_EXPECT(OnProgress_MIMETYPEAVAILABLE);
        if(!bind_to_object)
            ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
               download_state);
1296
        WideCharToMultiByte(CP_ACP, 0, szStatusText, -1, mime_type, sizeof(mime_type)-1, NULL, NULL);
Jacek Caban's avatar
Jacek Caban committed
1297 1298
        break;
    case BINDSTATUS_BEGINDOWNLOADDATA:
Jacek Caban's avatar
Jacek Caban committed
1299 1300 1301 1302
        if(iface == &objbsc)
            CHECK_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
        else
            CHECK_EXPECT(OnProgress_BEGINDOWNLOADDATA);
1303
        ok(szStatusText != NULL, "szStatusText == NULL\n");
1304 1305 1306 1307
        if(szStatusText) {
            if(filedwl_api) {
                /* FIXME */
            }else {
1308
                ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1309 1310
            }
        }
Jacek Caban's avatar
Jacek Caban committed
1311 1312 1313
        if(!bind_to_object)
            ok(download_state == BEFORE_DOWNLOAD, "Download state was %d, expected BEFORE_DOWNLOAD\n",
               download_state);
1314
        download_state = DOWNLOADING;
Jacek Caban's avatar
Jacek Caban committed
1315 1316 1317
        break;
    case BINDSTATUS_DOWNLOADINGDATA:
        CHECK_EXPECT2(OnProgress_DOWNLOADINGDATA);
1318
        ok(iface != &objbsc, "unexpected call\n");
1319 1320
        ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
           download_state);
Jacek Caban's avatar
Jacek Caban committed
1321 1322
        break;
    case BINDSTATUS_ENDDOWNLOADDATA:
Jacek Caban's avatar
Jacek Caban committed
1323 1324 1325 1326
        if(iface == &objbsc)
            CHECK_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
        else
            CHECK_EXPECT(OnProgress_ENDDOWNLOADDATA);
1327
        ok(szStatusText != NULL, "szStatusText == NULL\n");
1328 1329 1330 1331
        if(szStatusText) {
            if(filedwl_api) {
                /* FIXME */
            }else {
1332
                ok(!lstrcmpW(szStatusText, urls[test_protocol]), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
1333 1334
            }
        }
1335 1336 1337
        ok(download_state == DOWNLOADING, "Download state was %d, expected DOWNLOADING\n",
           download_state);
        download_state = END_DOWNLOAD;
1338 1339
        break;
    case BINDSTATUS_CACHEFILENAMEAVAILABLE:
1340
        if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST) {
Jacek Caban's avatar
Jacek Caban committed
1341 1342 1343 1344 1345 1346 1347 1348 1349
            if(iface == &objbsc)
                CHECK_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
            else
                CHECK_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
        }else {  /* FIXME */
            CLEAR_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
            CLEAR_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
        }

1350 1351
        ok(szStatusText != NULL, "szStatusText == NULL\n");
        if(szStatusText && test_protocol == FILE_TEST)
1352
            ok(!lstrcmpW(file_url+8, szStatusText), "wrong szStatusText %s\n", wine_dbgstr_w(szStatusText));
Jacek Caban's avatar
Jacek Caban committed
1353
        break;
1354 1355 1356 1357
    case BINDSTATUS_CLASSIDAVAILABLE:
    {
        CLSID clsid;
        HRESULT hr;
Jacek Caban's avatar
Jacek Caban committed
1358 1359 1360 1361 1362 1363
        if(iface != &objbsc)
            ok(0, "unexpected call\n");
        else if(1||emulate_protocol)
            CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
        else
            todo_wine CHECK_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
1364 1365 1366
        hr = CLSIDFromString((LPOLESTR)szStatusText, &clsid);
        ok(hr == S_OK, "CLSIDFromString failed with error 0x%08x\n", hr);
        ok(IsEqualCLSID(&clsid, &CLSID_HTMLDocument),
Jacek Caban's avatar
Jacek Caban committed
1367
            "Expected clsid to be CLSID_HTMLDocument instead of %s\n", debugstr_guid(&clsid));
1368 1369 1370
        break;
    }
    case BINDSTATUS_BEGINSYNCOPERATION:
Jacek Caban's avatar
Jacek Caban committed
1371 1372 1373
        CHECK_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
        if(iface != &objbsc)
            ok(0, "unexpected call\n");
1374 1375 1376
        ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
        break;
    case BINDSTATUS_ENDSYNCOPERATION:
Jacek Caban's avatar
Jacek Caban committed
1377 1378 1379
        CHECK_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
        if(iface != &objbsc)
            ok(0, "unexpected call\n");
1380 1381
        ok(szStatusText == NULL, "Expected szStatusText to be NULL\n");
        break;
1382 1383 1384
    case BINDSTATUS_PROXYDETECTING:
        trace("BINDSTATUS_PROXYDETECTING\n");
        break;
1385 1386 1387
    case BINDSTATUS_COOKIE_SENT:
        trace("BINDSTATUS_COOKIE_SENT\n");
        break;
Jacek Caban's avatar
Jacek Caban committed
1388
    default:
1389
        ok(0, "unexpected code %d\n", ulStatusCode);
Jacek Caban's avatar
Jacek Caban committed
1390
    };
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405

    if(current_binding) {
        IWinInetHttpInfo *http_info;
        HRESULT hres;

        hres = IBinding_QueryInterface(current_binding, &IID_IWinInetHttpInfo, (void**)&http_info);
        if(!emulate_protocol && test_protocol != FILE_TEST && is_urlmon_protocol(test_protocol))
            ok(hres == S_OK, "Could not get IWinInetHttpInfo iface: %08x\n", hres);
        else
            ok(hres == E_NOINTERFACE,
               "QueryInterface(IID_IWinInetHttpInfo) returned: %08x, expected E_NOINTERFACE\n", hres);
        if(SUCCEEDED(hres))
            IWinInetHttpInfo_Release(http_info);
    }

1406
    return S_OK;
1407 1408
}

1409
static HRESULT WINAPI statusclb_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError)
1410
{
Jacek Caban's avatar
Jacek Caban committed
1411 1412 1413 1414 1415 1416 1417
    if(iface == &objbsc) {
        CHECK_EXPECT(Obj_OnStopBinding);
        stopped_obj_binding = TRUE;
    }else {
        CHECK_EXPECT(OnStopBinding);
        stopped_binding = TRUE;
    }
Jacek Caban's avatar
Jacek Caban committed
1418

1419 1420
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1421
    /* ignore DNS failure */
1422 1423 1424
    if (hresult == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
        return S_OK;

1425 1426 1427 1428
    if(filedwl_api)
        ok(SUCCEEDED(hresult), "binding failed: %08x\n", hresult);
    else
        ok(hresult == binding_hres, "binding failed: %08x, expected %08x\n", hresult, binding_hres);
1429 1430
    ok(szError == NULL, "szError should be NULL\n");

1431
    if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) && emulate_protocol) {
1432
        SetEvent(complete_event);
Jacek Caban's avatar
Jacek Caban committed
1433 1434
        if(iface != &objbsc)
            WaitForSingleObject(complete_event2, INFINITE);
1435
    }
1436 1437

    return S_OK;
1438 1439
}

1440
static HRESULT WINAPI statusclb_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
1441
{
1442 1443
    DWORD cbSize;

Jacek Caban's avatar
Jacek Caban committed
1444 1445 1446 1447
    if(iface == &objbsc)
        CHECK_EXPECT(Obj_GetBindInfo);
    else
        CHECK_EXPECT(GetBindInfo);
Jacek Caban's avatar
Jacek Caban committed
1448

1449 1450
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1451
    *grfBINDF = bindf;
1452 1453 1454 1455 1456
    cbSize = pbindinfo->cbSize;
    memset(pbindinfo, 0, cbSize);
    pbindinfo->cbSize = cbSize;

    return S_OK;
1457 1458
}

1459
static HRESULT WINAPI statusclb_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF,
1460
        DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
1461
{
1462 1463 1464
    HRESULT hres;
    DWORD readed;
    BYTE buf[512];
1465
    CHAR clipfmt[512];
Jacek Caban's avatar
Jacek Caban committed
1466

Jacek Caban's avatar
Jacek Caban committed
1467 1468 1469
    if(iface == &objbsc)
        ok(0, "unexpected call\n");

Jacek Caban's avatar
Jacek Caban committed
1470
    CHECK_EXPECT2(OnDataAvailable);
1471 1472 1473

    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1474 1475 1476
    ok(download_state == DOWNLOADING || download_state == END_DOWNLOAD,
       "Download state was %d, expected DOWNLOADING or END_DOWNLOAD\n",
       download_state);
1477
    data_available = TRUE;
Jacek Caban's avatar
Jacek Caban committed
1478

1479 1480
    ok(pformatetc != NULL, "pformatetx == NULL\n");
    if(pformatetc) {
1481
        if (mime_type[0]) {
1482 1483 1484
            clipfmt[0] = 0;
            ok(GetClipboardFormatName(pformatetc->cfFormat, clipfmt, sizeof(clipfmt)-1),
               "GetClipboardFormatName failed, error %d\n", GetLastError());
Jacek Caban's avatar
Jacek Caban committed
1485 1486
            ok(!lstrcmp(clipfmt, mime_type), "clipformat %x != mime_type, \"%s\" != \"%s\"\n",
               pformatetc->cfFormat, clipfmt, mime_type);
1487 1488 1489
        } else {
            ok(pformatetc->cfFormat == 0, "clipformat=%x\n", pformatetc->cfFormat);
        }
1490
        ok(pformatetc->ptd == NULL, "ptd = %p\n", pformatetc->ptd);
1491 1492
        ok(pformatetc->dwAspect == 1, "dwAspect=%u\n", pformatetc->dwAspect);
        ok(pformatetc->lindex == -1, "lindex=%d\n", pformatetc->lindex);
Jacek Caban's avatar
Jacek Caban committed
1493
        ok(pformatetc->tymed == tymed, "tymed=%u, expected %u\n", pformatetc->tymed, tymed);
1494 1495 1496
    }

    ok(pstgmed != NULL, "stgmeg == NULL\n");
Jacek Caban's avatar
Jacek Caban committed
1497
    ok(pstgmed->tymed == tymed, "tymed=%u, expected %u\n", pstgmed->tymed, tymed);
1498
    ok(pstgmed->pUnkForRelease != NULL, "pUnkForRelease == NULL\n");
1499

Jacek Caban's avatar
Jacek Caban committed
1500 1501 1502 1503 1504 1505
    switch(pstgmed->tymed) {
    case TYMED_ISTREAM:
        if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
            hres = IStream_Write(U(*pstgmed).pstm, buf, 10, NULL);
            ok(hres == STG_E_ACCESSDENIED,
               "Write failed: %08x, expected STG_E_ACCESSDENIED\n", hres);
1506

Jacek Caban's avatar
Jacek Caban committed
1507 1508
            hres = IStream_Commit(U(*pstgmed).pstm, 0);
            ok(hres == E_NOTIMPL, "Commit failed: %08x, expected E_NOTIMPL\n", hres);
1509

Jacek Caban's avatar
Jacek Caban committed
1510 1511 1512
            hres = IStream_Revert(U(*pstgmed).pstm);
            ok(hres == E_NOTIMPL, "Revert failed: %08x, expected E_NOTIMPL\n", hres);
        }
1513

Jacek Caban's avatar
Jacek Caban committed
1514
        ok(U(*pstgmed).pstm != NULL, "U(*pstgmed).pstm == NULL\n");
Jacek Caban's avatar
Jacek Caban committed
1515 1516
        do hres = IStream_Read(U(*pstgmed).pstm, buf, 512, &readed);
        while(hres == S_OK);
1517
        ok(hres == S_FALSE || hres == E_PENDING, "IStream_Read returned %08x\n", hres);
Jacek Caban's avatar
Jacek Caban committed
1518 1519 1520 1521 1522
        break;

    case TYMED_FILE:
        if(test_protocol == FILE_TEST)
            ok(!lstrcmpW(pstgmed->u.lpszFileName, INDEX_HTML+7),
1523
               "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
Jacek Caban's avatar
Jacek Caban committed
1524 1525
        else if(emulate_protocol)
            ok(!lstrcmpW(pstgmed->u.lpszFileName, cache_fileW),
1526
               "unexpected file name %s\n", wine_dbgstr_w(pstgmed->u.lpszFileName));
Jacek Caban's avatar
Jacek Caban committed
1527 1528
        else
            ok(pstgmed->u.lpszFileName != NULL, "lpszFileName == NULL\n");
1529 1530
    }

1531 1532
    if((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
       && emulate_protocol && prot_state < 4 && (!bind_to_object || prot_state > 1))
1533 1534
        SetEvent(complete_event);

1535
    return S_OK;
1536 1537
}

1538
static HRESULT WINAPI statusclb_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk)
1539
{
1540
    CHECK_EXPECT(OnObjectAvailable);
Jacek Caban's avatar
Jacek Caban committed
1541 1542 1543 1544 1545 1546 1547

    if(iface != &objbsc)
        ok(0, "unexpected call\n");

    ok(IsEqualGUID(&IID_IUnknown, riid), "riid = %s\n", debugstr_guid(riid));
    ok(punk != NULL, "punk == NULL\n");

1548
    return S_OK;
1549 1550
}

1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
static HRESULT WINAPI statusclb_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo,
        DWORD *grfBINDF2, DWORD *pdwReserved)
{
    CHECK_EXPECT(GetBindInfoEx);

    ok(grfBINDF != NULL, "grfBINDF == NULL\n");
    ok(grfBINDF2 != NULL, "grfBINDF2 == NULL\n");
    ok(pbindinfo != NULL, "pbindinfo == NULL\n");
    ok(pdwReserved != NULL, "dwReserved == NULL\n");

    return S_OK;
}

static const IBindStatusCallbackExVtbl BindStatusCallbackVtbl = {
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574
    statusclb_QueryInterface,
    statusclb_AddRef,
    statusclb_Release,
    statusclb_OnStartBinding,
    statusclb_GetPriority,
    statusclb_OnLowResource,
    statusclb_OnProgress,
    statusclb_OnStopBinding,
    statusclb_GetBindInfo,
    statusclb_OnDataAvailable,
1575 1576
    statusclb_OnObjectAvailable,
    statusclb_GetBindInfoEx
1577 1578
};

1579 1580
static IBindStatusCallbackEx bsc = { &BindStatusCallbackVtbl };
static IBindStatusCallbackEx objbsc = { &BindStatusCallbackVtbl };
Jacek Caban's avatar
Jacek Caban committed
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603

static HRESULT WINAPI MonikerProp_QueryInterface(IMonikerProp *iface, REFIID riid, void **ppv)
{
    *ppv = NULL;
    ok(0, "unexpected riid %s\n", debugstr_guid(riid));
    return E_NOINTERFACE;
}

static ULONG WINAPI MonikerProp_AddRef(IMonikerProp *iface)
{
    return 2;
}

static ULONG WINAPI MonikerProp_Release(IMonikerProp *iface)
{
    return 1;
}

static HRESULT WINAPI MonikerProp_PutProperty(IMonikerProp *iface, MONIKERPROPERTY mkp, LPCWSTR val)
{
    switch(mkp) {
    case MIMETYPEPROP:
        CHECK_EXPECT(PutProperty_MIMETYPEPROP);
1604
        ok(!lstrcmpW(val, wszTextHtml), "val = %s\n", wine_dbgstr_w(val));
Jacek Caban's avatar
Jacek Caban committed
1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674
        break;
    case CLASSIDPROP:
        CHECK_EXPECT(PutProperty_CLASSIDPROP);
        break;
    default:
        break;
    }

    return S_OK;
}

static const IMonikerPropVtbl MonikerPropVtbl = {
    MonikerProp_QueryInterface,
    MonikerProp_AddRef,
    MonikerProp_Release,
    MonikerProp_PutProperty
};

static IMonikerProp MonikerProp = { &MonikerPropVtbl };

static HRESULT WINAPI PersistMoniker_QueryInterface(IPersistMoniker *iface, REFIID riid, void **ppv)
{
    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IPersistMoniker, riid))
        *ppv = iface;
    else if(IsEqualGUID(&IID_IMonikerProp, riid))
        *ppv = &MonikerProp;

    if(*ppv)
        return S_OK;

    ok(0, "unexpected riid %s\n", debugstr_guid(riid));
    return E_NOINTERFACE;
}

static ULONG WINAPI PersistMoniker_AddRef(IPersistMoniker *iface)
{
    return 2;
}

static ULONG WINAPI PersistMoniker_Release(IPersistMoniker *iface)
{
    return 1;
}

static HRESULT WINAPI PersistMoniker_GetClassID(IPersistMoniker *iface, CLSID *pClassID)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI PersistMoniker_IsDirty(IPersistMoniker *iface)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAvailable,
                                          IMoniker *pimkName, LPBC pibc, DWORD grfMode)
{
    IUnknown *unk;
    HRESULT hres;

    static WCHAR cbinding_contextW[] =
        {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};

    CHECK_EXPECT(Load);
    ok(GetCurrentThreadId() == thread_id, "wrong thread %d\n", GetCurrentThreadId());

1675
    if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
        ok(!fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
    else
        ok(fFullyAvailable, "fFulyAvailable = %x\n", fFullyAvailable);
    ok(pimkName != NULL, "pimkName == NULL\n");
    ok(pibc != NULL, "pibc == NULL\n");
    ok(grfMode == 0x12, "grfMode = %x\n", grfMode);

    hres = IBindCtx_GetObjectParam(pibc, cbinding_contextW, &unk);
    ok(hres == S_OK, "GetObjectParam(CBinding Context) failed: %08x\n", hres);
    if(SUCCEEDED(hres)) {
        IBinding *binding;

        hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
        ok(hres == S_OK, "Could not get IBinding: %08x\n", hres);

        IBinding_Release(binding);
        IUnknown_Release(unk);
    }

    SET_EXPECT(QueryInterface_IServiceProvider);
1696
    hres = RegisterBindStatusCallback(pibc, (IBindStatusCallback*)&bsc, NULL, 0);
Jacek Caban's avatar
Jacek Caban committed
1697 1698 1699
    ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
    CHECK_CALLED(QueryInterface_IServiceProvider);

1700
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
Jacek Caban's avatar
Jacek Caban committed
1701 1702 1703
    SET_EXPECT(GetBindInfo);
    SET_EXPECT(OnStartBinding);
    SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
1704 1705
    if(test_protocol == FILE_TEST)
        SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
1706
    if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
1707 1708 1709
        SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
    SET_EXPECT(LockRequest);
    SET_EXPECT(OnDataAvailable);
1710
    if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
1711 1712 1713 1714 1715
        SET_EXPECT(OnStopBinding);

    hres = IMoniker_BindToStorage(pimkName, pibc, NULL, &IID_IStream, (void**)&unk);
    ok(hres == S_OK, "Load failed: %08x\n", hres);

1716
    CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
Jacek Caban's avatar
Jacek Caban committed
1717 1718 1719
    CHECK_CALLED(GetBindInfo);
    CHECK_CALLED(OnStartBinding);
    CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
1720 1721
    if(test_protocol == FILE_TEST)
        CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
1722
    if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
1723 1724 1725
        CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
    CHECK_CALLED(LockRequest);
    CHECK_CALLED(OnDataAvailable);
1726
    if(test_protocol != HTTP_TEST && test_protocol != HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818
        CHECK_CALLED(OnStopBinding);

    if(unk)
        IUnknown_Release(unk);

    return S_OK;
}

static HRESULT WINAPI PersistMoniker_Save(IPersistMoniker *iface, IMoniker *pimkName, LPBC pbc, BOOL fRemember)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI PersistMoniker_SaveCompleted(IPersistMoniker *iface, IMoniker *pimkName, LPBC pibc)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static HRESULT WINAPI PersistMoniker_GetCurMoniker(IPersistMoniker *iface, IMoniker **pimkName)
{
    ok(0, "unexpected call\n");
    return E_NOTIMPL;
}

static const IPersistMonikerVtbl PersistMonikerVtbl = {
    PersistMoniker_QueryInterface,
    PersistMoniker_AddRef,
    PersistMoniker_Release,
    PersistMoniker_GetClassID,
    PersistMoniker_IsDirty,
    PersistMoniker_Load,
    PersistMoniker_Save,
    PersistMoniker_SaveCompleted,
    PersistMoniker_GetCurMoniker
};

static IPersistMoniker PersistMoniker = { &PersistMonikerVtbl };

static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
{
    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
        *ppv = iface;
        return S_OK;
    }

    if(IsEqualGUID(&IID_IMarshal, riid))
        return E_NOINTERFACE;
    if(IsEqualGUID(&CLSID_IdentityUnmarshal, riid))
        return E_NOINTERFACE;

    ok(0, "unexpected riid %s\n", debugstr_guid(riid));
    return E_NOTIMPL;
}

static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{
    return 2;
}

static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{
    return 1;
}

static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **ppv)
{
    CHECK_EXPECT(CreateInstance);
    ok(!outer, "outer = %p\n", outer);
    ok(IsEqualGUID(&IID_IUnknown, riid), "unexpected riid %s\n", debugstr_guid(riid));
    *ppv = &PersistMoniker;
    return S_OK;
}

static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
{
    ok(0, "unexpected call\n");
    return S_OK;
}

static const IClassFactoryVtbl ClassFactoryVtbl = {
    ClassFactory_QueryInterface,
    ClassFactory_AddRef,
    ClassFactory_Release,
    ClassFactory_CreateInstance,
    ClassFactory_LockServer
};

static IClassFactory mime_cf = { &ClassFactoryVtbl };
1819

1820
static void test_CreateAsyncBindCtx(void)
1821 1822
{
    IBindCtx *bctx = (IBindCtx*)0x0ff00ff0;
1823
    IUnknown *unk;
1824 1825 1826 1827 1828
    HRESULT hres;
    ULONG ref;
    BIND_OPTS bindopts;

    hres = CreateAsyncBindCtx(0, NULL, NULL, &bctx);
1829
    ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1830 1831 1832
    ok(bctx == (IBindCtx*)0x0ff00ff0, "bctx should not be changed\n");

    hres = CreateAsyncBindCtx(0, NULL, NULL, NULL);
1833
    ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed. expected: E_INVALIDARG, got: %08x\n", hres);
1834

1835
    SET_EXPECT(QueryInterface_IServiceProvider);
1836
    hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
1837
    ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n", hres);
1838
    CHECK_CALLED(QueryInterface_IServiceProvider);
1839

1840
    bindopts.cbStruct = sizeof(bindopts);
1841
    hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1842
    ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1843
    ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1844
                "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1845
    ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1846
                "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1847
                bindopts.grfMode);
1848
    ok(bindopts.dwTickCountDeadline == 0,
1849
                "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1850

1851 1852 1853 1854 1855
    hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
    ok(hres == E_NOINTERFACE, "QueryInterface(IID_IAsyncBindCtx) failed: %08x, expected E_NOINTERFACE\n", hres);
    if(SUCCEEDED(hres))
        IUnknown_Release(unk);

1856 1857 1858 1859
    ref = IBindCtx_Release(bctx);
    ok(ref == 0, "bctx should be destroyed here\n");
}

1860 1861
static void test_CreateAsyncBindCtxEx(void)
{
1862
    IBindCtx *bctx = NULL, *bctx2 = NULL, *bctx_arg = NULL;
1863
    IUnknown *unk;
1864 1865 1866
    BIND_OPTS bindopts;
    HRESULT hres;

1867 1868
    static WCHAR testW[] = {'t','e','s','t',0};

1869
    hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, NULL, 0);
1870
    ok(hres == E_INVALIDARG, "CreateAsyncBindCtx failed: %08x, expected E_INVALIDARG\n", hres);
1871 1872

    hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1873
    ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1874 1875 1876 1877

    if(SUCCEEDED(hres)) {
        bindopts.cbStruct = sizeof(bindopts);
        hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1878
        ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1879
        ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1880
                "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1881
        ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1882
                "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1883 1884
                bindopts.grfMode);
        ok(bindopts.dwTickCountDeadline == 0,
1885
                "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1886 1887 1888 1889 1890 1891

        IBindCtx_Release(bctx);
    }

    CreateBindCtx(0, &bctx_arg);
    hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
1892
    ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1893 1894 1895 1896

    if(SUCCEEDED(hres)) {
        bindopts.cbStruct = sizeof(bindopts);
        hres = IBindCtx_GetBindOptions(bctx, &bindopts);
1897
        ok(SUCCEEDED(hres), "IBindCtx_GetBindOptions failed: %08x\n", hres);
1898
        ok(bindopts.grfFlags == BIND_MAYBOTHERUSER,
1899
                "bindopts.grfFlags = %08x, expected: BIND_MAYBOTHERUSER\n", bindopts.grfFlags);
1900
        ok(bindopts.grfMode == (STGM_READWRITE | STGM_SHARE_EXCLUSIVE),
1901
                "bindopts.grfMode = %08x, expected: STGM_READWRITE | STGM_SHARE_EXCLUSIVE\n",
1902 1903
                bindopts.grfMode);
        ok(bindopts.dwTickCountDeadline == 0,
1904
                "bindopts.dwTickCountDeadline = %08x, expected: 0\n", bindopts.dwTickCountDeadline);
1905 1906 1907 1908 1909 1910

        IBindCtx_Release(bctx);
    }

    IBindCtx_Release(bctx_arg);

1911
    SET_EXPECT(QueryInterface_IServiceProvider);
1912
    hres = CreateAsyncBindCtxEx(NULL, 0, (IBindStatusCallback*)&bsc, NULL, &bctx, 0);
1913
    ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
1914
    CHECK_CALLED(QueryInterface_IServiceProvider);
1915

1916 1917 1918 1919 1920
    hres = IBindCtx_QueryInterface(bctx, &IID_IAsyncBindCtx, (void**)&unk);
    ok(hres == S_OK, "QueryInterface(IID_IAsyncBindCtx) failed: %08x\n", hres);
    if(SUCCEEDED(hres))
        IUnknown_Release(unk);

1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937
    IBindCtx_Release(bctx);

    hres = CreateBindCtx(0, &bctx2);
    ok(hres == S_OK, "CreateBindCtx failed: %08x\n", hres);

    hres = CreateAsyncBindCtxEx(bctx2, 0, NULL, NULL, &bctx, 0);
    ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);

    hres = IBindCtx_RegisterObjectParam(bctx2, testW, (IUnknown*)&Protocol);
    ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);

    hres = IBindCtx_GetObjectParam(bctx, testW, &unk);
    ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);
    ok(unk == (IUnknown*)&Protocol, "unexpected unk %p\n", unk);

    IBindCtx_Release(bctx);
    IBindCtx_Release(bctx2);
1938 1939
}

1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
static void test_GetBindInfoEx(IBindStatusCallback *holder)
{
    IBindStatusCallbackEx *bscex;
    BINDINFO bindinfo = {sizeof(bindinfo)};
    DWORD bindf, bindf2, dw;
    HRESULT hres;

    hres = IBindStatusCallback_QueryInterface(holder, &IID_IBindStatusCallbackEx, (void**)&bscex);
    if(FAILED(hres)) {
        win_skip("IBindStatusCallbackEx not supported\n");
        return;
    }

    use_bscex = TRUE;

    bindf = 0;
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
    SET_EXPECT(GetBindInfoEx);
    hres = IBindStatusCallback_GetBindInfo(holder, &bindf, &bindinfo);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
    CHECK_CALLED(GetBindInfoEx);

    bindf = bindf2 = dw = 0;
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
    SET_EXPECT(GetBindInfoEx);
    hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
    CHECK_CALLED(GetBindInfoEx);

    use_bscex = FALSE;

    bindf = bindf2 = dw = 0xdeadbeef;
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
    SET_EXPECT(GetBindInfo);
    hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, &bindf, &bindinfo, &bindf2, &dw);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
    CHECK_CALLED(QueryInterface_IBindStatusCallbackEx);
    CHECK_CALLED(GetBindInfo);
    ok(bindf2 == 0xdeadbeef, "bindf2 = %x\n", bindf2);
    ok(dw == 0xdeadbeef, "dw = %x\n", dw);

    IBindStatusCallbackEx_Release(bscex);
}

1986
static BOOL test_bscholder(IBindStatusCallback *holder)
1987 1988 1989 1990 1991 1992 1993
{
    IServiceProvider *serv_prov;
    IHttpNegotiate *http_negotiate, *http_negotiate_serv;
    IHttpNegotiate2 *http_negotiate2, *http_negotiate2_serv;
    IAuthenticate *authenticate, *authenticate_serv;
    IInternetProtocol *protocol;
    BINDINFO bindinfo = {sizeof(bindinfo)};
1994
    BOOL ret = TRUE;
1995 1996 1997 1998 1999 2000 2001 2002
    LPWSTR wstr;
    DWORD dw;
    HRESULT hres;

    hres = IBindStatusCallback_QueryInterface(holder, &IID_IServiceProvider, (void**)&serv_prov);
    ok(hres == S_OK, "Could not get IServiceProvider interface: %08x\n", hres);

    dw = 0xdeadbeef;
2003
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
2004 2005 2006
    SET_EXPECT(GetBindInfo);
    hres = IBindStatusCallback_GetBindInfo(holder, &dw, &bindinfo);
    ok(hres == S_OK, "GetBindInfo failed: %08x\n", hres);
2007
    CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
2008 2009
    CHECK_CALLED(GetBindInfo);

2010 2011
    test_GetBindInfoEx(holder);

2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
    SET_EXPECT(OnStartBinding);
    hres = IBindStatusCallback_OnStartBinding(holder, 0, (void*)0xdeadbeef);
    ok(hres == S_OK, "OnStartBinding failed: %08x\n", hres);
    CHECK_CALLED(OnStartBinding);

    hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate, (void**)&http_negotiate);
    ok(hres == S_OK, "Could not get IHttpNegotiate interface: %08x\n", hres);

    SET_EXPECT(QueryInterface_IHttpNegotiate);
    hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
                                         (void**)&http_negotiate_serv);
    ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
2024
    CLEAR_CALLED(QueryInterface_IHttpNegotiate); /* IE <8 */
2025 2026 2027 2028

    ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");

    wstr = (void*)0xdeadbeef;
2029
    SET_EXPECT(QueryInterface_IHttpNegotiate);
2030 2031
    SET_EXPECT(BeginningTransaction);
    hres = IHttpNegotiate_BeginningTransaction(http_negotiate_serv, urls[test_protocol], emptyW, 0, &wstr);
2032
    CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045
    CHECK_CALLED(BeginningTransaction);
    ok(hres == S_OK, "BeginningTransaction failed: %08x\n", hres);
    ok(wstr == NULL, "wstr = %p\n", wstr);

    IHttpNegotiate_Release(http_negotiate_serv);

    hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate, &IID_IHttpNegotiate,
                                         (void**)&http_negotiate_serv);
    ok(hres == S_OK, "Could not get IHttpNegotiate service: %08x\n", hres);
    ok(http_negotiate == http_negotiate_serv, "http_negotiate != http_negotiate_serv\n");
    IHttpNegotiate_Release(http_negotiate_serv);

    hres = IBindStatusCallback_QueryInterface(holder, &IID_IHttpNegotiate2, (void**)&http_negotiate2);
2046
    if(SUCCEEDED(hres)) {
2047
        have_IHttpNegotiate2 = TRUE;
2048

2049 2050 2051 2052
        SET_EXPECT(QueryInterface_IHttpNegotiate2);
        hres = IServiceProvider_QueryService(serv_prov, &IID_IHttpNegotiate2, &IID_IHttpNegotiate2,
                                             (void**)&http_negotiate2_serv);
        ok(hres == S_OK, "Could not get IHttpNegotiate2 service: %08x\n", hres);
2053
        CLEAR_CALLED(QueryInterface_IHttpNegotiate2); /* IE <8 */
2054
        ok(http_negotiate2 == http_negotiate2_serv, "http_negotiate != http_negotiate_serv\n");
2055

2056
        SET_EXPECT(QueryInterface_IHttpNegotiate2);
2057 2058 2059
        SET_EXPECT(GetRootSecurityId);
        hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, (void*)0xdeadbeef, (void*)0xdeadbeef, 0);
        ok(hres == E_NOTIMPL, "GetRootSecurityId failed: %08x\n", hres);
2060
        CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate2); /* IE8 */
2061
        CHECK_CALLED(GetRootSecurityId);
2062

2063 2064 2065 2066
        IHttpNegotiate_Release(http_negotiate2_serv);
        IHttpNegotiate_Release(http_negotiate2);
    }else {
        skip("Could not get IHttpNegotiate2\n");
2067
        ret = FALSE;
2068
    }
2069 2070 2071 2072 2073 2074

    SET_EXPECT(OnProgress_FINDINGRESOURCE);
    hres = IBindStatusCallback_OnProgress(holder, 0, 0, BINDSTATUS_FINDINGRESOURCE, NULL);
    ok(hres == S_OK, "OnProgress failed: %08x\n", hres);
    CHECK_CALLED(OnProgress_FINDINGRESOURCE);

2075
    SET_EXPECT(QueryInterface_IHttpNegotiate);
2076 2077 2078 2079
    SET_EXPECT(OnResponse);
    wstr = (void*)0xdeadbeef;
    hres = IHttpNegotiate_OnResponse(http_negotiate, 200, emptyW, NULL, NULL);
    ok(hres == S_OK, "OnResponse failed: %08x\n", hres);
2080
    CHECK_CALLED_BROKEN(QueryInterface_IHttpNegotiate); /* IE8 */
2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
    CHECK_CALLED(OnResponse);

    IHttpNegotiate_Release(http_negotiate);

    hres = IBindStatusCallback_QueryInterface(holder, &IID_IAuthenticate, (void**)&authenticate);
    ok(hres == S_OK, "Could not get IAuthenticate interface: %08x\n", hres);

    SET_EXPECT(QueryInterface_IAuthenticate);
    SET_EXPECT(QueryService_IAuthenticate);
    hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
                                         (void**)&authenticate_serv);
    ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
2093 2094
    CLEAR_CALLED(QueryInterface_IAuthenticate); /* IE <8 */
    CLEAR_CALLED(QueryService_IAuthenticate); /* IE <8 */
2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
    ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");
    IAuthenticate_Release(authenticate_serv);

    hres = IServiceProvider_QueryService(serv_prov, &IID_IAuthenticate, &IID_IAuthenticate,
                                         (void**)&authenticate_serv);
    ok(hres == S_OK, "Could not get IAuthenticate service: %08x\n", hres);
    ok(authenticate == authenticate_serv, "authenticate != authenticate_serv\n");

    IAuthenticate_Release(authenticate);
    IAuthenticate_Release(authenticate_serv);

    SET_EXPECT(OnStopBinding);
    hres = IBindStatusCallback_OnStopBinding(holder, S_OK, NULL);
    ok(hres == S_OK, "OnStopBinding failed: %08x\n", hres);
    CHECK_CALLED(OnStopBinding);

    SET_EXPECT(QueryInterface_IInternetProtocol);
    SET_EXPECT(QueryService_IInternetProtocol);
    hres = IServiceProvider_QueryService(serv_prov, &IID_IInternetProtocol, &IID_IInternetProtocol,
                                         (void**)&protocol);
    ok(hres == E_NOINTERFACE, "QueryService(IInternetProtocol) failed: %08x\n", hres);
    CHECK_CALLED(QueryInterface_IInternetProtocol);
    CHECK_CALLED(QueryService_IInternetProtocol);

    IServiceProvider_Release(serv_prov);
2120
    return ret;
2121 2122
}

2123
static BOOL test_RegisterBindStatusCallback(void)
2124 2125 2126
{
    IBindStatusCallback *prevbsc, *clb;
    IBindCtx *bindctx;
2127
    BOOL ret = TRUE;
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141
    IUnknown *unk;
    HRESULT hres;

    hres = CreateBindCtx(0, &bindctx);
    ok(hres == S_OK, "BindCtx failed: %08x\n", hres);

    SET_EXPECT(QueryInterface_IServiceProvider);

    hres = IBindCtx_RegisterObjectParam(bindctx, BSCBHolder, (IUnknown*)&bsc);
    ok(hres == S_OK, "RegisterObjectParam failed: %08x\n", hres);

    SET_EXPECT(QueryInterface_IBindStatusCallback);
    SET_EXPECT(QueryInterface_IBindStatusCallbackHolder);
    prevbsc = (void*)0xdeadbeef;
2142
    hres = RegisterBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc, &prevbsc, 0);
2143
    ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2144
    ok(prevbsc == (IBindStatusCallback*)&bsc, "prevbsc=%p\n", prevbsc);
2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155
    CHECK_CALLED(QueryInterface_IBindStatusCallback);
    CHECK_CALLED(QueryInterface_IBindStatusCallbackHolder);

    CHECK_CALLED(QueryInterface_IServiceProvider);

    hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
    ok(hres == S_OK, "GetObjectParam failed: %08x\n", hres);

    hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&clb);
    IUnknown_Release(unk);
    ok(hres == S_OK, "QueryInterface(IID_IBindStatusCallback) failed: %08x\n", hres);
2156
    ok(clb != (IBindStatusCallback*)&bsc, "bsc == clb\n");
2157

2158 2159
    if(!test_bscholder(clb))
        ret = FALSE;
2160 2161 2162

    IBindStatusCallback_Release(clb);

2163
    hres = RevokeBindStatusCallback(bindctx, (IBindStatusCallback*)&bsc);
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183
    ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);

    unk = (void*)0xdeadbeef;
    hres = IBindCtx_GetObjectParam(bindctx, BSCBHolder, &unk);
    ok(hres == E_FAIL, "GetObjectParam failed: %08x\n", hres);
    ok(unk == NULL, "unk != NULL\n");

    if(unk)
        IUnknown_Release(unk);

    hres = RevokeBindStatusCallback(bindctx, (void*)0xdeadbeef);
    ok(hres == S_OK, "RevokeBindStatusCallback failed: %08x\n", hres);

    hres = RevokeBindStatusCallback(NULL, (void*)0xdeadbeef);
    ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);

    hres = RevokeBindStatusCallback(bindctx, NULL);
    ok(hres == E_INVALIDARG, "RevokeBindStatusCallback failed: %08x\n", hres);

    IBindCtx_Release(bindctx);
2184
    return ret;
2185 2186
}

2187 2188 2189 2190 2191
#define BINDTEST_EMULATE     1
#define BINDTEST_TOOBJECT    2
#define BINDTEST_FILEDWLAPI  4

static void init_bind_test(int protocol, DWORD flags, DWORD t)
Jacek Caban's avatar
Jacek Caban committed
2192 2193
{
    test_protocol = protocol;
2194
    emulate_protocol = (flags & BINDTEST_EMULATE) != 0;
Jacek Caban's avatar
Jacek Caban committed
2195 2196 2197 2198 2199 2200
    download_state = BEFORE_DOWNLOAD;
    stopped_binding = FALSE;
    stopped_obj_binding = FALSE;
    data_available = FALSE;
    mime_type[0] = 0;
    binding_hres = S_OK;
2201
    bind_to_object = (flags & BINDTEST_TOOBJECT) != 0;
Jacek Caban's avatar
Jacek Caban committed
2202
    tymed = t;
2203
    filedwl_api = (flags & BINDTEST_FILEDWLAPI) != 0;
Jacek Caban's avatar
Jacek Caban committed
2204 2205
}

Jacek Caban's avatar
Jacek Caban committed
2206
static void test_BindToStorage(int protocol, BOOL emul, DWORD t)
2207 2208 2209 2210 2211 2212
{
    IMoniker *mon;
    HRESULT hres;
    LPOLESTR display_name;
    IBindCtx *bctx;
    MSG msg;
Jacek Caban's avatar
Jacek Caban committed
2213
    IBindStatusCallback *previousclb;
2214
    IUnknown *unk = (IUnknown*)0x00ff00ff;
2215
    IBinding *bind;
2216

2217
    init_bind_test(protocol, emul ? BINDTEST_EMULATE : 0, t);
Jacek Caban's avatar
Jacek Caban committed
2218

2219
    SET_EXPECT(QueryInterface_IServiceProvider);
2220
    hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
2221 2222
    ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
    CHECK_CALLED(QueryInterface_IServiceProvider);
Jacek Caban's avatar
Jacek Caban committed
2223
    if(FAILED(hres))
2224
        return;
2225 2226

    SET_EXPECT(QueryInterface_IServiceProvider);
2227
    hres = RegisterBindStatusCallback(bctx, (IBindStatusCallback*)&bsc, &previousclb, 0);
2228
    ok(hres == S_OK, "RegisterBindStatusCallback failed: %08x\n", hres);
2229
    ok(previousclb == (IBindStatusCallback*)&bsc, "previousclb(%p) != sclb(%p)\n", previousclb, &bsc);
2230
    CHECK_CALLED(QueryInterface_IServiceProvider);
2231 2232 2233
    if(previousclb)
        IBindStatusCallback_Release(previousclb);

2234
    hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2235
    ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
2236 2237 2238 2239 2240
    if(FAILED(hres)) {
        IBindCtx_Release(bctx);
        return;
    }

2241 2242 2243 2244 2245
    hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
    ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
    if(SUCCEEDED(hres))
        IBinding_Release(bind);

2246
    hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
2247
    ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
Jacek Caban's avatar
Jacek Caban committed
2248
    ok(!lstrcmpW(display_name, urls[test_protocol]),
2249
       "GetDisplayName got wrong name %s\n", wine_dbgstr_w(display_name));
2250
    CoTaskMemFree(display_name);
2251

Jacek Caban's avatar
Jacek Caban committed
2252 2253 2254
    if(tymed == TYMED_FILE && (test_protocol == ABOUT_TEST || test_protocol == ITS_TEST))
        binding_hres = INET_E_DATA_NOT_AVAILABLE;

2255
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
Jacek Caban's avatar
Jacek Caban committed
2256
    SET_EXPECT(GetBindInfo);
2257
    SET_EXPECT(QueryInterface_IInternetProtocol);
2258 2259
    if(!emulate_protocol)
        SET_EXPECT(QueryService_IInternetProtocol);
Jacek Caban's avatar
Jacek Caban committed
2260
    SET_EXPECT(OnStartBinding);
2261
    if(emulate_protocol) {
2262 2263
        if(is_urlmon_protocol(test_protocol))
            SET_EXPECT(SetPriority);
2264
        SET_EXPECT(Start);
2265
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2266
            SET_EXPECT(Terminate);
Jacek Caban's avatar
Jacek Caban committed
2267 2268
        if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
            SET_EXPECT(UnlockRequest);
2269
    }else {
2270
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
Jacek Caban's avatar
Jacek Caban committed
2271 2272
            SET_EXPECT(QueryInterface_IInternetBindInfo);
            SET_EXPECT(QueryService_IInternetBindInfo);
2273
            SET_EXPECT(QueryInterface_IHttpNegotiate);
2274 2275
            SET_EXPECT(QueryInterface_IWindowForBindingUI);
            SET_EXPECT(QueryService_IWindowForBindingUI);
2276
            SET_EXPECT(BeginningTransaction);
2277
            SET_EXPECT(QueryInterface_IHttpNegotiate2);
2278
            SET_EXPECT(GetRootSecurityId);
2279 2280 2281
            SET_EXPECT(OnProgress_FINDINGRESOURCE);
            SET_EXPECT(OnProgress_CONNECTING);
        }
2282 2283
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST
           || test_protocol == FILE_TEST)
2284
            SET_EXPECT(OnProgress_SENDINGREQUEST);
2285 2286
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
            SET_EXPECT(QueryInterface_IHttpNegotiate);
2287
            SET_EXPECT(OnResponse);
2288
        }
2289 2290
        SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
        SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
2291 2292
        if(test_protocol == FILE_TEST)
            SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2293
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2294 2295
            SET_EXPECT(OnProgress_DOWNLOADINGDATA);
        SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
2296 2297
        if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
            SET_EXPECT(OnDataAvailable);
2298 2299
        SET_EXPECT(OnStopBinding);
    }
Jacek Caban's avatar
Jacek Caban committed
2300

Jacek Caban's avatar
Jacek Caban committed
2301
    hres = IMoniker_BindToStorage(mon, bctx, NULL, tymed == TYMED_ISTREAM ? &IID_IStream : &IID_IUnknown, (void**)&unk);
2302 2303
    if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
        && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2304
    {
Jacek Caban's avatar
Jacek Caban committed
2305
        skip("Network unreachable, skipping tests\n");
2306 2307
        return;
    }
2308

Jacek Caban's avatar
Jacek Caban committed
2309 2310
    if(((bindf & BINDF_ASYNCHRONOUS) && !data_available)
       || (tymed == TYMED_FILE && test_protocol == FILE_TEST)) {
2311 2312
        ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToStorage failed: %08x\n", hres);
        ok(unk == NULL, "istr should be NULL\n");
Jacek Caban's avatar
Jacek Caban committed
2313 2314 2315 2316
    }else if(tymed == TYMED_FILE && test_protocol == ABOUT_TEST) {
        ok(hres == INET_E_DATA_NOT_AVAILABLE,
           "IMoniker_BindToStorage failed: %08x, expected INET_E_DATA_NOT_AVAILABLE\n", hres);
        ok(unk == NULL, "istr should be NULL\n");
2317
    }else {
2318
        ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
2319
        ok(unk != NULL, "unk == NULL\n");
2320 2321 2322 2323
    }
    if(unk)
        IUnknown_Release(unk);

Jacek Caban's avatar
Jacek Caban committed
2324 2325 2326
    if(FAILED(hres))
        return;

2327 2328
    while((bindf & BINDF_ASYNCHRONOUS) &&
          !stopped_binding && GetMessage(&msg,NULL,0,0)) {
2329 2330 2331 2332
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

2333
    CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
Jacek Caban's avatar
Jacek Caban committed
2334
    CHECK_CALLED(GetBindInfo);
2335
    CHECK_CALLED(QueryInterface_IInternetProtocol);
2336 2337
    if(!emulate_protocol)
        CHECK_CALLED(QueryService_IInternetProtocol);
Jacek Caban's avatar
Jacek Caban committed
2338
    CHECK_CALLED(OnStartBinding);
2339
    if(emulate_protocol) {
2340 2341
        if(is_urlmon_protocol(test_protocol))
            CHECK_CALLED(SetPriority);
2342
        CHECK_CALLED(Start);
2343
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
Jacek Caban's avatar
Jacek Caban committed
2344 2345
            if(tymed == TYMED_FILE)
                CLEAR_CALLED(Read);
2346
            CHECK_CALLED(Terminate);
Jacek Caban's avatar
Jacek Caban committed
2347 2348 2349
        }
        if(tymed != TYMED_FILE || (test_protocol != ABOUT_TEST && test_protocol != ITS_TEST))
            CHECK_CALLED(UnlockRequest);
2350
    }else {
2351
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
Jacek Caban's avatar
Jacek Caban committed
2352 2353
            CLEAR_CALLED(QueryInterface_IInternetBindInfo);
            CLEAR_CALLED(QueryService_IInternetBindInfo);
2354
            CHECK_CALLED(QueryInterface_IHttpNegotiate);
2355 2356
            CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
            CLEAR_CALLED(QueryService_IWindowForBindingUI);
2357
            CHECK_CALLED(BeginningTransaction);
2358 2359 2360 2361 2362
            if (have_IHttpNegotiate2)
            {
                CHECK_CALLED(QueryInterface_IHttpNegotiate2);
                CHECK_CALLED(GetRootSecurityId);
            }
2363
            if(http_is_first || test_protocol == HTTPS_TEST) {
2364 2365 2366 2367
                CHECK_CALLED(OnProgress_FINDINGRESOURCE);
                CHECK_CALLED(OnProgress_CONNECTING);
            }else todo_wine {
                CHECK_NOT_CALLED(OnProgress_FINDINGRESOURCE);
2368 2369
                /* IE7 does call this */
                CLEAR_CALLED(OnProgress_CONNECTING);
2370
            }
2371
        }
2372
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2373
            CHECK_CALLED(OnProgress_SENDINGREQUEST);
2374 2375
        else if(test_protocol == FTP_TEST)
            todo_wine CHECK_CALLED(OnProgress_SENDINGREQUEST);
2376 2377
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
            CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2378
            CHECK_CALLED(OnResponse);
2379
        }
2380
        CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
2381
        CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
2382 2383
        if(test_protocol == FILE_TEST)
            CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2384
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FTP_TEST)
2385
            CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
2386
        CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
2387 2388
        if(tymed != TYMED_FILE || test_protocol != ABOUT_TEST)
            CHECK_CALLED(OnDataAvailable);
2389 2390
        CHECK_CALLED(OnStopBinding);
    }
Jacek Caban's avatar
Jacek Caban committed
2391

2392 2393
    ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
    ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2394

2395
    if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2396
        http_is_first = FALSE;
2397 2398
}

2399 2400 2401 2402 2403 2404
static void test_BindToObject(int protocol, BOOL emul)
{
    IMoniker *mon;
    HRESULT hres;
    LPOLESTR display_name;
    IBindCtx *bctx;
Jacek Caban's avatar
Jacek Caban committed
2405
    DWORD regid;
2406 2407 2408 2409
    MSG msg;
    IUnknown *unk = (IUnknown*)0x00ff00ff;
    IBinding *bind;

2410
    init_bind_test(protocol, BINDTEST_TOOBJECT | (emul ? BINDTEST_EMULATE : 0), TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2411 2412 2413 2414

    if(emul)
        CoRegisterClassObject(&CLSID_HTMLDocument, (IUnknown *)&mime_cf,
                              CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
2415 2416

    SET_EXPECT(QueryInterface_IServiceProvider);
2417
    hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&objbsc, NULL, &bctx);
2418
    ok(SUCCEEDED(hres), "CreateAsyncBindCtx failed: %08x\n\n", hres);
Jacek Caban's avatar
Jacek Caban committed
2419
    CHECK_CALLED(QueryInterface_IServiceProvider);
2420 2421 2422
    if(FAILED(hres))
        return;

2423
    hres = CreateURLMoniker(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol], &mon);
2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438
    ok(SUCCEEDED(hres), "failed to create moniker: %08x\n", hres);
    if(FAILED(hres)) {
        IBindCtx_Release(bctx);
        return;
    }

    hres = IMoniker_QueryInterface(mon, &IID_IBinding, (void**)&bind);
    ok(hres == E_NOINTERFACE, "IMoniker should not have IBinding interface\n");
    if(SUCCEEDED(hres))
        IBinding_Release(bind);

    hres = IMoniker_GetDisplayName(mon, bctx, NULL, &display_name);
    ok(hres == S_OK, "GetDisplayName failed %08x\n", hres);
    ok(!lstrcmpW(display_name, urls[test_protocol]), "GetDisplayName got wrong name\n");

2439
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
Jacek Caban's avatar
Jacek Caban committed
2440
    SET_EXPECT(Obj_GetBindInfo);
2441 2442 2443
    SET_EXPECT(QueryInterface_IInternetProtocol);
    if(!emulate_protocol)
        SET_EXPECT(QueryService_IInternetProtocol);
Jacek Caban's avatar
Jacek Caban committed
2444
    SET_EXPECT(Obj_OnStartBinding);
2445
    if(emulate_protocol) {
2446 2447
        if(is_urlmon_protocol(test_protocol))
            SET_EXPECT(SetPriority);
2448
        SET_EXPECT(Start);
2449
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
2450
            SET_EXPECT(Terminate);
2451 2452
        if(test_protocol == FILE_TEST)
            SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
2453 2454
        SET_EXPECT(UnlockRequest);
    }else {
2455
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2456 2457 2458 2459
            SET_EXPECT(QueryInterface_IHttpNegotiate);
            SET_EXPECT(BeginningTransaction);
            SET_EXPECT(QueryInterface_IHttpNegotiate2);
            SET_EXPECT(GetRootSecurityId);
Jacek Caban's avatar
Jacek Caban committed
2460 2461
            SET_EXPECT(Obj_OnProgress_FINDINGRESOURCE);
            SET_EXPECT(Obj_OnProgress_CONNECTING);
2462 2463
            SET_EXPECT(QueryInterface_IWindowForBindingUI);
            SET_EXPECT(QueryService_IWindowForBindingUI);
2464
        }
2465
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
Jacek Caban's avatar
Jacek Caban committed
2466
            SET_EXPECT(Obj_OnProgress_SENDINGREQUEST);
2467 2468
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
            SET_EXPECT(QueryInterface_IHttpNegotiate);
2469
            SET_EXPECT(OnResponse);
2470
        }
Jacek Caban's avatar
Jacek Caban committed
2471 2472
        SET_EXPECT(Obj_OnProgress_MIMETYPEAVAILABLE);
        SET_EXPECT(Obj_OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
2473 2474
        if(test_protocol == FILE_TEST)
            SET_EXPECT(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2475
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2476
            SET_EXPECT(OnProgress_DOWNLOADINGDATA);
Jacek Caban's avatar
Jacek Caban committed
2477 2478 2479 2480
        SET_EXPECT(Obj_OnProgress_ENDDOWNLOADDATA);
        SET_EXPECT(Obj_OnProgress_CLASSIDAVAILABLE);
        SET_EXPECT(Obj_OnProgress_BEGINSYNCOPERATION);
        SET_EXPECT(Obj_OnProgress_ENDSYNCOPERATION);
2481
        SET_EXPECT(OnObjectAvailable);
Jacek Caban's avatar
Jacek Caban committed
2482
        SET_EXPECT(Obj_OnStopBinding);
2483 2484 2485
    }

    hres = IMoniker_BindToObject(mon, bctx, NULL, &IID_IUnknown, (void**)&unk);
Jacek Caban's avatar
Jacek Caban committed
2486

2487 2488
    if ((test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
        && hres == HRESULT_FROM_WIN32(ERROR_INTERNET_NAME_NOT_RESOLVED))
2489
    {
2490
        skip( "Network unreachable, skipping tests\n" );
2491 2492
        return;
    }
Jacek Caban's avatar
Jacek Caban committed
2493

2494
    /* no point testing the calls if binding didn't even work */
Jacek Caban's avatar
Jacek Caban committed
2495
    if (FAILED(hres)) return;
2496

Jacek Caban's avatar
Jacek Caban committed
2497 2498
    if(bindf & BINDF_ASYNCHRONOUS) {
        ok(hres == MK_S_ASYNCHRONOUS, "IMoniker_BindToObject failed: %08x\n", hres);
2499 2500 2501 2502
        ok(unk == NULL, "istr should be NULL\n");
    }else {
        ok(hres == S_OK, "IMoniker_BindToStorage failed: %08x\n", hres);
        ok(unk != NULL, "unk == NULL\n");
Jacek Caban's avatar
Jacek Caban committed
2503 2504
        if(emul)
            ok(unk == (IUnknown*)&PersistMoniker, "unk != PersistMoniker\n");
2505 2506 2507 2508 2509
    }
    if(unk)
        IUnknown_Release(unk);

    while((bindf & BINDF_ASYNCHRONOUS) &&
Jacek Caban's avatar
Jacek Caban committed
2510
          !((!emul || stopped_binding) && stopped_obj_binding) && GetMessage(&msg,NULL,0,0)) {
2511 2512 2513 2514
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

2515
    CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx);
Jacek Caban's avatar
Jacek Caban committed
2516
    CHECK_CALLED(Obj_GetBindInfo);
2517 2518 2519
    CHECK_CALLED(QueryInterface_IInternetProtocol);
    if(!emulate_protocol)
        CHECK_CALLED(QueryService_IInternetProtocol);
Jacek Caban's avatar
Jacek Caban committed
2520
    CHECK_CALLED(Obj_OnStartBinding);
2521
    if(emulate_protocol) {
2522 2523
        if(is_urlmon_protocol(test_protocol))
            CHECK_CALLED(SetPriority);
2524
        CHECK_CALLED(Start);
2525
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
Jacek Caban's avatar
Jacek Caban committed
2526
            CHECK_CALLED(Terminate);
2527 2528
        if(test_protocol == FILE_TEST)
            CLEAR_CALLED(OnProgress_MIMETYPEAVAILABLE); /* not called in IE7 */
2529 2530
        CHECK_CALLED(UnlockRequest);
    }else {
2531
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2532 2533
            CHECK_CALLED(QueryInterface_IHttpNegotiate);
            CHECK_CALLED(BeginningTransaction);
2534 2535 2536 2537 2538
            if (have_IHttpNegotiate2)
            {
                CHECK_CALLED(QueryInterface_IHttpNegotiate2);
                CHECK_CALLED(GetRootSecurityId);
            }
2539
            if(http_is_first) {
Jacek Caban's avatar
Jacek Caban committed
2540 2541
                CHECK_CALLED(Obj_OnProgress_FINDINGRESOURCE);
                CHECK_CALLED(Obj_OnProgress_CONNECTING);
2542
            }else todo_wine {
Jacek Caban's avatar
Jacek Caban committed
2543
                CHECK_NOT_CALLED(Obj_OnProgress_FINDINGRESOURCE);
2544 2545
                /* IE7 does call this */
                CLEAR_CALLED(Obj_OnProgress_CONNECTING);
2546
            }
2547 2548
            CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
            CLEAR_CALLED(QueryService_IWindowForBindingUI);
2549
        }
2550
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST) {
Jacek Caban's avatar
Jacek Caban committed
2551 2552 2553 2554 2555
            if(urls[test_protocol] == SHORT_RESPONSE_URL)
                CLEAR_CALLED(Obj_OnProgress_SENDINGREQUEST);
            else
                CHECK_CALLED(Obj_OnProgress_SENDINGREQUEST);
        }
2556 2557
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
            CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2558
            CHECK_CALLED(OnResponse);
2559
        }
Jacek Caban's avatar
Jacek Caban committed
2560 2561
        CHECK_CALLED(Obj_OnProgress_MIMETYPEAVAILABLE);
        CHECK_CALLED(Obj_OnProgress_BEGINDOWNLOADDATA);
Jacek Caban's avatar
Jacek Caban committed
2562 2563
        if(test_protocol == FILE_TEST)
            CHECK_CALLED(Obj_OnProgress_CACHEFILENAMEAVAILABLE);
2564
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2565
            CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
Jacek Caban's avatar
Jacek Caban committed
2566 2567 2568 2569
        CLEAR_CALLED(Obj_OnProgress_ENDDOWNLOADDATA);
        CHECK_CALLED(Obj_OnProgress_CLASSIDAVAILABLE);
        CHECK_CALLED(Obj_OnProgress_BEGINSYNCOPERATION);
        CHECK_CALLED(Obj_OnProgress_ENDSYNCOPERATION);
2570
        CHECK_CALLED(OnObjectAvailable);
Jacek Caban's avatar
Jacek Caban committed
2571
        CHECK_CALLED(Obj_OnStopBinding);
2572 2573
    }

2574
    if(test_protocol != HTTP_TEST || emul || urls[test_protocol] == SHORT_RESPONSE_URL || !(bindf & BINDF_ASYNCHRONOUS)) {
2575 2576
        ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
        ok(IBindCtx_Release(bctx) == 0, "bctx should be destroyed here\n");
2577 2578
    }else {
        todo_wine ok(IMoniker_Release(mon) == 0, "mon should be destroyed here\n");
2579
        IBindCtx_Release(bctx);
2580
    }
2581

Jacek Caban's avatar
Jacek Caban committed
2582 2583 2584
    if(emul)
        CoRevokeClassObject(regid);

2585
    if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2586 2587 2588
        http_is_first = FALSE;
}

2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603
static void test_URLDownloadToFile(DWORD prot, BOOL emul)
{
    BOOL res;
    HRESULT hres;

    init_bind_test(prot, BINDTEST_FILEDWLAPI | (emul ? BINDTEST_EMULATE : 0), TYMED_FILE);

    SET_EXPECT(GetBindInfo);
    SET_EXPECT(QueryInterface_IInternetProtocol);
    if(!emulate_protocol) {
        SET_EXPECT(QueryInterface_IServiceProvider);
        SET_EXPECT(QueryService_IInternetProtocol);
    }
    SET_EXPECT(OnStartBinding);
    if(emulate_protocol) {
2604 2605
        if(is_urlmon_protocol(test_protocol))
            SET_EXPECT(SetPriority);
2606 2607 2608
        SET_EXPECT(Start);
        SET_EXPECT(UnlockRequest);
    }else {
2609
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2610 2611 2612 2613
            SET_EXPECT(QueryInterface_IHttpNegotiate);
            SET_EXPECT(BeginningTransaction);
            SET_EXPECT(QueryInterface_IHttpNegotiate2);
            SET_EXPECT(GetRootSecurityId);
2614
            SET_EXPECT(QueryInterface_IWindowForBindingUI);
2615
        }
2616
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST || test_protocol == FILE_TEST)
2617
            SET_EXPECT(OnProgress_SENDINGREQUEST);
2618 2619
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
            SET_EXPECT(QueryInterface_IHttpNegotiate);
2620
            SET_EXPECT(OnResponse);
2621
        }
2622 2623 2624 2625
        SET_EXPECT(OnProgress_MIMETYPEAVAILABLE);
        SET_EXPECT(OnProgress_BEGINDOWNLOADDATA);
        if(test_protocol == FILE_TEST)
            SET_EXPECT(OnProgress_CACHEFILENAMEAVAILABLE);
2626
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2627 2628 2629 2630 2631
            SET_EXPECT(OnProgress_DOWNLOADINGDATA);
        SET_EXPECT(OnProgress_ENDDOWNLOADDATA);
        SET_EXPECT(OnStopBinding);
    }

2632 2633
    hres = URLDownloadToFileW(NULL, test_protocol == FILE_TEST ? file_url : urls[test_protocol],
            dwl_htmlW, 0, (IBindStatusCallback*)&bsc);
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643
    ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);

    CHECK_CALLED(GetBindInfo);
    CHECK_CALLED(QueryInterface_IInternetProtocol);
    if(!emulate_protocol) {
        CHECK_CALLED(QueryInterface_IServiceProvider);
        CHECK_CALLED(QueryService_IInternetProtocol);
    }
    CHECK_CALLED(OnStartBinding);
    if(emulate_protocol) {
2644 2645
        if(is_urlmon_protocol(test_protocol))
            CHECK_CALLED(SetPriority);
2646 2647 2648
        CHECK_CALLED(Start);
        CHECK_CALLED(UnlockRequest);
    }else {
2649
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
2650 2651
            CHECK_CALLED(QueryInterface_IHttpNegotiate);
            CHECK_CALLED(BeginningTransaction);
2652 2653 2654 2655 2656
            if (have_IHttpNegotiate2)
            {
                CHECK_CALLED(QueryInterface_IHttpNegotiate2);
                CHECK_CALLED(GetRootSecurityId);
            }
2657
            CLEAR_CALLED(QueryInterface_IWindowForBindingUI);
2658
        }
2659
        if(test_protocol == FILE_TEST)
2660
            CHECK_CALLED(OnProgress_SENDINGREQUEST);
2661
        else if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2662
            CLEAR_CALLED(OnProgress_SENDINGREQUEST); /* not called by IE7 */
2663 2664
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST) {
            CLEAR_CALLED(QueryInterface_IHttpNegotiate);
2665
            CHECK_CALLED(OnResponse);
2666
        }
2667 2668 2669 2670
        CHECK_CALLED(OnProgress_MIMETYPEAVAILABLE);
        CHECK_CALLED(OnProgress_BEGINDOWNLOADDATA);
        if(test_protocol == FILE_TEST)
            CHECK_CALLED(OnProgress_CACHEFILENAMEAVAILABLE);
2671
        if(test_protocol == HTTP_TEST || test_protocol == HTTPS_TEST)
2672 2673 2674 2675 2676
            CLEAR_CALLED(OnProgress_DOWNLOADINGDATA);
        CHECK_CALLED(OnProgress_ENDDOWNLOADDATA);
        CHECK_CALLED(OnStopBinding);
    }

2677
    res = DeleteFileA(dwl_htmlA);
2678 2679 2680 2681 2682 2683 2684 2685
    ok(res, "DeleteFile failed: %u\n", GetLastError());

    if(prot != FILE_TEST || emul)
        return;

    hres = URLDownloadToFileW(NULL, urls[test_protocol], dwl_htmlW, 0, NULL);
    ok(hres == S_OK, "URLDownloadToFile failed: %08x\n", hres);

2686
    res = DeleteFileA(dwl_htmlA);
2687 2688 2689
    ok(res, "DeleteFile failed: %u\n", GetLastError());
}

2690
static void set_file_url(char *path)
2691
{
2692 2693
    CHAR file_urlA[INTERNET_MAX_URL_LENGTH];
    CHAR INDEX_HTMLA[MAX_PATH];
2694

2695 2696 2697
    lstrcpyA(file_urlA, "file:///");
    lstrcatA(file_urlA, path);
    MultiByteToWideChar(CP_ACP, 0, file_urlA, -1, file_url, INTERNET_MAX_URL_LENGTH);
2698

2699 2700 2701
    lstrcpyA(INDEX_HTMLA, "file://");
    lstrcatA(INDEX_HTMLA, path);
    MultiByteToWideChar(CP_ACP, 0, INDEX_HTMLA, -1, INDEX_HTML, MAX_PATH);
2702 2703 2704 2705 2706 2707
}

static void create_file(void)
{
    HANDLE file;
    DWORD size;
2708
    CHAR path[MAX_PATH];
2709 2710 2711

    static const char html_doc[] = "<HTML></HTML>";

2712
    file = CreateFileA(wszIndexHtmlA, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
2713
            FILE_ATTRIBUTE_NORMAL, NULL);
Jacek Caban's avatar
Jacek Caban committed
2714
    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
2715 2716 2717 2718 2719 2720
    if(file == INVALID_HANDLE_VALUE)
        return;

    WriteFile(file, html_doc, sizeof(html_doc)-1, &size, NULL);
    CloseHandle(file);

2721 2722 2723 2724
    GetCurrentDirectoryA(MAX_PATH, path);
    lstrcatA(path, "\\");
    lstrcatA(path, wszIndexHtmlA);
    set_file_url(path);
2725 2726
}

Jacek Caban's avatar
Jacek Caban committed
2727 2728 2729 2730 2731 2732 2733
static void test_ReportResult(HRESULT exhres)
{
    IMoniker *mon = NULL;
    IBindCtx *bctx = NULL;
    IUnknown *unk = (void*)0xdeadbeef;
    HRESULT hres;

2734
    init_bind_test(ABOUT_TEST, BINDTEST_EMULATE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2735 2736 2737 2738 2739 2740
    binding_hres = exhres;

    hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
    ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);

    SET_EXPECT(QueryInterface_IServiceProvider);
2741
    hres = CreateAsyncBindCtx(0, (IBindStatusCallback*)&bsc, NULL, &bctx);
Jacek Caban's avatar
Jacek Caban committed
2742 2743 2744
    ok(hres == S_OK, "CreateAsyncBindCtx failed: %08x\n\n", hres);
    CHECK_CALLED(QueryInterface_IServiceProvider);

2745
    SET_EXPECT(QueryInterface_IBindStatusCallbackEx);
Jacek Caban's avatar
Jacek Caban committed
2746 2747 2748
    SET_EXPECT(GetBindInfo);
    SET_EXPECT(QueryInterface_IInternetProtocol);
    SET_EXPECT(OnStartBinding);
2749 2750
    if(is_urlmon_protocol(test_protocol))
        SET_EXPECT(SetPriority);
Jacek Caban's avatar
Jacek Caban committed
2751 2752 2753 2754
    SET_EXPECT(Start);

    hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
    if(SUCCEEDED(exhres))
Jacek Caban's avatar
Jacek Caban committed
2755
        ok(hres == S_OK || hres == MK_S_ASYNCHRONOUS, "BindToStorage failed: %08x\n", hres);
Jacek Caban's avatar
Jacek Caban committed
2756
    else
Jacek Caban's avatar
Jacek Caban committed
2757 2758
        ok(hres == exhres || hres == MK_S_ASYNCHRONOUS,
           "BindToStorage failed: %08x, expected %08x or MK_S_ASYNCHRONOUS\n", hres, exhres);
Jacek Caban's avatar
Jacek Caban committed
2759

2760
    CLEAR_CALLED(QueryInterface_IBindStatusCallbackEx); /* IE 8 */
Jacek Caban's avatar
Jacek Caban committed
2761 2762 2763
    CHECK_CALLED(GetBindInfo);
    CHECK_CALLED(QueryInterface_IInternetProtocol);
    CHECK_CALLED(OnStartBinding);
2764 2765
    if(is_urlmon_protocol(test_protocol))
        CHECK_CALLED(SetPriority);
Jacek Caban's avatar
Jacek Caban committed
2766 2767 2768 2769 2770 2771 2772 2773
    CHECK_CALLED(Start);

    ok(unk == NULL, "unk=%p\n", unk);

    IBindCtx_Release(bctx);
    IMoniker_Release(mon);
}

2774 2775 2776 2777 2778 2779 2780 2781
static void test_BindToStorage_fail(void)
{
    IMoniker *mon = NULL;
    IBindCtx *bctx = NULL;
    IUnknown *unk;
    HRESULT hres;

    hres = CreateURLMoniker(NULL, ABOUT_BLANK, &mon);
2782
    ok(hres == S_OK, "CreateURLMoniker failed: %08x\n", hres);
2783 2784 2785 2786
    if(FAILED(hres))
        return;

    hres = CreateAsyncBindCtxEx(NULL, 0, NULL, NULL, &bctx, 0);
2787
    ok(hres == S_OK, "CreateAsyncBindCtxEx failed: %08x\n", hres);
2788 2789

    hres = IMoniker_BindToStorage(mon, bctx, NULL, &IID_IStream, (void**)&unk);
Jacek Caban's avatar
Jacek Caban committed
2790
    ok(hres == MK_E_SYNTAX || hres == INET_E_DATA_NOT_AVAILABLE,
Jacek Caban's avatar
Jacek Caban committed
2791
       "hres=%08x, expected MK_E_SYNTAX or INET_E_DATA_NOT_AVAILABLE\n", hres);
2792 2793 2794 2795

    IBindCtx_Release(bctx);

    IMoniker_Release(mon);
Jacek Caban's avatar
Jacek Caban committed
2796 2797 2798

    test_ReportResult(E_NOTIMPL);
    test_ReportResult(S_FALSE);
2799 2800
}

2801 2802 2803
static void test_StdURLMoniker(void)
{
    IMoniker *mon, *async_mon;
2804
    LPOLESTR display_name;
2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817
    HRESULT hres;

    hres = CoCreateInstance(&IID_IInternet, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
            &IID_IMoniker, (void**)&mon);
    ok(hres == S_OK, "Could not create IInternet instance: %08x\n", hres);
    if(FAILED(hres))
        return;

    hres = IMoniker_QueryInterface(mon, &IID_IAsyncMoniker, (void**)&async_mon);
    ok(hres == S_OK, "Could not get IAsyncMoniker iface: %08x\n", hres);
    ok(mon == async_mon, "mon != async_mon\n");
    IMoniker_Release(async_mon);

2818 2819 2820
    hres = IMoniker_GetDisplayName(mon, NULL, NULL, &display_name);
    ok(hres == E_OUTOFMEMORY, "GetDisplayName failed: %08x, expected E_OUTOFMEMORY\n", hres);

2821 2822 2823
    IMoniker_Release(mon);
}

2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
static void gecko_installer_workaround(BOOL disable)
{
    HKEY hkey;
    DWORD res;

    static BOOL has_url = FALSE;
    static char url[2048];

    if(!disable && !has_url)
        return;

    res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
    if(res != ERROR_SUCCESS)
        return;

    if(disable) {
        DWORD type, size = sizeof(url);

        res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
        if(res == ERROR_SUCCESS && type == REG_SZ)
            has_url = TRUE;

        RegDeleteValue(hkey, "GeckoUrl");
    }else {
        RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
    }

    RegCloseKey(hkey);
}

2854 2855
START_TEST(url)
{
2856 2857
    gecko_installer_workaround(TRUE);

2858 2859 2860
    complete_event = CreateEvent(NULL, FALSE, FALSE, NULL);
    complete_event2 = CreateEvent(NULL, FALSE, FALSE, NULL);
    thread_id = GetCurrentThreadId();
2861
    create_file();
2862

2863
    test_create();
2864 2865

    trace("test CreateAsyncBindCtx...\n");
2866
    test_CreateAsyncBindCtx();
2867 2868

    trace("test CreateAsyncBindCtxEx...\n");
2869
    test_CreateAsyncBindCtxEx();
2870

2871
    trace("test RegisterBindStatusCallback...\n");
2872
    if(test_RegisterBindStatusCallback()) {
2873
        trace("test BindToStorage failures...\n");
2874 2875 2876 2877
        test_BindToStorage_fail();

        trace("synchronous http test (COM not initialised)...\n");
        test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
2878

2879
        CoInitialize(NULL);
2880

2881
        trace("test StdURLMoniker...\n");
2882 2883
        test_StdURLMoniker();

2884 2885
        trace("synchronous http test...\n");
        test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2886

2887 2888
        trace("synchronous http test (to object)...\n");
        test_BindToObject(HTTP_TEST, FALSE);
2889

2890 2891
        trace("synchronous file test...\n");
        test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2892

2893 2894
        trace("synchronous file test (to object)...\n");
        test_BindToObject(FILE_TEST, FALSE);
2895

2896
        bindf = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_PULLDATA;
2897

2898 2899
        trace("http test...\n");
        test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2900

2901 2902
        trace("http test (to file)...\n");
        test_BindToStorage(HTTP_TEST, FALSE, TYMED_FILE);
Jacek Caban's avatar
Jacek Caban committed
2903

2904 2905
        trace("http test (to object)...\n");
        test_BindToObject(HTTP_TEST, FALSE);
2906

2907 2908 2909 2910
        trace("http test (short response)...\n");
        http_is_first = TRUE;
        urls[HTTP_TEST] = SHORT_RESPONSE_URL;
        test_BindToStorage(HTTP_TEST, FALSE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2911

2912 2913
        trace("http test (short response, to object)...\n");
        test_BindToObject(HTTP_TEST, FALSE);
2914

2915 2916
        trace("emulated http test...\n");
        test_BindToStorage(HTTP_TEST, TRUE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2917

2918 2919
        trace("emulated http test (to object)...\n");
        test_BindToObject(HTTP_TEST, TRUE);
2920

2921 2922
        trace("emulated http test (to file)...\n");
        test_BindToStorage(HTTP_TEST, TRUE, TYMED_FILE);
Jacek Caban's avatar
Jacek Caban committed
2923

2924 2925 2926 2927 2928 2929
        trace("asynchronous https test...\n");
        test_BindToStorage(HTTPS_TEST, FALSE, TYMED_ISTREAM);

        trace("emulated https test...\n");
        test_BindToStorage(HTTPS_TEST, TRUE, TYMED_ISTREAM);

2930 2931
        trace("about test...\n");
        test_BindToStorage(ABOUT_TEST, FALSE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2932

2933 2934
        trace("about test (to file)...\n");
        test_BindToStorage(ABOUT_TEST, FALSE, TYMED_FILE);
Jacek Caban's avatar
Jacek Caban committed
2935

2936 2937
        trace("about test (to object)...\n");
        test_BindToObject(ABOUT_TEST, FALSE);
2938

2939 2940
        trace("emulated about test...\n");
        test_BindToStorage(ABOUT_TEST, TRUE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2941

2942 2943
        trace("emulated about test (to file)...\n");
        test_BindToStorage(ABOUT_TEST, TRUE, TYMED_FILE);
Jacek Caban's avatar
Jacek Caban committed
2944

2945 2946
        trace("emulated about test (to object)...\n");
        test_BindToObject(ABOUT_TEST, TRUE);
2947

2948 2949
        trace("file test...\n");
        test_BindToStorage(FILE_TEST, FALSE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2950

2951 2952
        trace("file test (to file)...\n");
        test_BindToStorage(FILE_TEST, FALSE, TYMED_FILE);
Jacek Caban's avatar
Jacek Caban committed
2953

2954 2955
        trace("file test (to object)...\n");
        test_BindToObject(FILE_TEST, FALSE);
2956

2957 2958
        trace("emulated file test...\n");
        test_BindToStorage(FILE_TEST, TRUE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2959

2960 2961
        trace("emulated file test (to file)...\n");
        test_BindToStorage(FILE_TEST, TRUE, TYMED_FILE);
Jacek Caban's avatar
Jacek Caban committed
2962

2963 2964
        trace("emulated file test (to object)...\n");
        test_BindToObject(FILE_TEST, TRUE);
2965

2966 2967
        trace("emulated its test...\n");
        test_BindToStorage(ITS_TEST, TRUE, TYMED_ISTREAM);
Jacek Caban's avatar
Jacek Caban committed
2968

2969 2970
        trace("emulated its test (to file)...\n");
        test_BindToStorage(ITS_TEST, TRUE, TYMED_FILE);
2971

2972 2973
        trace("emulated mk test...\n");
        test_BindToStorage(MK_TEST, TRUE, TYMED_ISTREAM);
2974

2975 2976
        trace("test URLDownloadToFile for file protocol...\n");
        test_URLDownloadToFile(FILE_TEST, FALSE);
2977

2978 2979
        trace("test URLDownloadToFile for emulated file protocol...\n");
        test_URLDownloadToFile(FILE_TEST, TRUE);
2980

2981 2982
        trace("test URLDownloadToFile for http protocol...\n");
        test_URLDownloadToFile(HTTP_TEST, FALSE);
2983

2984 2985 2986 2987 2988
        bindf |= BINDF_NOWRITECACHE;

        trace("ftp test...\n");
        test_BindToStorage(FTP_TEST, FALSE, TYMED_ISTREAM);

2989 2990 2991
        trace("test failures...\n");
        test_BindToStorage_fail();
    }
2992

2993
    DeleteFileA(wszIndexHtmlA);
2994 2995
    CloseHandle(complete_event);
    CloseHandle(complete_event2);
2996
    CoUninitialize();
2997 2998

    gecko_installer_workaround(FALSE);
2999
}