46 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
47 .getService(
Ci.nsIIOService);
48 var fileProtocolHandler = ioService.getProtocolHandler(
"file")
49 .QueryInterface(
Ci.nsIFileProtocolHandler);
52 var temporaryFileFactory;
54 temporaryFileFactory =
55 Cc[
"@songbirdnest.com/Songbird/TemporaryFileFactory;1"]
56 .getService(
Ci.sbITemporaryFileFactory);
59 "Temporary file factory component is not available.");
62 var rootTemporaryDirectory = temporaryFileFactory.rootTemporaryDirectory;
64 "Temporary file factory directory is null.");
66 "Temporary file factory directory does not exist.");
69 var tmpFile1 = temporaryFileFactory.createFile(
Ci.nsIFile.NORMAL_FILE_TYPE);
70 assertTrue(tmpFile1,
"Could not create temporary file.");
71 assertTrue(tmpFile1.exists(),
"Temporary file does not exist.");
74 var tmpFile2 = temporaryFileFactory.createFile(
Ci.nsIFile.NORMAL_FILE_TYPE);
75 assertTrue(tmpFile2,
"Could not create temporary file.");
76 assertTrue(tmpFile2.exists(),
"Temporary file does not exist.");
77 assertTrue(!tmpFile2.equals(tmpFile1),
"Temporary file is not unique.");
80 var fileBaseName =
"test";
81 tmpFile1 = temporaryFileFactory.createFile(
Ci.nsIFile.NORMAL_FILE_TYPE,
83 assertTrue(tmpFile1,
"Could not create temporary file.");
84 var fileURL = fileProtocolHandler.newFileURI(tmpFile1);
85 fileURL = fileURL.QueryInterface(
Ci.nsIURL);
86 assertEqual(fileURL.fileBaseName.search(fileBaseName), 0);
89 tmpFile1 = temporaryFileFactory.createFile(
Ci.nsIFile.NORMAL_FILE_TYPE,
92 assertTrue(tmpFile1,
"Could not create temporary file.");
93 assertTrue(tmpFile1.path.match(/\.tst$/),
"File extension incorrect.");
97 temporaryFileFactory.clear();
99 "Failed to clear temporary files.");
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function runTest()
Advanced DataRemote unit tests.