Skip to content

Commit

Permalink
Backed out changeset 9ddc25fb2246 - bug 459114 - helper function to p…
Browse files Browse the repository at this point in the history
…rovide a clean profile directory for xpcshell tests. r=sdwilsh - for test failures
  • Loading branch information
Ted Mielczarek committed Aug 5, 2009
2 parents 01df21e + bf94951 commit ae69d11
Show file tree
Hide file tree
Showing 28 changed files with 556 additions and 304 deletions.
16 changes: 14 additions & 2 deletions browser/components/places/tests/unit/head_bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion extensions/cookie/test/unit/test_permmanager_removeall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"].
Expand Down Expand Up @@ -33,4 +56,8 @@ function run_test() {

// remove all should not throw
pm.removeAll();

// cleanup
dirSvc.unregisterProvider(provider);
}

66 changes: 0 additions & 66 deletions modules/plugin/test/unit/head_plugins.js

This file was deleted.

77 changes: 74 additions & 3 deletions modules/plugin/test/unit/test_bug455213.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
Expand All @@ -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"].
Expand All @@ -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");
Expand Down Expand Up @@ -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
}
}
32 changes: 29 additions & 3 deletions netwerk/test/unit/test_bug248970_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions testing/xpcshell/example/unit/test_get_file.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
52 changes: 0 additions & 52 deletions testing/xpcshell/example/unit/test_profile.js

This file was deleted.

Loading

0 comments on commit ae69d11

Please sign in to comment.