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