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