bug 459114 - helper function to provide a clean profile directory for xpcshell tests. r=sdwilsh

--HG--
extra : rebase_source : 76f547c1f055f18f57e09c67f1a2f7b2f548c3cd
This commit is contained in:
Ted Mielczarek 2009-05-14 07:37:40 -04:00
Родитель 2696585b63
Коммит e681fe983b
28 изменённых файлов: 305 добавлений и 554 удалений

Просмотреть файл

@ -54,26 +54,14 @@ function LOG(aMsg) {
print(aMsg); print(aMsg);
} }
var gProfD = do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
// Remove '/unit/*.js'.
var gTestRoot = __LOCATION__.parent.parent;
gTestRoot.normalize();
// Need to create and register a profile folder.
var gProfD = gTestRoot.clone();
gProfD.append("profile");
if (gProfD.exists())
gProfD.remove(true);
gProfD.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
var dirProvider = { var dirProvider = {
getFile: function(prop, persistent) { getFile: function(prop, persistent) {
persistent.value = true; persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR || if (prop == NS_APP_BOOKMARKS_50_FILE) {
prop == NS_APP_PROFILE_DIR_STARTUP)
return gProfD.clone();
else if (prop == NS_APP_BOOKMARKS_50_FILE) {
var bmarks = gProfD.clone(); var bmarks = gProfD.clone();
bmarks.append("bookmarks.html"); bmarks.append("bookmarks.html");
return bmarks; return bmarks;

Просмотреть файл

@ -3,30 +3,7 @@ const Ci = Components.interfaces;
function run_test() { function run_test() {
// setup a profile directory // setup a profile directory
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. var dir = do_get_profile();
getService(Ci.nsIProperties);
var leafRandomName = "PermMgr" + Math.floor(Math.random() * 10000);
var dir = dirSvc.get("TmpD", Ci.nsILocalFile);
dir.append(leafRandomName);
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfLD" ||
prop == "ProfD")
return dir.clone();
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).
registerProvider(provider);
// initialize the permission manager service // initialize the permission manager service
var pm = Cc["@mozilla.org/permissionmanager;1"]. var pm = Cc["@mozilla.org/permissionmanager;1"].
@ -56,8 +33,4 @@ function run_test() {
// remove all should not throw // remove all should not throw
pm.removeAll(); pm.removeAll();
// cleanup
dirSvc.unregisterProvider(provider);
} }

Просмотреть файл

@ -0,0 +1,66 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Dave Townsend <dtownsend@oxymoronical.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK *****
*/
// Finds the test plugin library
function get_test_plugin() {
var plugins = gDirSvc.get("CurProcD", Ci.nsILocalFile);
plugins.append("plugins");
do_check_true(plugins.exists());
var plugin = plugins.clone();
// OSX plugin
plugin.append("Test.plugin");
if (plugin.exists()) {
plugin.normalize();
return plugin;
}
plugin = plugins.clone();
// *nix plugin
plugin.append("libnptest.so");
if (plugin.exists()) {
plugin.normalize();
return plugin;
}
// Windows plugin
plugin = plugins.clone();
plugin.append("nptest.dll");
if (plugin.exists()) {
plugin.normalize();
return plugin;
}
return null;
}

Просмотреть файл

@ -39,9 +39,6 @@
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
// v0.9 registry field meanings are different on Mac OS X // v0.9 registry field meanings are different on Mac OS X
const CWD = do_get_cwd(); const CWD = do_get_cwd();
function checkOS(os) { function checkOS(os) {
@ -56,41 +53,10 @@ var DELIM = ":";
if ("@mozilla.org/windows-registry-key;1" in Components.classes) if ("@mozilla.org/windows-registry-key;1" in Components.classes)
DELIM = "|"; DELIM = "|";
var gProfD; var gProfD = do_get_profile();
var gDirSvc = Cc["@mozilla.org/file/directory_service;1"]. var gDirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
// Creates a fake profile folder that the pluginhost will read our crafted
// pluginreg.dat from
function createProfileFolder() {
// Remove '/unit/*.js'.
gProfD = do_get_cwd();
gProfD.append("profile");
if (gProfD.exists())
gProfD.remove(true);
gProfD.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
var dirProvider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR ||
prop == NS_APP_PROFILE_DIR_STARTUP)
return gProfD.clone();
return null;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
gDirSvc.QueryInterface(Ci.nsIDirectoryService)
.registerProvider(dirProvider);
}
// Writes out some plugin registry to the profile // Writes out some plugin registry to the profile
function write_registry(version, info) { function write_registry(version, info) {
var header = "Generated File. Do not edit.\n\n"; var header = "Generated File. Do not edit.\n\n";
@ -103,47 +69,18 @@ function write_registry(version, info) {
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream); .createInstance(Components.interfaces.nsIFileOutputStream);
// write, create, truncate // write, create, truncate
foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0); foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0);
var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports
var os = Cc["@mozilla.org/intl/converter-output-stream;1"]. var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
createInstance(Ci.nsIConverterOutputStream); createInstance(Ci.nsIConverterOutputStream);
os.init(foStream, charset, 0, 0x0000); os.init(foStream, charset, 0, 0x0000);
os.writeString(header); os.writeString(header);
os.writeString(info); os.writeString(info);
os.close(); os.close();
} }
// Finds the test plugin library
function get_test_plugin() {
var plugins = gDirSvc.get("CurProcD", Ci.nsILocalFile);
plugins.append("plugins");
do_check_true(plugins.exists());
var plugin = plugins.clone();
// OSX plugin
plugin.append("Test.plugin");
if (plugin.exists()) {
plugin.normalize();
return plugin;
}
plugin = plugins.clone();
// *nix plugin
plugin.append("libnptest.so");
if (plugin.exists()) {
plugin.normalize();
return plugin;
}
// Windows plugin
plugin = plugins.clone();
plugin.append("nptest.dll");
if (plugin.exists()) {
plugin.normalize();
return plugin;
}
return null;
}
// Finds the test nsIPluginTag // Finds the test nsIPluginTag
function get_test_plugintag() { function get_test_plugintag() {
var host = Cc["@mozilla.org/plugin/host;1"]. var host = Cc["@mozilla.org/plugin/host;1"].
@ -157,7 +94,6 @@ function get_test_plugintag() {
} }
function run_test() { function run_test() {
createProfileFolder();
var file = get_test_plugin(); var file = get_test_plugin();
if (!file) if (!file)
do_throw("Plugin library not found"); do_throw("Plugin library not found");
@ -189,11 +125,4 @@ function run_test() {
// If the plugin registry was not read then the plugin will not be disabled // If the plugin registry was not read then the plugin will not be disabled
do_check_true(plugin.disabled); do_check_true(plugin.disabled);
do_check_false(plugin.blocklisted); do_check_false(plugin.blocklisted);
try {
gProfD.remove(true);
}
catch (e) {
// Failure to remove temp dir shouldn't be a test failure
}
} }

Просмотреть файл

@ -70,37 +70,11 @@ function get_cache_service() {
getService(Ci.nsICacheService); getService(Ci.nsICacheService);
} }
function setup_profile_dir() {
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var dir = dirSvc.get("TmpD", Ci.nsILocalFile);
dir.append("Cache" + Math.floor(Math.random() * 10000));
dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700);
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfLD" ||
prop == "ProfD" ||
prop == "cachePDir")
return dir;
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
function check_devices_available(devices) { function check_devices_available(devices) {
var cs = get_cache_service(); var cs = get_cache_service();
@ -234,7 +208,7 @@ function run_test() {
kTestContent = "test content"; kTestContent = "test content";
// Simulate a profile dir for xpcshell // Simulate a profile dir for xpcshell
setup_profile_dir(); do_get_profile();
var cs = get_cache_service(); var cs = get_cache_service();

Просмотреть файл

@ -1,4 +1,3 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */ /* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1

Просмотреть файл

@ -0,0 +1,52 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ted Mielczarek <ted.mielczarek@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
function run_test()
{
let profd = do_get_profile();
do_check_true(profd.exists());
do_check_true(profd.isDirectory());
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
let profd2 = dirSvc.get("ProfD", Components.interfaces.nsILocalFile);
do_check_true(profd2.exists());
do_check_true(profd2.isDirectory());
// make sure we got the same thing back...
do_check_true(profd.equals(profd2));
}

Просмотреть файл

@ -1,4 +1,3 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */ /* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -366,3 +365,41 @@ function do_register_cleanup(aFunction)
{ {
_cleanupFunctions.push(aFunction); _cleanupFunctions.push(aFunction);
} }
/**
* Registers a directory with the profile service,
* and return the directory as an nsILocalFile.
*
* @return nsILocalFile of the profile directory.
*/
function do_get_profile() {
let env = Components.classes["@mozilla.org/process/environment;1"]
.getService(Components.interfaces.nsIEnvironment);
// the python harness sets this in the environment for us
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
let file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(profd);
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
let provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfD" || prop == "ProfLD" || prop == "ProfDS") {
return file.clone();
}
throw Components.results.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIDirectoryProvider) ||
iid.equals(Components.interfaces.nsISupports)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
.registerProvider(provider);
return file.clone();
}

Просмотреть файл

@ -37,11 +37,12 @@
# #
# ***** END LICENSE BLOCK ***** */ # ***** END LICENSE BLOCK ***** */
import re, sys, os, os.path, logging import re, sys, os, os.path, logging, shutil
import tempfile import tempfile
from glob import glob from glob import glob
from optparse import OptionParser from optparse import OptionParser
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
from tempfile import mkdtemp
from automationutils import addCommonOptions, checkForCrashes from automationutils import addCommonOptions, checkForCrashes
@ -223,11 +224,17 @@ def runTests(xpcshell, testdirs=[], xrePath=None, testPath=None,
# The test file will have to be loaded after the head files. # The test file will have to be loaded after the head files.
cmdT = ['-e', 'const _TEST_FILE = ["%s"];' % cmdT = ['-e', 'const _TEST_FILE = ["%s"];' %
os.path.join(testdir, test).replace('\\', '/')] os.path.join(testdir, test).replace('\\', '/')]
# create a temp dir that the JS harness can stick a profile in
profd = mkdtemp()
env["XPCSHELL_TEST_PROFILE_DIR"] = profd
proc = Popen(cmdH + cmdT + xpcsRunArgs, proc = Popen(cmdH + cmdT + xpcsRunArgs,
stdout=pStdout, stderr=pStderr, env=env, cwd=testdir) stdout=pStdout, stderr=pStderr, env=env, cwd=testdir)
# |stderr == None| as |pStderr| was either |None| or redirected to |stdout|. # |stderr == None| as |pStderr| was either |None| or redirected to |stdout|.
stdout, stderr = proc.communicate() stdout, stderr = proc.communicate()
shutil.rmtree(profd, True)
if interactive: if interactive:
# not sure what else to do here... # not sure what else to do here...
return True return True

Просмотреть файл

@ -38,38 +38,10 @@ const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cr = Components.results; const Cr = Components.results;
do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
var profileDir = null;
try {
profileDir = dirSvc.get("ProfD", Ci.nsIFile);
} catch (e) { }
if (!profileDir) {
// Register our own provider for the profile directory.
// It will simply return the current directory.
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfD") {
return dirSvc.get("CurProcD", Ci.nsILocalFile);
} else if (prop == "DLoads") {
var file = dirSvc.get("CurProcD", Ci.nsILocalFile);
file.append("downloads.rdf");
return file;
}
print("*** Throwing trying to get " + prop);
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
function importDatabaseFile(aFName) function importDatabaseFile(aFName)
{ {

Просмотреть файл

@ -38,6 +38,7 @@
// This file tests the download manager backend // This file tests the download manager backend
do_load_httpd_js(); do_load_httpd_js();
do_get_profile();
function createURI(aObj) function createURI(aObj)
{ {
@ -49,37 +50,27 @@ function createURI(aObj)
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
var profileDir = null;
try {
profileDir = dirSvc.get("ProfD", Ci.nsIFile);
} catch (e) { }
if (!profileDir) {
// Register our own provider for the profile directory.
// It will simply return the current directory.
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfD") {
return dirSvc.get("CurProcD", Ci.nsILocalFile);
} else if (prop == "DLoads") {
var file = dirSvc.get("CurProcD", Ci.nsILocalFile);
file.append("downloads.rdf");
return file;
}
print("*** Throwing trying to get " + prop);
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "DLoads") {
var file = dirSvc.get("ProfD", Ci.nsILocalFile);
file.append("downloads.rdf");
return file;
}
print("*** Throwing trying to get " + prop);
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
/** /**
* Imports a download test file to use. Works with rdf and sqlite files. * Imports a download test file to use. Works with rdf and sqlite files.
@ -100,31 +91,6 @@ function importDownloadsFile(aFName)
do_throw("Unexpected filename!"); do_throw("Unexpected filename!");
} }
function cleanup()
{
// removing rdf
var rdfFile = dirSvc.get("DLoads", Ci.nsIFile);
if (rdfFile.exists()) rdfFile.remove(true);
// removing database
var dbFile = dirSvc.get("ProfD", Ci.nsIFile);
dbFile.append("downloads.sqlite");
if (dbFile.exists())
try { dbFile.remove(true); } catch(e) { /* stupid windows box */ }
// remove places.sqlite since expiration won't work properly if we do not have
// a clean database file.
dbFile = dirSvc.get("ProfD", Ci.nsIFile);
dbFile.append("places.sqlite");
if (dbFile.exists())
try { dbFile.remove(true); } catch(e) { /* stupid windows box */ }
// removing downloaded file
var destFile = dirSvc.get("ProfD", Ci.nsIFile);
destFile.append("download.result");
if (destFile.exists()) destFile.remove(true);
}
var gDownloadCount = 0; var gDownloadCount = 0;
/** /**
* Adds a download to the DM, and starts it. * Adds a download to the DM, and starts it.
@ -147,7 +113,7 @@ function addDownload(aParams)
aParams.targetFile.append(aParams.resultFileName); aParams.targetFile.append(aParams.resultFileName);
} }
if (!("sourceURI" in aParams)) if (!("sourceURI" in aParams))
aParams.sourceURI = "http://localhost:4444/res/language.properties"; aParams.sourceURI = "http://localhost:4444/head_download_manager.js";
if (!("downloadName" in aParams)) if (!("downloadName" in aParams))
aParams.downloadName = null; aParams.downloadName = null;
if (!("runBeforeStart" in aParams)) if (!("runBeforeStart" in aParams))
@ -210,6 +176,3 @@ function getDownloadListener()
// Disable alert service notifications // Disable alert service notifications
let ps = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch); let ps = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
ps.setBoolPref("browser.download.manager.showAlertOnComplete", false); ps.setBoolPref("browser.download.manager.showAlertOnComplete", false);
cleanup();

Просмотреть файл

@ -73,13 +73,11 @@ var httpserv = null;
function run_test() function run_test()
{ {
httpserv = new nsHttpServer(); httpserv = new nsHttpServer();
httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile)); httpserv.registerDirectory("/", do_get_cwd());
httpserv.start(4444); httpserv.start(4444);
dm.addListener(getDownloadListener()); dm.addListener(getDownloadListener());
for (var i = 0; i < tests.length; i++) for (var i = 0; i < tests.length; i++)
tests[i](); tests[i]();
cleanup();
} }

Просмотреть файл

@ -64,7 +64,7 @@ var timer = null;
function run_test() function run_test()
{ {
httpserv = new nsHttpServer(); httpserv = new nsHttpServer();
httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile)); httpserv.registerDirectory("/", do_get_cwd());
httpserv.start(4444); httpserv.start(4444);
// our download listener // our download listener

Просмотреть файл

@ -48,8 +48,7 @@ const resultFileName = "test\u00e3\u041b\u3056" + Date.now() + ".doc";
function checkResult() { function checkResult() {
// delete the saved file (this doesn't affect the "recent documents" list) // delete the saved file (this doesn't affect the "recent documents" list)
var resultFile = dirSvc.get("ProfD", Ci.nsIFile); var resultFile = do_get_file(resultFileName);
resultFile.append(resultFileName);
resultFile.remove(false); resultFile.remove(false);
do_check_true(checkRecentDocsFor(resultFileName)); do_check_true(checkRecentDocsFor(resultFileName));
@ -99,7 +98,7 @@ function run_test()
do_test_pending(); do_test_pending();
httpserv = new nsHttpServer(); httpserv = new nsHttpServer();
httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile)); httpserv.registerDirectory("/", do_get_cwd());
httpserv.start(4444); httpserv.start(4444);
var listener = { var listener = {
@ -119,6 +118,4 @@ function run_test()
dm.addListener(getDownloadListener()); dm.addListener(getDownloadListener());
var dl = addDownload({resultFileName: resultFileName}); var dl = addDownload({resultFileName: resultFileName});
cleanup();
} }

Просмотреть файл

@ -38,8 +38,6 @@
// This tests that downloads in the scanning state are set to a completed state // This tests that downloads in the scanning state are set to a completed state
// upon service initialization. // upon service initialization.
cleanup();
importDownloadsFile("bug_401582_downloads.sqlite"); importDownloadsFile("bug_401582_downloads.sqlite");
const nsIDownloadManager = Ci.nsIDownloadManager; const nsIDownloadManager = Ci.nsIDownloadManager;
@ -64,6 +62,4 @@ function run_test()
{ {
for (var i = 0; i < tests.length; i++) for (var i = 0; i < tests.length; i++)
tests[i](); tests[i]();
cleanup();
} }

Просмотреть файл

@ -38,8 +38,6 @@
// This file ensures that the download manager service can be instantiated with // This file ensures that the download manager service can be instantiated with
// a certain downloads.sqlite file that had incorrect data. // a certain downloads.sqlite file that had incorrect data.
cleanup();
importDownloadsFile("bug_409179_downloads.sqlite"); importDownloadsFile("bug_409179_downloads.sqlite");
function run_test() function run_test()
@ -52,6 +50,4 @@ function run_test()
caughtException = true; caughtException = true;
} }
do_check_false(caughtException); do_check_false(caughtException);
cleanup();
} }

Просмотреть файл

@ -47,13 +47,13 @@ function run_test()
do_test_pending(); do_test_pending();
function addDownload() { function addDownload() {
const nsIWBP = Ci.nsIWebBrowserPersist; const nsIWBP = Ci.nsIWebBrowserPersist;
var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"] var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
.createInstance(Ci.nsIWebBrowserPersist); .createInstance(Ci.nsIWebBrowserPersist);
persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES | persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
nsIWBP.PERSIST_FLAGS_BYPASS_CACHE | nsIWBP.PERSIST_FLAGS_BYPASS_CACHE |
nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION; nsIWBP.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
// Download to a temp local file // Download to a temp local file
let file = dirSvc.get("ProfD", Ci.nsIFile); let file = dirSvc.get("ProfD", Ci.nsIFile);
file.append("policychecktest.png"); file.append("policychecktest.png");
@ -63,16 +63,16 @@ function run_test()
gDownloadCount++; gDownloadCount++;
var dl = dm.addDownload(Ci.nsIDownloadManager.DOWNLOAD_TYPE_DOWNLOA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b7esAAAAaZmNUTAAAAAUAAAAQAAAADwAAAAAAAAABAPoD6AEBp98YvwAAAflmZEFUAAAABiiRrZHhSxNxGMf3X4YRUohE0ZsgfBERrpCkMMGCItqwdZvu3Ezdzq3cWnodpqbQbNvN3dTOztttE01qld7t04vlYM7Rmx74vvnxfD+fB34u1/8cvVJjYrGCsFDiRcogvGgyu1rmfW6P9NY3CsZ3VP2AjoDJpQrpr0eolkPOcsiVHGaTCp7xKKHIHII4zZi03A44bfYmdnj2+guipDDy6iOyustPYHnTwivGqFar/NOcLTmMBmcYWzIo7EPGguwexNImsfhcK8D3bhfVcsiXG1Eth4xp4xVCrFmwUYXSIVR+QG4fPEK4FeBJ7JC3bFTL5rNps27YpA2bUSHI/MY+Vg1+2XDoQDJj4vcHWgFP49vky43S4uYRsnaEov0mGIoiTKdQ9TLHwErB4PHzl5im2Qp4FNFYN22U4jELhUYmZmREMUTfzX4mwlP4A2N4fUFGxuX2X3g4qbK8bTfLorSEvq3Te/U6smYjazaXh5LIxTrdA/F2wGAwg1JsLIrhGPqWzsXea7zN1pA1B1lz6Lk/h1ys0+WW2gF3hU/NxQ/zCfrcQ3imVv6+1ZvmgFym594ZF9waXW0CTgqn0+WWuOCOoqR32gH9vlUmVw7OLMrFemfzyaxtWNx4onBlOEXvgySXBt/QPRDn/B2Jc7cjnc0ul+sPqZsqAeXgvCsAAAAASUVORK5CYII="),
createURI(file), null, null, createURI(file), null, null,
Math.round(Date.now() * 1000), null, persist); Math.round(Date.now() * 1000), null, persist);
persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener); persist.progressListener = dl.QueryInterface(Ci.nsIWebProgressListener);
persist.saveURI(dl.source, null, null, null, null, dl.targetFile); persist.saveURI(dl.source, null, null, null, null, dl.targetFile);
return dl; return dl;
} }
let listener = { let listener = {
onDownloadStateChange: function(aState, aDownload) onDownloadStateChange: function(aState, aDownload)
@ -89,7 +89,7 @@ function run_test()
do_throw("data: uri failed to download successfully"); do_throw("data: uri failed to download successfully");
do_test_finished(); do_test_finished();
break; break;
case dm.DOWNLOAD_FINISHED: case dm.DOWNLOAD_FINISHED:
do_check_true(aDownload.targetFile.exists()); do_check_true(aDownload.targetFile.exists());
aDownload.targetFile.remove(false); aDownload.targetFile.remove(false);
@ -103,8 +103,6 @@ function run_test()
dm.addListener(listener); dm.addListener(listener);
dm.addListener(getDownloadListener()); dm.addListener(getDownloadListener());
addDownload();
cleanup(); addDownload();
} }

Просмотреть файл

@ -112,12 +112,12 @@ function test_addDownload_cancel()
do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state); do_check_eq(nsIDownloadManager.DOWNLOAD_CANCELED, dl.state);
} }
// This test is actually ran by the observer // This test is actually ran by the observer
function test_dm_getDownload(aDl) function test_dm_getDownload(aDl)
{ {
// this will get it from the database // this will get it from the database
var dl = dm.getDownload(aDl.id); var dl = dm.getDownload(aDl.id);
do_check_eq(aDl.displayName, dl.displayName); do_check_eq(aDl.displayName, dl.displayName);
} }
@ -130,7 +130,7 @@ var httpserv = null;
function run_test() function run_test()
{ {
httpserv = new nsHttpServer(); httpserv = new nsHttpServer();
httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile)); httpserv.registerDirectory("/", do_get_cwd());
httpserv.start(4444); httpserv.start(4444);
// our download listener // our download listener
@ -161,6 +161,4 @@ function run_test()
for (var i = 0; i < tests.length; i++) for (var i = 0; i < tests.length; i++)
tests[i](); tests[i]();
cleanup();
} }

Просмотреть файл

@ -53,7 +53,7 @@
Start it and enter private browsing mode immediately after. Start it and enter private browsing mode immediately after.
* Check that Download-C has been paused. * Check that Download-C has been paused.
* Exit the private browsing mode. * Exit the private browsing mode.
* Verify that Download-C resumes and finishes correctly now. * Verify that Download-C resumes and finishes correctly now.
**/ **/
this.__defineGetter__("pb", function () { this.__defineGetter__("pb", function () {
@ -115,7 +115,7 @@ function run_test() {
do_test_pending(); do_test_pending();
let httpserv = new nsHttpServer(); let httpserv = new nsHttpServer();
httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile)); httpserv.registerDirectory("/", do_get_cwd());
let tmpDir = Cc["@mozilla.org/file/directory_service;1"]. let tmpDir = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties). getService(Ci.nsIProperties).
@ -308,7 +308,7 @@ function run_test() {
// properties of Download-C // properties of Download-C
let downloadC = -1; let downloadC = -1;
const downloadCSource = "http://localhost:4444/res/language.properties"; const downloadCSource = "http://localhost:4444/head_download_manager.js";
const downloadCDest = "download-file-C"; const downloadCDest = "download-file-C";
const downloadCName = "download-C"; const downloadCName = "download-C";

Просмотреть файл

@ -5,40 +5,9 @@ const Ci = Components.interfaces;
const Cc = Components.classes; const Cc = Components.classes;
const Cr = Components.results; const Cr = Components.results;
// Various functions common to the tests. // Various functions common to the tests.
const LoginTest = { const LoginTest = {
/*
* makeDirectoryService
*
*/
makeDirectoryService : function () {
// Register our own provider for the profile directory.
// It will simply return the current directory.
const provider = {
getFile : function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR) {
return dirSvc.get("CurProcD", Ci.nsIFile);
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface : function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
},
/* /*
* initStorage * initStorage
* *
@ -207,7 +176,7 @@ const LoginTest = {
var line = { value : null }; var line = { value : null };
var lineCount = 1; // Empty files were dealt with above. var lineCount = 1; // Empty files were dealt with above.
while (lineStream.readLine(line)) while (lineStream.readLine(line))
lineCount++; lineCount++;
return lineCount; return lineCount;
@ -217,9 +186,9 @@ const LoginTest = {
var ID; var ID;
if (STORAGE_TYPE == "legacy") if (STORAGE_TYPE == "legacy")
ID = "@mozilla.org/login-manager/storage/legacy;1"; ID = "@mozilla.org/login-manager/storage/legacy;1";
else if (STORAGE_TYPE == "mozStorage") else if (STORAGE_TYPE == "mozStorage")
ID = "@mozilla.org/login-manager/storage/mozStorage;1"; ID = "@mozilla.org/login-manager/storage/mozStorage;1";
else else
throw "Unknown STORAGE_TYPE"; throw "Unknown STORAGE_TYPE";
@ -271,22 +240,8 @@ const LoginTest = {
} }
}; };
// If there's no location registered for the profile direcotry, register one
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
try {
var profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
} catch (e) { }
if (!profileDir) {
LoginTest.makeDirectoryService();
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
}
// nsIFiles... // nsIFiles...
var PROFDIR = profileDir; var PROFDIR = do_get_profile();
var DATADIR = do_get_file("data/"); var DATADIR = do_get_file("data/");
// string versions... // string versions...
var OUTDIR = PROFDIR.path; var OUTDIR = PROFDIR.path;

Просмотреть файл

@ -43,38 +43,28 @@ const Ci = Components.interfaces;
const Cc = Components.classes; const Cc = Components.classes;
const Cr = Components.results; const Cr = Components.results;
// If there's no location registered for the profile direcotry, register one now. var profDir = do_get_profile();
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
let profileDir = null; let provider = {
try { getFile: function(prop, persistent) {
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile); persistent.value = true;
} catch (e) {} if (prop == NS_APP_HISTORY_50_FILE) {
if (!profileDir) { let histFile = profDir.clone();
// Register our own provider for the profile directory. histFile.append("history.dat");
// It will simply return the current directory. return histFile;
let provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR) {
return dirSvc.get("CurProcD", Ci.nsIFile);
}
if (prop == NS_APP_HISTORY_50_FILE) {
let histFile = dirSvc.get("CurProcD", Ci.nsIFile);
histFile.append("history.dat");
return histFile;
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
} }
}; throw Cr.NS_ERROR_FAILURE;
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider); },
} QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
// Delete a previously created sqlite file // Delete a previously created sqlite file
function clearDB() { function clearDB() {

Просмотреть файл

@ -49,34 +49,9 @@ function LOG(aMsg) {
print(aMsg); print(aMsg);
} }
// If there's no location registered for the profile direcotry, register one now. do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var profileDir = null;
try {
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
} catch (e) {}
if (!profileDir) {
// Register our own provider for the profile directory.
// It will simply return the current directory.
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR) {
return dirSvc.get("CurProcD", Ci.nsIFile);
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
function uri(spec) { function uri(spec) {

Просмотреть файл

@ -59,36 +59,27 @@ function LOG(aMsg) {
// If there's no location registered for the profile directory, register one now. // If there's no location registered for the profile directory, register one now.
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var profileDir = null; var profileDir = do_get_profile();
try {
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile); var provider = {
} catch (e) {} getFile: function(prop, persistent) {
if (!profileDir) { persistent.value = true;
// Register our own provider for the profile directory. if (prop == NS_APP_HISTORY_50_FILE) {
// It will simply return the current directory. var histFile = profileDir.clone();
var provider = { histFile.append("history.dat");
getFile: function(prop, persistent) { return histFile;
persistent.value = true; }
if (prop == NS_APP_USER_PROFILE_50_DIR) { throw Cr.NS_ERROR_FAILURE;
return dirSvc.get("CurProcD", Ci.nsIFile); },
} QueryInterface: function(iid) {
if (prop == NS_APP_HISTORY_50_FILE) { if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
var histFile = dirSvc.get("CurProcD", Ci.nsIFile); iid.equals(Ci.nsISupports)) {
histFile.append("history.dat"); return this;
return histFile; }
} throw Cr.NS_ERROR_NO_INTERFACE;
throw Cr.NS_ERROR_FAILURE; }
}, };
QueryInterface: function(iid) { dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);

Просмотреть файл

@ -51,38 +51,28 @@ function LOG(aMsg) {
print(aMsg); print(aMsg);
} }
// If there's no location registered for the profile direcotry, register one now. do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var profileDir = null; var provider = {
try { getFile: function(prop, persistent) {
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile); persistent.value = true;
} catch (e) {} if (prop == NS_APP_HISTORY_50_FILE) {
if (!profileDir) { var histFile = dirSvc.get("ProfD", Ci.nsIFile);
// Register our own provider for the profile directory. histFile.append("history.dat");
// It will simply return the current directory. return histFile;
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR) {
return dirSvc.get("CurProcD", Ci.nsIFile);
}
if (prop == NS_APP_HISTORY_50_FILE) {
var histFile = dirSvc.get("CurProcD", Ci.nsIFile);
histFile.append("history.dat");
return histFile;
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
} }
}; throw Cr.NS_ERROR_FAILURE;
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider); },
} QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);

Просмотреть файл

@ -34,46 +34,18 @@
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cc = Components.classes; const Cc = Components.classes;
const CURRENT_SCHEMA = 2; const CURRENT_SCHEMA = 2;
const PR_HOURS = 60 * 60 * 1000000; const PR_HOURS = 60 * 60 * 1000000;
do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties); getService(Ci.nsIProperties);
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var profileDir = null;
try {
profileDir = dirSvc.get("ProfD", Ci.nsIFile);
} catch (e) { }
if (!profileDir) {
// Register our own provider for the profile directory.
// It will simply return the current directory.
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == "ProfD") {
return dirSvc.get("CurProcD", Ci.nsILocalFile);
}
print("*** Throwing trying to get " + prop);
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
function getDBVersion(dbfile) { function getDBVersion(dbfile) {
var ss = Cc["@mozilla.org/storage/service;1"]. var ss = Cc["@mozilla.org/storage/service;1"].
getService(Ci.mozIStorageService); getService(Ci.mozIStorageService);

Просмотреть файл

@ -8,36 +8,9 @@ const Ci = Components.interfaces;
const Cc = Components.classes; const Cc = Components.classes;
const Cr = Components.results; const Cr = Components.results;
// If there's no location registered for the profile direcotry, register one now. do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var profileDir = null;
try {
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
} catch (e) {}
if (!profileDir) { var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
// Register our own provider for the profile directory.
// It will simply return the current directory.
var provider = {
getFile: function(prop, persistent) {
dump("getting file " + prop + "\n");
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR ||
prop == NS_APP_USER_PROFILE_LOCAL_50_DIR) {
return dirSvc.get("CurProcD", Ci.nsIFile);
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
@ -272,7 +245,7 @@ function updateError(arg)
do_throw(arg); do_throw(arg);
} }
// Runs a set of updates, and then checks a set of assertions. // Runs a set of updates, and then checks a set of assertions.
function doUpdateTest(updates, assertions, successCallback, errorCallback, clientKey) { function doUpdateTest(updates, assertions, successCallback, errorCallback, clientKey) {
var errorUpdate = function() { var errorUpdate = function() {
checkAssertions(assertions, errorCallback); checkAssertions(assertions, errorCallback);

Просмотреть файл

@ -45,10 +45,6 @@ const PREFIX_NS_EM = "http://www.mozilla.org/2004/em-rdf#";
const PREFIX_NS_CHROME = "http://www.mozilla.org/rdf/chrome#"; const PREFIX_NS_CHROME = "http://www.mozilla.org/rdf/chrome#";
const PREFIX_ITEM_URI = "urn:mozilla:item:"; const PREFIX_ITEM_URI = "urn:mozilla:item:";
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
const NS_OS_TEMP_DIR = "TmpD";
const NS_INSTALL_LOCATION_APPPROFILE = "app-profile"; const NS_INSTALL_LOCATION_APPPROFILE = "app-profile";
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1"; const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
@ -115,9 +111,9 @@ function intData(literal) {
/** /**
* Gets a RDF Resource for item with the given ID * Gets a RDF Resource for item with the given ID
* @param id * @param id
* The GUID of the item to construct a RDF resource to the * The GUID of the item to construct a RDF resource to the
* active item for * active item for
* @returns The RDF Resource to the Active item. * @returns The RDF Resource to the Active item.
*/ */
function getResourceForID(id) { function getResourceForID(id) {
return gRDF.GetResource(PREFIX_ITEM_URI + id); return gRDF.GetResource(PREFIX_ITEM_URI + id);
@ -172,17 +168,17 @@ function createAppInfo(id, name, version, platformVersion)
logConsoleErrors: true, logConsoleErrors: true,
OS: "XPCShell", OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey", XPCOMABI: "noarch-spidermonkey",
QueryInterface: function QueryInterface(iid) { QueryInterface: function QueryInterface(iid) {
if (iid.equals(Components.interfaces.nsIXULAppInfo) if (iid.equals(Components.interfaces.nsIXULAppInfo)
|| iid.equals(Components.interfaces.nsIXULRuntime) || iid.equals(Components.interfaces.nsIXULRuntime)
|| iid.equals(Components.interfaces.nsISupports)) || iid.equals(Components.interfaces.nsISupports))
return this; return this;
throw Components.results.NS_ERROR_NO_INTERFACE; throw Components.results.NS_ERROR_NO_INTERFACE;
} }
}; };
var XULAppInfoFactory = { var XULAppInfoFactory = {
createInstance: function (outer, iid) { createInstance: function (outer, iid) {
if (outer != null) if (outer != null)
@ -204,10 +200,10 @@ function startupEM()
// Make sure the update service is initialised. // Make sure the update service is initialised.
var updateSvc = Components.classes["@mozilla.org/updates/update-service;1"] var updateSvc = Components.classes["@mozilla.org/updates/update-service;1"]
.getService(Components.interfaces.nsISupports); .getService(Components.interfaces.nsISupports);
gEM = Components.classes["@mozilla.org/extensions/manager;1"] gEM = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager); .getService(Components.interfaces.nsIExtensionManager);
gEM.QueryInterface(Components.interfaces.nsIObserver); gEM.QueryInterface(Components.interfaces.nsIObserver);
gEM.observe(null, "profile-after-change", "startup"); gEM.observe(null, "profile-after-change", "startup");
@ -235,7 +231,6 @@ function startupEM()
function shutdownEM() function shutdownEM()
{ {
// xpcshell calls xpcom-shutdown so we don't actually do anything here. // xpcshell calls xpcom-shutdown so we don't actually do anything here.
gDirSvc.unregisterProvider(dirProvider);
gEM = null; gEM = null;
} }
@ -254,30 +249,7 @@ var gDirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties); .getService(Components.interfaces.nsIProperties);
// Need to create and register a profile folder. // Need to create and register a profile folder.
var gProfD = do_get_cwd(); var gProfD = do_get_profile();
gProfD.append("profile");
if (gProfD.exists())
gProfD.remove(true);
gProfD.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0755);
var dirProvider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_USER_PROFILE_50_DIR ||
prop == NS_APP_PROFILE_DIR_STARTUP)
return gProfD.clone();
return null;
},
QueryInterface: function(iid) {
if (iid.equals(Components.interfaces.nsIDirectoryServiceProvider) ||
iid.equals(Components.interfaces.nsISupports)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
gDirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
.registerProvider(dirProvider);
var gPrefs = Components.classes["@mozilla.org/preferences;1"] var gPrefs = Components.classes["@mozilla.org/preferences;1"]
.getService(Components.interfaces.nsIPrefBranch); .getService(Components.interfaces.nsIPrefBranch);

Просмотреть файл

@ -39,13 +39,3 @@
// Close down any remaining EM // Close down any remaining EM
if (gEM) if (gEM)
shutdownEM(); shutdownEM();
// Clean up the temporary profile dir.
try {
if (gProfD.exists())
gProfD.remove(true);
}
catch (e) {
// There are many valid reasons for being unable to remove the temporary
// profile dir so not much point in failing on it.
}