mshtml: Added test of calling IDispatchEx properties.
[wine] / dlls / mshtml / tests / jstest.html
1 <html>
2 <head>
3 <script>
4 function ok(b,m) {
5     return external.ok(b, m);
6 }
7
8 function test_removeAttribute(e) {
9     ok(e.removeAttribute('nonexisting') === false, "removeAttribute('nonexisting') didn't return false");
10
11     e.title = "title";
12     ok(e.removeAttribute('title') === true, "removeAttribute('title') didn't return true");
13     ok(e.title === "", "e.title = " + e.title);
14     ok(("title" in e) === true, "title is not in e");
15
16     e["myattr"] = "test";
17     ok(e.removeAttribute('myattr') === true, "removeAttribute('myattr') didn't return true");
18     ok(e["myattr"] === undefined, "e['myattr'] = " + e['myattr']);
19     ok(("myattr" in e) === false, "myattr is in e");
20
21 }
22
23 function test_select_index() {
24     var s = document.getElementById("sel");
25
26     ok("0" in s, "'0' is not in s");
27     ok(s[0].text === "opt1", "s[0].text = " + s[0].text);
28     ok("1" in s, "'1 is not in s");
29     ok(s[1].text === "opt2", "s[1].text = " + s[1].text);
30     ok("2" in s, "'2' is in s");
31     ok(s[2] === null, "s[2] = " + s[2]);
32 }
33
34 function test_createDocumentFragment() {
35     var fragment = document.createDocumentFragment();
36
37     ok(typeof(fragment) === "object", "typeof(fragmend) = " + typeof(fragment));
38     ok(fragment.nodeType === 11, "fragment.nodeType = " + fragment.nodeType);
39     ok(fragment.nodeName === "#document-fragment", "fragment.nodeName = " + fragment.nodeName);
40
41     var cloned = fragment.cloneNode(true);
42     ok(cloned.nodeType === 11, "cloned.nodeType = " + cloned.nodeType);
43     ok(cloned.nodeName === "#document-fragment", "cloned.nodeName = " + cloned.nodeName);
44 }
45
46 function test_document_name_as_index() {
47     document.body.innerHTML = '<form name="formname"></form>';
48     var e = document.getElementById("formname");
49     ok(!!e, "e is null");
50
51     ok(document.formname === e, "document.formname != getElementById('formname')");
52     ok("formname" in document, "formname' is not in document");
53
54     document.body.removeChild(e);
55
56     ok(document.formname === undefined, "document.formname is not undefined");
57     ok(!("formname" in document), "formname' is in document");
58
59     document.body.innerHTML = '<form id="formid"></form>';
60     var e = document.getElementById("formid");
61     ok(!!e, "e is null");
62     ok(!("formid" in document), "formid is in document");
63
64     document.body.innerHTML = '<form name="formname"></form>';
65     ok("formname" in window, "formname' is not in window");
66     ok(typeof(window.formname) === "object", "typeof(window.formname) = " + typeof(window.formname));
67     window.formname = 1;
68     ok(window.formname === 1, "window.formname = " + window.formname);
69     formname = 2;
70     ok(window.formname === 2, "window.formname = " + window.formname);
71 }
72
73 function test_remove_style_attribute() {
74     var s = document.body.style, b;
75
76     s.somevar = "test";
77     b = s.removeAttribute("somevar", 1);
78     ok(b, "removeAttribute returned " + b + " expected true");
79     b = s.removeAttribute("somevar", 1);
80     ok(b === false, "removeAttribute returned " + b + " expected false");
81 }
82
83 function test_clone_node() {
84     var elem, cloned;
85
86     elem = document.getElementById("divid");
87     elem.style.filter = "alpha(opacity=50)";
88     ok(elem.style.filter === "alpha(opacity=50)", "elem.style.filter = " + elem.style.filter);
89
90     cloned = elem.cloneNode(true);
91     ok(cloned.style.filter === "alpha(opacity=50)", "cloned.style.filter = " + cloned.style.filter);
92 }
93
94 function test_getter_call() {
95     document.body.innerHTML = '<div id="divid"></div>';
96
97     var e = document.getElementById("divid");
98
99     e.myfunc = function(x) { this.myfinc_called = x; };
100     e.myfunc("test");
101     ok(e.myfinc_called === "test", "e.myfinc_called = " + e.myfinc_called);
102
103     e.onmousedown = function(x) { this.onmousedown_called = x; };
104     e.onmousedown("test");
105     ok(e.onmousedown_called === "test", "e.onmousedown_called = " + e.onmousedown_called);
106 }
107
108 var globalVar = false;
109
110 function runTest() {
111     obj = new Object();
112     ok(obj === window.obj, "obj !== window.obj");
113
114     ok(typeof(divid) === "object", "typeof(divid) = " + typeof(divid));
115
116     test_removeAttribute(document.getElementById("divid"));
117     test_removeAttribute(document.body);
118     test_select_index();
119     test_clone_node();
120     test_createDocumentFragment();
121     test_document_name_as_index();
122     test_remove_style_attribute();
123     test_getter_call();
124
125     var r = window.execScript("globalVar = true;");
126     ok(r === undefined, "execScript returned " + r);
127     ok(globalVar === true, "globalVar = " + globalVar);
128
129     external.reportSuccess();
130 }
131 </script>
132 <body onload="runTest();">
133 <div id="divid"></div>
134 <select id="sel">
135 <option>opt1</option>
136 <option>opt2</option>
137 </select>
138 </body>
139 </html>