Bug 1346716 - Remove the entry for "mimeTypes.rdf" in the directory service. r=mak

This improves performance because we won't try to fix the permissions of the file every time the nsIHandlerService implementation wants to open it, and makes it easier to access the file path from xpcshell tests.

MozReview-Commit-ID: DZmLa92qUnZ

--HG--
extra : source : bd0fdce03cc7442079e96318d3a9b519a4d403a9
This commit is contained in:
Paolo Amadini 2017-03-30 15:51:18 +01:00
Родитель 65b97eaee4
Коммит bc9668cdff
11 изменённых файлов: 39 добавлений и 192 удалений

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

@ -539,10 +539,6 @@ nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
ensureFilePermissions = true;
}
}
else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
ensureFilePermissions = true;
}
else if (!strcmp(aProperty, NS_APP_DOWNLOADS_50_FILE)) {
rv = file->AppendNative(NS_LITERAL_CSTRING("downloads.rdf"));
}

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

@ -928,7 +928,8 @@ HandlerService.prototype = {
__ds: null,
get _ds() {
if (!this.__ds) {
var file = this._dirSvc.get("UMimTyp", Ci.nsIFile);
var file = this._dirSvc.get("ProfD", Ci.nsIFile);
file.append("mimeTypes.rdf");
// FIXME: make this a memoizing getter if we use it anywhere else.
var ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);

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

@ -9,8 +9,6 @@
* of handlerService (JSON backend and RDF backend).
*/
"use strict"
Cu.import("resource://gre/modules/osfile.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://testing-common/TestUtils.jsm");
@ -26,7 +24,7 @@ const pdfHandlerInfo = gMIMEService.getFromTypeAndExtension("application/pdf", n
const gzipHandlerInfo = gMIMEService.getFromTypeAndExtension("application/x-gzip", null);
const ircHandlerInfo = gExternalProtocolService.getProtocolHandlerInfo("irc");
let executable = HandlerServiceTest._dirSvc.get("TmpD", Ci.nsIFile);
let executable = Services.dirsvc.get("TmpD", Ci.nsIFile);
let localHandler = {
name: "Local Handler",
executable: executable,

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

@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* Initialization for tests related to invoking external handler applications.
*/
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/Services.jsm");
do_get_profile();
let rdfFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
rdfFile.append("mimeTypes.rdf")
function deleteDatasourceFile() {
if (rdfFile.exists()) {
rdfFile.remove(false);
}
}
// Delete the existing datasource file, if any, so we start from scratch.
// We also do this after finishing the tests, so there shouldn't be an old
// file lying around, but just in case we delete it here as well.
deleteDatasourceFile();
do_register_cleanup(deleteDatasourceFile);

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

@ -1,168 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Inspired by the Places infrastructure in head_bookmarks.js
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
var HandlerServiceTest = {
//**************************************************************************//
// Convenience Getters
__dirSvc: null,
get _dirSvc() {
if (!this.__dirSvc)
this.__dirSvc = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
QueryInterface(Ci.nsIDirectoryService);
return this.__dirSvc;
},
__consoleSvc: null,
get _consoleSvc() {
if (!this.__consoleSvc)
this.__consoleSvc = Cc["@mozilla.org/consoleservice;1"].
getService(Ci.nsIConsoleService);
return this.__consoleSvc;
},
//**************************************************************************//
// nsISupports
interfaces: [Ci.nsIDirectoryServiceProvider, Ci.nsISupports],
QueryInterface: function HandlerServiceTest_QueryInterface(iid) {
if (!this.interfaces.some( function(v) { return iid.equals(v) } ))
throw Cr.NS_ERROR_NO_INTERFACE;
return this;
},
//**************************************************************************//
// Initialization & Destruction
init: function HandlerServiceTest_init() {
// Register ourselves as a directory provider for the datasource file
// if there isn't one registered already.
try {
this._dirSvc.get("UMimTyp", Ci.nsIFile);
} catch (ex) {
do_get_profile();
this._dirSvc.registerProvider(this);
this._providerRegistered = true;
}
// Delete the existing datasource file, if any, so we start from scratch.
// We also do this after finishing the tests, so there shouldn't be an old
// file lying around, but just in case we delete it here as well.
this._deleteDatasourceFile();
// Turn on logging so we can troubleshoot problems with the tests.
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
prefBranch.setBoolPref("browser.contentHandling.log", true);
},
destroy: function HandlerServiceTest_destroy() {
// Delete the existing datasource file, if any, so we don't leave test files
// lying around and we start from scratch the next time.
this._deleteDatasourceFile();
// Unregister the directory service provider
if (this._providerRegistered)
this._dirSvc.unregisterProvider(this);
},
//**************************************************************************//
// nsIDirectoryServiceProvider
getFile: function HandlerServiceTest_getFile(property, persistent) {
this.log("getFile: requesting " + property);
persistent.value = true;
if (property == "UMimTyp") {
var datasourceFile = this._dirSvc.get("ProfD", Ci.nsIFile);
datasourceFile.append("mimeTypes.rdf");
return datasourceFile;
}
// This causes extraneous errors to show up in the log when the directory
// service asks us first for CurProcD and MozBinD. I wish there was a way
// to suppress those errors.
this.log("the following NS_ERROR_FAILURE exception in " +
"nsIDirectoryServiceProvider::getFile is expected, " +
"as we don't provide the '" + property + "' file");
throw Cr.NS_ERROR_FAILURE;
},
//**************************************************************************//
// Utilities
/**
* Delete the datasource file.
*/
_deleteDatasourceFile: function HandlerServiceTest__deleteDatasourceFile() {
var file = this._dirSvc.get("UMimTyp", Ci.nsIFile);
if (file.exists())
file.remove(false);
},
/**
* Get the contents of the datasource as a serialized string. Useful for
* debugging problems with test failures, i.e.:
*
* HandlerServiceTest.log(HandlerServiceTest.getDatasourceContents());
*
* @returns {string} the serialized datasource
*/
getDatasourceContents: function HandlerServiceTest_getDatasourceContents() {
var rdf = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
var ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var fileHandler = ioService.getProtocolHandler("file").
QueryInterface(Ci.nsIFileProtocolHandler);
var fileURL = fileHandler.getURLSpecFromFile(this.getDatasourceFile());
var ds = rdf.GetDataSourceBlocking(fileURL);
var outputStream = {
data: "",
close: function() {},
flush: function() {},
write: function (buffer,count) {
this.data += buffer;
return count;
},
writeFrom: function (stream,count) {},
isNonBlocking: false
};
ds.QueryInterface(Components.interfaces.nsIRDFXMLSource);
ds.Serialize(outputStream);
return outputStream.data;
},
/**
* Log a message to the console and the test log.
*/
log: function HandlerServiceTest_log(message) {
message = "*** HandlerServiceTest: " + message;
this._consoleSvc.logStringMessage(message);
print(message);
}
};
HandlerServiceTest.init();
do_register_cleanup(function() {
HandlerServiceTest.destroy();
});

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

@ -64,7 +64,7 @@ function run_test() {
// that exists on all platforms (except possibly the application being
// tested, but there doesn't seem to be a way to get a reference to that
// from the directory service), we use the temporary directory itself.
var executable = HandlerServiceTest._dirSvc.get("TmpD", Ci.nsIFile);
var executable = Services.dirsvc.get("TmpD", Ci.nsIFile);
// XXX We could, of course, create an actual executable in the directory:
//executable.append("localhandler");
//if (!executable.exists())
@ -438,7 +438,6 @@ function run_test() {
do_check_true(handlerSvc.exists(lolHandler));
// Get a file:// string pointing to mimeTypes.rdf
var rdfFile = HandlerServiceTest._dirSvc.get("UMimTyp", Ci.nsIFile);
var fileHandler = ioService.getProtocolHandler("file").QueryInterface(Ci.nsIFileProtocolHandler);
var rdfFileURI = fileHandler.getURLSpecFromFile(rdfFile);

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

@ -7,9 +7,6 @@
* Tests the handlerService interfaces using JSON backend.
*/
"use strict"
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");

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

@ -7,8 +7,6 @@
* Tests the handlerService interfaces using RDF backend.
*/
"use strict"
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
@ -23,16 +21,13 @@ Services.scriptloader.loadSubScript(NetUtil.newURI(scriptFile).spec);
var prepareImportDB = Task.async(function* () {
yield reloadData();
let dst = HandlerServiceTest._dirSvc.get("UMimTyp", Ci.nsIFile);
yield OS.File.copy(do_get_file("mimeTypes.rdf").path, dst.path);
Assert.ok((yield OS.File.exists(dst.path)), "should have a DB now");
yield OS.File.copy(do_get_file("mimeTypes.rdf").path, rdfFile.path);
});
var removeImportDB = Task.async(function* () {
yield reloadData();
HandlerServiceTest._deleteDatasourceFile();
let dst = HandlerServiceTest._dirSvc.get("UMimTyp", Ci.nsIFile);
Assert.ok(!(yield OS.File.exists(dst.path)), "should not have a DB now");
yield OS.File.remove(rdfFile.path, { ignoreAbsent: true });
});
var reloadData = Task.async(function* () {

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

@ -102,7 +102,7 @@ function run_test() {
// The Write Argument file needs to know where its libraries are, so
// just force the path variable
// For mac
var greDir = HandlerServiceTest._dirSvc.get("GreD", Components.interfaces.nsIFile);
var greDir = Services.dirsvc.get("GreD", Components.interfaces.nsIFile);
envSvc.set("DYLD_LIBRARY_PATH", greDir.path);
// For Linux

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

@ -1,5 +1,5 @@
[DEFAULT]
head = head_handlerService.js
head = head.js
run-sequentially = Bug 912235 - Intermittent failures
firefox-appdir = browser
support-files = common_test_handlerService.js

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

@ -71,7 +71,6 @@
#define NS_APP_LOCALSTORE_50_FILE "LclSt"
#define NS_APP_USER_PANELS_50_FILE "UPnls"
#define NS_APP_USER_MIMETYPES_50_FILE "UMimTyp"
#define NS_APP_CACHE_PARENT_DIR "cachePDir"
#define NS_APP_DOWNLOADS_50_FILE "DLoads"