2013-12-05 12:54:15 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
|
|
|
"makeFakeAppDir",
|
|
|
|
];
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/osfile.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Promise.jsm");
|
2018-02-12 20:10:00 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2013-12-05 12:54:15 +04:00
|
|
|
|
|
|
|
// Reference needed in order for fake app dir provider to be active.
|
2015-09-15 21:19:45 +03:00
|
|
|
var gFakeAppDirectoryProvider;
|
2013-12-05 12:54:15 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs a fake UAppData directory.
|
|
|
|
*
|
|
|
|
* This is needed by tests because a UAppData directory typically isn't
|
|
|
|
* present in the test environment.
|
|
|
|
*
|
|
|
|
* We create the new UAppData directory under the profile's directory
|
|
|
|
* because the profile directory is automatically cleaned as part of
|
|
|
|
* test shutdown.
|
|
|
|
*
|
|
|
|
* This returns a promise that will be resolved once the new directory
|
|
|
|
* is created and installed.
|
|
|
|
*/
|
2017-06-24 00:08:02 +03:00
|
|
|
this.makeFakeAppDir = function() {
|
2013-12-05 12:54:15 +04:00
|
|
|
let dirMode = OS.Constants.libc.S_IRWXU;
|
2018-02-12 20:10:00 +03:00
|
|
|
let baseFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
2013-12-05 12:54:15 +04:00
|
|
|
let appD = baseFile.clone();
|
|
|
|
appD.append("UAppData");
|
|
|
|
|
|
|
|
if (gFakeAppDirectoryProvider) {
|
|
|
|
return Promise.resolve(appD.path);
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeDir(f) {
|
|
|
|
if (f.exists()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump("Creating directory: " + f.path + "\n");
|
|
|
|
f.create(Ci.nsIFile.DIRECTORY_TYPE, dirMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
makeDir(appD);
|
|
|
|
|
|
|
|
let reportsD = appD.clone();
|
|
|
|
reportsD.append("Crash Reports");
|
|
|
|
|
|
|
|
let pendingD = reportsD.clone();
|
|
|
|
pendingD.append("pending");
|
|
|
|
let submittedD = reportsD.clone();
|
|
|
|
submittedD.append("submitted");
|
|
|
|
|
|
|
|
makeDir(reportsD);
|
|
|
|
makeDir(pendingD);
|
|
|
|
makeDir(submittedD);
|
|
|
|
|
|
|
|
let provider = {
|
2017-06-24 00:08:02 +03:00
|
|
|
getFile(prop, persistent) {
|
2013-12-05 12:54:15 +04:00
|
|
|
persistent.value = true;
|
|
|
|
if (prop == "UAppData") {
|
|
|
|
return appD.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Cr.NS_ERROR_FAILURE;
|
|
|
|
},
|
|
|
|
|
2017-06-24 00:08:02 +03:00
|
|
|
QueryInterace(iid) {
|
2013-12-05 12:54:15 +04:00
|
|
|
if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
|
|
|
|
iid.equals(Ci.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register the new provider.
|
2018-02-12 20:10:00 +03:00
|
|
|
Services.dirsvc.registerProvider(provider);
|
2013-12-05 12:54:15 +04:00
|
|
|
|
|
|
|
// And undefine the old one.
|
|
|
|
try {
|
2018-02-12 20:10:00 +03:00
|
|
|
Services.dirsvc.undefine("UAppData");
|
2017-06-24 00:08:02 +03:00
|
|
|
} catch (ex) {}
|
2013-12-05 12:54:15 +04:00
|
|
|
|
|
|
|
gFakeAppDirectoryProvider = provider;
|
|
|
|
|
|
|
|
dump("Successfully installed fake UAppDir\n");
|
|
|
|
return Promise.resolve(appD.path);
|
|
|
|
};
|