msvcrt: Resolve symbols clashes with FreeBSD libc.
[wine] / dlls / mshtml / tests / dom.c
1 /*
2  * Copyright 2007 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20 #define CONST_VTABLE
21
22 #include <wine/test.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "ole2.h"
29 #include "mshtml.h"
30 #include "docobj.h"
31
32 static const char doc_blank[] = "<html></html>";
33 static const char doc_str1[] = "<html><body>test</body></html>";
34 static const char doc_str2[] =
35     "<html><body>test a<font size=\"2\">bc 123<br />it's </font>text<br /></body></html>";
36
37 static const WCHAR noneW[] = {'N','o','n','e',0};
38
39 static WCHAR characterW[] = {'c','h','a','r','a','c','t','e','r',0};
40 static WCHAR wordW[] = {'w','o','r','d',0};
41
42 static const char *dbgstr_w(LPCWSTR str)
43 {
44     static char buf[512];
45     if(!str)
46         return "(null)";
47     WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
48     return buf;
49 }
50
51 static int strcmp_wa(LPCWSTR strw, const char *stra)
52 {
53     WCHAR buf[512];
54     MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
55     return lstrcmpW(strw, buf);
56 }
57
58 static IHTMLDocument2 *create_document(void)
59 {
60     IHTMLDocument2 *doc;
61     HRESULT hres;
62
63     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
64             &IID_IHTMLDocument2, (void**)&doc);
65     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
66
67     return doc;
68 }
69
70 #define test_node_name(u,n) _test_node_name(__LINE__,u,n)
71 static void _test_node_name(unsigned line, IUnknown *unk, const char *exname)
72 {
73     IHTMLDOMNode *node;
74     BSTR name;
75     HRESULT hres;
76
77     hres = IUnknown_QueryInterface(unk, &IID_IHTMLDOMNode, (void**)&node);
78     ok_(__FILE__, line) (hres == S_OK, "QueryInterface(IID_IHTMLNode) failed: %08x\n", hres);
79
80     hres = IHTMLDOMNode_get_nodeName(node, &name);
81     IHTMLDOMNode_Release(node);
82     ok_(__FILE__, line) (hres == S_OK, "get_nodeName failed: %08x\n", hres);
83     ok_(__FILE__, line) (!strcmp_wa(name, exname), "got name: %s, expected HTML\n", dbgstr_w(name));
84
85     SysFreeString(name);
86 }
87
88 static void test_doc_elem(IHTMLDocument2 *doc)
89 {
90     IHTMLElement *elem;
91     IHTMLDocument3 *doc3;
92     HRESULT hres;
93
94     hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument3, (void**)&doc3);
95     ok(hres == S_OK, "QueryInterface(IID_IHTMLDocument3) failed: %08x\n", hres);
96
97     hres = IHTMLDocument3_get_documentElement(doc3, &elem);
98     IHTMLDocument3_Release(doc3);
99     ok(hres == S_OK, "get_documentElement failed: %08x\n", hres);
100
101     test_node_name((IUnknown*)elem, "HTML");
102
103     IHTMLElement_Release(elem);
104 }
105
106 #define test_range_text(r,t) _test_range_text(__LINE__,r,t)
107 static void _test_range_text(unsigned line, IHTMLTxtRange *range, const char *extext)
108 {
109     BSTR text;
110     HRESULT hres;
111
112     hres = IHTMLTxtRange_get_text(range, &text);
113     ok_(__FILE__, line) (hres == S_OK, "get_text failed: %08x\n", hres);
114
115     if(extext) {
116         ok_(__FILE__, line) (text != NULL, "text == NULL\n");
117         ok_(__FILE__, line) (!strcmp_wa(text, extext), "text=\"%s\", expected \"%s\"\n", dbgstr_w(text), extext);
118     }else {
119         ok_(__FILE__, line) (text == NULL, "text=\"%s\", expected NULL\n", dbgstr_w(text));
120     }
121
122     SysFreeString(text);
123
124 }
125
126 #define test_range_collapse(r,b) _test_range_collapse(__LINE__,r,b)
127 static void _test_range_collapse(unsigned line, IHTMLTxtRange *range, BOOL b)
128 {
129     HRESULT hres;
130
131     hres = IHTMLTxtRange_collapse(range, b);
132     ok_(__FILE__, line) (hres == S_OK, "collapse failed: %08x\n", hres);
133     _test_range_text(line, range, NULL);
134 }
135
136 #define test_range_expand(r,u,b,t) _test_range_expand(__LINE__,r,u,b,t)
137 static void _test_range_expand(unsigned line, IHTMLTxtRange *range, LPWSTR unit,
138         VARIANT_BOOL exb, const char *extext)
139 {
140     VARIANT_BOOL b = 0xe0e0;
141     HRESULT hres;
142
143     hres = IHTMLTxtRange_expand(range, unit, &b);
144     ok_(__FILE__,line) (hres == S_OK, "expand failed: %08x\n", hres);
145     ok_(__FILE__,line) (b == exb, "b=%x, expected %x\n", b, exb);
146     _test_range_text(line, range, extext);
147 }
148
149 #define test_range_move(r,u,c,e) _test_range_move(__LINE__,r,u,c,e)
150 static void _test_range_move(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
151 {
152     long c = 0xdeadbeef;
153     HRESULT hres;
154
155     hres = IHTMLTxtRange_move(range, unit, cnt, &c);
156     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
157     ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
158     _test_range_text(line, range, NULL);
159 }
160
161 #define test_range_moveend(r,u,c,e) _test_range_moveend(__LINE__,r,u,c,e)
162 static void _test_range_moveend(unsigned line, IHTMLTxtRange *range, LPWSTR unit, long cnt, long excnt)
163 {
164     long c = 0xdeadbeef;
165     HRESULT hres;
166
167     hres = IHTMLTxtRange_moveEnd(range, unit, cnt, &c);
168     ok_(__FILE__,line) (hres == S_OK, "move failed: %08x\n", hres);
169     ok_(__FILE__,line) (c == excnt, "count=%ld, expected %ld\n", c, excnt);
170 }
171
172 #define test_range_put_text(r,t) _test_range_put_text(__LINE__,r,t)
173 static void _test_range_put_text(unsigned line, IHTMLTxtRange *range, LPCWSTR text)
174 {
175     HRESULT hres;
176
177     hres = IHTMLTxtRange_put_text(range, (BSTR)text);
178     ok_(__FILE__,line) (hres == S_OK, "put_text failed: %08x\n", hres);
179     _test_range_text(line, range, NULL);
180 }
181
182 #define test_range_inrange(r1,r2,b) _test_range_inrange(__LINE__,r1,r2,b)
183 static void _test_range_inrange(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
184 {
185     VARIANT_BOOL b;
186     HRESULT hres;
187
188     b = 0xe0e0;
189     hres = IHTMLTxtRange_inRange(range1, range2, &b);
190     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
191     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
192 }
193
194 #define test_range_isequal(r1,r2,b) _test_range_isequal(__LINE__,r1,r2,b)
195 static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRange *range2, VARIANT_BOOL exb)
196 {
197     VARIANT_BOOL b;
198     HRESULT hres;
199
200     b = 0xe0e0;
201     hres = IHTMLTxtRange_isEqual(range1, range2, &b);
202     ok_(__FILE__,line) (hres == S_OK, "(1->2) isEqual failed: %08x\n", hres);
203     ok_(__FILE__,line) (b == exb, "(1->2) b=%x, expected %x\n", b, exb);
204
205     b = 0xe0e0;
206     hres = IHTMLTxtRange_isEqual(range2, range1, &b);
207     ok_(__FILE__,line) (hres == S_OK, "(2->1) isEqual failed: %08x\n", hres);
208     ok_(__FILE__,line) (b == exb, "(2->1) b=%x, expected %x\n", b, exb);
209
210     if(exb) {
211         test_range_inrange(range1, range2, VARIANT_TRUE);
212         test_range_inrange(range2, range1, VARIANT_TRUE);
213     }
214 }
215
216 static void test_txtrange(IHTMLDocument2 *doc)
217 {
218     IHTMLElement *elem;
219     IHTMLBodyElement *body;
220     IHTMLTxtRange *body_range, *range, *range2;
221     HRESULT hres;
222
223     hres = IHTMLDocument2_get_body(doc, &elem);
224     ok(hres == S_OK, "get_body failed: %08x\n", hres);
225
226     hres = IHTMLElement_QueryInterface(elem, &IID_IHTMLBodyElement, (void**)&body);
227     IHTMLElement_Release(elem);
228
229     hres = IHTMLBodyElement_createTextRange(body, &body_range);
230     IHTMLBodyElement_Release(body);
231     ok(hres == S_OK, "createTextRange failed: %08x\n", hres);
232
233     test_range_text(body_range, "test abc 123\r\nit's text");
234
235     hres = IHTMLTxtRange_duplicate(body_range, &range);
236     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
237
238     hres = IHTMLTxtRange_duplicate(body_range, &range2);
239     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
240     test_range_isequal(range, range2, VARIANT_TRUE);
241
242     test_range_text(range, "test abc 123\r\nit's text");
243     test_range_text(body_range, "test abc 123\r\nit's text");
244
245     test_range_collapse(range, TRUE);
246     test_range_isequal(range, range2, VARIANT_FALSE);
247     test_range_inrange(range, range2, VARIANT_FALSE);
248     test_range_inrange(range2, range, VARIANT_TRUE);
249     IHTMLTxtRange_Release(range2);
250
251     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
252     test_range_expand(range, wordW, VARIANT_FALSE, "test ");
253     test_range_move(range, characterW, 2, 2);
254     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
255
256     test_range_collapse(range, FALSE);
257     test_range_expand(range, wordW, VARIANT_TRUE, "abc ");
258
259     test_range_collapse(range, FALSE);
260     test_range_expand(range, wordW, VARIANT_TRUE, "123");
261     test_range_expand(range, wordW, VARIANT_FALSE, "123");
262     test_range_move(range, characterW, 2, 2);
263     test_range_expand(range, wordW, VARIANT_TRUE, "123");
264
265     IHTMLTxtRange_Release(range);
266
267     hres = IHTMLTxtRange_duplicate(body_range, &range);
268     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
269
270     test_range_text(range, "test abc 123\r\nit's text");
271     test_range_move(range, characterW, 3, 3);
272     test_range_moveend(range, characterW, 1, 1);
273     test_range_text(range, "t");
274     test_range_moveend(range, characterW, 3, 3);
275     test_range_text(range, "t ab");
276     test_range_moveend(range, characterW, -2, -2);
277     test_range_text(range, "t ");
278     test_range_move(range, characterW, 6, 6);
279     test_range_moveend(range, characterW, 3, 3);
280     test_range_text(range, "123");
281     test_range_moveend(range, characterW, 2, 2);
282     test_range_text(range, "123\r\ni");
283
284     IHTMLTxtRange_Release(range);
285
286     hres = IHTMLTxtRange_duplicate(body_range, &range);
287     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
288
289     test_range_move(range, wordW, 1, 1);
290     test_range_moveend(range, characterW, 2, 2);
291     test_range_text(range, "ab");
292
293     test_range_move(range, characterW, -2, -2);
294     test_range_moveend(range, characterW, 2, 2);
295     test_range_text(range, "t ");
296
297     test_range_move(range, wordW, 3, 3);
298     test_range_move(range, wordW, -2, -2);
299     test_range_moveend(range, characterW, 2, 2);
300     test_range_text(range, "ab");
301
302     test_range_move(range, characterW, -6, -5);
303     test_range_moveend(range, characterW, -1, 0);
304     test_range_moveend(range, characterW, -6, 0);
305     test_range_move(range, characterW, 2, 2);
306     test_range_moveend(range, characterW, 2, 2);
307     test_range_text(range, "st");
308     test_range_moveend(range, characterW, -6, -4);
309     test_range_moveend(range, characterW, 2, 2);
310
311     IHTMLTxtRange_Release(range);
312
313     hres = IHTMLTxtRange_duplicate(body_range, &range);
314     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
315
316     test_range_move(range, wordW, 2, 2);
317     test_range_moveend(range, characterW, 2, 2);
318     test_range_text(range, "12");
319
320     test_range_move(range, characterW, 15, 14);
321     test_range_move(range, characterW, -2, -2);
322     test_range_moveend(range, characterW, 3, 2);
323     test_range_text(range, "t");
324     test_range_moveend(range, characterW, -1, -1);
325     test_range_text(range, "t");
326     test_range_expand(range, wordW, VARIANT_TRUE, "text");
327     test_range_move(range, characterW, -2, -2);
328     test_range_moveend(range, characterW, 2, 2);
329     test_range_text(range, "s ");
330     test_range_move(range, characterW, 100, 7);
331     test_range_move(range, wordW, 1, 0);
332     test_range_move(range, characterW, -2, -2);
333     test_range_moveend(range, characterW, 3, 2);
334     test_range_text(range, "t");
335
336     IHTMLTxtRange_Release(range);
337
338     hres = IHTMLTxtRange_duplicate(body_range, &range);
339     ok(hres == S_OK, "duplicate failed: %08x\n", hres);
340
341     test_range_collapse(range, TRUE);
342     test_range_expand(range, wordW, VARIANT_TRUE, "test ");
343     test_range_put_text(range, wordW);
344     test_range_text(body_range, "wordabc 123\r\nit's text");
345
346     IHTMLTxtRange_Release(range);
347     IHTMLTxtRange_Release(body_range);
348 }
349
350 static void test_default_style(IHTMLStyle *style)
351 {
352     VARIANT_BOOL b;
353     VARIANT v;
354     BSTR str;
355     HRESULT hres;
356
357     str = (void*)0xdeadbeef;
358     hres = IHTMLStyle_get_fontFamily(style, &str);
359     ok(hres == S_OK, "get_fontFamily failed: %08x\n", hres);
360     ok(!str, "fontFamily = %s\n", dbgstr_w(str));
361
362     str = (void*)0xdeadbeef;
363     hres = IHTMLStyle_get_fontWeight(style, &str);
364     ok(hres == S_OK, "get_fontWeight failed: %08x\n", hres);
365     ok(!str, "fontWeight = %s\n", dbgstr_w(str));
366
367     V_VT(&v) = VT_NULL;
368     hres = IHTMLStyle_get_fontSize(style, &v);
369     ok(hres == S_OK, "get_fontSize failed: %08x\n", hres);
370     ok(V_VT(&v) == VT_BSTR, "V_VT(fontSize) = %d\n", V_VT(&v));
371     ok(!V_BSTR(&v), "V_BSTR(fontSize) = %s\n", dbgstr_w(V_BSTR(&v)));
372
373     V_VT(&v) = VT_NULL;
374     hres = IHTMLStyle_get_color(style, &v);
375     ok(hres == S_OK, "get_color failed: %08x\n", hres);
376     ok(V_VT(&v) == VT_BSTR, "V_VT(color) = %d\n", V_VT(&v));
377     ok(!V_BSTR(&v), "V_BSTR(color) = %s\n", dbgstr_w(V_BSTR(&v)));
378
379     b = 0xfefe;
380     hres = IHTMLStyle_get_textDecorationUnderline(style, &b);
381     ok(hres == S_OK, "get_textDecorationUnderline failed: %08x\n", hres);
382     ok(b == VARIANT_FALSE, "textDecorationUnderline = %x\n", b);
383
384     b = 0xfefe;
385     hres = IHTMLStyle_get_textDecorationLineThrough(style, &b);
386     ok(hres == S_OK, "get_textDecorationLineThrough failed: %08x\n", hres);
387     ok(b == VARIANT_FALSE, "textDecorationLineThrough = %x\n", b);
388 }
389
390 static void test_default_selection(IHTMLDocument2 *doc)
391 {
392     IHTMLSelectionObject *selection;
393     IHTMLTxtRange *range;
394     IDispatch *disp;
395     BSTR str;
396     HRESULT hres;
397
398     hres = IHTMLDocument2_get_selection(doc, &selection);
399     ok(hres == S_OK, "get_selection failed: %08x\n", hres);
400
401     hres = IHTMLSelectionObject_get_type(selection, &str);
402     ok(hres == S_OK, "get_type failed: %08x\n", hres);
403     ok(!lstrcmpW(str, noneW), "type = %s\n", dbgstr_w(str));
404     SysFreeString(str);
405
406     hres = IHTMLSelectionObject_createRange(selection, &disp);
407     IHTMLSelectionObject_Release(selection);
408     ok(hres == S_OK, "createRange failed: %08x\n", hres);
409
410     hres = IDispatch_QueryInterface(disp, &IID_IHTMLTxtRange, (void**)&range);
411     IDispatch_Release(disp);
412     ok(hres == S_OK, "Could not get IHTMLTxtRange interface: %08x\n", hres);
413
414     test_range_text(range, NULL);
415     IHTMLTxtRange_Release(range);
416 }
417
418 static void test_defaults(IHTMLDocument2 *doc)
419 {
420     IHTMLStyleSheetsCollection *stylesheetcol;
421     IHTMLElement *elem;
422     IHTMLStyle *style;
423     long l;
424     HRESULT hres;
425
426     hres = IHTMLDocument2_get_body(doc, &elem);
427     ok(hres == S_OK, "get_body failed: %08x\n", hres);
428
429     hres = IHTMLElement_get_style(elem, &style);
430     IHTMLElement_Release(elem);
431     ok(hres == S_OK, "get_style failed: %08x\n", hres);
432
433     test_default_style(style);
434
435     IHTMLStyle_Release(style);
436
437     hres = IHTMLDocument2_get_styleSheets(doc, &stylesheetcol);
438     ok(hres == S_OK, "get_styleSheets failed: %08x\n", hres);
439
440     l = 0xdeadbeef;
441     hres = IHTMLStyleSheetsCollection_get_length(stylesheetcol, &l);
442     ok(hres == S_OK, "get_length failed: %08x\n", hres);
443     ok(l == 0, "length = %ld\n", l);
444
445     IHTMLStyleSheetsCollection_Release(stylesheetcol);
446
447     test_default_selection(doc);
448 }
449
450 static IHTMLDocument2 *notif_doc;
451 static BOOL doc_complete;
452
453 static HRESULT WINAPI PropertyNotifySink_QueryInterface(IPropertyNotifySink *iface,
454         REFIID riid, void**ppv)
455 {
456     if(IsEqualGUID(&IID_IPropertyNotifySink, riid)) {
457         *ppv = iface;
458         return S_OK;
459     }
460
461     ok(0, "unexpected call\n");
462     return E_NOINTERFACE;
463 }
464
465 static ULONG WINAPI PropertyNotifySink_AddRef(IPropertyNotifySink *iface)
466 {
467     return 2;
468 }
469
470 static ULONG WINAPI PropertyNotifySink_Release(IPropertyNotifySink *iface)
471 {
472     return 1;
473 }
474
475 static HRESULT WINAPI PropertyNotifySink_OnChanged(IPropertyNotifySink *iface, DISPID dispID)
476 {
477     if(dispID == DISPID_READYSTATE){
478         BSTR state;
479         HRESULT hres;
480
481         static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
482
483         hres = IHTMLDocument2_get_readyState(notif_doc, &state);
484         ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
485
486         if(!lstrcmpW(state, completeW))
487             doc_complete = TRUE;
488
489         SysFreeString(state);        
490     }
491
492     return S_OK;
493 }
494
495 static HRESULT WINAPI PropertyNotifySink_OnRequestEdit(IPropertyNotifySink *iface, DISPID dispID)
496 {
497     ok(0, "unexpected call\n");
498     return E_NOTIMPL;
499 }
500
501 static IPropertyNotifySinkVtbl PropertyNotifySinkVtbl = {
502     PropertyNotifySink_QueryInterface,
503     PropertyNotifySink_AddRef,
504     PropertyNotifySink_Release,
505     PropertyNotifySink_OnChanged,
506     PropertyNotifySink_OnRequestEdit
507 };
508
509 static IPropertyNotifySink PropertyNotifySink = { &PropertyNotifySinkVtbl };
510
511 static IHTMLDocument2 *create_doc_with_string(const char *str)
512 {
513     IPersistStreamInit *init;
514     IStream *stream;
515     IHTMLDocument2 *doc;
516     HGLOBAL mem;
517     SIZE_T len;
518
519     notif_doc = doc = create_document();
520     if(!doc)
521         return NULL;
522
523     doc_complete = FALSE;
524     len = strlen(str);
525     mem = GlobalAlloc(0, len);
526     memcpy(mem, str, len);
527     CreateStreamOnHGlobal(mem, TRUE, &stream);
528
529     IHTMLDocument2_QueryInterface(doc, &IID_IPersistStreamInit, (void**)&init);
530
531     IPersistStreamInit_Load(init, stream);
532     IPersistStreamInit_Release(init);
533     IStream_Release(stream);
534
535     return doc;
536 }
537
538 static void do_advise(IUnknown *unk, REFIID riid, IUnknown *unk_advise)
539 {
540     IConnectionPointContainer *container;
541     IConnectionPoint *cp;
542     DWORD cookie;
543     HRESULT hres;
544
545     hres = IUnknown_QueryInterface(unk, &IID_IConnectionPointContainer, (void**)&container);
546     ok(hres == S_OK, "QueryInterface(IID_IConnectionPointContainer) failed: %08x\n", hres);
547
548     hres = IConnectionPointContainer_FindConnectionPoint(container, riid, &cp);
549     IConnectionPointContainer_Release(container);
550     ok(hres == S_OK, "FindConnectionPoint failed: %08x\n", hres);
551
552     hres = IConnectionPoint_Advise(cp, unk_advise, &cookie);
553     IConnectionPoint_Release(cp);
554     ok(hres == S_OK, "Advise failed: %08x\n", hres);
555 }
556
557 typedef void (*domtest_t)(IHTMLDocument2*);
558
559 static void run_domtest(const char *str, domtest_t test)
560 {
561     IHTMLDocument2 *doc;
562     ULONG ref;
563     MSG msg;
564
565     doc = create_doc_with_string(str);
566     do_advise((IUnknown*)doc, &IID_IPropertyNotifySink, (IUnknown*)&PropertyNotifySink);
567
568     while(!doc_complete && GetMessage(&msg, NULL, 0, 0)) {
569         TranslateMessage(&msg);
570         DispatchMessage(&msg);
571     }
572
573     test(doc);
574
575     ref = IHTMLDocument2_Release(doc);
576     ok(!ref, "ref = %d\n", ref);
577 }
578
579 static void gecko_installer_workaround(BOOL disable)
580 {
581     HKEY hkey;
582     DWORD res;
583
584     static BOOL has_url = FALSE;
585     static char url[2048];
586
587     if(!disable && !has_url)
588         return;
589
590     res = RegOpenKey(HKEY_CURRENT_USER, "Software\\Wine\\MSHTML", &hkey);
591     if(res != ERROR_SUCCESS)
592         return;
593
594     if(disable) {
595         DWORD type, size = sizeof(url);
596
597         res = RegQueryValueEx(hkey, "GeckoUrl", NULL, &type, (PVOID)url, &size);
598         if(res == ERROR_SUCCESS && type == REG_SZ)
599             has_url = TRUE;
600
601         RegDeleteValue(hkey, "GeckoUrl");
602     }else {
603         RegSetValueEx(hkey, "GeckoUrl", 0, REG_SZ, (PVOID)url, lstrlenA(url)+1);
604     }
605
606     RegCloseKey(hkey);
607 }
608
609 START_TEST(dom)
610 {
611     gecko_installer_workaround(TRUE);
612     CoInitialize(NULL);
613
614     run_domtest(doc_str1, test_doc_elem);
615     run_domtest(doc_str2, test_txtrange);
616     run_domtest(doc_blank, test_defaults);
617
618     CoUninitialize();
619     gecko_installer_workaround(FALSE);
620 }