87 var timer =
Cc[
"@mozilla.org/timer;1"].createInstance(
Ci.nsITimer);
88 timer.initWithCallback(func, delay, timer.TYPE_ONE_SHOT);
97 var tm =
Cc[
"@mozilla.org/thread-manager;1"].getService(
Ci.nsIThreadManager);
98 var mainThread = tm.mainThread;
101 mainThread.processNextEvent(
true);
111 var frame = Components.stack;
112 while (frame !=
null) {
114 frame = frame.caller;
128 throw Cr.NS_ERROR_ABORT;
133 var
msg = (aMessage !=
null) ? (
" : " + aMessage ) :
"";
143 if (aExpected != aActual) {
144 var
msg = (aMessage !=
null) ? (
" : " + aMessage ) :
"";
145 doThrow(aExpected +
" != " + aActual + msg);
150 if (aExpected == aActual) {
151 var
msg = (aMessage !=
null) ? (
" : " + aMessage ) :
"";
152 doThrow(aExpected +
" != " + aActual + msg);
165 function verbose (aMessage) {
168 log(
"[Test Harness] Scanning extensions...");
214 let rdfService =
Cc[
"@mozilla.org/rdf/rdf-service;1"]
215 .getService(
Ci.nsIRDFService);
216 let extensionsDS = rdfService.GetDataSource(
"rdf:extensions");
217 verbose(
"extensions datasource [" + extensionsDS.URI +
"]");
219 let container =
Cc[
"@mozilla.org/rdf/container;1"]
220 .createInstance(
Ci.nsIRDFContainer);
221 container.Init(extensionsDS,
222 rdfService.GetResource(
"urn:mozilla:item:root"));
223 let
each = container.GetElements();
226 const PREFIX_NS_EM =
"http://www.mozilla.org/2004/em-rdf#";
227 const ADDONID_ARC = rdfService.GetResource(
PREFIX_NS_EM +
"addonID");
228 const STATE_ARC = rdfService.GetResource(
PREFIX_NS_EM +
"state");
229 const DISABLED_ARC = rdfService.GetResource(
PREFIX_NS_EM +
"isDisabled");
230 const VERSION_ARC = rdfService.GetResource(
PREFIX_NS_EM +
"version");
236 while (each.hasMoreElements()) {
237 let extensionRdf = each.getNext().QueryInterface(
Ci.nsIRDFResource);
238 verbose(
"extension [" + extensionRdf.ValueUTF8 +
"]");
241 let addonID = extensionsDS.GetTarget(extensionRdf, ADDONID_ARC,
true);
242 if (!(addonID instanceof
Ci.nsIRDFLiteral)) {
243 verbose(
"INVALID " + ADDONID_ARC.ValueUTF8);
248 let installState = extensionsDS.GetTarget(extensionRdf, STATE_ARC,
true);
249 let disabled = extensionsDS.GetTarget(extensionRdf, DISABLED_ARC,
true);
250 let
version = extensionsDS.GetTarget(extensionRdf, VERSION_ARC,
true);
255 if (installState instanceof
Ci.nsIRDFLiteral) {
256 verbose(
"install state [" + installState.Value +
"]");
261 else if (disabled instanceof
Ci.nsIRDFLiteral &&
262 disabled.Value ==
"true")
264 verbose(
"disabled [" + disabled.Value +
"]");
267 else if (version instanceof
Ci.nsIRDFLiteral) {
268 verbose(
"version [" + version.Value +
"]");
272 verbose(
"RDF PROPERTIES INFO NOT FOUND <<<\n");
285 "No such extension: " + aExtensionID);
287 let status = _extensionStates[aExtensionID];
292 fail(
"Required extension failed to install: " + aExtensionID);
296 fail(
"Required extension is disabled: " + aExtensionID);
300 skip(
"Required extension " + aExtensionID +
301 " is newly installed. You must relaunch to run this test.");
311 var
msg = (aMessage !=
null) ? (
"FAIL : " + aMessage ) :
"FAIL";
316 var
msg = (aMessage !=
null) ? (
"FAIL : " + aMessage ) :
"FAIL";
323 aMessage =
"SKIPPING TEST";
355 var sysInfo =
Cc[
"@mozilla.org/system-info;1"].getService(
Ci.nsIPropertyBag2);
356 return sysInfo.getProperty(
"name");
359 function sleep(ms, suppressOutput) {
360 var threadManager =
Cc[
"@mozilla.org/thread-manager;1"].
362 var mainThread = threadManager.mainThread;
364 if (!suppressOutput) {
365 log(
"*** [" +
_test_name +
"] - waiting for " + ms +
" milliseconds...");
367 var then =
new Date().getTime(),
now = then;
368 for (;
now - then < ms;
now =
new Date().getTime()) {
369 mainThread.processNextEvent(
true);
371 if (!suppressOutput) {
377 var DEFAULT_PORT = 8180;
378 const ENV_VAR_PORT =
"SONGBIRD_TEST_SERVER_PORT";
381 Components.classes[
"@mozilla.org/process/environment;1"]
382 .getService(Components.interfaces.nsIEnvironment);
384 var port = DEFAULT_PORT;
385 if (environment.exists(ENV_VAR_PORT)) {
386 var envPort = parseInt(environment.get(ENV_VAR_PORT));
392 log(
"*** [" +
_test_name +
"] - using test server port " + port);
398 this._array = aArray;
403 return this._current < this._array.length;
407 return this._array[this._current++];
411 if (!iid.equals(Components.interfaces.nsIStringEnumerator) &&
412 !iid.equals(Components.interfaces.nsISupports))
413 throw Components.results.NS_ERROR_NO_INTERFACE;
418 this._extensions = aExtensions;
419 this._schemes = aSchemes;
425 if(aStr.lastIndexOf(
"." +
this._extensions[0]) ==
426 aStr.length - this._extensions[0].length + 1) {
430 var extensionSep = aStr.lastIndexOf(
".");
431 if(extensionSep >= 0) {
432 var extension = aStr.substring(extensionSep + 1);
433 var rv = this._extensions.some(
function(ext) {
434 return extension == ext;
441 var schemeSep = aStr.indexOf(
"://");
443 var scheme = aStr.substring(0, schemeSep);
444 var rv = this._schemes.some(
function(sch) {
445 return scheme == sch;
457 function loadData(databaseGuid, databaseLocation) {
459 var dbq =
Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
460 .createInstance(
Ci.sbIDatabaseQuery);
462 dbq.setDatabaseGUID(databaseGuid);
463 if (databaseLocation) {
464 dbq.databaseLocation = databaseLocation;
466 dbq.setAsyncQuery(
false);
467 dbq.addQuery(
"create temporary table tmp_rowids (id integer);");
468 dbq.addQuery(
"begin");
471 var a = data.split(
"\n");
472 for(var
i = 0;
i < a.length - 1;
i++) {
473 var b = a[
i].split(
"\t");
474 dbq.addQuery(
"insert into media_items (guid, created, updated, content_url, content_mime_type, content_length, hidden, media_list_type_id, is_list) values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
475 dbq.bindStringParameter(0, b[1]);
476 dbq.bindInt64Parameter(1, b[2]);
477 dbq.bindInt64Parameter(2, b[3]);
478 dbq.bindStringParameter(3, b[4]);
479 dbq.bindStringParameter(4, b[5]);
481 dbq.bindNullParameter(5);
484 dbq.bindInt32Parameter(5, b[6]);
486 dbq.bindInt32Parameter(6, b[7]);
487 if(b[8] ==
"" || b[8] ==
"0") {
488 dbq.bindNullParameter(7);
489 dbq.bindInt32Parameter(8, 0);
492 dbq.bindInt32Parameter(7, b[8]);
493 dbq.bindInt32Parameter(8, 1);
497 data =
readFile(
"resource_properties.txt");
498 a = data.split(
"\n");
499 for(var
i = 0;
i < a.length - 1;
i++) {
500 var b = a[
i].split(
"\t");
501 dbq.addQuery(
"insert into resource_properties (media_item_id, property_id, obj, obj_searchable, obj_sortable) values ((select media_item_id from media_items where guid = ?), ?, ?, ?, ?)");
502 dbq.bindStringParameter(0, b[0]);
503 dbq.bindInt32Parameter(1, b[1]);
504 dbq.bindStringParameter(2, b[2]);
505 dbq.bindStringParameter(3, b[3]);
506 dbq.bindStringParameter(4, b[4]);
509 data =
readFile(
"simple_media_lists.txt");
510 a = data.split(
"\n");
511 for(var
i = 0;
i < a.length - 1;
i++) {
512 var b = a[
i].split(
"\t");
513 dbq.addQuery(
"insert into simple_media_lists (media_item_id, member_media_item_id, ordinal) values ((select media_item_id from media_items where guid = ?), (select media_item_id from media_items where guid = ?), ?)");
514 dbq.bindStringParameter(0, b[0]);
515 dbq.bindStringParameter(1, b[1]);
516 dbq.bindInt32Parameter(2, b[2]);
527 dbq.addQuery(
"delete from tmp_rowids");
528 dbq.addQuery(
"insert into tmp_rowids select rowid from resource_properties_fts_all;");
529 dbq.addQuery(
"insert into resource_properties_fts_all (rowid, alldata) " +
530 " select media_item_id, group_concat(obj, ' ') from resource_properties where media_item_id not in (" +
531 "select id from tmp_rowids) group by media_item_id");
533 dbq.addQuery(
"insert into resource_properties_fts_all (alldata) values ('foo');");
535 dbq.addQuery(
"commit");
536 dbq.addQuery(
"drop table tmp_rowids");
544 var
file =
Cc[
"@mozilla.org/file/directory_service;1"]
545 .getService(
Ci.nsIProperties)
546 .get(
"resource:app",
Ci.nsIFile);
547 file.append(
"testharness");
548 file.append(
"localdatabaselibrary");
549 file.append(fileName);
552 var fstream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
553 .createInstance(
Ci.nsIFileInputStream);
554 var sstream =
Cc[
"@mozilla.org/scriptableinputstream;1"]
555 .createInstance(
Ci.nsIScriptableInputStream);
556 fstream.init(file, -1, 0, 0);
557 sstream.init(fstream);
559 var
str = sstream.read(4096);
560 while (str.length > 0) {
562 str = sstream.read(4096);
572 if (typeof(
init) ==
"undefined") {
577 if (databaseLocation) {
578 directory = databaseLocation.QueryInterface(
Ci.nsIFileURL).file;
581 directory =
Cc[
"@mozilla.org/file/directory_service;1"].
583 get(
"ProfD",
Ci.nsIFile);
584 directory.append(
"db");
587 var
file = directory.clone();
588 file.append(databaseGuid +
".db");
591 Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
592 .getService(
Ci.sbILibraryFactory);
593 var hashBag =
Cc[
"@mozilla.org/hash-property-bag;1"].
595 hashBag.setPropertyAsInterface(
"databaseFile", file);
596 var library = libraryFactory.createLibrary(hashBag);
606 loadData(databaseGuid, databaseLocation);
614 assertEqual(a1.length, a2.length,
"arrays are different lengths");
615 for (var
i=0;
i<a1.length;
i++) {
616 assertEqual(a1[
i], a2[i],
"data mismatch at index " + i);
622 for (var
i = 0;
i < s1.length;
i++) {
624 "set 1 member " + s1[
i] +
" not in set 2");
626 for (var
i = 0;
i < s2.length;
i++) {
628 "set 2 member " + s2[
i] +
" not in set 1");
630 assertEqual(s1.length, s2.length,
"sets are different lengths");
636 var
msg = (aMessage !=
null) ? (
" : " + aMessage ) :
"";
637 doThrow(aFile1.path +
" != " + aFile2.path +
" " + msg);
642 if (!aFile1.exists() || !aFile2.exists())
645 var fileStream1 =
Cc[
"@mozilla.org/network/file-input-stream;1"]
646 .createInstance(
Ci.nsIFileInputStream);
647 var scriptableFileStream1 =
Cc[
"@mozilla.org/scriptableinputstream;1"]
648 .createInstance(
Ci.nsIScriptableInputStream);
649 fileStream1.init(aFile1, -1, 0, 0);
650 scriptableFileStream1.init(fileStream1);
652 var fileStream2 =
Cc[
"@mozilla.org/network/file-input-stream;1"]
653 .createInstance(
Ci.nsIFileInputStream);
654 var scriptableFileStream2 =
Cc[
"@mozilla.org/scriptableinputstream;1"]
655 .createInstance(
Ci.nsIScriptableInputStream);
656 fileStream2.init(aFile2, -1, 0, 0);
657 scriptableFileStream2.init(fileStream2);
659 var filesEqual =
true;
661 var data1 = scriptableFileStream1.read(4096);
662 var data2 = scriptableFileStream2.read(4096);
664 if (data1 != data2) {
668 }
while(data1.length > 0);
671 scriptableFileStream1.close();
673 scriptableFileStream2.close();
680 var
file =
Cc[
"@mozilla.org/file/directory_service;1"]
681 .getService(
Ci.nsIProperties)
682 .get(
"resource:app",
Ci.nsIFile);
685 var nodes =
path.split(
"/");
686 for ( var
i = 0, end = nodes.length;
i < end;
i++ )
688 file.append( nodes[
i ] );
711 (aURLString instanceof
String) || typeof(aURLString) ==
"string"))
712 throw Components.results.NS_ERROR_INVALID_ARG;
715 Components.classes[
"@mozilla.org/network/io-service;1"]
716 .getService(Components.interfaces.nsIIOService);
719 return ioService.newURI(aURLString,
null,
null);
729 Components.classes[
"@mozilla.org/network/io-service;1"]
730 .getService(Components.interfaces.nsIIOService);
732 return ioService.newFileURI(
file);
771 for (var option in config) {
772 this[option] = config[option];
780 run:
function TestCase_run(
args) {
782 if (this.pre && typeof this.pre ===
'function')
783 this.pre.apply(
this,
args);
785 this.exec.apply(
this,
args);
787 if (this.post && typeof this.post ===
'function')
788 this.post.apply(
this,
args);
796 stub:
function TestCase_stub(receiver, property, stub) {
801 stash: receiver[property]
804 if (!(property in receiver)) {
809 throw new Error(
"Attempted to stub property: " + property +
810 "on an object that doesn't contain that property from " +
811 " test case: " + this.desc);
814 receiver[property] = stub;
817 unstub:
function TestCase_unstub() {
818 var stubs = this._stubs,
822 for (let
i = 0;
i < len;
i++) {
824 stub.receiver[stub.property] = stub.stash;
function loadData(databaseGuid, databaseLocation)
function sleep(ms, suppressOutput)
function TestCase(config)
function newAppRelativeFile(path)
function assertNotEqual(aExpected, aActual, aMessage)
function assertTrue(aTest, aMessage)
function assertSetsEqual(s1, s2)
function assertEqual(aExpected, aActual, aMessage)
function getTestFile(aFileName)
getService(Ci.sbIFaceplateManager)
function assertArraysEqual(a1, a2)
function assertFilesEqual(aFile1, aFile2, aMessage)
function newFileURI(file)
function testFilesEqual(aFile1, aFile2)
function newURI(aURLString)
function StringArrayEnumerator(aArray)
function assertFalse(aTest, aMessage)
function ExtensionSchemeMatcher(aExtensions, aSchemes)
const _TH_EXTENSION_DISABLED
function failNoThrow(aMessage)
function assertExtension(aExtensionID)
function readFile(fileName)
function createLibrary(databaseGuid, databaseLocation, init)
function doTimeout(delay, func)
function getTestServerPortNumber()
_getSelectedPageStyle s i
const _TH_EXTENSION_NEEDS_RESTART