1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 this.EXPORTED_SYMBOLS = [
11 const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
13 Cu.import("resource://gre/modules/osfile.jsm");
14 Cu.import("resource://gre/modules/Promise.jsm");
16 // Reference needed in order for fake app dir provider to be active.
17 let gFakeAppDirectoryProvider;
20 * Installs a fake UAppData directory.
22 * This is needed by tests because a UAppData directory typically isn't
23 * present in the test environment.
25 * We create the new UAppData directory under the profile's directory
26 * because the profile directory is automatically cleaned as part of
29 * This returns a promise that will be resolved once the new directory
30 * is created and installed.
32 this.makeFakeAppDir = function () {
33 let dirMode = OS.Constants.libc.S_IRWXU;
34 let dirService = Cc["@mozilla.org/file/directory_service;1"]
35 .getService(Ci.nsIProperties);
36 let baseFile = dirService.get("ProfD", Ci.nsIFile);
37 let appD = baseFile.clone();
38 appD.append("UAppData");
40 if (gFakeAppDirectoryProvider) {
41 return Promise.resolve(appD.path);
49 dump("Creating directory: " + f.path + "\n");
50 f.create(Ci.nsIFile.DIRECTORY_TYPE, dirMode);
55 let reportsD = appD.clone();
56 reportsD.append("Crash Reports");
58 let pendingD = reportsD.clone();
59 pendingD.append("pending");
60 let submittedD = reportsD.clone();
61 submittedD.append("submitted");
68 getFile: function (prop, persistent) {
69 persistent.value = true;
70 if (prop == "UAppData") {
74 throw Cr.NS_ERROR_FAILURE;
77 QueryInterace: function (iid) {
78 if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
79 iid.equals(Ci.nsISupports)) {
83 throw Cr.NS_ERROR_NO_INTERFACE;
87 // Register the new provider.
88 dirService.QueryInterface(Ci.nsIDirectoryService)
89 .registerProvider(provider);
91 // And undefine the old one.
93 dirService.undefine("UAppData");
96 gFakeAppDirectoryProvider = provider;
98 dump("Successfully installed fake UAppDir\n");
99 return Promise.resolve(appD.path);