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/. */
5 // Reference needed in order for fake app dir provider to be active.
6 var gFakeAppDirectoryProvider;
9 * Installs a fake UAppData directory.
11 * This is needed by tests because a UAppData directory typically isn't
12 * present in the test environment.
14 * We create the new UAppData directory under the profile's directory
15 * because the profile directory is automatically cleaned as part of
18 * This returns a promise that will be resolved once the new directory
19 * is created and installed.
21 export var makeFakeAppDir = function () {
23 let baseFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
24 let appD = baseFile.clone();
25 appD.append("UAppData");
27 if (gFakeAppDirectoryProvider) {
28 return Promise.resolve(appD.path);
36 dump("Creating directory: " + f.path + "\n");
37 f.create(Ci.nsIFile.DIRECTORY_TYPE, dirMode);
42 let reportsD = appD.clone();
43 reportsD.append("Crash Reports");
45 let pendingD = reportsD.clone();
46 pendingD.append("pending");
47 let submittedD = reportsD.clone();
48 submittedD.append("submitted");
55 getFile(prop, persistent) {
56 persistent.value = true;
57 if (prop == "UAppData") {
61 throw Components.Exception("", Cr.NS_ERROR_FAILURE);
66 iid.equals(Ci.nsIDirectoryServiceProvider) ||
67 iid.equals(Ci.nsISupports)
72 throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
76 // Register the new provider.
77 Services.dirsvc.registerProvider(provider);
79 // And undefine the old one.
81 Services.dirsvc.undefine("UAppData");
84 gFakeAppDirectoryProvider = provider;
86 dump("Successfully installed fake UAppDir\n");
87 return Promise.resolve(appD.path);