Backed out changeset 8000c25ea07c (bug 1649617) for xpcshell failures on ClientID.jsm. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2020-11-13 02:43:25 +02:00
Родитель 2bd1948f4f
Коммит bd1f96ff2d
2 изменённых файлов: 31 добавлений и 49 удалений

Просмотреть файл

@ -28,6 +28,7 @@ ChromeUtils.defineModuleGetter(
"CommonUtils",
"resource://services-common/utils.js"
);
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
XPCOMUtils.defineLazyGetter(this, "CryptoHash", () => {
return Components.Constructor(
@ -37,14 +38,12 @@ XPCOMUtils.defineLazyGetter(this, "CryptoHash", () => {
);
});
XPCOMUtils.defineLazyGetter(this, "gDatareportingPath", async () => {
let profileDir = await PathUtils.getProfileDir();
return PathUtils.join(profileDir, "datareporting");
XPCOMUtils.defineLazyGetter(this, "gDatareportingPath", () => {
return OS.Path.join(OS.Constants.Path.profileDir, "datareporting");
});
XPCOMUtils.defineLazyGetter(this, "gStateFilePath", async () => {
let path = await gDatareportingPath;
return PathUtils.join(path, "state.json");
XPCOMUtils.defineLazyGetter(this, "gStateFilePath", () => {
return OS.Path.join(gDatareportingPath, "state.json");
});
const PREF_CACHED_CLIENTID = "toolkit.telemetry.cachedClientID";
@ -210,7 +209,7 @@ var ClientIDImpl = {
let hasCurrentClientID = false;
let hasCurrentEcosystemClientID = false;
try {
let state = await CommonUtils.readJSON(await gStateFilePath);
let state = await CommonUtils.readJSON(gStateFilePath);
if (AppConstants.platform == "android" && state && "wasCanary" in state) {
this._wasCanary = state.wasCanary;
}
@ -268,8 +267,8 @@ var ClientIDImpl = {
if (AppConstants.platform == "android" && this._wasCanary) {
obj.wasCanary = true;
}
await IOUtils.makeDirectory(await gDatareportingPath);
await CommonUtils.writeJSON(obj, await gStateFilePath);
await OS.File.makeDir(gDatareportingPath);
await CommonUtils.writeJSON(obj, gStateFilePath);
this._saveClientIdsTask = null;
},
@ -413,7 +412,7 @@ var ClientIDImpl = {
await this._saveClientIdsTask;
// Remove the client id from disk
await IOUtils.remove(await gStateFilePath);
await OS.File.remove(gStateFilePath, { ignoreAbsent: true });
},
async removeClientIDs() {

Просмотреть файл

@ -53,9 +53,8 @@ const APP_NAME = "XPCShell";
var gClientID = null;
XPCOMUtils.defineLazyGetter(this, "DATAREPORTING_PATH", async function() {
let profileDir = await PathUtils.getProfileDir();
return PathUtils.join(profileDir, "datareporting");
XPCOMUtils.defineLazyGetter(this, "DATAREPORTING_PATH", function() {
return OS.Path.join(OS.Constants.Path.profileDir, "datareporting");
});
function sendPing(aSendClientId, aSendEnvironment) {
@ -668,32 +667,25 @@ add_task(async function test_telemetryCleanFHRDatabase() {
const DEFAULT_DB_NAME = "healthreport.sqlite";
// Check that we're able to remove a FHR DB with a custom name.
const profileDir = await PathUtils.getProfileDir();
const CUSTOM_DB_PATHS = [
PathUtils.join(profileDir, CUSTOM_DB_NAME),
PathUtils.join(profileDir, CUSTOM_DB_NAME + "-wal"),
PathUtils.join(profileDir, CUSTOM_DB_NAME + "-shm"),
OS.Path.join(OS.Constants.Path.profileDir, CUSTOM_DB_NAME),
OS.Path.join(OS.Constants.Path.profileDir, CUSTOM_DB_NAME + "-wal"),
OS.Path.join(OS.Constants.Path.profileDir, CUSTOM_DB_NAME + "-shm"),
];
Preferences.set(FHR_DBNAME_PREF, CUSTOM_DB_NAME);
// Write fake DB files to the profile directory.
for (let dbFilePath of CUSTOM_DB_PATHS) {
await IOUtils.writeAtomicUTF8(dbFilePath, "some data");
await OS.File.writeAtomic(dbFilePath, "some data");
}
// Trigger the cleanup and check that the files were removed.
await TelemetryStorage.removeFHRDatabase();
for (let dbFilePath of CUSTOM_DB_PATHS) {
try {
await IOUtils.read(dbFilePath);
} catch (e) {
Assert.ok(e instanceof DOMException);
Assert.equal(
e.name,
"NotFoundError",
"The DB must not be on the disk anymore: " + dbFilePath
);
}
Assert.ok(
!(await OS.File.exists(dbFilePath)),
"The DB must not be on the disk anymore: " + dbFilePath
);
}
// We should not break anything if there's no DB file.
@ -703,29 +695,23 @@ add_task(async function test_telemetryCleanFHRDatabase() {
Preferences.reset(FHR_DBNAME_PREF);
const DEFAULT_DB_PATHS = [
PathUtils.join(profileDir, DEFAULT_DB_NAME),
PathUtils.join(profileDir, DEFAULT_DB_NAME + "-wal"),
PathUtils.join(profileDir, DEFAULT_DB_NAME + "-shm"),
OS.Path.join(OS.Constants.Path.profileDir, DEFAULT_DB_NAME),
OS.Path.join(OS.Constants.Path.profileDir, DEFAULT_DB_NAME + "-wal"),
OS.Path.join(OS.Constants.Path.profileDir, DEFAULT_DB_NAME + "-shm"),
];
// Write fake DB files to the profile directory.
for (let dbFilePath of DEFAULT_DB_PATHS) {
await IOUtils.writeAtomicUTF8(dbFilePath, "some data");
await OS.File.writeAtomic(dbFilePath, "some data");
}
// Trigger the cleanup and check that the files were removed.
await TelemetryStorage.removeFHRDatabase();
for (let dbFilePath of DEFAULT_DB_PATHS) {
try {
await IOUtils.read(dbFilePath);
} catch (e) {
Assert.ok(e instanceof DOMException);
Assert.equal(
e.name,
"NotFoundError",
"The DB must not be on the disk anymore: " + dbFilePath
);
}
Assert.ok(
!(await OS.File.exists(dbFilePath)),
"The DB must not be on the disk anymore: " + dbFilePath
);
}
});
@ -755,11 +741,8 @@ add_task(async function test_sendNewProfile() {
await resetTest();
// Make sure to reset all the new-profile ping prefs.
const stateFilePath = PathUtils.join(
await DATAREPORTING_PATH,
"session-state.json"
);
await IOUtils.remove(stateFilePath);
const stateFilePath = OS.Path.join(DATAREPORTING_PATH, "session-state.json");
await OS.File.remove(stateFilePath, { ignoreAbsent: true });
Preferences.set(PREF_NEWPROFILE_DELAY, 1);
Preferences.set(PREF_NEWPROFILE_ENABLED, true);
@ -788,7 +771,7 @@ add_task(async function test_sendNewProfile() {
// Make sure that the new-profile ping is sent at shutdown if it wasn't sent before.
await resetTest();
await IOUtils.remove(stateFilePath);
await OS.File.remove(stateFilePath, { ignoreAbsent: true });
Preferences.reset(PREF_NEWPROFILE_DELAY);
nextReq = PingServer.promiseNextRequest();
@ -831,7 +814,7 @@ add_task(async function test_sendNewProfile() {
// Check that we don't send the new-profile ping if the profile already contains
// a state file (but no "newProfilePingSent" property).
await resetTest();
await IOUtils.remove(stateFilePath);
await OS.File.remove(stateFilePath, { ignoreAbsent: true });
const sessionState = {
sessionId: null,
subsessionId: null,