Bug 1236551 - Update tests to cover Telemetry profile migrator. r=MattN

--HG--
rename : browser/components/migration/tests/unit/test_fx_fhr.js => browser/components/migration/tests/unit/test_fx_telemetry.js
This commit is contained in:
Georg Fritzsche 2016-01-18 16:31:06 +01:00
parent 942276cd2a
commit 2c809e437f
2 changed files with 131 additions and 106 deletions

View File

@ -77,6 +77,13 @@ function writeToFile(dir, leafName, contents) {
outputStream.close(); outputStream.close();
} }
function createSubDir(dir, subDirName) {
let subDir = dir.clone();
subDir.append(subDirName);
subDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
return subDir;
}
function promiseMigrator(name, srcDir, targetDir) { function promiseMigrator(name, srcDir, targetDir) {
let migrator = Cc["@mozilla.org/profile/migrator;1?app=browser&type=firefox"] let migrator = Cc["@mozilla.org/profile/migrator;1?app=browser&type=firefox"]
.createInstance(Ci.nsISupports) .createInstance(Ci.nsISupports)
@ -92,150 +99,168 @@ function promiseMigrator(name, srcDir, targetDir) {
throw new Error("failed to find the " + name + " migrator"); throw new Error("failed to find the " + name + " migrator");
} }
function promiseFHRMigrator(srcDir, targetDir) { function promiseTelemetryMigrator(srcDir, targetDir) {
return promiseMigrator("healthreporter", srcDir, targetDir); return promiseMigrator("telemetry", srcDir, targetDir);
} }
add_task(function* test_empty() { add_task(function* test_empty() {
let [srcDir, targetDir] = getTestDirs(); let [srcDir, targetDir] = getTestDirs();
let ok = yield promiseFHRMigrator(srcDir, targetDir); let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true with empty directories"); Assert.ok(ok, "callback should have been true with empty directories");
// check both are empty // check both are empty
checkDirectoryContains(srcDir, {}); checkDirectoryContains(srcDir, {});
checkDirectoryContains(targetDir, {}); checkDirectoryContains(targetDir, {});
}); });
add_task(function* test_just_sqlite() { add_task(function* test_migrate_files() {
let [srcDir, targetDir] = getTestDirs(); let [srcDir, targetDir] = getTestDirs();
let contents = "hello there\n\n"; // Set up datareporting files, some to copy, some not.
writeToFile(srcDir, "healthreport.sqlite", contents); let stateContent = JSON.stringify({
clientId: "68d5474e-19dc-45c1-8e9a-81fca592707c",
let ok = yield promiseFHRMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true with sqlite file copied");
checkDirectoryContains(targetDir, {
"healthreport.sqlite": contents,
}); });
}); let sessionStateContent = "foobar 5432";
let subDir = createSubDir(srcDir, "datareporting");
writeToFile(subDir, "state.json", stateContent);
writeToFile(subDir, "session-state.json", sessionStateContent);
writeToFile(subDir, "other.file", "do not copy");
add_task(function* test_sqlite_extras() { let archived = createSubDir(subDir, "archived");
let [srcDir, targetDir] = getTestDirs(); writeToFile(archived, "other.file", "do not copy");
let contents_sqlite = "hello there\n\n"; // Set up FHR files, they should not be copied.
writeToFile(srcDir, "healthreport.sqlite", contents_sqlite); writeToFile(srcDir, "healthreport.sqlite", "do not copy");
writeToFile(srcDir, "healthreport.sqlite-wal", "do not copy");
subDir = createSubDir(srcDir, "healthreport");
writeToFile(subDir, "state.json", "do not copy");
writeToFile(subDir, "other.file", "do not copy");
let contents_wal = "this is the wal\n\n"; // Perform migration.
writeToFile(srcDir, "healthreport.sqlite-wal", contents_wal); let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true with important telemetry files copied");
// and the -shm - this should *not* be copied.
writeToFile(srcDir, "healthreport.sqlite-shm", "whatever");
let ok = yield promiseFHRMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true with sqlite file copied");
checkDirectoryContains(targetDir, { checkDirectoryContains(targetDir, {
"healthreport.sqlite": contents_sqlite, "datareporting": {
"healthreport.sqlite-wal": contents_wal, "state.json": stateContent,
}); "session-state.json": sessionStateContent,
});
add_task(function* test_sqlite_healthreport_not_dir() {
let [srcDir, targetDir] = getTestDirs();
let contents = "hello there\n\n";
writeToFile(srcDir, "healthreport.sqlite", contents);
writeToFile(srcDir, "healthreport", "I'm a file but should be a directory");
let ok = yield promiseFHRMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true even though the directory was a file");
// We should have only the sqlite file
checkDirectoryContains(targetDir, {
"healthreport.sqlite": contents,
});
});
add_task(function* test_sqlite_healthreport_empty() {
let [srcDir, targetDir] = getTestDirs();
let contents = "hello there\n\n";
writeToFile(srcDir, "healthreport.sqlite", contents);
// create an empty 'healthreport' subdir.
let subDir = srcDir.clone();
subDir.append("healthreport");
subDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
let ok = yield promiseFHRMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true");
// we should end up with the .sqlite file and an empty subdir in the target.
checkDirectoryContains(targetDir, {
"healthreport.sqlite": contents,
"healthreport": {},
});
});
add_task(function* test_sqlite_healthreport_contents() {
let [srcDir, targetDir] = getTestDirs();
let contents = "hello there\n\n";
writeToFile(srcDir, "healthreport.sqlite", contents);
// create an empty 'healthreport' subdir.
let subDir = srcDir.clone();
subDir.append("healthreport");
subDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
writeToFile(subDir, "file1", "this is file 1");
writeToFile(subDir, "file2", "this is file 2");
let ok = yield promiseFHRMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true");
// we should end up with the .sqlite file and an empty subdir in the target.
checkDirectoryContains(targetDir, {
"healthreport.sqlite": contents,
"healthreport": {
"file1": "this is file 1",
"file2": "this is file 2",
}, },
}); });
}); });
add_task(function* test_fallback_fhr_state() {
let [srcDir, targetDir] = getTestDirs();
// Test that we fall back to migrating FHR state if the datareporting
// state file does not exist.
let stateContent = JSON.stringify({
clientId: "68d5474e-19dc-45c1-8e9a-81fca592707c",
});
let subDir = createSubDir(srcDir, "healthreport");
writeToFile(subDir, "state.json", stateContent);
// Perform migration.
let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true");
checkDirectoryContains(targetDir, {
"healthreport": {
"state.json": stateContent,
},
});
});
add_task(function* test_datareporting_not_dir() {
let [srcDir, targetDir] = getTestDirs();
writeToFile(srcDir, "datareporting", "I'm a file but should be a directory");
let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true even though the directory was a file");
checkDirectoryContains(targetDir, {});
});
add_task(function* test_datareporting_empty() { add_task(function* test_datareporting_empty() {
let [srcDir, targetDir] = getTestDirs(); let [srcDir, targetDir] = getTestDirs();
// create an empty 'datareporting' subdir. // Migrate with an empty 'datareporting' subdir.
let subDir = srcDir.clone(); let subDir = createSubDir(srcDir, "datareporting");
subDir.append("datareporting"); let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
subDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
let ok = yield promiseFHRMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true"); Assert.ok(ok, "callback should have been true");
// we should end up with nothing at all in the destination - state.json was // We should end up with no migrated files.
// missing so we didn't even create the target dir. checkDirectoryContains(targetDir, {
"datareporting": {},
});
});
add_task(function* test_healthreport_empty() {
let [srcDir, targetDir] = getTestDirs();
// Migrate with no 'datareporting' and an empty 'healthreport' subdir.
let subDir = createSubDir(srcDir, "healthreport");
let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true");
// We should end up with no migrated files.
checkDirectoryContains(targetDir, {}); checkDirectoryContains(targetDir, {});
}); });
add_task(function* test_datareporting_many() { add_task(function* test_datareporting_many() {
let [srcDir, targetDir] = getTestDirs(); let [srcDir, targetDir] = getTestDirs();
// create an empty 'datareporting' subdir. // Create some datareporting files.
let subDir = srcDir.clone(); let subDir = createSubDir(srcDir, "datareporting");
subDir.append("datareporting"); let shouldBeCopied = "should be copied";
subDir.create(Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); writeToFile(subDir, "state.json", shouldBeCopied);
writeToFile(subDir, "session-state.json", shouldBeCopied);
writeToFile(subDir, "state.json", "should be copied");
writeToFile(subDir, "something.else", "should not"); writeToFile(subDir, "something.else", "should not");
createSubDir(subDir, "emptyDir");
let ok = yield promiseFHRMigrator(srcDir, targetDir); let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true"); Assert.ok(ok, "callback should have been true");
checkDirectoryContains(targetDir, { checkDirectoryContains(targetDir, {
"datareporting" : { "datareporting" : {
"state.json": "should be copied", "state.json": shouldBeCopied,
"session-state.json": shouldBeCopied,
}
});
});
add_task(function* test_no_session_state() {
let [srcDir, targetDir] = getTestDirs();
// Check that migration still works properly if we only have state.json.
let subDir = createSubDir(srcDir, "datareporting");
let stateContent = "abcd984";
writeToFile(subDir, "state.json", stateContent);
let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true");
checkDirectoryContains(targetDir, {
"datareporting" : {
"state.json": stateContent,
}
});
});
add_task(function* test_no_state() {
let [srcDir, targetDir] = getTestDirs();
// Check that migration still works properly if we only have session-state.json.
let subDir = createSubDir(srcDir, "datareporting");
let sessionStateContent = "abcd512";
writeToFile(subDir, "session-state.json", sessionStateContent);
let ok = yield promiseTelemetryMigrator(srcDir, targetDir);
Assert.ok(ok, "callback should have been true");
checkDirectoryContains(targetDir, {
"datareporting" : {
"session-state.json": sessionStateContent,
} }
}); });
}); });

View File

@ -12,7 +12,7 @@ skip-if = os != "mac" # Relies on ULibDir
[test_Chrome_passwords.js] [test_Chrome_passwords.js]
skip-if = os != "win" skip-if = os != "win"
[test_Edge_availability.js] [test_Edge_availability.js]
[test_fx_fhr.js] [test_fx_telemetry.js]
[test_IE_bookmarks.js] [test_IE_bookmarks.js]
skip-if = os != "win" skip-if = os != "win"
[test_IE_cookies.js] [test_IE_cookies.js]