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 { Promise } = ChromeUtils.import("resource://gre/modules/Promise.jsm");
11 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
13 // Reference needed in order for fake app dir provider to be active.
14 var gFakeAppDirectoryProvider;
17 * Installs a fake UAppData directory.
19 * This is needed by tests because a UAppData directory typically isn't
20 * present in the test environment.
22 * We create the new UAppData directory under the profile's directory
23 * because the profile directory is automatically cleaned as part of
26 * This returns a promise that will be resolved once the new directory
27 * is created and installed.
29 var makeFakeAppDir = function() {
30 let dirMode = OS.Constants.libc.S_IRWXU;
31 let baseFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
32 let appD = baseFile.clone();
33 appD.append("UAppData");
35 if (gFakeAppDirectoryProvider) {
36 return Promise.resolve(appD.path);
44 dump("Creating directory: " + f.path + "\n");
45 f.create(Ci.nsIFile.DIRECTORY_TYPE, dirMode);
50 let reportsD = appD.clone();
51 reportsD.append("Crash Reports");
53 let pendingD = reportsD.clone();
54 pendingD.append("pending");
55 let submittedD = reportsD.clone();
56 submittedD.append("submitted");
63 getFile(prop, persistent) {
64 persistent.value = true;
65 if (prop == "UAppData") {
69 throw Components.Exception("", Cr.NS_ERROR_FAILURE);
74 iid.equals(Ci.nsIDirectoryServiceProvider) ||
75 iid.equals(Ci.nsISupports)
80 throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
84 // Register the new provider.
85 Services.dirsvc.registerProvider(provider);
87 // And undefine the old one.
89 Services.dirsvc.undefine("UAppData");
92 gFakeAppDirectoryProvider = provider;
94 dump("Successfully installed fake UAppDir\n");
95 return Promise.resolve(appD.path);