diff --git a/browser/components/migration/MigrationUtils.jsm b/browser/components/migration/MigrationUtils.jsm index b0629d2b9eab..ba87d93b6dbd 100644 --- a/browser/components/migration/MigrationUtils.jsm +++ b/browser/components/migration/MigrationUtils.jsm @@ -374,7 +374,10 @@ var MigratorPrototype = { // Import the default bookmarks. We ignore whether or not we succeed. await BookmarkHTMLUtils.importFromURL( - "chrome://browser/locale/bookmarks.html", true).catch(r => r); + "chrome://browser/locale/bookmarks.html", { + replace: true, + source: PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP, + }).catch(Cu.reportError); // We'll tell nsBrowserGlue we've imported bookmarks, but before that // we need to make sure we're going to know when it's finished diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index ecec8e89397b..6e7003063fb3 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -1604,7 +1604,10 @@ BrowserGlue.prototype = { lastBackupFile = await PlacesBackups.getMostRecentBackup(); if (lastBackupFile) { // restore from JSON backup - await BookmarkJSONUtils.importFromFile(lastBackupFile, true); + await BookmarkJSONUtils.importFromFile(lastBackupFile, { + replace: true, + source: PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP, + }); importBookmarks = false; } else { // We have created a new database but we don't have any backup available @@ -1652,7 +1655,10 @@ BrowserGlue.prototype = { if (bookmarksUrl) { // Import from bookmarks.html file. try { - await BookmarkHTMLUtils.importFromURL(bookmarksUrl, true); + await BookmarkHTMLUtils.importFromURL(bookmarksUrl, { + replace: true, + source: PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP, + }); } catch (e) { Cu.reportError("Bookmarks.html file could be corrupt. " + e); } diff --git a/browser/components/places/content/places.js b/browser/components/places/content/places.js index 8097a64586af..c8e011dc1d93 100644 --- a/browser/components/places/content/places.js +++ b/browser/components/places/content/places.js @@ -406,7 +406,7 @@ var PlacesOrganizer = { let fpCallback = function fpCallback_done(aResult) { if (aResult != Ci.nsIFilePicker.returnCancel && fp.fileURL) { ChromeUtils.import("resource://gre/modules/BookmarkHTMLUtils.jsm"); - BookmarkHTMLUtils.importFromURL(fp.fileURL.spec, false) + BookmarkHTMLUtils.importFromURL(fp.fileURL.spec) .catch(Cu.reportError); } }; @@ -545,7 +545,9 @@ var PlacesOrganizer = { (async function() { try { - await BookmarkJSONUtils.importFromFile(aFilePath, true); + await BookmarkJSONUtils.importFromFile(aFilePath, { + replace: true, + }); } catch (ex) { PlacesOrganizer._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); } diff --git a/services/sync/modules/engines/bookmarks.js b/services/sync/modules/engines/bookmarks.js index e27cf0707faa..37e2b5d92ee8 100644 --- a/services/sync/modules/engines/bookmarks.js +++ b/services/sync/modules/engines/bookmarks.js @@ -36,12 +36,6 @@ XPCOMUtils.defineLazyGetter(this, "ANNOS_TO_TRACK", () => [ ]); const FOLDER_SORTINDEX = 1000000; -const { - SOURCE_SYNC, - SOURCE_IMPORT, - SOURCE_IMPORT_REPLACE, - SOURCE_SYNC_REPARENT_REMOVED_FOLDER_CHILDREN, -} = Ci.nsINavBookmarksService; // Roots that should be deleted from the server, instead of applied locally. // This matches `AndroidBrowserBookmarksRepositorySession::forbiddenGUID`, @@ -54,12 +48,16 @@ const FORBIDDEN_INCOMING_IDS = ["pinned", "places", "readinglist"]; // descendants of custom roots. const FORBIDDEN_INCOMING_PARENT_IDS = ["pinned", "readinglist"]; -// The tracker ignores changes made by bookmark import and restore, and -// changes made by Sync. We don't need to exclude `SOURCE_IMPORT`, but both -// import and restore fire `bookmarks-restore-*` observer notifications, and -// the tracker doesn't currently distinguish between the two. -const IGNORED_SOURCES = [SOURCE_SYNC, SOURCE_IMPORT, SOURCE_IMPORT_REPLACE, - SOURCE_SYNC_REPARENT_REMOVED_FOLDER_CHILDREN]; +// The tracker ignores changes made by import and restore, to avoid bumping the +// score and triggering syncs during the process, as well as changes made by +// Sync. +XPCOMUtils.defineLazyGetter(this, "IGNORED_SOURCES", () => [ + PlacesUtils.bookmarks.SOURCES.SYNC, + PlacesUtils.bookmarks.SOURCES.IMPORT, + PlacesUtils.bookmarks.SOURCES.RESTORE, + PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP, + PlacesUtils.bookmarks.SOURCES.SYNC_REPARENT_REMOVED_FOLDER_CHILDREN, +]); function isSyncedRootNode(node) { return node.root == "bookmarksMenuFolder" || diff --git a/services/sync/tests/unit/test_bookmark_engine.js b/services/sync/tests/unit/test_bookmark_engine.js index c9283d88c843..713d5fbf99bb 100644 --- a/services/sync/tests/unit/test_bookmark_engine.js +++ b/services/sync/tests/unit/test_bookmark_engine.js @@ -307,7 +307,7 @@ async function test_restoreOrImport(engine, { replace }) { Assert.equal(wbos[0], bmk2.guid); _(`Now ${verb} from a backup.`); - await bookmarkUtils.importFromFile(backupFilePath, replace); + await bookmarkUtils.importFromFile(backupFilePath, { replace }); await engine._tracker.asyncObserver.promiseObserversComplete(); let bookmarksCollection = server.user("foo").collection("bookmarks"); diff --git a/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/places.py b/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/places.py index 16b6858632bb..4238da6a53c4 100644 --- a/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/places.py +++ b/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/places.py @@ -79,7 +79,7 @@ class Places(BaseLib): let defaultBookmarks = 'chrome://browser/locale/bookmarks.html'; // Trigger the import of the default bookmarks - BookmarkHTMLUtils.importFromURL(defaultBookmarks, true) + BookmarkHTMLUtils.importFromURL(defaultBookmarks, { replace: true }) .then(() => marionetteScriptFinished(true)) .catch(() => marionetteScriptFinished(false)); """, script_timeout=10000) diff --git a/toolkit/components/places/BookmarkHTMLUtils.jsm b/toolkit/components/places/BookmarkHTMLUtils.jsm index 09314b0910e7..58343a972491 100644 --- a/toolkit/components/places/BookmarkHTMLUtils.jsm +++ b/toolkit/components/places/BookmarkHTMLUtils.jsm @@ -127,17 +127,26 @@ var BookmarkHTMLUtils = Object.freeze({ * @param aSpec * String containing the "file:" URI for the existing "bookmarks.html" * file to be loaded. - * @param aInitialImport - * Whether this is the initial import executed on a new profile. + * @param [options.replace] + * Whether we should erase existing bookmarks before loading. + * Defaults to `false`. + * @param [options.source] + * The bookmark change source, used to determine the sync status for + * imported bookmarks. Defaults to `RESTORE` if `replace = true`, or + * `IMPORT` otherwise. * * @return {Promise} * @resolves When the new bookmarks have been created. * @rejects JavaScript exception. */ - async importFromURL(aSpec, aInitialImport) { + async importFromURL(aSpec, { + replace: aInitialImport = false, + source: aSource = aInitialImport ? PlacesUtils.bookmarks.SOURCES.RESTORE : + PlacesUtils.bookmarks.SOURCES.IMPORT, + } = {}) { notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_BEGIN, aInitialImport); try { - let importer = new BookmarkImporter(aInitialImport); + let importer = new BookmarkImporter(aInitialImport, aSource); await importer.importFromURL(aSpec); notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_SUCCESS, aInitialImport); @@ -153,20 +162,29 @@ var BookmarkHTMLUtils = Object.freeze({ * * @param aFilePath * OS.File path string of the "bookmarks.html" file to be loaded. - * @param aInitialImport - * Whether this is the initial import executed on a new profile. + * @param [options.replace] + * Whether we should erase existing bookmarks before loading. + * Defaults to `false`. + * @param [options.source] + * The bookmark change source, used to determine the sync status for + * imported bookmarks. Defaults to `RESTORE` if `replace = true`, or + * `IMPORT` otherwise. * * @return {Promise} * @resolves When the new bookmarks have been created. * @rejects JavaScript exception. */ - async importFromFile(aFilePath, aInitialImport) { + async importFromFile(aFilePath, { + replace: aInitialImport = false, + source: aSource = aInitialImport ? PlacesUtils.bookmarks.SOURCES.RESTORE : + PlacesUtils.bookmarks.SOURCES.IMPORT, + } = {}) { notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_BEGIN, aInitialImport); try { if (!(await OS.File.exists(aFilePath))) { throw new Error("Cannot import from nonexisting html file: " + aFilePath); } - let importer = new BookmarkImporter(aInitialImport); + let importer = new BookmarkImporter(aInitialImport, aSource); await importer.importFromURL(OS.Path.toFileURI(aFilePath)); notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_SUCCESS, aInitialImport); @@ -286,12 +304,9 @@ function Frame(aFolder) { this.previousLastModifiedDate = null; } -function BookmarkImporter(aInitialImport) { +function BookmarkImporter(aInitialImport, aSource) { this._isImportDefaults = aInitialImport; - // The bookmark change source, used to determine the sync status and change - // counter. - this._source = aInitialImport ? PlacesUtils.bookmarks.SOURCE_IMPORT_REPLACE : - PlacesUtils.bookmarks.SOURCE_IMPORT; + this._source = aSource; // This root is where we construct the bookmarks tree into, following the format // of the imported file. diff --git a/toolkit/components/places/BookmarkJSONUtils.jsm b/toolkit/components/places/BookmarkJSONUtils.jsm index c9b90d3a501c..285634ad13d4 100644 --- a/toolkit/components/places/BookmarkJSONUtils.jsm +++ b/toolkit/components/places/BookmarkJSONUtils.jsm @@ -41,26 +41,32 @@ var BookmarkJSONUtils = Object.freeze({ * * @param aSpec * url of the bookmark data. - * @param aReplace - * Boolean if true, replace existing bookmarks, else merge. + * @param [options.replace] + * Whether we should erase existing bookmarks before importing. + * @param [options.source] + * The bookmark change source, used to determine the sync status for + * imported bookmarks. Defaults to `RESTORE` if `replace = true`, or + * `IMPORT` otherwise. * * @return {Promise} * @resolves When the new bookmarks have been created. * @rejects JavaScript exception. */ - importFromURL: function BJU_importFromURL(aSpec, aReplace) { - return (async function() { - notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_BEGIN, aReplace); - try { - let importer = new BookmarkImporter(aReplace); - await importer.importFromURL(aSpec); + async importFromURL(aSpec, { + replace: aReplace = false, + source: aSource = aReplace ? PlacesUtils.bookmarks.SOURCES.RESTORE : + PlacesUtils.bookmarks.SOURCES.IMPORT, + } = {}) { + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_BEGIN, aReplace); + try { + let importer = new BookmarkImporter(aReplace, aSource); + await importer.importFromURL(aSpec); - notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_SUCCESS, aReplace); - } catch (ex) { - Cu.reportError("Failed to restore bookmarks from " + aSpec + ": " + ex); - notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED, aReplace); - } - })(); + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_SUCCESS, aReplace); + } catch (ex) { + Cu.reportError("Failed to restore bookmarks from " + aSpec + ": " + ex); + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED, aReplace); + } }, /** @@ -70,20 +76,28 @@ var BookmarkJSONUtils = Object.freeze({ * * @param aFilePath * OS.File path string of bookmarks in JSON or JSONlz4 format to be restored. - * @param aReplace - * Boolean if true, replace existing bookmarks, else merge. + * @param [options.replace] + * Whether we should erase existing bookmarks before importing. + * @param [options.source] + * The bookmark change source, used to determine the sync status for + * imported bookmarks. Defaults to `RESTORE` if `replace = true`, or + * `IMPORT` otherwise. * * @return {Promise} * @resolves When the new bookmarks have been created. * @rejects JavaScript exception. */ - async importFromFile(aFilePath, aReplace) { + async importFromFile(aFilePath, { + replace: aReplace = false, + source: aSource = aReplace ? PlacesUtils.bookmarks.SOURCES.RESTORE : + PlacesUtils.bookmarks.SOURCES.IMPORT, + } = {}) { notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_BEGIN, aReplace); try { if (!(await OS.File.exists(aFilePath))) throw new Error("Cannot restore from nonexisting json file"); - let importer = new BookmarkImporter(aReplace); + let importer = new BookmarkImporter(aReplace, aSource); if (aFilePath.endsWith("jsonlz4")) { await importer.importFromCompressedFile(aFilePath); } else { @@ -147,12 +161,9 @@ var BookmarkJSONUtils = Object.freeze({ } }); -function BookmarkImporter(aReplace) { +function BookmarkImporter(aReplace, aSource) { this._replace = aReplace; - // The bookmark change source, used to determine the sync status and change - // counter. - this._source = aReplace ? PlacesUtils.bookmarks.SOURCE_IMPORT_REPLACE : - PlacesUtils.bookmarks.SOURCE_IMPORT; + this._source = aSource; } BookmarkImporter.prototype = { /** diff --git a/toolkit/components/places/Bookmarks.jsm b/toolkit/components/places/Bookmarks.jsm index 9f35fa5740f9..ce78bbab4904 100644 --- a/toolkit/components/places/Bookmarks.jsm +++ b/toolkit/components/places/Bookmarks.jsm @@ -127,8 +127,9 @@ var Bookmarks = Object.freeze({ DEFAULT: Ci.nsINavBookmarksService.SOURCE_DEFAULT, SYNC: Ci.nsINavBookmarksService.SOURCE_SYNC, IMPORT: Ci.nsINavBookmarksService.SOURCE_IMPORT, - IMPORT_REPLACE: Ci.nsINavBookmarksService.SOURCE_IMPORT_REPLACE, SYNC_REPARENT_REMOVED_FOLDER_CHILDREN: Ci.nsINavBookmarksService.SOURCE_SYNC_REPARENT_REMOVED_FOLDER_CHILDREN, + RESTORE: Ci.nsINavBookmarksService.SOURCE_RESTORE, + RESTORE_ON_STARTUP: Ci.nsINavBookmarksService.SOURCE_RESTORE_ON_STARTUP, }, /** diff --git a/toolkit/components/places/PlacesSyncUtils.jsm b/toolkit/components/places/PlacesSyncUtils.jsm index bb0848c19d98..86a9b71ae402 100644 --- a/toolkit/components/places/PlacesSyncUtils.jsm +++ b/toolkit/components/places/PlacesSyncUtils.jsm @@ -984,7 +984,8 @@ const BookmarkSyncUtils = PlacesSyncUtils.bookmarks = Object.freeze({ // Incoming bookmarks are "NORMAL", since they already exist on the server. return PlacesUtils.bookmarks.SYNC_STATUS.NORMAL; } - if (source == PlacesUtils.bookmarks.SOURCES.IMPORT_REPLACE) { + if (source == PlacesUtils.bookmarks.SOURCES.RESTORE || + source == PlacesUtils.bookmarks.SOURCES.RESTORE_ON_STARTUP) { // If the user restores from a backup, or Places automatically recovers // from a corrupt database, all prior record tracking is lost. Setting the // status to "UNKNOWN" allows Record to reconcile restored bookmarks with diff --git a/toolkit/components/places/nsINavBookmarksService.idl b/toolkit/components/places/nsINavBookmarksService.idl index ce3d1741f7f5..45014c4dbb09 100644 --- a/toolkit/components/places/nsINavBookmarksService.idl +++ b/toolkit/components/places/nsINavBookmarksService.idl @@ -319,23 +319,34 @@ interface nsINavBookmarksService : nsISupports const unsigned short SOURCE_DEFAULT = 0; const unsigned short SOURCE_SYNC = 1; const unsigned short SOURCE_IMPORT = 2; - const unsigned short SOURCE_IMPORT_REPLACE = 3; const unsigned short SOURCE_SYNC_REPARENT_REMOVED_FOLDER_CHILDREN = 4; + const unsigned short SOURCE_RESTORE = 5; + const unsigned short SOURCE_RESTORE_ON_STARTUP = 6; /** - * Sync status flags. + * Sync status flags, stored in Places for each item. These affect conflict + * resolution, when an item is changed both locally and remotely; deduping, + * when a local item matches a remote item with similar contents and different + * GUIDs; and whether we write a tombstone when an item is deleted locally. + * + * Status | Description | Conflict | Can | Needs + * | | resolution | dedupe? | tombstone? + * ----------------------------------------------------------------------- + * UNKNOWN | Automatically restored | Prefer | No | No + * | on startup to recover | deletion | | + * | from database corruption, | | | + * | or sync ID change on | | | + * | server. | | | + * ----------------------------------------------------------------------- + * NEW | Item not uploaded to | Prefer | Yes | No + * | server yet, or Sync | newer | | + * | disconnected. | | | + * ----------------------------------------------------------------------- + * NORMAL | Item uploaded to server. | Prefer | No | Yes + * | | newer | | */ - // "UNKNOWN" means sync tracking information was lost because the item - // was restored from a backup, and needs to be reconciled with the server. - // This is set for migrated and restored bookmarks, and changed to "NORMAL" - // before upload. const unsigned short SYNC_STATUS_UNKNOWN = 0; - // "NEW" means the item has never been synced, so we don't need to write - // a tombstone if it's deleted. This is set for all new local bookmarks, and - // changed to "NORMAL" before upload. const unsigned short SYNC_STATUS_NEW = 1; - // "NORMAL" means the item has been uploaded to the server, and needs a - // tombstone if it's deleted. const unsigned short SYNC_STATUS_NORMAL = 2; /** diff --git a/toolkit/components/places/nsNavBookmarks.cpp b/toolkit/components/places/nsNavBookmarks.cpp index 1615c02ad236..e45c3c7c4b62 100644 --- a/toolkit/components/places/nsNavBookmarks.cpp +++ b/toolkit/components/places/nsNavBookmarks.cpp @@ -139,7 +139,8 @@ DetermineInitialSyncStatus(uint16_t aSource) { if (aSource == nsINavBookmarksService::SOURCE_SYNC) { return nsINavBookmarksService::SYNC_STATUS_NORMAL; } - if (aSource == nsINavBookmarksService::SOURCE_IMPORT_REPLACE) { + if (aSource == nsINavBookmarksService::SOURCE_RESTORE || + aSource == nsINavBookmarksService::SOURCE_RESTORE_ON_STARTUP) { return nsINavBookmarksService::SYNC_STATUS_UNKNOWN; } return nsINavBookmarksService::SYNC_STATUS_NEW; diff --git a/toolkit/components/places/tests/bookmarks/test_1129529.js b/toolkit/components/places/tests/bookmarks/test_1129529.js index c193be90b9b6..19b209e98b2f 100644 --- a/toolkit/components/places/tests/bookmarks/test_1129529.js +++ b/toolkit/components/places/tests/bookmarks/test_1129529.js @@ -59,7 +59,7 @@ add_task(async function() { let contentType = "application/json"; let uri = "data:" + contentType + "," + JSON.stringify(aData); - await BookmarkJSONUtils.importFromURL(uri, false); + await BookmarkJSONUtils.importFromURL(uri); let [bookmarks] = await PlacesBackups.getBookmarksTree(); let unsortedBookmarks = bookmarks.children[2].children; diff --git a/toolkit/components/places/tests/bookmarks/test_405938_restore_queries.js b/toolkit/components/places/tests/bookmarks/test_405938_restore_queries.js index 47919589a580..094e74a1b41f 100644 --- a/toolkit/components/places/tests/bookmarks/test_405938_restore_queries.js +++ b/toolkit/components/places/tests/bookmarks/test_405938_restore_queries.js @@ -279,7 +279,7 @@ add_task(async function() { } // restore json file - await BookmarkJSONUtils.importFromFile(jsonFile, true); + await BookmarkJSONUtils.importFromFile(jsonFile, { replace: true }); // validate for (let singleTest of tests) { diff --git a/toolkit/components/places/tests/bookmarks/test_424958-json-quoted-folders.js b/toolkit/components/places/tests/bookmarks/test_424958-json-quoted-folders.js index 0b845e69c46b..a866d6ef756f 100644 --- a/toolkit/components/places/tests/bookmarks/test_424958-json-quoted-folders.js +++ b/toolkit/components/places/tests/bookmarks/test_424958-json-quoted-folders.js @@ -74,7 +74,7 @@ add_task(async function() { }); // restore json file - await BookmarkJSONUtils.importFromFile(jsonFile, true); + await BookmarkJSONUtils.importFromFile(jsonFile, { replace: true }); // validate tests.forEach(function(aTest) { diff --git a/toolkit/components/places/tests/bookmarks/test_448584.js b/toolkit/components/places/tests/bookmarks/test_448584.js index c5dd89ccdb32..788c8fee1c97 100644 --- a/toolkit/components/places/tests/bookmarks/test_448584.js +++ b/toolkit/components/places/tests/bookmarks/test_448584.js @@ -78,7 +78,7 @@ add_task(async function() { // restore json file try { - await BookmarkJSONUtils.importFromFile(jsonFile, true); + await BookmarkJSONUtils.importFromFile(jsonFile, { replace: true }); } catch (ex) { do_throw("couldn't import the exported file: " + ex); } // validate diff --git a/toolkit/components/places/tests/bookmarks/test_458683.js b/toolkit/components/places/tests/bookmarks/test_458683.js index 639cea277581..64a6ecb68ccb 100644 --- a/toolkit/components/places/tests/bookmarks/test_458683.js +++ b/toolkit/components/places/tests/bookmarks/test_458683.js @@ -93,7 +93,7 @@ add_task(async function() { await PlacesUtils.bookmarks.remove(item); // restore json file - await BookmarkJSONUtils.importFromFile(jsonFile, true); + await BookmarkJSONUtils.importFromFile(jsonFile, { replace: true }); validateResults(); diff --git a/toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js b/toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js index b41bbc346fa9..0d4f0664d8aa 100644 --- a/toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js +++ b/toolkit/components/places/tests/bookmarks/test_818587_compress-bookmarks-backups.js @@ -41,7 +41,7 @@ add_task(async function compress_bookmark_backups_test() { await PlacesBackups.create(undefined, true); let recentBackup = await PlacesBackups.getMostRecentBackup(); await PlacesUtils.bookmarks.remove(bm); - await BookmarkJSONUtils.importFromFile(recentBackup, true); + await BookmarkJSONUtils.importFromFile(recentBackup, { replace: true }); let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root; let node = root.getChild(0); Assert.equal(node.uri, url); diff --git a/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js b/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js index a52d8567e9fc..99fad92dddf1 100644 --- a/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js +++ b/toolkit/components/places/tests/bookmarks/test_992901-backup-unsorted-hierarchy.js @@ -36,7 +36,8 @@ add_task(async function() { // Remove the bookmarks, then restore the backup. await PlacesUtils.bookmarks.remove(folder1); - await BookmarkJSONUtils.importFromFile((await PlacesBackups.getMostRecentBackup()), true); + await BookmarkJSONUtils.importFromFile((await PlacesBackups.getMostRecentBackup()), + { replace: true }); info("Checking first level"); let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root; diff --git a/toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js b/toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js index d68a65d7d41c..94eaadcb7dcb 100644 --- a/toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js +++ b/toolkit/components/places/tests/bookmarks/test_997030-bookmarks-html-encode.js @@ -21,7 +21,7 @@ add_task(async function() { // Remove the bookmarks, then restore the backup. await PlacesUtils.bookmarks.remove(bm); - await BookmarkHTMLUtils.importFromFile(file, true); + await BookmarkHTMLUtils.importFromFile(file, { replace: true }); info("Checking first level"); let root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root; diff --git a/toolkit/components/places/tests/sync/test_bookmark_deletion.js b/toolkit/components/places/tests/sync/test_bookmark_deletion.js index 25ea2e563c09..e61393457a06 100644 --- a/toolkit/components/places/tests/sync/test_bookmark_deletion.js +++ b/toolkit/components/places/tests/sync/test_bookmark_deletion.js @@ -598,7 +598,7 @@ add_task(async function test_nonexistent_on_one_side() { url: "http://example.com/a", // Pretend a bookmark restore added A, so that we'll write a tombstone when // we remove it. - source: PlacesUtils.bookmarks.SOURCES.IMPORT_REPLACE, + source: PlacesUtils.bookmarks.SOURCES.RESTORE, }); await PlacesUtils.bookmarks.remove("bookmarkAAAA"); diff --git a/toolkit/components/places/tests/sync/test_sync_utils.js b/toolkit/components/places/tests/sync/test_sync_utils.js index 267dd182e712..bf7e9b174e23 100644 --- a/toolkit/components/places/tests/sync/test_sync_utils.js +++ b/toolkit/components/places/tests/sync/test_sync_utils.js @@ -2025,7 +2025,7 @@ add_task(async function test_pullChanges_import_html() { info("Import new bookmarks from HTML"); let { path } = do_get_file("./sync_utils_bookmarks.html"); - await BookmarkHTMLUtils.importFromFile(path, false); + await BookmarkHTMLUtils.importFromFile(path); // Bookmarks.html doesn't store IDs, so we need to look these up. let mozBmk = await PlacesUtils.bookmarks.fetch({ @@ -2087,7 +2087,7 @@ add_task(async function test_pullChanges_import_json() { info("Import new bookmarks from JSON"); let { path } = do_get_file("./sync_utils_bookmarks.json"); - await BookmarkJSONUtils.importFromFile(path, false); + await BookmarkJSONUtils.importFromFile(path); { let fields = await PlacesTestUtils.fetchBookmarkSyncFields( syncedFolder.guid, "NnvGl3CRA4hC", "APzP8MupzA8l"); @@ -2154,7 +2154,7 @@ add_task(async function test_pullChanges_restore_json_tracked() { info("Restore from JSON, replacing existing items"); let { path } = do_get_file("./sync_utils_bookmarks.json"); - await BookmarkJSONUtils.importFromFile(path, true); + await BookmarkJSONUtils.importFromFile(path, { replace: true }); { let fields = await PlacesTestUtils.fetchBookmarkSyncFields( "NnvGl3CRA4hC", "APzP8MupzA8l"); diff --git a/toolkit/components/places/tests/unit/test_384370.js b/toolkit/components/places/tests/unit/test_384370.js index 8b489236ca57..d7d295a34ac9 100644 --- a/toolkit/components/places/tests/unit/test_384370.js +++ b/toolkit/components/places/tests/unit/test_384370.js @@ -31,7 +31,7 @@ add_task(async function() { // Test importing a pre-Places canonical bookmarks file. // Note: we do not empty the db before this import to catch bugs like 380999 let htmlFile = OS.Path.join(do_get_cwd().path, "bookmarks.preplaces.html"); - await BookmarkHTMLUtils.importFromFile(htmlFile, true); + await BookmarkHTMLUtils.importFromFile(htmlFile, { replace: true }); // Populate the database. for (let { uri, tags } of tagData) { @@ -57,7 +57,7 @@ add_task(async function() { // 2. empty bookmarks db // 3. import bookmarks.exported.json - await BookmarkJSONUtils.importFromFile(jsonFile, true); + await BookmarkJSONUtils.importFromFile(jsonFile, { replace: true }); info("imported json"); // 4. run the test-suite diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html.js b/toolkit/components/places/tests/unit/test_bookmarks_html.js index d8b1809daddc..2692c4159080 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_html.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_html.js @@ -94,7 +94,7 @@ add_task(async function setup() { // 1. import bookmarks.preplaces.html // 2. run the test-suite // Note: we do not empty the db before this import to catch bugs like 380999 - await BookmarkHTMLUtils.importFromFile(gBookmarksFileOld, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileOld, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); @@ -107,7 +107,7 @@ add_task(async function test_import_new() { // Test importing a Places bookmarks.html file. // 1. import bookmarks.exported.html // 2. run the test-suite - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); @@ -128,7 +128,7 @@ add_task(async function test_emptytitle_export() { // 8. export to bookmarks.exported.html // 9. empty bookmarks db and continue - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); const NOTITLE_URL = "http://notitle.mozilla.org/"; @@ -142,7 +142,7 @@ add_task(async function test_emptytitle_export() { await PlacesTestUtils.promiseAsyncUpdates(); await PlacesUtils.bookmarks.eraseEverything(); - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); @@ -178,7 +178,7 @@ add_task(async function test_import_chromefavicon() { const CHROME_FAVICON_URI_2 = NetUtil.newURI("chrome://global/skin/icons/error-16.png"); info("Importing from html"); - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); info("Insert bookmark"); @@ -222,7 +222,7 @@ add_task(async function test_import_chromefavicon() { info("import from html"); await PlacesUtils.bookmarks.eraseEverything(); - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); info("Test imported bookmarks"); @@ -251,12 +251,12 @@ add_task(async function test_import_ontop() { // 3. import the exported bookmarks file // 4. run the test-suite - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); await PlacesTestUtils.promiseAsyncUpdates(); - await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); + await BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); await PlacesTestUtils.promiseAsyncUpdates(); diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js b/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js index f7f1fa443131..2ffd79b7a828 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js @@ -15,7 +15,7 @@ add_task(async function test_corrupt_file() { // Import bookmarks from the corrupt file. let corruptHtml = OS.Path.join(do_get_cwd().path, "bookmarks.corrupt.html"); - await BookmarkHTMLUtils.importFromFile(corruptHtml, true); + await BookmarkHTMLUtils.importFromFile(corruptHtml, { replace: true }); // Check that bookmarks that are not corrupt have been imported. await PlacesTestUtils.promiseAsyncUpdates(); @@ -39,7 +39,7 @@ add_task(async function test_corrupt_database() { // Import again and check for correctness. await PlacesUtils.bookmarks.eraseEverything(); - await BookmarkHTMLUtils.importFromFile(bookmarksFile, true); + await BookmarkHTMLUtils.importFromFile(bookmarksFile, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await database_check(); }); diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html_import_tags.js b/toolkit/components/places/tests/unit/test_bookmarks_html_import_tags.js index bb3cc9794be9..49f159b2d543 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_html_import_tags.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_html_import_tags.js @@ -44,7 +44,7 @@ add_task(async function test_import_tags() { } // Re-imports the bookmarks from the HTML file. - await BookmarkHTMLUtils.importFromFile(HTMLFile, true); + await BookmarkHTMLUtils.importFromFile(HTMLFile, { replace: true }); // Tests to ensure that the tags are still present for each bookmark URI. for (let { uri, tags } of bookmarkData) { diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js b/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js index 99bf52db3857..3dec1e29bb18 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_html_singleframe.js @@ -11,7 +11,7 @@ ChromeUtils.import("resource://gre/modules/BookmarkHTMLUtils.jsm"); add_task(async function test_bookmarks_html_singleframe() { let bookmarksFile = OS.Path.join(do_get_cwd().path, "bookmarks_html_singleframe.html"); - await BookmarkHTMLUtils.importFromFile(bookmarksFile, true); + await BookmarkHTMLUtils.importFromFile(bookmarksFile, { replace: true }); let root = PlacesUtils.getFolderContents(PlacesUtils.bookmarksMenuFolderId).root; Assert.equal(root.childCount, 1); diff --git a/toolkit/components/places/tests/unit/test_bookmarks_json.js b/toolkit/components/places/tests/unit/test_bookmarks_json.js index 44b9b49ccd54..f085ef5405db 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_json.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_json.js @@ -100,7 +100,7 @@ var bookmarksExportedFile; add_task(async function test_import_bookmarks() { let bookmarksFile = OS.Path.join(do_get_cwd().path, "bookmarks.json"); - await BookmarkJSONUtils.importFromFile(bookmarksFile, true); + await BookmarkJSONUtils.importFromFile(bookmarksFile, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); }); @@ -114,18 +114,18 @@ add_task(async function test_export_bookmarks() { add_task(async function test_import_exported_bookmarks() { await PlacesUtils.bookmarks.eraseEverything(); - await BookmarkJSONUtils.importFromFile(bookmarksExportedFile, true); + await BookmarkJSONUtils.importFromFile(bookmarksExportedFile, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); }); add_task(async function test_import_ontop() { await PlacesUtils.bookmarks.eraseEverything(); - await BookmarkJSONUtils.importFromFile(bookmarksExportedFile, true); + await BookmarkJSONUtils.importFromFile(bookmarksExportedFile, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await BookmarkJSONUtils.exportToFile(bookmarksExportedFile); await PlacesTestUtils.promiseAsyncUpdates(); - await BookmarkJSONUtils.importFromFile(bookmarksExportedFile, true); + await BookmarkJSONUtils.importFromFile(bookmarksExportedFile, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); await testImportedBookmarks(); }); diff --git a/toolkit/components/places/tests/unit/test_bookmarks_json_corrupt.js b/toolkit/components/places/tests/unit/test_bookmarks_json_corrupt.js index 734f2b0109f6..bdec6f587dd6 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_json_corrupt.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_json_corrupt.js @@ -10,7 +10,7 @@ var bookmarksExportedFile; add_task(async function test_import_bookmarks() { let bookmarksFile = OS.Path.join(do_get_cwd().path, "bookmarks_corrupt.json"); - await BookmarkJSONUtils.importFromFile(bookmarksFile, true); + await BookmarkJSONUtils.importFromFile(bookmarksFile, { replace: true }); await PlacesTestUtils.promiseAsyncUpdates(); let bookmarks = await PlacesUtils.promiseBookmarksTree(PlacesUtils.bookmarks.menuGuid); diff --git a/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js b/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js index 3322a53baee6..ee0a1e1836d6 100644 --- a/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js +++ b/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js @@ -153,7 +153,7 @@ add_task(async function test_json_restore_normal() { await BookmarkJSONUtils.exportToFile(file); await PlacesUtils.bookmarks.eraseEverything(); try { - await BookmarkJSONUtils.importFromFile(file, true); + await BookmarkJSONUtils.importFromFile(file, { replace: true }); } catch (e) { do_throw(" Restore should not have failed" + e); } @@ -172,7 +172,7 @@ add_task(async function test_json_restore_empty() { info("JSON restore: empty file should succeed"); let file = await promiseFile("bookmarks-test_restoreNotification.json"); try { - await BookmarkJSONUtils.importFromFile(file, true); + await BookmarkJSONUtils.importFromFile(file, { replace: true }); } catch (e) { do_throw(" Restore should not have failed" + e); } @@ -191,7 +191,7 @@ add_task(async function test_json_restore_nonexist() { info("JSON restore: nonexistent file should fail"); let file = Services.dirsvc.get("ProfD", Ci.nsIFile); file.append("this file doesn't exist because nobody created it 1"); - Assert.rejects(BookmarkJSONUtils.importFromFile(file.path, true), + Assert.rejects(BookmarkJSONUtils.importFromFile(file.path, { replace: true }), /Cannot restore from nonexisting json file/, "Restore should reject for a non-existent file."); await checkObservers(expectPromises, expectedData); @@ -211,7 +211,7 @@ add_task(async function test_html_restore_normal() { await BookmarkHTMLUtils.exportToFile(file); await PlacesUtils.bookmarks.eraseEverything(); try { - BookmarkHTMLUtils.importFromFile(file, false) + BookmarkHTMLUtils.importFromFile(file) .catch(do_report_unexpected_exception); } catch (e) { do_throw(" Restore should not have failed"); @@ -231,7 +231,7 @@ add_task(async function test_html_restore_empty() { info("HTML restore: empty file should succeed"); let file = await promiseFile("bookmarks-test_restoreNotification.init.html"); try { - BookmarkHTMLUtils.importFromFile(file, false) + BookmarkHTMLUtils.importFromFile(file) .catch(do_report_unexpected_exception); } catch (e) { do_throw(" Restore should not have failed"); @@ -251,7 +251,7 @@ add_task(async function test_html_restore_nonexist() { info("HTML restore: nonexistent file should fail"); let file = Services.dirsvc.get("ProfD", Ci.nsIFile); file.append("this file doesn't exist because nobody created it 2"); - Assert.rejects(BookmarkHTMLUtils.importFromFile(file.path, false), + Assert.rejects(BookmarkHTMLUtils.importFromFile(file.path), /Cannot import from nonexisting html file/, "Restore should reject for a non-existent file."); await checkObservers(expectPromises, expectedData); @@ -271,7 +271,7 @@ add_task(async function test_html_init_restore_normal() { await BookmarkHTMLUtils.exportToFile(file); await PlacesUtils.bookmarks.eraseEverything(); try { - BookmarkHTMLUtils.importFromFile(file, true) + BookmarkHTMLUtils.importFromFile(file, { replace: true }) .catch(do_report_unexpected_exception); } catch (e) { do_throw(" Restore should not have failed"); @@ -291,7 +291,7 @@ add_task(async function test_html_init_restore_empty() { info("HTML initial restore: empty file should succeed"); let file = await promiseFile("bookmarks-test_restoreNotification.init.html"); try { - BookmarkHTMLUtils.importFromFile(file, true) + BookmarkHTMLUtils.importFromFile(file, { replace: true }) .catch(do_report_unexpected_exception); } catch (e) { do_throw(" Restore should not have failed"); @@ -311,7 +311,7 @@ add_task(async function test_html_init_restore_nonexist() { info("HTML initial restore: nonexistent file should fail"); let file = Services.dirsvc.get("ProfD", Ci.nsIFile); file.append("this file doesn't exist because nobody created it 3"); - Assert.rejects(BookmarkHTMLUtils.importFromFile(file.path, true), + Assert.rejects(BookmarkHTMLUtils.importFromFile(file.path, { replace: true }), /Cannot import from nonexisting html file/, "Restore should reject for a non-existent file."); await checkObservers(expectPromises, expectedData); diff --git a/toolkit/components/places/tests/unit/test_import_mobile_bookmarks.js b/toolkit/components/places/tests/unit/test_import_mobile_bookmarks.js index 16865074b2c2..6e9b0df7e251 100644 --- a/toolkit/components/places/tests/unit/test_import_mobile_bookmarks.js +++ b/toolkit/components/places/tests/unit/test_import_mobile_bookmarks.js @@ -3,7 +3,7 @@ async function importFromFixture(fixture, replace) { let path = OS.Path.join(cwd, fixture); info(`Importing from ${path}`); - await BookmarkJSONUtils.importFromFile(path, replace); + await BookmarkJSONUtils.importFromFile(path, { replace }); await PlacesTestUtils.promiseAsyncUpdates(); }