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 var EXPORTED_SYMBOLS = ["makeFakeAppDir"];
9 const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
10 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
12 // Reference needed in order for fake app dir provider to be active.
13 var gFakeAppDirectoryProvider;
16 * Installs a fake UAppData directory.
18 * This is needed by tests because a UAppData directory typically isn't
19 * present in the test environment.
21 * We create the new UAppData directory under the profile's directory
22 * because the profile directory is automatically cleaned as part of
25 * This returns a promise that will be resolved once the new directory
26 * is created and installed.
28 var makeFakeAppDir = function() {
29 let dirMode = OS.Constants.libc.S_IRWXU;
30 let baseFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
31 let appD = baseFile.clone();
32 appD.append("UAppData");
34 if (gFakeAppDirectoryProvider) {
35 return Promise.resolve(appD.path);
43 dump("Creating directory: " + f.path + "\n");
44 f.create(Ci.nsIFile.DIRECTORY_TYPE, dirMode);
49 let reportsD = appD.clone();
50 reportsD.append("Crash Reports");
52 let pendingD = reportsD.clone();
53 pendingD.append("pending");
54 let submittedD = reportsD.clone();
55 submittedD.append("submitted");
62 getFile(prop, persistent) {
63 persistent.value = true;
64 if (prop == "UAppData") {
68 throw Components.Exception("", Cr.NS_ERROR_FAILURE);
73 iid.equals(Ci.nsIDirectoryServiceProvider) ||
74 iid.equals(Ci.nsISupports)
79 throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
83 // Register the new provider.
84 Services.dirsvc.registerProvider(provider);
86 // And undefine the old one.
88 Services.dirsvc.undefine("UAppData");
91 gFakeAppDirectoryProvider = provider;
93 dump("Successfully installed fake UAppDir\n");
94 return Promise.resolve(appD.path);