wined3d: Recognize Nvidia GT520 cards.
[wine] / dlls / msxml3 / tests / httpreq.c
1 /*
2  * XML test
3  *
4  * Copyright 2010-2012 Nikolay Sivov for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21
22 #define COBJMACROS
23 #define CONST_VTABLE
24
25 #include <stdio.h>
26 #include <assert.h>
27
28 #include "windows.h"
29
30 #include "msxml2.h"
31 #include "msxml2did.h"
32 #include "dispex.h"
33
34 #include "initguid.h"
35 #include "objsafe.h"
36 #include "mshtml.h"
37
38 #include "wine/test.h"
39
40 #define EXPECT_HR(hr,hr_exp) \
41     ok(hr == hr_exp, "got 0x%08x, expected 0x%08x\n", hr, hr_exp)
42
43 #define EXPECT_REF(node,ref) _expect_ref((IUnknown*)node, ref, __LINE__)
44 static void _expect_ref(IUnknown* obj, ULONG ref, int line)
45 {
46     ULONG rc = IUnknown_AddRef(obj);
47     IUnknown_Release(obj);
48     ok_(__FILE__,line)(rc-1 == ref, "expected refcount %d, got %d\n", ref, rc-1);
49 }
50
51 DEFINE_GUID(SID_SContainerDispatch, 0xb722be00, 0x4e68, 0x101b, 0xa2, 0xbc, 0x00, 0xaa, 0x00, 0x40, 0x47, 0x70);
52 DEFINE_GUID(SID_UnknownSID, 0x75dd09cb, 0x6c40, 0x11d5, 0x85, 0x43, 0x00, 0xc0, 0x4f, 0xa0, 0xfb, 0xa3);
53
54 #define DEFINE_EXPECT(func) \
55     static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
56
57 #define SET_EXPECT(func) \
58     expect_ ## func = TRUE
59
60 #define CHECK_EXPECT2(func) \
61     do { \
62         ok(expect_ ##func, "unexpected call " #func "\n"); \
63         called_ ## func = TRUE; \
64     }while(0)
65
66 #define CHECK_CALLED(func) \
67     do { \
68         ok(called_ ## func, "expected " #func "\n"); \
69         expect_ ## func = called_ ## func = FALSE; \
70     }while(0)
71
72 /* object site */
73 DEFINE_EXPECT(site_qi_IServiceProvider);
74 DEFINE_EXPECT(site_qi_IXMLDOMDocument);
75 DEFINE_EXPECT(site_qi_IOleClientSite);
76
77 DEFINE_EXPECT(sp_queryservice_SID_SBindHost);
78 DEFINE_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
79 DEFINE_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
80 DEFINE_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
81 DEFINE_EXPECT(sp_queryservice_SID_secmgr_secmgr);
82
83 DEFINE_EXPECT(htmldoc2_get_all);
84 DEFINE_EXPECT(htmldoc2_get_url);
85 DEFINE_EXPECT(collection_get_length);
86
87 static const char *debugstr_guid(REFIID riid)
88 {
89     static char buf[50];
90
91     if(!riid)
92         return "(null)";
93
94     sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
95             riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
96             riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
97             riid->Data4[5], riid->Data4[6], riid->Data4[7]);
98
99     return buf;
100 }
101
102 static int g_unexpectedcall, g_expectedcall;
103
104 static BSTR alloc_str_from_narrow(const char *str)
105 {
106     int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
107     BSTR ret = SysAllocStringLen(NULL, len - 1);  /* NUL character added automatically */
108     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len-1);
109     return ret;
110 }
111
112 static BSTR alloced_bstrs[256];
113 static int alloced_bstrs_count;
114
115 static BSTR _bstr_(const char *str)
116 {
117     if(!str)
118         return NULL;
119
120     assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
121     alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
122     return alloced_bstrs[alloced_bstrs_count++];
123 }
124
125 static void free_bstrs(void)
126 {
127     int i;
128     for (i = 0; i < alloced_bstrs_count; i++)
129         SysFreeString(alloced_bstrs[i]);
130     alloced_bstrs_count = 0;
131 }
132
133 static BSTR a2bstr(const char *str)
134 {
135     BSTR ret;
136     int len;
137
138     if(!str)
139         return NULL;
140
141     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
142     ret = SysAllocStringLen(NULL, len);
143     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
144
145     return ret;
146 }
147
148 typedef struct
149 {
150     IServiceProvider IServiceProvider_iface;
151 } testprov_t;
152
153 testprov_t testprov;
154
155 static HRESULT WINAPI site_QueryInterface(IUnknown *iface, REFIID riid, void **ppvObject)
156 {
157     *ppvObject = NULL;
158
159     if (IsEqualGUID(riid, &IID_IServiceProvider))
160         CHECK_EXPECT2(site_qi_IServiceProvider);
161
162     if (IsEqualGUID(riid, &IID_IXMLDOMDocument))
163         CHECK_EXPECT2(site_qi_IXMLDOMDocument);
164
165     if (IsEqualGUID(riid, &IID_IOleClientSite))
166         CHECK_EXPECT2(site_qi_IOleClientSite);
167
168     if (IsEqualGUID(riid, &IID_IUnknown))
169          *ppvObject = iface;
170     else if (IsEqualGUID(riid, &IID_IServiceProvider))
171          *ppvObject = &testprov.IServiceProvider_iface;
172
173     if (*ppvObject) IUnknown_AddRef(iface);
174
175     return *ppvObject ? S_OK : E_NOINTERFACE;
176 }
177
178 static ULONG WINAPI site_AddRef(IUnknown *iface)
179 {
180     return 2;
181 }
182
183 static ULONG WINAPI site_Release(IUnknown *iface)
184 {
185     return 1;
186 }
187
188 static const IUnknownVtbl testsiteVtbl =
189 {
190     site_QueryInterface,
191     site_AddRef,
192     site_Release
193 };
194
195 typedef struct
196 {
197     IUnknown IUnknown_iface;
198 } testsite_t;
199
200 static testsite_t testsite = { { &testsiteVtbl } };
201
202 /* test IHTMLElementCollection */
203 static HRESULT WINAPI htmlecoll_QueryInterface(IHTMLElementCollection *iface, REFIID riid, void **ppvObject)
204 {
205     ok(0, "unexpected call\n");
206     *ppvObject = NULL;
207     return E_NOINTERFACE;
208 }
209
210 static ULONG WINAPI htmlecoll_AddRef(IHTMLElementCollection *iface)
211 {
212     return 2;
213 }
214
215 static ULONG WINAPI htmlecoll_Release(IHTMLElementCollection *iface)
216 {
217     return 1;
218 }
219
220 static HRESULT WINAPI htmlecoll_GetTypeInfoCount(IHTMLElementCollection *iface, UINT *pctinfo)
221 {
222     ok(0, "unexpected call\n");
223     return E_NOTIMPL;
224 }
225
226 static HRESULT WINAPI htmlecoll_GetTypeInfo(IHTMLElementCollection *iface, UINT iTInfo,
227                                                 LCID lcid, ITypeInfo **ppTInfo)
228 {
229     ok(0, "unexpected call\n");
230     return E_NOTIMPL;
231 }
232
233 static HRESULT WINAPI htmlecoll_GetIDsOfNames(IHTMLElementCollection *iface, REFIID riid,
234                                                 LPOLESTR *rgszNames, UINT cNames,
235                                                 LCID lcid, DISPID *rgDispId)
236 {
237     ok(0, "unexpected call\n");
238     return E_NOTIMPL;
239 }
240
241 static HRESULT WINAPI htmlecoll_Invoke(IHTMLElementCollection *iface, DISPID dispIdMember,
242                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
243                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
244 {
245     ok(0, "unexpected call\n");
246     return E_NOTIMPL;
247 }
248
249 static HRESULT WINAPI htmlecoll_toString(IHTMLElementCollection *iface, BSTR *String)
250 {
251     ok(0, "unexpected call\n");
252     return E_NOTIMPL;
253 }
254
255 static HRESULT WINAPI htmlecoll_put_length(IHTMLElementCollection *iface, LONG v)
256 {
257     ok(0, "unexpected call\n");
258     return E_NOTIMPL;
259 }
260
261 static HRESULT WINAPI htmlecoll_get_length(IHTMLElementCollection *iface, LONG *v)
262 {
263     CHECK_EXPECT2(collection_get_length);
264     return E_NOTIMPL;
265 }
266
267 static HRESULT WINAPI htmlecoll_get__newEnum(IHTMLElementCollection *iface, IUnknown **p)
268 {
269     ok(0, "unexpected call\n");
270     return E_NOTIMPL;
271 }
272
273 static HRESULT WINAPI htmlecoll_item(IHTMLElementCollection *iface, VARIANT name, VARIANT index, IDispatch **pdisp)
274 {
275     ok(0, "unexpected call\n");
276     return E_NOTIMPL;
277 }
278
279 static HRESULT WINAPI htmlecoll_tags(IHTMLElementCollection *iface, VARIANT tagName, IDispatch **pdisp)
280 {
281     ok(0, "unexpected call\n");
282     return E_NOTIMPL;
283 }
284
285 static const IHTMLElementCollectionVtbl TestHTMLECollectionVtbl = {
286     htmlecoll_QueryInterface,
287     htmlecoll_AddRef,
288     htmlecoll_Release,
289     htmlecoll_GetTypeInfoCount,
290     htmlecoll_GetTypeInfo,
291     htmlecoll_GetIDsOfNames,
292     htmlecoll_Invoke,
293
294     htmlecoll_toString,
295     htmlecoll_put_length,
296     htmlecoll_get_length,
297     htmlecoll_get__newEnum,
298     htmlecoll_item,
299     htmlecoll_tags
300 };
301
302 typedef struct
303 {
304     IHTMLElementCollection IHTMLElementCollection_iface;
305 } testhtmlecoll_t;
306
307 static testhtmlecoll_t htmlecoll = { { &TestHTMLECollectionVtbl } };
308
309 /* test IHTMLDocument2 */
310 static HRESULT WINAPI htmldoc2_QueryInterface(IHTMLDocument2 *iface, REFIID riid, void **ppvObject)
311 {
312    trace("\n");
313    *ppvObject = NULL;
314    return E_NOINTERFACE;
315 }
316
317 static ULONG WINAPI htmldoc2_AddRef(IHTMLDocument2 *iface)
318 {
319     return 2;
320 }
321
322 static ULONG WINAPI htmldoc2_Release(IHTMLDocument2 *iface)
323 {
324     return 1;
325 }
326
327 static HRESULT WINAPI htmldoc2_GetTypeInfoCount(IHTMLDocument2 *iface, UINT *pctinfo)
328 {
329     ok(0, "unexpected call\n");
330     return E_NOTIMPL;
331 }
332
333 static HRESULT WINAPI htmldoc2_GetTypeInfo(IHTMLDocument2 *iface, UINT iTInfo,
334                                                 LCID lcid, ITypeInfo **ppTInfo)
335 {
336     ok(0, "unexpected call\n");
337     return E_NOTIMPL;
338 }
339
340 static HRESULT WINAPI htmldoc2_GetIDsOfNames(IHTMLDocument2 *iface, REFIID riid,
341                                                 LPOLESTR *rgszNames, UINT cNames,
342                                                 LCID lcid, DISPID *rgDispId)
343 {
344     ok(0, "unexpected call\n");
345     return E_NOTIMPL;
346 }
347
348 static HRESULT WINAPI htmldoc2_Invoke(IHTMLDocument2 *iface, DISPID dispIdMember,
349                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
350                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
351 {
352     ok(0, "unexpected call\n");
353     return E_NOTIMPL;
354 }
355
356 static HRESULT WINAPI htmldoc2_get_Script(IHTMLDocument2 *iface, IDispatch **p)
357 {
358     ok(0, "unexpected call\n");
359     return E_NOTIMPL;
360 }
361
362 static HRESULT WINAPI htmldoc2_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
363 {
364     CHECK_EXPECT2(htmldoc2_get_all);
365     *p = &htmlecoll.IHTMLElementCollection_iface;
366     return S_OK;
367 }
368
369 static HRESULT WINAPI htmldoc2_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
370 {
371     ok(0, "unexpected call\n");
372     return E_NOTIMPL;
373 }
374
375 static HRESULT WINAPI htmldoc2_get_activeElement(IHTMLDocument2 *iface, IHTMLElement **p)
376 {
377     ok(0, "unexpected call\n");
378     return E_NOTIMPL;
379 }
380
381 static HRESULT WINAPI htmldoc2_get_images(IHTMLDocument2 *iface, IHTMLElementCollection **p)
382 {
383     ok(0, "unexpected call\n");
384     return E_NOTIMPL;
385 }
386
387 static HRESULT WINAPI htmldoc2_get_applets(IHTMLDocument2 *iface, IHTMLElementCollection **p)
388 {
389     ok(0, "unexpected call\n");
390     return E_NOTIMPL;
391 }
392
393 static HRESULT WINAPI htmldoc2_get_links(IHTMLDocument2 *iface, IHTMLElementCollection **p)
394 {
395     ok(0, "unexpected call\n");
396     return E_NOTIMPL;
397 }
398
399 static HRESULT WINAPI htmldoc2_get_forms(IHTMLDocument2 *iface, IHTMLElementCollection **p)
400 {
401     ok(0, "unexpected call\n");
402     return E_NOTIMPL;
403 }
404
405 static HRESULT WINAPI htmldoc2_get_anchors(IHTMLDocument2 *iface, IHTMLElementCollection **p)
406 {
407     ok(0, "unexpected call\n");
408     return E_NOTIMPL;
409 }
410
411 static HRESULT WINAPI htmldoc2_put_title(IHTMLDocument2 *iface, BSTR v)
412 {
413     ok(0, "unexpected call\n");
414     return E_NOTIMPL;
415 }
416
417 static HRESULT WINAPI htmldoc2_get_title(IHTMLDocument2 *iface, BSTR *p)
418 {
419     ok(0, "unexpected call\n");
420     return E_NOTIMPL;
421 }
422
423 static HRESULT WINAPI htmldoc2_get_scripts(IHTMLDocument2 *iface, IHTMLElementCollection **p)
424 {
425     ok(0, "unexpected call\n");
426     return E_NOTIMPL;
427 }
428
429 static HRESULT WINAPI htmldoc2_put_designMode(IHTMLDocument2 *iface, BSTR v)
430 {
431     ok(0, "unexpected call\n");
432     return E_NOTIMPL;
433 }
434
435 static HRESULT WINAPI htmldoc2_get_designMode(IHTMLDocument2 *iface, BSTR *p)
436 {
437     ok(0, "unexpected call\n");
438     return E_NOTIMPL;
439 }
440
441 static HRESULT WINAPI htmldoc2_get_selection(IHTMLDocument2 *iface, IHTMLSelectionObject **p)
442 {
443     ok(0, "unexpected call\n");
444     return E_NOTIMPL;
445 }
446
447 static HRESULT WINAPI htmldoc2_get_readyState(IHTMLDocument2 *iface, BSTR *p)
448 {
449     ok(0, "unexpected call\n");
450     return E_NOTIMPL;
451 }
452
453 static HRESULT WINAPI htmldoc2_get_frames(IHTMLDocument2 *iface, IHTMLFramesCollection2 **p)
454 {
455     ok(0, "unexpected call\n");
456     return E_NOTIMPL;
457 }
458
459 static HRESULT WINAPI htmldoc2_get_embeds(IHTMLDocument2 *iface, IHTMLElementCollection **p)
460 {
461     ok(0, "unexpected call\n");
462     return E_NOTIMPL;
463 }
464
465 static HRESULT WINAPI htmldoc2_get_plugins(IHTMLDocument2 *iface, IHTMLElementCollection **p)
466 {
467     ok(0, "unexpected call\n");
468     return E_NOTIMPL;
469 }
470
471 static HRESULT WINAPI htmldoc2_put_alinkColor(IHTMLDocument2 *iface, VARIANT v)
472 {
473     ok(0, "unexpected call\n");
474     return E_NOTIMPL;
475 }
476
477 static HRESULT WINAPI htmldoc2_get_alinkColor(IHTMLDocument2 *iface, VARIANT *p)
478 {
479     ok(0, "unexpected call\n");
480     return E_NOTIMPL;
481 }
482
483 static HRESULT WINAPI htmldoc2_put_bgColor(IHTMLDocument2 *iface, VARIANT v)
484 {
485     ok(0, "unexpected call\n");
486     return E_NOTIMPL;
487 }
488
489 static HRESULT WINAPI htmldoc2_get_bgColor(IHTMLDocument2 *iface, VARIANT *p)
490 {
491     ok(0, "unexpected call\n");
492     return E_NOTIMPL;
493 }
494
495 static HRESULT WINAPI htmldoc2_put_fgColor(IHTMLDocument2 *iface, VARIANT v)
496 {
497     ok(0, "unexpected call\n");
498     return E_NOTIMPL;
499 }
500
501 static HRESULT WINAPI htmldoc2_get_fgColor(IHTMLDocument2 *iface, VARIANT *p)
502 {
503     ok(0, "unexpected call\n");
504     return E_NOTIMPL;
505 }
506
507 static HRESULT WINAPI htmldoc2_put_linkColor(IHTMLDocument2 *iface, VARIANT v)
508 {
509     ok(0, "unexpected call\n");
510     return E_NOTIMPL;
511 }
512
513 static HRESULT WINAPI htmldoc2_get_linkColor(IHTMLDocument2 *iface, VARIANT *p)
514 {
515     ok(0, "unexpected call\n");
516     return E_NOTIMPL;
517 }
518
519 static HRESULT WINAPI htmldoc2_put_vlinkColor(IHTMLDocument2 *iface, VARIANT v)
520 {
521     ok(0, "unexpected call\n");
522     return E_NOTIMPL;
523 }
524
525 static HRESULT WINAPI htmldoc2_get_vlinkColor(IHTMLDocument2 *iface, VARIANT *p)
526 {
527     ok(0, "unexpected call\n");
528     return E_NOTIMPL;
529 }
530
531 static HRESULT WINAPI htmldoc2_get_referrer(IHTMLDocument2 *iface, BSTR *p)
532 {
533     ok(0, "unexpected call\n");
534     return E_NOTIMPL;
535 }
536
537 static HRESULT WINAPI htmldoc2_get_location(IHTMLDocument2 *iface, IHTMLLocation **p)
538 {
539     ok(0, "unexpected call\n");
540     return E_NOTIMPL;
541 }
542
543 static HRESULT WINAPI htmldoc2_get_lastModified(IHTMLDocument2 *iface, BSTR *p)
544 {
545     ok(0, "unexpected call\n");
546     return E_NOTIMPL;
547 }
548
549 static HRESULT WINAPI htmldoc2_put_URL(IHTMLDocument2 *iface, BSTR v)
550 {
551     ok(0, "unexpected call\n");
552     return E_NOTIMPL;
553 }
554
555 static HRESULT WINAPI htmldoc2_get_URL(IHTMLDocument2 *iface, BSTR *p)
556 {
557     CHECK_EXPECT2(htmldoc2_get_url);
558     *p = a2bstr("http://test.winehq.org/");
559     return S_OK;
560 }
561
562 static HRESULT WINAPI htmldoc2_put_domain(IHTMLDocument2 *iface, BSTR v)
563 {
564     ok(0, "unexpected call\n");
565     return E_NOTIMPL;
566 }
567
568 static HRESULT WINAPI htmldoc2_get_domain(IHTMLDocument2 *iface, BSTR *p)
569 {
570     ok(0, "unexpected call\n");
571     return E_NOTIMPL;
572 }
573
574 static HRESULT WINAPI htmldoc2_put_cookie(IHTMLDocument2 *iface, BSTR v)
575 {
576     ok(0, "unexpected call\n");
577     return E_NOTIMPL;
578 }
579
580 static HRESULT WINAPI htmldoc2_get_cookie(IHTMLDocument2 *iface, BSTR *p)
581 {
582     ok(0, "unexpected call\n");
583     return E_NOTIMPL;
584 }
585
586 static HRESULT WINAPI htmldoc2_put_expando(IHTMLDocument2 *iface, VARIANT_BOOL v)
587 {
588     ok(0, "unexpected call\n");
589     return E_NOTIMPL;
590 }
591
592 static HRESULT WINAPI htmldoc2_get_expando(IHTMLDocument2 *iface, VARIANT_BOOL *p)
593 {
594     ok(0, "unexpected call\n");
595     return E_NOTIMPL;
596 }
597
598 static HRESULT WINAPI htmldoc2_put_charset(IHTMLDocument2 *iface, BSTR v)
599 {
600     ok(0, "unexpected call\n");
601     return E_NOTIMPL;
602 }
603
604 static HRESULT WINAPI htmldoc2_get_charset(IHTMLDocument2 *iface, BSTR *p)
605 {
606     ok(0, "unexpected call\n");
607     return E_NOTIMPL;
608 }
609
610 static HRESULT WINAPI htmldoc2_put_defaultCharset(IHTMLDocument2 *iface, BSTR v)
611 {
612     ok(0, "unexpected call\n");
613     return E_NOTIMPL;
614 }
615
616 static HRESULT WINAPI htmldoc2_get_defaultCharset(IHTMLDocument2 *iface, BSTR *p)
617 {
618     ok(0, "unexpected call\n");
619     return E_NOTIMPL;
620 }
621
622 static HRESULT WINAPI htmldoc2_get_mimeType(IHTMLDocument2 *iface, BSTR *p)
623 {
624     ok(0, "unexpected call\n");
625     return E_NOTIMPL;
626 }
627
628 static HRESULT WINAPI htmldoc2_get_fileSize(IHTMLDocument2 *iface, BSTR *p)
629 {
630     ok(0, "unexpected call\n");
631     return E_NOTIMPL;
632 }
633
634 static HRESULT WINAPI htmldoc2_get_fileCreatedDate(IHTMLDocument2 *iface, BSTR *p)
635 {
636     ok(0, "unexpected call\n");
637     return E_NOTIMPL;
638 }
639
640 static HRESULT WINAPI htmldoc2_get_fileModifiedDate(IHTMLDocument2 *iface, BSTR *p)
641 {
642     ok(0, "unexpected call\n");
643     return E_NOTIMPL;
644 }
645
646 static HRESULT WINAPI htmldoc2_get_fileUpdatedDate(IHTMLDocument2 *iface, BSTR *p)
647 {
648     ok(0, "unexpected call\n");
649     return E_NOTIMPL;
650 }
651
652 static HRESULT WINAPI htmldoc2_get_security(IHTMLDocument2 *iface, BSTR *p)
653 {
654     ok(0, "unexpected call\n");
655     return E_NOTIMPL;
656 }
657
658 static HRESULT WINAPI htmldoc2_get_protocol(IHTMLDocument2 *iface, BSTR *p)
659 {
660     ok(0, "unexpected call\n");
661     return E_NOTIMPL;
662 }
663
664 static HRESULT WINAPI htmldoc2_get_nameProp(IHTMLDocument2 *iface, BSTR *p)
665 {
666     ok(0, "unexpected call\n");
667     return E_NOTIMPL;
668 }
669
670 static HRESULT WINAPI htmldoc2_write(IHTMLDocument2 *iface, SAFEARRAY *psarray)
671 {
672     ok(0, "unexpected call\n");
673     return E_NOTIMPL;
674 }
675
676 static HRESULT WINAPI htmldoc2_writeln(IHTMLDocument2 *iface, SAFEARRAY *psarray)
677 {
678     ok(0, "unexpected call\n");
679     return E_NOTIMPL;
680 }
681
682 static HRESULT WINAPI htmldoc2_open(IHTMLDocument2 *iface, BSTR url, VARIANT name,
683                         VARIANT features, VARIANT replace, IDispatch **pomWindowResult)
684 {
685     ok(0, "unexpected call\n");
686     return E_NOTIMPL;
687 }
688
689 static HRESULT WINAPI htmldoc2_close(IHTMLDocument2 *iface)
690 {
691     ok(0, "unexpected call\n");
692     return E_NOTIMPL;
693 }
694
695 static HRESULT WINAPI htmldoc2_clear(IHTMLDocument2 *iface)
696 {
697     ok(0, "unexpected call\n");
698     return E_NOTIMPL;
699 }
700
701 static HRESULT WINAPI htmldoc2_queryCommandSupported(IHTMLDocument2 *iface, BSTR cmdID,
702                                                         VARIANT_BOOL *pfRet)
703 {
704     ok(0, "unexpected call\n");
705     return E_NOTIMPL;
706 }
707
708 static HRESULT WINAPI htmldoc2_queryCommandEnabled(IHTMLDocument2 *iface, BSTR cmdID,
709                                                         VARIANT_BOOL *pfRet)
710 {
711     ok(0, "unexpected call\n");
712     return E_NOTIMPL;
713 }
714
715 static HRESULT WINAPI htmldoc2_queryCommandState(IHTMLDocument2 *iface, BSTR cmdID,
716                                                         VARIANT_BOOL *pfRet)
717 {
718     ok(0, "unexpected call\n");
719     return E_NOTIMPL;
720 }
721
722 static HRESULT WINAPI htmldoc2_queryCommandIndeterm(IHTMLDocument2 *iface, BSTR cmdID,
723                                                         VARIANT_BOOL *pfRet)
724 {
725     ok(0, "unexpected call\n");
726     return E_NOTIMPL;
727 }
728
729 static HRESULT WINAPI htmldoc2_queryCommandText(IHTMLDocument2 *iface, BSTR cmdID,
730                                                         BSTR *pfRet)
731 {
732     ok(0, "unexpected call\n");
733     return E_NOTIMPL;
734 }
735
736 static HRESULT WINAPI htmldoc2_queryCommandValue(IHTMLDocument2 *iface, BSTR cmdID,
737                                                         VARIANT *pfRet)
738 {
739     ok(0, "unexpected call\n");
740     return E_NOTIMPL;
741 }
742
743 static HRESULT WINAPI htmldoc2_execCommand(IHTMLDocument2 *iface, BSTR cmdID,
744                                 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
745 {
746     ok(0, "unexpected call\n");
747     return E_NOTIMPL;
748 }
749
750 static HRESULT WINAPI htmldoc2_execCommandShowHelp(IHTMLDocument2 *iface, BSTR cmdID,
751                                                         VARIANT_BOOL *pfRet)
752 {
753     ok(0, "unexpected call\n");
754     return E_NOTIMPL;
755 }
756
757 static HRESULT WINAPI htmldoc2_createElement(IHTMLDocument2 *iface, BSTR eTag,
758                                                  IHTMLElement **newElem)
759 {
760     ok(0, "unexpected call\n");
761     return E_NOTIMPL;
762 }
763
764 static HRESULT WINAPI htmldoc2_put_onhelp(IHTMLDocument2 *iface, VARIANT v)
765 {
766     ok(0, "unexpected call\n");
767     return E_NOTIMPL;
768 }
769
770 static HRESULT WINAPI htmldoc2_get_onhelp(IHTMLDocument2 *iface, VARIANT *p)
771 {
772     ok(0, "unexpected call\n");
773     return E_NOTIMPL;
774 }
775
776 static HRESULT WINAPI htmldoc2_put_onclick(IHTMLDocument2 *iface, VARIANT v)
777 {
778     ok(0, "unexpected call\n");
779     return E_NOTIMPL;
780 }
781
782 static HRESULT WINAPI htmldoc2_get_onclick(IHTMLDocument2 *iface, VARIANT *p)
783 {
784     ok(0, "unexpected call\n");
785     return E_NOTIMPL;
786 }
787
788 static HRESULT WINAPI htmldoc2_put_ondblclick(IHTMLDocument2 *iface, VARIANT v)
789 {
790     ok(0, "unexpected call\n");
791     return E_NOTIMPL;
792 }
793
794 static HRESULT WINAPI htmldoc2_get_ondblclick(IHTMLDocument2 *iface, VARIANT *p)
795 {
796     ok(0, "unexpected call\n");
797     return E_NOTIMPL;
798 }
799
800 static HRESULT WINAPI htmldoc2_put_onkeyup(IHTMLDocument2 *iface, VARIANT v)
801 {
802     ok(0, "unexpected call\n");
803     return E_NOTIMPL;
804 }
805
806 static HRESULT WINAPI htmldoc2_get_onkeyup(IHTMLDocument2 *iface, VARIANT *p)
807 {
808     ok(0, "unexpected call\n");
809     return E_NOTIMPL;
810 }
811
812 static HRESULT WINAPI htmldoc2_put_onkeydown(IHTMLDocument2 *iface, VARIANT v)
813 {
814     ok(0, "unexpected call\n");
815     return E_NOTIMPL;
816 }
817
818 static HRESULT WINAPI htmldoc2_get_onkeydown(IHTMLDocument2 *iface, VARIANT *p)
819 {
820     ok(0, "unexpected call\n");
821     return E_NOTIMPL;
822 }
823
824 static HRESULT WINAPI htmldoc2_put_onkeypress(IHTMLDocument2 *iface, VARIANT v)
825 {
826     ok(0, "unexpected call\n");
827     return E_NOTIMPL;
828 }
829
830 static HRESULT WINAPI htmldoc2_get_onkeypress(IHTMLDocument2 *iface, VARIANT *p)
831 {
832     ok(0, "unexpected call\n");
833     return E_NOTIMPL;
834 }
835
836 static HRESULT WINAPI htmldoc2_put_onmouseup(IHTMLDocument2 *iface, VARIANT v)
837 {
838     ok(0, "unexpected call\n");
839     return E_NOTIMPL;
840 }
841
842 static HRESULT WINAPI htmldoc2_get_onmouseup(IHTMLDocument2 *iface, VARIANT *p)
843 {
844     ok(0, "unexpected call\n");
845     return E_NOTIMPL;
846 }
847
848 static HRESULT WINAPI htmldoc2_put_onmousedown(IHTMLDocument2 *iface, VARIANT v)
849 {
850     ok(0, "unexpected call\n");
851     return E_NOTIMPL;
852 }
853
854 static HRESULT WINAPI htmldoc2_get_onmousedown(IHTMLDocument2 *iface, VARIANT *p)
855 {
856     ok(0, "unexpected call\n");
857     return E_NOTIMPL;
858 }
859
860 static HRESULT WINAPI htmldoc2_put_onmousemove(IHTMLDocument2 *iface, VARIANT v)
861 {
862     ok(0, "unexpected call\n");
863     return E_NOTIMPL;
864 }
865
866 static HRESULT WINAPI htmldoc2_get_onmousemove(IHTMLDocument2 *iface, VARIANT *p)
867 {
868     ok(0, "unexpected call\n");
869     return E_NOTIMPL;
870 }
871
872 static HRESULT WINAPI htmldoc2_put_onmouseout(IHTMLDocument2 *iface, VARIANT v)
873 {
874     ok(0, "unexpected call\n");
875     return E_NOTIMPL;
876 }
877
878 static HRESULT WINAPI htmldoc2_get_onmouseout(IHTMLDocument2 *iface, VARIANT *p)
879 {
880     ok(0, "unexpected call\n");
881     return E_NOTIMPL;
882 }
883
884 static HRESULT WINAPI htmldoc2_put_onmouseover(IHTMLDocument2 *iface, VARIANT v)
885 {
886     ok(0, "unexpected call\n");
887     return E_NOTIMPL;
888 }
889
890 static HRESULT WINAPI htmldoc2_get_onmouseover(IHTMLDocument2 *iface, VARIANT *p)
891 {
892     ok(0, "unexpected call\n");
893     return E_NOTIMPL;
894 }
895
896 static HRESULT WINAPI htmldoc2_put_onreadystatechange(IHTMLDocument2 *iface, VARIANT v)
897 {
898     ok(0, "unexpected call\n");
899     return E_NOTIMPL;
900 }
901
902 static HRESULT WINAPI htmldoc2_get_onreadystatechange(IHTMLDocument2 *iface, VARIANT *p)
903 {
904     ok(0, "unexpected call\n");
905     return E_NOTIMPL;
906 }
907
908 static HRESULT WINAPI htmldoc2_put_onafterupdate(IHTMLDocument2 *iface, VARIANT v)
909 {
910     ok(0, "unexpected call\n");
911     return E_NOTIMPL;
912 }
913
914 static HRESULT WINAPI htmldoc2_get_onafterupdate(IHTMLDocument2 *iface, VARIANT *p)
915 {
916     ok(0, "unexpected call\n");
917     return E_NOTIMPL;
918 }
919
920 static HRESULT WINAPI htmldoc2_put_onrowexit(IHTMLDocument2 *iface, VARIANT v)
921 {
922     ok(0, "unexpected call\n");
923     return E_NOTIMPL;
924 }
925
926 static HRESULT WINAPI htmldoc2_get_onrowexit(IHTMLDocument2 *iface, VARIANT *p)
927 {
928     ok(0, "unexpected call\n");
929     return E_NOTIMPL;
930 }
931
932 static HRESULT WINAPI htmldoc2_put_onrowenter(IHTMLDocument2 *iface, VARIANT v)
933 {
934     ok(0, "unexpected call\n");
935     return E_NOTIMPL;
936 }
937
938 static HRESULT WINAPI htmldoc2_get_onrowenter(IHTMLDocument2 *iface, VARIANT *p)
939 {
940     ok(0, "unexpected call\n");
941     return E_NOTIMPL;
942 }
943
944 static HRESULT WINAPI htmldoc2_put_ondragstart(IHTMLDocument2 *iface, VARIANT v)
945 {
946     ok(0, "unexpected call\n");
947     return E_NOTIMPL;
948 }
949
950 static HRESULT WINAPI htmldoc2_get_ondragstart(IHTMLDocument2 *iface, VARIANT *p)
951 {
952     ok(0, "unexpected call\n");
953     return E_NOTIMPL;
954 }
955
956 static HRESULT WINAPI htmldoc2_put_onselectstart(IHTMLDocument2 *iface, VARIANT v)
957 {
958     ok(0, "unexpected call\n");
959     return E_NOTIMPL;
960 }
961
962 static HRESULT WINAPI htmldoc2_get_onselectstart(IHTMLDocument2 *iface, VARIANT *p)
963 {
964     ok(0, "unexpected call\n");
965     return E_NOTIMPL;
966 }
967
968 static HRESULT WINAPI htmldoc2_elementFromPoint(IHTMLDocument2 *iface, LONG x, LONG y,
969                                                         IHTMLElement **elementHit)
970 {
971     ok(0, "unexpected call\n");
972     return E_NOTIMPL;
973 }
974
975 static HRESULT WINAPI htmldoc2_get_parentWindow(IHTMLDocument2 *iface, IHTMLWindow2 **p)
976 {
977     ok(0, "unexpected call\n");
978     return E_NOTIMPL;
979 }
980
981 static HRESULT WINAPI htmldoc2_get_styleSheets(IHTMLDocument2 *iface,
982                                                    IHTMLStyleSheetsCollection **p)
983 {
984     ok(0, "unexpected call\n");
985     return E_NOTIMPL;
986 }
987
988 static HRESULT WINAPI htmldoc2_put_onbeforeupdate(IHTMLDocument2 *iface, VARIANT v)
989 {
990     ok(0, "unexpected call\n");
991     return E_NOTIMPL;
992 }
993
994 static HRESULT WINAPI htmldoc2_get_onbeforeupdate(IHTMLDocument2 *iface, VARIANT *p)
995 {
996     ok(0, "unexpected call\n");
997     return E_NOTIMPL;
998 }
999
1000 static HRESULT WINAPI htmldoc2_put_onerrorupdate(IHTMLDocument2 *iface, VARIANT v)
1001 {
1002     ok(0, "unexpected call\n");
1003     return E_NOTIMPL;
1004 }
1005
1006 static HRESULT WINAPI htmldoc2_get_onerrorupdate(IHTMLDocument2 *iface, VARIANT *p)
1007 {
1008     ok(0, "unexpected call\n");
1009     return E_NOTIMPL;
1010 }
1011
1012 static HRESULT WINAPI htmldoc2_toString(IHTMLDocument2 *iface, BSTR *String)
1013 {
1014     ok(0, "unexpected call\n");
1015     return E_NOTIMPL;
1016 }
1017
1018 static HRESULT WINAPI htmldoc2_createStyleSheet(IHTMLDocument2 *iface, BSTR bstrHref,
1019                                             LONG lIndex, IHTMLStyleSheet **ppnewStyleSheet)
1020 {
1021     ok(0, "unexpected call\n");
1022     return E_NOTIMPL;
1023 }
1024
1025 static const IHTMLDocument2Vtbl TestHTMLDocumentVtbl = {
1026     htmldoc2_QueryInterface,
1027     htmldoc2_AddRef,
1028     htmldoc2_Release,
1029     htmldoc2_GetTypeInfoCount,
1030     htmldoc2_GetTypeInfo,
1031     htmldoc2_GetIDsOfNames,
1032     htmldoc2_Invoke,
1033     htmldoc2_get_Script,
1034     htmldoc2_get_all,
1035     htmldoc2_get_body,
1036     htmldoc2_get_activeElement,
1037     htmldoc2_get_images,
1038     htmldoc2_get_applets,
1039     htmldoc2_get_links,
1040     htmldoc2_get_forms,
1041     htmldoc2_get_anchors,
1042     htmldoc2_put_title,
1043     htmldoc2_get_title,
1044     htmldoc2_get_scripts,
1045     htmldoc2_put_designMode,
1046     htmldoc2_get_designMode,
1047     htmldoc2_get_selection,
1048     htmldoc2_get_readyState,
1049     htmldoc2_get_frames,
1050     htmldoc2_get_embeds,
1051     htmldoc2_get_plugins,
1052     htmldoc2_put_alinkColor,
1053     htmldoc2_get_alinkColor,
1054     htmldoc2_put_bgColor,
1055     htmldoc2_get_bgColor,
1056     htmldoc2_put_fgColor,
1057     htmldoc2_get_fgColor,
1058     htmldoc2_put_linkColor,
1059     htmldoc2_get_linkColor,
1060     htmldoc2_put_vlinkColor,
1061     htmldoc2_get_vlinkColor,
1062     htmldoc2_get_referrer,
1063     htmldoc2_get_location,
1064     htmldoc2_get_lastModified,
1065     htmldoc2_put_URL,
1066     htmldoc2_get_URL,
1067     htmldoc2_put_domain,
1068     htmldoc2_get_domain,
1069     htmldoc2_put_cookie,
1070     htmldoc2_get_cookie,
1071     htmldoc2_put_expando,
1072     htmldoc2_get_expando,
1073     htmldoc2_put_charset,
1074     htmldoc2_get_charset,
1075     htmldoc2_put_defaultCharset,
1076     htmldoc2_get_defaultCharset,
1077     htmldoc2_get_mimeType,
1078     htmldoc2_get_fileSize,
1079     htmldoc2_get_fileCreatedDate,
1080     htmldoc2_get_fileModifiedDate,
1081     htmldoc2_get_fileUpdatedDate,
1082     htmldoc2_get_security,
1083     htmldoc2_get_protocol,
1084     htmldoc2_get_nameProp,
1085     htmldoc2_write,
1086     htmldoc2_writeln,
1087     htmldoc2_open,
1088     htmldoc2_close,
1089     htmldoc2_clear,
1090     htmldoc2_queryCommandSupported,
1091     htmldoc2_queryCommandEnabled,
1092     htmldoc2_queryCommandState,
1093     htmldoc2_queryCommandIndeterm,
1094     htmldoc2_queryCommandText,
1095     htmldoc2_queryCommandValue,
1096     htmldoc2_execCommand,
1097     htmldoc2_execCommandShowHelp,
1098     htmldoc2_createElement,
1099     htmldoc2_put_onhelp,
1100     htmldoc2_get_onhelp,
1101     htmldoc2_put_onclick,
1102     htmldoc2_get_onclick,
1103     htmldoc2_put_ondblclick,
1104     htmldoc2_get_ondblclick,
1105     htmldoc2_put_onkeyup,
1106     htmldoc2_get_onkeyup,
1107     htmldoc2_put_onkeydown,
1108     htmldoc2_get_onkeydown,
1109     htmldoc2_put_onkeypress,
1110     htmldoc2_get_onkeypress,
1111     htmldoc2_put_onmouseup,
1112     htmldoc2_get_onmouseup,
1113     htmldoc2_put_onmousedown,
1114     htmldoc2_get_onmousedown,
1115     htmldoc2_put_onmousemove,
1116     htmldoc2_get_onmousemove,
1117     htmldoc2_put_onmouseout,
1118     htmldoc2_get_onmouseout,
1119     htmldoc2_put_onmouseover,
1120     htmldoc2_get_onmouseover,
1121     htmldoc2_put_onreadystatechange,
1122     htmldoc2_get_onreadystatechange,
1123     htmldoc2_put_onafterupdate,
1124     htmldoc2_get_onafterupdate,
1125     htmldoc2_put_onrowexit,
1126     htmldoc2_get_onrowexit,
1127     htmldoc2_put_onrowenter,
1128     htmldoc2_get_onrowenter,
1129     htmldoc2_put_ondragstart,
1130     htmldoc2_get_ondragstart,
1131     htmldoc2_put_onselectstart,
1132     htmldoc2_get_onselectstart,
1133     htmldoc2_elementFromPoint,
1134     htmldoc2_get_parentWindow,
1135     htmldoc2_get_styleSheets,
1136     htmldoc2_put_onbeforeupdate,
1137     htmldoc2_get_onbeforeupdate,
1138     htmldoc2_put_onerrorupdate,
1139     htmldoc2_get_onerrorupdate,
1140     htmldoc2_toString,
1141     htmldoc2_createStyleSheet
1142 };
1143
1144 typedef struct
1145 {
1146     IHTMLDocument2 IHTMLDocument2_iface;
1147 } testhtmldoc2_t;
1148
1149 static testhtmldoc2_t htmldoc2 = { { &TestHTMLDocumentVtbl } };
1150
1151 static HRESULT WINAPI sp_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppvObject)
1152 {
1153     *ppvObject = NULL;
1154
1155     if (IsEqualGUID(riid, &IID_IUnknown) ||
1156         IsEqualGUID(riid, &IID_IServiceProvider))
1157     {
1158         *ppvObject = iface;
1159         IServiceProvider_AddRef(iface);
1160         return S_OK;
1161     }
1162
1163     ok(0, "unexpected query interface: %s\n", debugstr_guid(riid));
1164
1165     return E_NOINTERFACE;
1166 }
1167
1168 static ULONG WINAPI sp_AddRef(IServiceProvider *iface)
1169 {
1170     return 2;
1171 }
1172
1173 static ULONG WINAPI sp_Release(IServiceProvider *iface)
1174 {
1175     return 1;
1176 }
1177
1178 static HRESULT WINAPI sp_QueryService(IServiceProvider *iface, REFGUID service, REFIID riid, void **obj)
1179 {
1180     *obj = NULL;
1181
1182     if (IsEqualGUID(service, &SID_SBindHost) &&
1183         IsEqualGUID(riid, &IID_IBindHost))
1184     {
1185         CHECK_EXPECT2(sp_queryservice_SID_SBindHost);
1186     }
1187     else if (IsEqualGUID(service, &SID_SContainerDispatch) &&
1188              IsEqualGUID(riid, &IID_IHTMLDocument2))
1189     {
1190         CHECK_EXPECT2(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1191     }
1192     else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1193              IsEqualGUID(riid, &IID_IHTMLDocument2))
1194     {
1195         CHECK_EXPECT2(sp_queryservice_SID_secmgr_htmldoc2);
1196         *obj = &htmldoc2.IHTMLDocument2_iface;
1197         return S_OK;
1198     }
1199     else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1200              IsEqualGUID(riid, &IID_IXMLDOMDocument))
1201     {
1202         CHECK_EXPECT2(sp_queryservice_SID_secmgr_xmldomdoc);
1203     }
1204     else if (IsEqualGUID(service, &SID_SInternetHostSecurityManager) &&
1205              IsEqualGUID(riid, &IID_IInternetHostSecurityManager))
1206     {
1207         CHECK_EXPECT2(sp_queryservice_SID_secmgr_secmgr);
1208     }
1209     else if (IsEqualGUID(service, &SID_UnknownSID) &&
1210              IsEqualGUID(riid, &IID_IStream))
1211     {
1212         /* FIXME: unidentified service id */
1213     }
1214     else
1215         ok(0, "unexpected request: sid %s, riid %s\n", debugstr_guid(service), debugstr_guid(riid));
1216
1217     return E_NOTIMPL;
1218 }
1219
1220 static const IServiceProviderVtbl testprovVtbl =
1221 {
1222     sp_QueryInterface,
1223     sp_AddRef,
1224     sp_Release,
1225     sp_QueryService
1226 };
1227
1228 testprov_t testprov = { { &testprovVtbl } };
1229
1230 typedef struct
1231 {
1232     IDispatch IDispatch_iface;
1233     LONG ref;
1234 } dispevent;
1235
1236 static inline dispevent *impl_from_IDispatch( IDispatch *iface )
1237 {
1238     return CONTAINING_RECORD(iface, dispevent, IDispatch_iface);
1239 }
1240
1241 static HRESULT WINAPI dispevent_QueryInterface(IDispatch *iface, REFIID riid, void **ppvObject)
1242 {
1243     *ppvObject = NULL;
1244
1245     if ( IsEqualGUID( riid, &IID_IDispatch) ||
1246          IsEqualGUID( riid, &IID_IUnknown) )
1247     {
1248         *ppvObject = iface;
1249     }
1250     else
1251         return E_NOINTERFACE;
1252
1253     IDispatch_AddRef( iface );
1254
1255     return S_OK;
1256 }
1257
1258 static ULONG WINAPI dispevent_AddRef(IDispatch *iface)
1259 {
1260     dispevent *This = impl_from_IDispatch( iface );
1261     return InterlockedIncrement( &This->ref );
1262 }
1263
1264 static ULONG WINAPI dispevent_Release(IDispatch *iface)
1265 {
1266     dispevent *This = impl_from_IDispatch( iface );
1267     ULONG ref = InterlockedDecrement( &This->ref );
1268
1269     if (ref == 0)
1270         HeapFree(GetProcessHeap(), 0, This);
1271
1272     return ref;
1273 }
1274
1275 static HRESULT WINAPI dispevent_GetTypeInfoCount(IDispatch *iface, UINT *pctinfo)
1276 {
1277     g_unexpectedcall++;
1278     *pctinfo = 0;
1279     return S_OK;
1280 }
1281
1282 static HRESULT WINAPI dispevent_GetTypeInfo(IDispatch *iface, UINT iTInfo,
1283         LCID lcid, ITypeInfo **ppTInfo)
1284 {
1285     g_unexpectedcall++;
1286     return S_OK;
1287 }
1288
1289 static HRESULT WINAPI dispevent_GetIDsOfNames(IDispatch *iface, REFIID riid,
1290         LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1291 {
1292     g_unexpectedcall++;
1293     return S_OK;
1294 }
1295
1296 static HRESULT WINAPI dispevent_Invoke(IDispatch *iface, DISPID member, REFIID riid,
1297         LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result,
1298         EXCEPINFO *excepInfo, UINT *argErr)
1299 {
1300     ok(member == 0, "expected 0 member, got %d\n", member);
1301     ok(lcid == LOCALE_SYSTEM_DEFAULT, "expected LOCALE_SYSTEM_DEFAULT, got lcid %x\n", lcid);
1302     ok(flags == DISPATCH_METHOD, "expected DISPATCH_METHOD, got %d\n", flags);
1303
1304     ok(params->cArgs == 0, "got %d\n", params->cArgs);
1305     ok(params->cNamedArgs == 0, "got %d\n", params->cNamedArgs);
1306     ok(params->rgvarg == NULL, "got %p\n", params->rgvarg);
1307     ok(params->rgdispidNamedArgs == NULL, "got %p\n", params->rgdispidNamedArgs);
1308
1309     ok(result == NULL, "got %p\n", result);
1310     ok(excepInfo == NULL, "got %p\n", excepInfo);
1311     ok(argErr == NULL, "got %p\n", argErr);
1312
1313     g_expectedcall++;
1314     return E_FAIL;
1315 }
1316
1317 static const IDispatchVtbl dispeventVtbl =
1318 {
1319     dispevent_QueryInterface,
1320     dispevent_AddRef,
1321     dispevent_Release,
1322     dispevent_GetTypeInfoCount,
1323     dispevent_GetTypeInfo,
1324     dispevent_GetIDsOfNames,
1325     dispevent_Invoke
1326 };
1327
1328 static IDispatch* create_dispevent(void)
1329 {
1330     dispevent *event = HeapAlloc(GetProcessHeap(), 0, sizeof(*event));
1331
1332     event->IDispatch_iface.lpVtbl = &dispeventVtbl;
1333     event->ref = 1;
1334
1335     return (IDispatch*)&event->IDispatch_iface;
1336 }
1337
1338 static IXMLHttpRequest *create_xhr(void)
1339 {
1340     IXMLHttpRequest *ret;
1341     HRESULT hr;
1342
1343     hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL, CLSCTX_INPROC_SERVER,
1344         &IID_IXMLHttpRequest, (void**)&ret);
1345
1346     return SUCCEEDED(hr) ? ret : NULL;
1347 }
1348
1349 static void set_safety_opt(IUnknown *unk, DWORD mask, DWORD opts)
1350 {
1351     IObjectSafety *obj_safety;
1352     HRESULT hr;
1353
1354     hr = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&obj_safety);
1355     ok(hr == S_OK, "Could not get IObjectSafety iface: %08x\n", hr);
1356
1357     hr = IObjectSafety_SetInterfaceSafetyOptions(obj_safety, &IID_IDispatch, mask, mask&opts);
1358     ok(hr == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hr);
1359
1360     IObjectSafety_Release(obj_safety);
1361 }
1362
1363 static void set_xhr_site(IXMLHttpRequest *xhr)
1364 {
1365     IObjectWithSite *obj_site;
1366     HRESULT hr;
1367
1368     hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
1369     ok(hr == S_OK, "Could not get IObjectWithSite iface: %08x\n", hr);
1370
1371     SET_EXPECT(site_qi_IServiceProvider);
1372     SET_EXPECT(sp_queryservice_SID_SBindHost);
1373     SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1374     SET_EXPECT(sp_queryservice_SID_secmgr_htmldoc2);
1375     SET_EXPECT(sp_queryservice_SID_secmgr_xmldomdoc);
1376     SET_EXPECT(sp_queryservice_SID_secmgr_secmgr);
1377
1378     /* calls to IHTMLDocument2 */
1379     SET_EXPECT(htmldoc2_get_all);
1380     SET_EXPECT(collection_get_length);
1381     SET_EXPECT(htmldoc2_get_url);
1382
1383     SET_EXPECT(site_qi_IXMLDOMDocument);
1384     SET_EXPECT(site_qi_IOleClientSite);
1385
1386     hr = IObjectWithSite_SetSite(obj_site, &testsite.IUnknown_iface);
1387     EXPECT_HR(hr, S_OK);
1388
1389     CHECK_CALLED(site_qi_IServiceProvider);
1390 todo_wine
1391     CHECK_CALLED(sp_queryservice_SID_SBindHost);
1392     CHECK_CALLED(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1393 todo_wine {
1394     CHECK_CALLED(sp_queryservice_SID_secmgr_htmldoc2);
1395     CHECK_CALLED(sp_queryservice_SID_secmgr_xmldomdoc);
1396     /* this one isn't very reliable
1397     CHECK_CALLED(sp_queryservice_SID_secmgr_secmgr); */
1398
1399     CHECK_CALLED(htmldoc2_get_all);
1400     CHECK_CALLED(collection_get_length);
1401     CHECK_CALLED(htmldoc2_get_url);
1402
1403     CHECK_CALLED(site_qi_IXMLDOMDocument);
1404     CHECK_CALLED(site_qi_IOleClientSite);
1405 }
1406
1407     IObjectWithSite_Release(obj_site);
1408 }
1409
1410 #define test_open(a,b,c,d) _test_open(__LINE__,a,b,c,d)
1411 static void _test_open(unsigned line, IXMLHttpRequest *xhr, const char *method, const char *url, HRESULT exhres)
1412 {
1413     VARIANT empty, vfalse;
1414     HRESULT hr;
1415
1416     V_VT(&empty) = VT_EMPTY;
1417     V_VT(&vfalse) = VT_BOOL;
1418     V_BOOL(&vfalse) = VARIANT_FALSE;
1419
1420     hr = IXMLHttpRequest_open(xhr, _bstr_(method), _bstr_(url), vfalse, empty, empty);
1421     ok_(__FILE__,line)(hr == exhres, "open(%s %s) failed: %08x, expected %08x\n", method, url, hr, exhres);
1422 }
1423
1424 static void test_XMLHTTP(void)
1425 {
1426     static const char bodyA[] = "mode=Test";
1427     static const char urlA[] = "http://crossover.codeweavers.com/posttest.php";
1428     static const char xmltestA[] = "http://crossover.codeweavers.com/xmltest.xml";
1429     static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
1430     static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
1431
1432     IXMLHttpRequest *xhr;
1433     IObjectWithSite *obj_site, *obj_site2;
1434     BSTR bstrResponse, str, str1;
1435     VARIANT varbody, varbody_ref;
1436     VARIANT dummy;
1437     LONG state, status, bound;
1438     IDispatch *event;
1439     void *ptr;
1440     HRESULT hr;
1441     HGLOBAL g;
1442
1443     xhr = create_xhr();
1444
1445     VariantInit(&dummy);
1446     V_VT(&dummy) = VT_ERROR;
1447     V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
1448
1449     hr = IXMLHttpRequest_put_onreadystatechange(xhr, NULL);
1450     EXPECT_HR(hr, S_OK);
1451
1452     hr = IXMLHttpRequest_abort(xhr);
1453     EXPECT_HR(hr, S_OK);
1454
1455     V_VT(&varbody) = VT_I2;
1456     V_I2(&varbody) = 1;
1457     hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
1458     EXPECT_HR(hr, E_PENDING);
1459     ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody));
1460     ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody));
1461
1462     V_VT(&varbody) = VT_I2;
1463     V_I2(&varbody) = 1;
1464     hr = IXMLHttpRequest_get_responseStream(xhr, &varbody);
1465     EXPECT_HR(hr, E_PENDING);
1466     ok(V_VT(&varbody) == VT_EMPTY, "got type %d\n", V_VT(&varbody));
1467     ok(V_I2(&varbody) == 1, "got %d\n", V_I2(&varbody));
1468
1469     /* send before open */
1470     hr = IXMLHttpRequest_send(xhr, dummy);
1471     ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1472
1473     /* initial status code */
1474     hr = IXMLHttpRequest_get_status(xhr, NULL);
1475     EXPECT_HR(hr, E_INVALIDARG);
1476
1477     status = 0xdeadbeef;
1478     hr = IXMLHttpRequest_get_status(xhr, &status);
1479     ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1480     ok(status == 0xdeadbeef, "got %d\n", status);
1481
1482     hr = IXMLHttpRequest_get_statusText(xhr, &str);
1483     ok(hr == E_FAIL, "got 0x%08x\n", hr);
1484
1485     /* invalid parameters */
1486     test_open(xhr, NULL, NULL, E_INVALIDARG);
1487     test_open(xhr, "POST", NULL, E_INVALIDARG);
1488     test_open(xhr, NULL, urlA, E_INVALIDARG);
1489
1490     hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, NULL);
1491     EXPECT_HR(hr, E_INVALIDARG);
1492
1493     hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), NULL);
1494     ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1495
1496     hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
1497     EXPECT_HR(hr, E_INVALIDARG);
1498
1499     hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
1500     ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1501
1502     hr = IXMLHttpRequest_get_readyState(xhr, NULL);
1503     EXPECT_HR(hr, E_INVALIDARG);
1504
1505     state = -1;
1506     hr = IXMLHttpRequest_get_readyState(xhr, &state);
1507     EXPECT_HR(hr, S_OK);
1508     ok(state == READYSTATE_UNINITIALIZED, "got %d, expected READYSTATE_UNINITIALIZED\n", state);
1509
1510     event = create_dispevent();
1511
1512     EXPECT_REF(event, 1);
1513     hr = IXMLHttpRequest_put_onreadystatechange(xhr, event);
1514     EXPECT_HR(hr, S_OK);
1515     EXPECT_REF(event, 2);
1516
1517     g_unexpectedcall = g_expectedcall = 0;
1518
1519     test_open(xhr, "POST", urlA, S_OK);
1520
1521     ok(g_unexpectedcall == 0, "unexpected disp event call\n");
1522     ok(g_expectedcall == 1 || broken(g_expectedcall == 0) /* win2k */, "no expected disp event call\n");
1523
1524     /* status code after ::open() */
1525     status = 0xdeadbeef;
1526     hr = IXMLHttpRequest_get_status(xhr, &status);
1527     ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1528     ok(status == 0xdeadbeef, "got %d\n", status);
1529
1530     state = -1;
1531     hr = IXMLHttpRequest_get_readyState(xhr, &state);
1532     EXPECT_HR(hr, S_OK);
1533     ok(state == READYSTATE_LOADING, "got %d, expected READYSTATE_LOADING\n", state);
1534
1535     hr = IXMLHttpRequest_abort(xhr);
1536     EXPECT_HR(hr, S_OK);
1537
1538     state = -1;
1539     hr = IXMLHttpRequest_get_readyState(xhr, &state);
1540     EXPECT_HR(hr, S_OK);
1541     ok(state == READYSTATE_UNINITIALIZED || broken(state == READYSTATE_LOADING) /* win2k */,
1542         "got %d, expected READYSTATE_UNINITIALIZED\n", state);
1543
1544     test_open(xhr, "POST", urlA, S_OK);
1545
1546     hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_("header1"), _bstr_("value1"));
1547     EXPECT_HR(hr, S_OK);
1548
1549     hr = IXMLHttpRequest_setRequestHeader(xhr, NULL, _bstr_("value1"));
1550     EXPECT_HR(hr, E_INVALIDARG);
1551
1552     hr = IXMLHttpRequest_setRequestHeader(xhr, _bstr_(""), _bstr_("value1"));
1553     EXPECT_HR(hr, E_INVALIDARG);
1554
1555     V_VT(&varbody) = VT_BSTR;
1556     V_BSTR(&varbody) = _bstr_(bodyA);
1557
1558     hr = IXMLHttpRequest_send(xhr, varbody);
1559     if (hr == INET_E_RESOURCE_NOT_FOUND)
1560     {
1561         skip("No connection could be made with crossover.codeweavers.com\n");
1562         IXMLHttpRequest_Release(xhr);
1563         return;
1564     }
1565     EXPECT_HR(hr, S_OK);
1566
1567     /* response headers */
1568     hr = IXMLHttpRequest_getAllResponseHeaders(xhr, NULL);
1569     EXPECT_HR(hr, E_INVALIDARG);
1570     hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str);
1571     EXPECT_HR(hr, S_OK);
1572     /* status line is stripped already */
1573     ok(memcmp(str, _bstr_("HTTP"), 4*sizeof(WCHAR)), "got response headers %s\n", wine_dbgstr_w(str));
1574     ok(*str, "got empty headers\n");
1575     hr = IXMLHttpRequest_getAllResponseHeaders(xhr, &str1);
1576     EXPECT_HR(hr, S_OK);
1577     ok(str1 != str, "got %p\n", str1);
1578     SysFreeString(str1);
1579     SysFreeString(str);
1580
1581     hr = IXMLHttpRequest_getResponseHeader(xhr, NULL, NULL);
1582     EXPECT_HR(hr, E_INVALIDARG);
1583     hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), NULL);
1584     EXPECT_HR(hr, E_INVALIDARG);
1585     hr = IXMLHttpRequest_getResponseHeader(xhr, _bstr_("Date"), &str);
1586     EXPECT_HR(hr, S_OK);
1587     ok(*str != ' ', "got leading space in header %s\n", wine_dbgstr_w(str));
1588     SysFreeString(str);
1589
1590     /* status code after ::send() */
1591     status = 0xdeadbeef;
1592     hr = IXMLHttpRequest_get_status(xhr, &status);
1593     EXPECT_HR(hr, S_OK);
1594     ok(status == 200, "got %d\n", status);
1595
1596     hr = IXMLHttpRequest_get_statusText(xhr, NULL);
1597     EXPECT_HR(hr, E_INVALIDARG);
1598
1599     hr = IXMLHttpRequest_get_statusText(xhr, &str);
1600     EXPECT_HR(hr, S_OK);
1601     ok(!lstrcmpW(str, _bstr_("OK")), "got status %s\n", wine_dbgstr_w(str));
1602     SysFreeString(str);
1603
1604     /* another ::send() after completed request */
1605     V_VT(&varbody) = VT_BSTR;
1606     V_BSTR(&varbody) = _bstr_(bodyA);
1607
1608     hr = IXMLHttpRequest_send(xhr, varbody);
1609     ok(hr == E_FAIL || broken(hr == E_UNEXPECTED) /* win2k */, "got 0x%08x\n", hr);
1610
1611     hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
1612     EXPECT_HR(hr, S_OK);
1613     /* the server currently returns "FAILED" because the Content-Type header is
1614      * not what the server expects */
1615     if(hr == S_OK)
1616     {
1617         ok(!memcmp(bstrResponse, wszExpectedResponse, sizeof(wszExpectedResponse)),
1618             "expected %s, got %s\n", wine_dbgstr_w(wszExpectedResponse), wine_dbgstr_w(bstrResponse));
1619         SysFreeString(bstrResponse);
1620     }
1621
1622     /* POST: VT_VARIANT|VT_BYREF body */
1623     test_open(xhr, "POST", urlA, S_OK);
1624
1625     V_VT(&varbody_ref) = VT_VARIANT|VT_BYREF;
1626     V_VARIANTREF(&varbody_ref) = &varbody;
1627     hr = IXMLHttpRequest_send(xhr, varbody_ref);
1628     EXPECT_HR(hr, S_OK);
1629
1630     /* GET request */
1631     test_open(xhr, "GET", xmltestA, S_OK);
1632
1633     V_VT(&varbody) = VT_EMPTY;
1634
1635     hr = IXMLHttpRequest_send(xhr, varbody);
1636     if (hr == INET_E_RESOURCE_NOT_FOUND)
1637     {
1638         skip("No connection could be made with crossover.codeweavers.com\n");
1639         IXMLHttpRequest_Release(xhr);
1640         return;
1641     }
1642     EXPECT_HR(hr, S_OK);
1643
1644     hr = IXMLHttpRequest_get_responseText(xhr, NULL);
1645     EXPECT_HR(hr, E_INVALIDARG);
1646
1647     hr = IXMLHttpRequest_get_responseText(xhr, &bstrResponse);
1648     EXPECT_HR(hr, S_OK);
1649     ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
1650         "expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
1651     SysFreeString(bstrResponse);
1652
1653     hr = IXMLHttpRequest_get_responseBody(xhr, NULL);
1654     EXPECT_HR(hr, E_INVALIDARG);
1655
1656     V_VT(&varbody) = VT_EMPTY;
1657     hr = IXMLHttpRequest_get_responseBody(xhr, &varbody);
1658     EXPECT_HR(hr, S_OK);
1659     ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
1660     ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
1661
1662     bound = -1;
1663     hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
1664     EXPECT_HR(hr, S_OK);
1665     ok(bound == 0, "got %d, expected zero bound\n", bound);
1666
1667     hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
1668     EXPECT_HR(hr, S_OK);
1669     ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrong body data\n");
1670     SafeArrayUnaccessData(V_ARRAY(&varbody));
1671
1672     VariantClear(&varbody);
1673
1674     /* get_responseStream */
1675     hr = IXMLHttpRequest_get_responseStream(xhr, NULL);
1676     EXPECT_HR(hr, E_INVALIDARG);
1677
1678     V_VT(&varbody) = VT_EMPTY;
1679     hr = IXMLHttpRequest_get_responseStream(xhr, &varbody);
1680     ok(V_VT(&varbody) == VT_UNKNOWN, "got type %d\n", V_VT(&varbody));
1681     EXPECT_HR(hr, S_OK);
1682     EXPECT_REF(V_UNKNOWN(&varbody), 1);
1683
1684     g = NULL;
1685     hr = GetHGlobalFromStream((IStream*)V_UNKNOWN(&varbody), &g);
1686     EXPECT_HR(hr, S_OK);
1687     ok(g != NULL, "got %p\n", g);
1688
1689     IDispatch_Release(event);
1690
1691     /* interaction with object site */
1692     EXPECT_REF(xhr, 1);
1693     hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site);
1694     EXPECT_HR(hr, S_OK);
1695 todo_wine {
1696     EXPECT_REF(xhr, 1);
1697     EXPECT_REF(obj_site, 1);
1698 }
1699
1700     hr = IObjectWithSite_SetSite(obj_site, NULL);
1701     ok(hr == S_OK, "got 0x%08x\n", hr);
1702
1703     IObjectWithSite_AddRef(obj_site);
1704 todo_wine {
1705     EXPECT_REF(obj_site, 2);
1706     EXPECT_REF(xhr, 1);
1707 }
1708     IObjectWithSite_Release(obj_site);
1709
1710     hr = IXMLHttpRequest_QueryInterface(xhr, &IID_IObjectWithSite, (void**)&obj_site2);
1711     EXPECT_HR(hr, S_OK);
1712 todo_wine {
1713     EXPECT_REF(xhr, 1);
1714     EXPECT_REF(obj_site, 1);
1715     EXPECT_REF(obj_site2, 1);
1716     ok(obj_site != obj_site2, "expected new instance\n");
1717 }
1718     IObjectWithSite_Release(obj_site);
1719
1720     set_xhr_site(xhr);
1721
1722     /* try to set site another time */
1723
1724     /* to be removed once IObjectWithSite is properly separated */
1725     SET_EXPECT(site_qi_IServiceProvider);
1726     SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1727
1728     hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
1729     EXPECT_HR(hr, S_OK);
1730
1731     todo_wine EXPECT_REF(xhr, 1);
1732     IXMLHttpRequest_Release(xhr);
1733
1734     /* still works after request is released */
1735
1736     /* to be removed once IObjectWithSite is properly separated */
1737     SET_EXPECT(site_qi_IServiceProvider);
1738     SET_EXPECT(sp_queryservice_SID_SContainerDispatch_htmldoc2);
1739
1740     hr = IObjectWithSite_SetSite(obj_site2, &testsite.IUnknown_iface);
1741     EXPECT_HR(hr, S_OK);
1742     IObjectWithSite_Release(obj_site2);
1743
1744     free_bstrs();
1745 }
1746
1747 static void test_safe_httpreq(void)
1748 {
1749     IXMLHttpRequest *xhr;
1750
1751     xhr = create_xhr();
1752
1753     set_safety_opt((IUnknown*)xhr, INTERFACESAFE_FOR_UNTRUSTED_DATA, -1);
1754     set_xhr_site(xhr);
1755
1756     /* different scheme */
1757     test_open(xhr, "GET", "https://test.winehq.org/tests/hello.html", E_ACCESSDENIED);
1758
1759     /* different host */
1760     test_open(xhr, "GET", "http://tests.winehq.org/tests/hello.html", E_ACCESSDENIED);
1761     test_open(xhr, "GET", "http://www.test.winehq.org/tests/hello.html", E_ACCESSDENIED);
1762
1763     IXMLHttpRequest_Release(xhr);
1764 }
1765
1766 START_TEST(httpreq)
1767 {
1768     IXMLHttpRequest *xhr;
1769
1770     CoInitialize(NULL);
1771
1772     if((xhr = create_xhr())) {
1773         IXMLHttpRequest_Release(xhr);
1774
1775         test_XMLHTTP();
1776         test_safe_httpreq();
1777     }else {
1778         win_skip("IXMLHTTPRequest is not available\n");
1779     }
1780
1781     CoUninitialize();
1782 }