1 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=javascript: */
3 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 /* Base object for javascript tests */
22 function JSTest(testF, checkF)
34 QueryInterface : function (iid)
36 if (iid.equals(nsCI.nsITest) ||
37 iid.equals(nsCI.nsITimerCallback) ||
38 iid.equals(nsCI.nsIWebProgressListener) ||
39 iid.equals(nsCI.nsIFactory) ||
40 iid.equals(nsCI.nsISupports))
43 throw Components.results.NS_ERROR_NO_INTERFACE;
48 test : function (runner)
50 runner.markTestStart();
54 set async() { throw "readonly property"; },
55 get async() { return true; },
57 /* nsITimerCallback */
59 notify : function (timer)
61 var runner = Components.classes["@aasii.org/cxxunit/testrunner"]
62 .getService(nsCI.nsITestRunner);
66 runner.markTestEnd(this);
70 /* nsIWebProgressListener */
72 onStateChange: function( aWebProgress, aRequest, aStateFlags, aStatus)
74 var runner = Components.classes["@aasii.org/cxxunit/testrunner"]
75 .getService(nsCI.nsITestRunner);
79 onProgressChange: function() {},
81 onLocationChange: function() {},
83 onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
87 onSecurityChange: function() {},
91 createInstance : function (outer, iid)
94 throw Components.results.NS_ERROR_NO_AGGREGATION;
96 return this.QueryInterface(iid);
99 lockFactory : function (lock)
106 function JSTestModule()
110 JSTestModule.prototype =
112 get name() { return this._name; },
113 set name() { throw "readonly property"; },
116 get CID() { return this._CID; },
117 set CID() { throw "readonly property"; },
120 get contractID() { return this._contractID; },
121 set contractID() { throw "readonly property"; },
128 _add : function (cid, contractID, name, testF, checkF)
130 var i = this._tests.length;
131 this._tests[i] = { cid : cid,
132 contractID : contractID,
137 this._tests[i].instance = new JSTest(testF, checkF);
140 _repeat : function (index)
142 var i = this._tests.length;
143 this._tests[i] = this._tests[index];
147 QueryInterface : function mod_QI(iid)
149 if (iid.equals(nsCI.nsIModule) ||
150 iid.equals(nsCI.nsITest) ||
151 iid.equals(nsCI.nsIUTF8StringEnumerator) ||
152 iid.equals(nsCI.nsIFactory) ||
153 iid.equals(nsCI.nsISupports))
156 throw Components.results.NS_ERROR_NO_INTERFACE;
161 test : function (runner)
166 set async() { throw "readonly property"; },
167 get async() { return false; },
169 /* nsIStringEnumerator */
171 hasMore : function ()
173 if (this._child < this._tests.length)
179 getNext : function ()
181 if (this._child >= this._tests.length)
182 throw Components.results.NS_ERROR_NOT_AVAILABLE;
183 return this._tests[this._child++].contractID;
188 createInstance : function (outer, iid)
191 throw Components.results.NS_ERROR_NO_AGGREGATION;
193 return this.QueryInterface(iid);
196 lockFactory : function (lock)
202 getClassObject : function mod_gch(compMgr, cid, iid)
204 if (cid.equals(this.CID)){
205 return this.QueryInterface(iid);
208 if (cid in this._map) {
209 return this._tests[this._map[cid]].instance.QueryInterface(iid);
212 throw Components.results.NS_ERROR_NOT_REGISTERED;
215 registerSelf : function mod_regself(compMgr, fileSpec, location, type)
217 compMgr.QueryInterface(nsCI.nsIComponentRegistrar);
219 compMgr.registerFactoryLocation(this._CID, this._name, this._contractID,
220 fileSpec, location, type);
222 var i, count = this._tests.length;
223 for (i = 0; i < count ; i++) {
224 var o = this._tests[i];
226 compMgr.registerFactoryLocation(o.cid, o.name, o.contractID,
227 fileSpec, location, type);
233 unregisterSelf : function mod_unreg(compMgr, location, type)
235 compMgr.QueryInterface(nsCI.nsIComponentRegistrar);
237 compMgr.unregisterFactoryLocation(this.CID, location);
239 var i, count = this._tests.length;
240 for (i = 0; i < count ; i++) {
241 var o = this._tests[i];
243 compMgr.unregisterFactoryLocation(o.cid, location);
249 canUnload : function (compMgr)
256 function sendOnInput(target)
258 var evnt = target.ownerDocument.createEvent("Event");
259 evnt.initEvent("input",true,true);
260 target.dispatchEvent(evnt);
263 function sendOnChange(target)
265 var evnt = target.ownerDocument.createEvent("Event");
266 evnt.initEvent("change",true,true);
267 target.dispatchEvent(evnt);
270 function sendOnClick(target)
272 var wnd = target.ownerDocument.defaultView;
273 var evt = target.ownerDocument.createEvent("MouseEvents");
274 evt.initMouseEvent("click", true, true, wnd,
275 1, 0, 0, 0, 0, false, false, false, false, 0, null);
276 target.dispatchEvent(evt);