Bug 1199077 - Split change sources for automatic and manual bookmark restores. r=mak

MozReview-Commit-ID: 1glcCPj2X90

--HG--
extra : rebase_source : 2d8372029df5851ecbb30a65393325442addd84c
This commit is contained in:
Kit Cambridge 2018-03-01 13:37:13 -08:00
Родитель ea2bd76222
Коммит 0c40fa1232
31 изменённых файлов: 160 добавлений и 110 удалений

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

@ -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

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

@ -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);
}

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

@ -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"));
}

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

@ -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" ||

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

@ -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");

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

@ -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)

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

@ -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.

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

@ -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 = {
/**

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

@ -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,
},
/**

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

@ -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

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

@ -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;
/**

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

@ -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;

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

@ -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;

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

@ -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) {

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

@ -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) {

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

@ -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

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

@ -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();

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

@ -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);

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

@ -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;

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

@ -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;

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

@ -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");

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

@ -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");

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

@ -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

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

@ -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();

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

@ -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();
});

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

@ -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) {

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

@ -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);

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

@ -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();
});

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

@ -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);

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

@ -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);

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

@ -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();
}