Bug 1455183 - Create fresh bookmarks mirror database copies for each migration test. r?mak
MozReview-Commit-ID: 1Mr8NERSrN8
--- a/toolkit/components/places/tests/sync/head_sync.js
+++ b/toolkit/components/places/tests/sync/head_sync.js
@@ -1,28 +1,29 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
ChromeUtils.import("resource://gre/modules/Services.jsm");
-ChromeUtils.import("resource://gre/modules/CanonicalJSON.jsm");
// Import common head.
{
/* import-globals-from ../head_common.js */
let commonFile = do_get_file("../head_common.js", false);
let uri = Services.io.newFileURI(commonFile);
Services.scriptloader.loadSubScript(uri.spec, this);
}
// Put any other stuff relative to this test folder below.
+ChromeUtils.import("resource://gre/modules/CanonicalJSON.jsm");
ChromeUtils.import("resource://gre/modules/Log.jsm");
ChromeUtils.import("resource://gre/modules/ObjectUtils.jsm");
ChromeUtils.import("resource://gre/modules/PlacesSyncUtils.jsm");
ChromeUtils.import("resource://gre/modules/SyncedBookmarksMirror.jsm");
+ChromeUtils.import("resource://testing-common/FileTestUtils.jsm");
ChromeUtils.import("resource://testing-common/httpd.js");
// These titles are defined in Database::CreateBookmarkRoots
const BookmarksMenuTitle = "menu";
const BookmarksToolbarTitle = "toolbar";
const UnfiledBookmarksTitle = "unfiled";
const MobileBookmarksTitle = "mobile";
@@ -239,8 +240,17 @@ BookmarkObserver.prototype = {
},
};
function expectBookmarkChangeNotifications(options) {
let observer = new BookmarkObserver(options);
PlacesUtils.bookmarks.addObserver(observer);
return observer;
}
+
+// Copies a support file to a temporary fixture file, allowing the support
+// file to be reused for multiple tests.
+async function setupFixtureFile(fixturePath) {
+ let fixtureFile = do_get_file(fixturePath);
+ let tempFile = FileTestUtils.getTempFile(fixturePath);
+ await OS.File.copy(fixtureFile.path, tempFile.path);
+ return tempFile;
+}
--- a/toolkit/components/places/tests/sync/test_bookmark_mirror_migration.js
+++ b/toolkit/components/places/tests/sync/test_bookmark_mirror_migration.js
@@ -1,14 +1,14 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Migrations between 1 and 2 discard the entire database.
add_task(async function test_migrate_from_1_to_2() {
- let dbFile = do_get_file("mirror_v1.sqlite");
+ let dbFile = await setupFixtureFile("mirror_v1.sqlite");
let telemetryEvents = [];
let buf = await SyncedBookmarksMirror.open({
path: dbFile.path,
recordTelemetryEvent(object, method, value, extra) {
telemetryEvents.push({ object, method, value, extra });
},
});
deepEqual(telemetryEvents, [{
@@ -16,17 +16,17 @@ add_task(async function test_migrate_fro
method: "open",
value: "retry",
extra: { why: "corrupt" },
}]);
await buf.finalize();
});
add_task(async function test_database_corrupt() {
- let corruptFile = do_get_file("mirror_corrupt.sqlite");
+ let corruptFile = await setupFixtureFile("mirror_corrupt.sqlite");
let telemetryEvents = [];
let buf = await SyncedBookmarksMirror.open({
path: corruptFile.path,
recordTelemetryEvent(object, method, value, extra) {
telemetryEvents.push({ object, method, value, extra });
},
});
deepEqual(telemetryEvents, [{
@@ -34,17 +34,17 @@ add_task(async function test_database_co
method: "open",
value: "retry",
extra: { why: "corrupt" },
}]);
await buf.finalize();
});
add_task(async function test_database_readonly() {
- let dbFile = do_get_file("mirror_v1.sqlite");
+ let dbFile = await setupFixtureFile("mirror_v1.sqlite");
try {
await OS.File.setPermissions(dbFile.path, {
unixMode: 0o400,
winAttributes: { readOnly: true },
});
} catch (ex) {
if (ex instanceof OS.File.Error &&
ex.unixErrno == OS.Constants.libc.EPERM) {