source: trunk/icedtea-web/plugin/tests/LiveConnect/common.js

Last change on this file was 348, checked in by dmik, 13 years ago

vendor: Add icedtea-web v1.1.2 to current.

File size: 7.5 KB
Line 
1/*
2 * Commonly used functions
3 */
4
5 var cell, cellText; // reused
6
7 function updateTotals() {
8 document.getElementById("totals").innerHTML = "<table class=\"results\" width=\"100%\"><tr><th>Total tests run </th><th> Passed </th><th> Failed </th><th> Errors </th></tr>" +
9 "<tr><td>" + (passed+failed+errored) + " </td><td> " + passed + " </td><td> " + failed + " </td><td> " + errored + " </td></tr>";
10 }
11
12 function pass(row) {
13 cell = document.createElement("td");
14 cell.setAttribute("style","color:green;text-align:center;font-weight: bold");
15 cellText = document.createTextNode("passed");
16 cell.appendChild(cellText);
17 row.appendChild(cell);
18
19 passed++;
20 updateTotals();
21 }
22
23 function fail(row, reason) {
24 cell = document.createElement("td");
25 cell.setAttribute("style","color:red;text-align:center;font-weight: bold");
26 if (reason)
27 cellText = document.createTextNode(reason);
28 else
29 cellText = document.createTextNode("failed");
30 cell.appendChild(cellText);
31 row.appendChild(cell);
32
33 failed++;
34 updateTotals();
35 }
36
37 function error(type, expected, e, row) {
38
39 cell = document.createElement("td");
40 cell.setAttribute("style","color:red;text-align:center;font-weight: bold");
41 cell.setAttribute("colspan","5");
42 cellText = document.createTextNode("An error occurred when running this test: " + e);
43 cell.appendChild(cellText);
44 row.appendChild(cell);
45
46 errored++;
47 updateTotals();
48 }
49
50 function check(actual, expected, expectedtype, row) {
51 if (actual == expected) {
52 if (typeof(actual) == expectedtype) {
53 pass(row);
54 } else {
55 fail(row, "Type mismatch: " + typeof(actual) + " != " + expectedtype);
56 }
57 } else {
58 fail(row, "Failed: " + actual + " [" + typeof(actual) + "] != " + expected + " [" + typeof(expected) + "]");
59 }
60 }
61
62 function doTest() {
63
64 passed = 0;
65 failed = 0;
66 errored = 0;
67 document.getElementById("results").innerHTML = "";
68 updateTotals();
69
70 try {
71 if (document.getElementById("testForm").jsjget.checked == 1)
72 getMemberTests();
73
74 if (document.getElementById("testForm").jsjset.checked == 1)
75 setMemberTests();
76
77 if (document.getElementById("testForm").jsjfp.checked == 1)
78 fpCallTests();
79
80 if (document.getElementById("testForm").jsjfrt.checked == 1)
81 rtCallTests();
82
83 if (document.getElementById("testForm").jsjfr.checked == 1)
84 frCallTests();
85
86 if (document.getElementById("testForm").jsjtc.checked == 1)
87 typeCastingTests();
88
89 if (document.getElementById("testForm").jjsget.checked == 1)
90 jjsGetMemberTests();
91
92 if (document.getElementById("testForm").jjsset.checked == 1)
93 jjsSetMemberTests();
94
95 if (document.getElementById("testForm").jjcparam.checked == 1)
96 jjsCallParameterTests();
97
98 if (document.getElementById("testForm").jjcrt.checked == 1)
99 jjsCallReturnTypeTests();
100
101 if (document.getElementById("testForm").jjeval.checked == 1)
102 jjsEvalTests();
103 } catch (e) {
104 document.getElementById("results").innerHTML += "<font color=\"red\">ERROR:<BR>" + e;
105 }
106 }
107
108 function testAll() {
109 document.getElementById("testForm").jsjget.checked = 1;
110 document.getElementById("testForm").jsjset.checked = 1;
111 document.getElementById("testForm").jsjfp.checked = 1;
112 document.getElementById("testForm").jsjfrt.checked = 1;
113 document.getElementById("testForm").jsjfr.checked = 1;
114 document.getElementById("testForm").jsjtc.checked = 1;
115 document.getElementById("testForm").jjsget.checked = 1;
116 document.getElementById("testForm").jjsset.checked = 1;
117 document.getElementById("testForm").jjcparam.checked = 1;
118 document.getElementById("testForm").jjcrt.checked = 1;
119 document.getElementById("testForm").jjeval.checked = 1;
120
121 doTest();
122 }
123
124
125var intvar;
126var doublevar;
127var boolvar;
128var stringvar;
129var objectvar;
130var arrayvar;
131var arrayvar2;
132var setvar;
133
134function initVars() {
135 intvar = 1;
136 doublevar = 1.1;
137 boolvar = true;
138 stringvar = "stringvar";
139 objectvar = new PluginTest.Packages.DummyObject("DummyObject1");
140 arrayvar = new Array();
141 arrayvar[1] = 100;
142
143 arrayvar2 = new Array();
144 arrayvar2[1] = new Array();
145 arrayvar2[1][2] = 200;
146}
147
148function createResultTable(tbl, tblBody, columnNames) {
149 tbl.setAttribute("border", "5");
150 tbl.setAttribute("width", "100%");
151 tbl.setAttribute("class", "results");
152 row = document.createElement("tr");
153
154 for (var i=0; i < columnNames.length; i++) {
155 cell = document.createElement("th");
156 cellText = document.createTextNode(columnNames[i]);
157 cell.appendChild(cellText);
158 row.appendChild(cell);
159 }
160
161 tblBody.appendChild(row);
162 tbl.appendChild(tblBody);
163 document.getElementById("results").appendChild(tbl);
164}
165
166function addResult() {
167
168 var row = arguments[arguments.length-1];
169
170 // Different length arguments imply different width distributions
171
172 if (arguments.length == 4) {
173
174 cell = document.createElement("td");
175 cell.setAttribute("width","25%");
176 cellText = document.createTextNode(arguments[0]);
177 cell.appendChild(cellText);
178 row.appendChild(cell);
179
180 cell = document.createElement("td");
181 cell.setAttribute("width","20%");
182 cellText = document.createTextNode(arguments[1]);
183 cell.appendChild(cellText);
184 row.appendChild(cell);
185
186 cell = document.createElement("td");
187 cell.setAttribute("width","40%");
188 cellText = document.createTextNode(arguments[2]);
189 cell.appendChild(cellText);
190 row.appendChild(cell);
191
192 } else if (arguments.length == 5) {
193
194 cell = document.createElement("td");
195 cell.setAttribute("width","25%");
196 cellText = document.createTextNode(arguments[0]);
197 cell.appendChild(cellText);
198 row.appendChild(cell);
199
200 cell = document.createElement("td");
201 cell.setAttribute("width","20%");
202 cellText = document.createTextNode(arguments[1]);
203 cell.appendChild(cellText);
204 row.appendChild(cell);
205
206 cell = document.createElement("td");
207 cell.setAttribute("width","20%");
208 cellText = document.createTextNode(arguments[2]);
209 cell.appendChild(cellText);
210 row.appendChild(cell);
211
212 cell = document.createElement("td");
213 cell.setAttribute("width","20%");
214 cellText = document.createTextNode(arguments[3]);
215 cell.appendChild(cellText);
216 row.appendChild(cell);
217
218 }
219}
Note: See TracBrowser for help on using the repository browser.