34 const Ci = Components.interfaces;
35 const Cc = Components.classes;
36 const Cr = Components.results;
59 mTestComponents :
null,
71 mOldScriptTimeout: -1,
73 _disableScriptTimeout :
function() {
80 _enableScriptTimeout :
function() {
81 if (mOldScriptTimeout > -1) {
87 _disableDatabaseLocaleCollation :
function() {
88 var
dbe =
Cc[
"@songbirdnest.com/Songbird/DatabaseEngine;1"]
89 .getService(
Ci.sbIDatabaseEngine)
90 dbe.localeCollationEnabled =
false;
93 _enableDatabaseLocaleCollation :
function() {
94 var
dbe =
Cc[
"@songbirdnest.com/Songbird/DatabaseEngine;1"]
95 .getService(
Ci.sbIDatabaseEngine)
96 dbe.localeCollationEnabled =
true;
99 mTempDownloadFolder:
null,
100 mOldDownloadPath:
"",
101 mOldDownloadPromptSetting:
false,
103 _setTempDownloadFolder:
function() {
104 this.mTempDownloadFolder =
Cc[
"@mozilla.org/file/directory_service;1"].
106 get(
"TmpD",
Ci.nsIFile);
107 this.mTempDownloadFolder.append(
"songbird_test_downloads");
109 if (!(this.mTempDownloadFolder.exists() &&
110 this.mTempDownloadFolder.isDirectory())) {
111 this.mTempDownloadFolder.create(
Ci.nsIFile.DIRECTORY_TYPE, 0755);
117 this.mOldDownloadPath =
126 var
str =
Cc[
"@mozilla.org/supports-string;1"].
128 str.data = this.mTempDownloadFolder.path;
132 _unsetTempDownloadFolder:
function() {
135 if (this.mOldDownloadPath) {
136 var
str =
Cc[
"@mozilla.org/supports-string;1"].
138 str.data = this.mOldDownloadPath;
145 if (this.mOldDownloadPromptSetting) {
149 if (this.mTempDownloadFolder && this.mTempDownloadFolder.exists()) {
150 this.mTempDownloadFolder.remove(
true);
152 this.mTempDownloadFolder =
null;
157 _registerExtensionComponents:
function() {
161 var marker =
Cc[
"@mozilla.org/file/directory_service;1"].
163 get(
"ProfD", Components.interfaces.nsIFile);
164 marker.append(
".autoreg");
165 if (!marker.exists()) {
171 var compReg = Components.manager.QueryInterface(
Ci.nsIComponentRegistrar);
173 var em =
Cc[
"@mozilla.org/extensions/manager;1"]
174 .getService(
Ci.nsIExtensionManager);
175 var appInfo =
Cc[
"@mozilla.org/xre/runtime;1"]
176 .getService(
Ci.nsIXULRuntime);
178 var itemList = em.getItemList(
Ci.nsIUpdateItem.TYPE_EXTENSION, {});
179 for each (var item
in itemList) {
180 var installLocation = em.getInstallLocation(item.id);
181 var
dir = installLocation.getItemLocation(item.id);
182 dir.append(
"components");
184 compReg.autoRegister(dir);
188 dir = installLocation.getItemLocation(item.id);
189 dir.append(
"platform");
190 dir.append(appInfo.OS +
"_" + appInfo.XPCOMABI);
191 dir.append(
"components");
193 compReg.autoRegister(dir);
198 init :
function ( aTests ) {
199 this._registerExtensionComponents();
203 if (aTests && aTests !=
"")
204 this.mTestComponents = aTests.split(
",");
207 var dirService =
Cc[
"@mozilla.org/file/directory_service;1"].getService(
Ci.nsIProperties);
208 var rootDir = dirService.get(
"resource:app" ,
Ci.nsIFile);
211 this.mTestDir = rootDir.clone().QueryInterface(
Ci.nsILocalFile);
212 this.mTestDir.appendRelativePath(
"testharness");
215 this.mHeadSongbird = this.mTestDir.clone().QueryInterface(
Ci.nsILocalFile);
219 this.mTailSongbird = this.mTestDir.clone().QueryInterface(
Ci.nsILocalFile);
223 this._disableDatabaseLocaleCollation();
224 this._disableScriptTimeout();
225 this._setTempDownloadFolder();
230 var consoleService =
Cc[
"@mozilla.org/consoleservice;1"].getService(
Ci.nsIConsoleService);
231 var
consoleListener =
Cc[
"@songbirdnest.com/Songbird/TestHarness/ConsoleListener;1"].createInstance(
Ci.nsIConsoleListener);
232 consoleService.registerListener(consoleListener);
234 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"].getService(
Ci.nsIIOService);
235 var jsLoader =
Cc[
"@mozilla.org/moz/jssubscript-loader;1"].getService(
Ci.mozIJSSubScriptLoader);
237 var
log =
function (s) {
238 consoleService.logStringMessage(s);
242 if (!this.mTestComponents)
243 this.buildTestComponents();
246 for ( var index in this.mTestComponents ) {
249 var testDir = this.mTestDir.clone().QueryInterface(
Ci.nsILocalFile);
250 var testCompTests = this.mTestComponents[index].split(
":");
251 var testComp = testCompTests.shift();
252 testDir.append(testComp);
254 if (testCompTests.length !=0) {
255 testCompTests = testCompTests[0].split(
"+");
258 if ( !testDir.exists() || !testDir.isDirectory() )
262 var testNameArray =
new Array();
264 if ( testCompTests.length == 0 ) {
268 let dirEnum = testDir.directoryEntries;
270 while ( dirEnum.hasMoreElements() ) {
271 let testFile = dirEnum.getNext().QueryInterface(
Ci.nsIFile);
275 if (testFile.isDirectory())
280 var regex = /^test_(.+)\.js$/;
281 var result = testFile.leafName.match(regex);
285 testNameArray.push(result[1]);
289 testNameArray.sort();
293 testNameArray = testCompTests;
297 for ( let index = 0; index < testNameArray.length; index++ ) {
298 let testBase = testNameArray[index];
301 var testFile = testDir.clone().QueryInterface(
Ci.nsILocalFile);
302 var testHeadFile = testDir.clone().QueryInterface(
Ci.nsILocalFile);
303 var compHeadFile = testDir.clone().QueryInterface(
Ci.nsILocalFile);
304 var testTailFile = testDir.clone().QueryInterface(
Ci.nsILocalFile);
305 var compTailFile = testDir.clone().QueryInterface(
Ci.nsILocalFile);
308 testFile.append(
"test_" + testBase +
".js");
309 testHeadFile.append(
"head_" + testBase +
".js");
310 compHeadFile.append(
"head_" + testComp +
".js");
311 testTailFile.append(
"tail_" + testBase +
".js");
312 compTailFile.append(
"tail_" + testComp +
".js");
315 var scriptUri =
null;
318 var
scope = { __proto__ : (
function()
this)(),
321 scope.wrappedJSObject =
scope;
324 if (this.mHeadSongbird.exists()) {
325 scriptUri = ioService.newFileURI(this.mHeadSongbird);
326 jsLoader.loadSubScript( scriptUri.spec, scope );
330 if (compHeadFile.exists()) {
331 scriptUri = ioService.newFileURI(compHeadFile);
332 jsLoader.loadSubScript( scriptUri.spec, scope );
336 if (testHeadFile.exists()) {
337 scriptUri = ioService.newFileURI(testHeadFile);
338 jsLoader.loadSubScript( scriptUri.spec, scope );
342 scope._test_name = testComp +
" - " + testBase;
345 scope._test_comp = testComp;
348 if (testFile.exists()) {
349 log(
"*** [" + scope._test_name +
"] - Testing...");
350 scriptUri = ioService.newFileURI(testFile);
351 jsLoader.loadSubScript( scriptUri.spec, scope );
355 if (this.mTailSongbird.exists()) {
357 scriptUri = ioService.newFileURI(this.mTailSongbird);
358 jsLoader.loadSubScript( scriptUri.spec, scope );
362 if (testTailFile.exists()) {
364 scriptUri = ioService.newFileURI(testTailFile);
365 jsLoader.loadSubScript( scriptUri.spec, scope );
369 if (compTailFile.exists()) {
371 scriptUri = ioService.newFileURI(compTailFile);
372 jsLoader.loadSubScript( scriptUri.spec, scope );
377 Components.utils.forceGC();
381 if ( this.mFailedTests ) {
383 log(
"[Test Harness] *** The following tests failed:");
384 for ( var index = 0; index < this.mFailedTests.length ; index++ )
385 log(
"[Test Harness] - " + this.mFailedTests[index]);
388 else if (this.mTestCount > 0) {
390 log(
"[Test Harness] *** ALL TESTS PASSED\n\n");
394 log(
"[Test Harness] *** NO TESTS FOUND\n\n");
397 consoleService.unregisterListener(consoleListener);
398 this._unsetTempDownloadFolder();
399 this._enableScriptTimeout();
400 this._enableDatabaseLocaleCollation();
402 if (this.mFailedTests) {
403 throw Cr.NS_ERROR_ABORT;
409 buildTestComponents :
function() {
412 if (!this.mTestDir.exists()) {
417 let dirEnum = this.mTestDir.directoryEntries;
418 this.mTestComponents =
new Array();
419 while ( dirEnum.hasMoreElements() ) {
420 var
entry = dirEnum.getNext().QueryInterface(
Ci.nsIFile);
421 if (entry.isDirectory()) {
422 this.mTestComponents.push(entry.leafName);
425 this.mTestComponents.sort();
428 logFailure:
function (aComponentName) {
429 if (! this.mFailedTests)
430 this.mFailedTests =
new Array();
431 this.mFailedTests.push(aComponentName);
436 !iid.equals(
Ci.nsISupports))
437 throw Cr.NS_ERROR_NO_INTERFACE;
448 registerSelf:
function(compMgr, fileSpec, location, type) {
449 compMgr = compMgr.QueryInterface(
Ci.nsIComponentRegistrar);
460 throw Cr.NS_ERROR_NO_INTERFACE;
462 if (!iid.equals(
Ci.nsIFactory))
463 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
465 return this.mFactory;
471 throw Cr.NS_ERROR_NO_AGGREGATION;
476 canUnload:
function(compMgr) {
481 if ( !iid.equals(
Ci.nsIModule) &&
482 !iid.equals(
Ci.nsISupports) )
483 throw Cr.NS_ERROR_NO_INTERFACE;
function NSGetModule(compMgr, fileSpec)
const PREF_DOWNLOAD_ALWAYSPROMPT
const SONGBIRD_TESTHARNESS_CONTRACTID
SafebrowsingApplicationMod prototype registerSelf
const NS_PREFSERVICE_CONTRACTID
sbOSDControlService prototype QueryInterface
const sbTestHarnessModule
getService(Ci.sbIFaceplateManager)
const SONGBIRD_TESTHARNESS_IID
SafebrowsingApplicationMod prototype getClassObject
const NS_SCRIPT_TIMEOUT_PREF
const PREF_DOWNLOAD_FOLDER
const SONGBIRD_TESTHARNESS_CLASSNAME
const SONGBIRD_TESTHARNESS_CID
const SONGBIRD_DEFAULT_DIR