Backed out changeset 9ddc25fb2246 - bug 459114 - helper function to provide a clean profile directory for xpcshell tests. r=sdwilsh - for test failures

This commit is contained in:
Ted Mielczarek 2009-08-05 15:36:49 -04:00
commit ae69d113a8
28 changed files with 554 additions and 302 deletions

View File

@ -54,14 +54,26 @@ function LOG(aMsg) {
print(aMsg);
}
var gProfD = do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
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 = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_BOOKMARKS_50_FILE) {
if (prop == NS_APP_USER_PROFILE_50_DIR ||
prop == NS_APP_PROFILE_DIR_STARTUP)
return gProfD.clone();
else if (prop == NS_APP_BOOKMARKS_50_FILE) {
var bmarks = gProfD.clone();
bmarks.append("bookmarks.html");
return bmarks;

View File

@ -3,7 +3,30 @@ const Ci = Components.interfaces;
function run_test() {
// setup a profile directory
var dir = do_get_profile();
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
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
var pm = Cc["@mozilla.org/permissionmanager;1"].
@ -33,4 +56,8 @@ function run_test() {
// remove all should not throw
pm.removeAll();
// cleanup
dirSvc.unregisterProvider(provider);
}

View File

@ -1,66 +0,0 @@
/* ***** 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;
}

View File

@ -39,6 +39,9 @@
const Cc = Components.classes;
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
const CWD = do_get_cwd();
function checkOS(os) {
@ -53,10 +56,41 @@ var DELIM = ":";
if ("@mozilla.org/windows-registry-key;1" in Components.classes)
DELIM = "|";
var gProfD = do_get_profile();
var gProfD;
var gDirSvc = Cc["@mozilla.org/file/directory_service;1"].
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
function write_registry(version, info) {
var header = "Generated File. Do not edit.\n\n";
@ -69,18 +103,47 @@ function write_registry(version, info) {
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
// 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 os = Cc["@mozilla.org/intl/converter-output-stream;1"].
createInstance(Ci.nsIConverterOutputStream);
os.init(foStream, charset, 0, 0x0000);
os.writeString(header);
os.writeString(info);
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
function get_test_plugintag() {
var host = Cc["@mozilla.org/plugin/host;1"].
@ -94,6 +157,7 @@ function get_test_plugintag() {
}
function run_test() {
createProfileFolder();
var file = get_test_plugin();
if (!file)
do_throw("Plugin library not found");
@ -125,4 +189,11 @@ function run_test() {
// If the plugin registry was not read then the plugin will not be disabled
do_check_true(plugin.disabled);
do_check_false(plugin.blocklisted);
try {
gProfD.remove(true);
}
catch (e) {
// Failure to remove temp dir shouldn't be a test failure
}
}

View File

@ -70,11 +70,37 @@ function get_cache_service() {
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) {
var cs = get_cache_service();
@ -208,7 +234,7 @@ function run_test() {
kTestContent = "test content";
// Simulate a profile dir for xpcshell
do_get_profile();
setup_profile_dir();
var cs = get_cache_service();

View File

@ -1,3 +1,4 @@
/* -*- 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

View File

@ -1,52 +0,0 @@
/* -*- 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));
}

View File

@ -1,3 +1,4 @@
/* -*- 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
@ -354,39 +355,3 @@ function do_register_cleanup(aFunction)
{
_cleanupFunctions.push(aFunction);
}
/*
* Register a directory with the profile service,
* and return the directory as an nsILocalFile.
*/
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();
}

View File

@ -37,12 +37,11 @@
#
# ***** END LICENSE BLOCK ***** */
import re, sys, os, os.path, logging, shutil
import re, sys, os, os.path, logging
import tempfile
from glob import glob
from optparse import OptionParser
from subprocess import Popen, PIPE, STDOUT
from tempfile import mkdtemp
from automationutils import addCommonOptions, checkForCrashes
@ -227,13 +226,8 @@ def runTests(xpcshell, testdirs=[], xrePath=None, testPath=None,
proc = Popen(cmdH + cmdT + xpcsRunArgs,
stdout=pStdout, stderr=pStderr, env=env, cwd=testdir)
# |stderr == None| as |pStderr| was either |None| or redirected to |stdout|.
# create a temp dir that the JS harness can stick a profile in
profd = mkdtemp()
env["XPCSHELL_TEST_PROFILE_DIR"] = profd
stdout, stderr = proc.communicate()
shutil.rmtree(profd, True)
if interactive:
# not sure what else to do here...
return True

View File

@ -38,10 +38,38 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
do_get_profile();
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);
} 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)
{

View File

@ -38,7 +38,6 @@
// This file tests the download manager backend
do_load_httpd_js();
do_get_profile();
function createURI(aObj)
{
@ -50,27 +49,37 @@ function createURI(aObj)
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
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;
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;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
/**
* Imports a download test file to use. Works with rdf and sqlite files.
@ -91,6 +100,31 @@ function importDownloadsFile(aFName)
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;
/**
* Adds a download to the DM, and starts it.
@ -113,7 +147,7 @@ function addDownload(aParams)
aParams.targetFile.append(aParams.resultFileName);
}
if (!("sourceURI" in aParams))
aParams.sourceURI = "http://localhost:4444/head_download_manager.js";
aParams.sourceURI = "http://localhost:4444/res/language.properties";
if (!("downloadName" in aParams))
aParams.downloadName = null;
if (!("runBeforeStart" in aParams))
@ -176,3 +210,6 @@ function getDownloadListener()
// Disable alert service notifications
let ps = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
ps.setBoolPref("browser.download.manager.showAlertOnComplete", false);
cleanup();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -112,12 +112,12 @@ function test_addDownload_cancel()
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)
{
// this will get it from the database
var dl = dm.getDownload(aDl.id);
do_check_eq(aDl.displayName, dl.displayName);
}
@ -130,7 +130,7 @@ var httpserv = null;
function run_test()
{
httpserv = new nsHttpServer();
httpserv.registerDirectory("/", do_get_cwd());
httpserv.registerDirectory("/", dirSvc.get("ProfD", Ci.nsILocalFile));
httpserv.start(4444);
// our download listener
@ -161,4 +161,6 @@ function run_test()
for (var i = 0; i < tests.length; i++)
tests[i]();
cleanup();
}

View File

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

View File

@ -5,9 +5,40 @@ const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
// Various functions common to the tests.
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
*
@ -176,7 +207,7 @@ const LoginTest = {
var line = { value : null };
var lineCount = 1; // Empty files were dealt with above.
while (lineStream.readLine(line))
while (lineStream.readLine(line))
lineCount++;
return lineCount;
@ -186,9 +217,9 @@ const LoginTest = {
var ID;
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")
ID = "@mozilla.org/login-manager/storage/mozStorage;1";
ID = "@mozilla.org/login-manager/storage/mozStorage;1";
else
throw "Unknown STORAGE_TYPE";
@ -240,8 +271,22 @@ 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...
var PROFDIR = do_get_profile();
var PROFDIR = profileDir;
var DATADIR = do_get_file("data/");
// string versions...
var OUTDIR = PROFDIR.path;

View File

@ -43,28 +43,38 @@ const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
var profDir = do_get_profile();
// If there's no location registered for the profile direcotry, register one now.
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
let provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_HISTORY_50_FILE) {
let histFile = profDir.clone();
histFile.append("history.dat");
return histFile;
let 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.
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;
},
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);
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
// Delete a previously created sqlite file
function clearDB() {

View File

@ -49,9 +49,34 @@ function LOG(aMsg) {
print(aMsg);
}
do_get_profile();
// If there's no location registered for the profile direcotry, register one now.
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 iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
function uri(spec) {

View File

@ -59,27 +59,36 @@ function LOG(aMsg) {
// 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 profileDir = do_get_profile();
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_HISTORY_50_FILE) {
var histFile = profileDir.clone();
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;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
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);
}
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;
}
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);

View File

@ -51,28 +51,38 @@ function LOG(aMsg) {
print(aMsg);
}
do_get_profile();
// If there's no location registered for the profile direcotry, register one now.
var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
var provider = {
getFile: function(prop, persistent) {
persistent.value = true;
if (prop == NS_APP_HISTORY_50_FILE) {
var histFile = dirSvc.get("ProfD", Ci.nsIFile);
histFile.append("history.dat");
return histFile;
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);
}
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;
},
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);
};
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
}
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);

View File

@ -34,18 +34,46 @@
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cc = Components.classes;
const CURRENT_SCHEMA = 2;
const PR_HOURS = 60 * 60 * 1000000;
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;
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) {
var ss = Cc["@mozilla.org/storage/service;1"].
getService(Ci.mozIStorageService);

View File

@ -8,9 +8,36 @@ const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
do_get_profile();
// If there's no location registered for the profile direcotry, register one now.
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) {
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);
@ -245,7 +272,7 @@ function updateError(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) {
var errorUpdate = function() {
checkAssertions(assertions, errorCallback);

View File

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

View File

@ -39,3 +39,13 @@
// Close down any remaining EM
if (gEM)
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.
}