mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1094846 - Convert xpcshell-tests in browser/components/places to Bookmarks.jsm API r=mak
This commit is contained in:
parent
f784b5ed68
commit
f5f4cff46d
@ -12,26 +12,24 @@ Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/LoadContextInfo.jsm");
|
||||
|
||||
// Import common head.
|
||||
let (commonFile = do_get_file("../../../../../toolkit/components/places/tests/head_common.js", false)) {
|
||||
let commonFile = do_get_file("../../../../../toolkit/components/places/tests/head_common.js", false);
|
||||
if (commonFile) {
|
||||
let uri = Services.io.newFileURI(commonFile);
|
||||
Services.scriptloader.loadSubScript(uri.spec, this);
|
||||
}
|
||||
|
||||
// Put any other stuff relative to this test folder below.
|
||||
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "PlacesUIUtils", function() {
|
||||
Cu.import("resource:///modules/PlacesUIUtils.jsm");
|
||||
return PlacesUIUtils;
|
||||
});
|
||||
|
||||
|
||||
const ORGANIZER_FOLDER_ANNO = "PlacesOrganizer/OrganizerFolder";
|
||||
const ORGANIZER_QUERY_ANNO = "PlacesOrganizer/OrganizerQuery";
|
||||
|
||||
|
||||
// Needed by some test that relies on having an app registered.
|
||||
let (XULAppInfo = {
|
||||
let XULAppInfo = {
|
||||
vendor: "Mozilla",
|
||||
name: "PlacesTest",
|
||||
ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}",
|
||||
@ -48,19 +46,19 @@ let (XULAppInfo = {
|
||||
Ci.nsIXULAppInfo,
|
||||
Ci.nsIXULRuntime,
|
||||
])
|
||||
}) {
|
||||
let XULAppInfoFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
|
||||
"XULAppInfo", "@mozilla.org/xre/app-info;1",
|
||||
XULAppInfoFactory);
|
||||
}
|
||||
};
|
||||
|
||||
let XULAppInfoFactory = {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}"),
|
||||
"XULAppInfo", "@mozilla.org/xre/app-info;1",
|
||||
XULAppInfoFactory);
|
||||
|
||||
// Smart bookmarks constants.
|
||||
const SMART_BOOKMARKS_VERSION = 7;
|
||||
@ -70,3 +68,41 @@ const SMART_BOOKMARKS_ON_MENU = 3; // Takes into account the additional separat
|
||||
// Default bookmarks constants.
|
||||
const DEFAULT_BOOKMARKS_ON_TOOLBAR = 1;
|
||||
const DEFAULT_BOOKMARKS_ON_MENU = 1;
|
||||
|
||||
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
||||
|
||||
function checkItemHasAnnotation(guid, name) {
|
||||
return PlacesUtils.promiseItemId(guid).then(id => {
|
||||
let hasAnnotation = PlacesUtils.annotations.itemHasAnnotation(id, name);
|
||||
Assert.ok(hasAnnotation, `Expected annotation ${name}`);
|
||||
});
|
||||
}
|
||||
|
||||
function waitForImportAndSmartBookmarks() {
|
||||
return Promise.all([
|
||||
promiseTopicObserved("bookmarks-restore-success"),
|
||||
PlacesTestUtils.promiseAsyncUpdates()
|
||||
]);
|
||||
}
|
||||
|
||||
function promiseEndUpdateBatch() {
|
||||
return new Promise(resolve => {
|
||||
PlacesUtils.bookmarks.addObserver({
|
||||
__proto__: NavBookmarkObserver.prototype,
|
||||
onEndUpdateBatch: resolve
|
||||
}, false);
|
||||
});
|
||||
}
|
||||
|
||||
let createCorruptDB = Task.async(function* () {
|
||||
let dbPath = OS.Path.join(OS.Constants.Path.profileDir, "places.sqlite");
|
||||
yield OS.File.remove(dbPath);
|
||||
|
||||
// Create a corrupt database.
|
||||
let dir = yield OS.File.getCurrentDirectory();
|
||||
let src = OS.Path.join(dir, "corruptDB.sqlite");
|
||||
yield OS.File.copy(src, dbPath);
|
||||
|
||||
// Check there's a DB now.
|
||||
Assert.ok((yield OS.File.exists(dbPath)), "should have a DB now");
|
||||
});
|
||||
|
@ -5,7 +5,6 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
||||
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
|
||||
|
||||
let gluesvc = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
@ -18,64 +17,88 @@ function run_test() {
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function smart_bookmarks_disabled() {
|
||||
add_task(function* smart_bookmarks_disabled() {
|
||||
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1);
|
||||
gluesvc.ensurePlacesDefaultQueriesInitialized();
|
||||
|
||||
let smartBookmarkItemIds =
|
||||
PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
||||
do_check_eq(smartBookmarkItemIds.length, 0);
|
||||
Assert.equal(smartBookmarkItemIds.length, 0);
|
||||
|
||||
do_print("check that pref has not been bumped up");
|
||||
do_check_eq(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), -1);
|
||||
Assert.equal(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), -1);
|
||||
});
|
||||
|
||||
add_task(function create_smart_bookmarks() {
|
||||
add_task(function* create_smart_bookmarks() {
|
||||
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
||||
gluesvc.ensurePlacesDefaultQueriesInitialized();
|
||||
|
||||
let smartBookmarkItemIds =
|
||||
PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
||||
do_check_neq(smartBookmarkItemIds.length, 0);
|
||||
Assert.notEqual(smartBookmarkItemIds.length, 0);
|
||||
|
||||
do_print("check that pref has been bumped up");
|
||||
do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0);
|
||||
Assert.ok(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0);
|
||||
});
|
||||
|
||||
add_task(function remove_smart_bookmark_and_restore() {
|
||||
add_task(function* remove_smart_bookmark_and_restore() {
|
||||
let smartBookmarkItemIds =
|
||||
PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
||||
let smartBookmarksCount = smartBookmarkItemIds.length;
|
||||
do_print("remove one smart bookmark and restore");
|
||||
PlacesUtils.bookmarks.removeItem(smartBookmarkItemIds[0]);
|
||||
|
||||
let guid = yield PlacesUtils.promiseItemGuid(smartBookmarkItemIds[0]);
|
||||
yield PlacesUtils.bookmarks.remove(guid);
|
||||
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
||||
|
||||
gluesvc.ensurePlacesDefaultQueriesInitialized();
|
||||
smartBookmarkItemIds =
|
||||
PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
||||
do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount);
|
||||
Assert.equal(smartBookmarkItemIds.length, smartBookmarksCount);
|
||||
|
||||
do_print("check that pref has been bumped up");
|
||||
do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0);
|
||||
Assert.ok(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0);
|
||||
});
|
||||
|
||||
add_task(function move_smart_bookmark_rename_and_restore() {
|
||||
add_task(function* move_smart_bookmark_rename_and_restore() {
|
||||
let smartBookmarkItemIds =
|
||||
PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
||||
let smartBookmarksCount = smartBookmarkItemIds.length;
|
||||
do_print("smart bookmark should be restored in place");
|
||||
let parent = PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]);
|
||||
let oldTitle = PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]);
|
||||
|
||||
let guid = yield PlacesUtils.promiseItemGuid(smartBookmarkItemIds[0]);
|
||||
let bm = yield PlacesUtils.bookmarks.fetch(guid);
|
||||
let oldTitle = bm.title;
|
||||
|
||||
// create a subfolder and move inside it
|
||||
let newParent =
|
||||
PlacesUtils.bookmarks.createFolder(parent, "test",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
PlacesUtils.bookmarks.moveItem(smartBookmarkItemIds[0], newParent,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
// change title
|
||||
PlacesUtils.bookmarks.setItemTitle(smartBookmarkItemIds[0], "new title");
|
||||
let subfolder = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: bm.parentGuid,
|
||||
title: "test",
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER
|
||||
});
|
||||
|
||||
// change title and move into new subfolder
|
||||
yield PlacesUtils.bookmarks.update({
|
||||
guid: guid,
|
||||
parentGuid: subfolder.guid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
title: "new title"
|
||||
});
|
||||
|
||||
// restore
|
||||
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
||||
gluesvc.ensurePlacesDefaultQueriesInitialized();
|
||||
|
||||
smartBookmarkItemIds =
|
||||
PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO);
|
||||
do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount);
|
||||
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]), newParent);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]), oldTitle);
|
||||
Assert.equal(smartBookmarkItemIds.length, smartBookmarksCount);
|
||||
|
||||
guid = yield PlacesUtils.promiseItemGuid(smartBookmarkItemIds[0]);
|
||||
bm = yield PlacesUtils.bookmarks.fetch(guid);
|
||||
Assert.equal(bm.parentGuid, subfolder.guid);
|
||||
Assert.equal(bm.title, oldTitle);
|
||||
|
||||
do_print("check that pref has been bumped up");
|
||||
do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0);
|
||||
Assert.ok(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0);
|
||||
});
|
||||
|
@ -9,78 +9,51 @@
|
||||
* database is corrupt and one backup is available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||
// folder. It should be ignored.
|
||||
// Create our bookmarks.html from bookmarks.glue.html.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
|
||||
// Create our JSON backup copying bookmarks.glue.json to the profile folder.
|
||||
remove_all_JSON_backups();
|
||||
|
||||
// Create our JSON backup from bookmarks.glue.json.
|
||||
create_JSON_backup("bookmarks.glue.json");
|
||||
|
||||
// Remove current database file.
|
||||
let db = gProfD.clone();
|
||||
db.append("places.sqlite");
|
||||
if (db.exists()) {
|
||||
db.remove(false);
|
||||
do_check_false(db.exists());
|
||||
}
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
do_register_cleanup(function () {
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
return PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
add_task(function* test_main() {
|
||||
// Create a corrupt database.
|
||||
let corruptDB = gTestDir.clone();
|
||||
corruptDB.append("corruptDB.sqlite");
|
||||
corruptDB.copyTo(gProfD, "places.sqlite");
|
||||
do_check_true(db.exists());
|
||||
yield createCorruptDB();
|
||||
|
||||
// Initialize nsBrowserGlue before Places.
|
||||
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
// Check the database was corrupt.
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
|
||||
Assert.equal(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CORRUPT);
|
||||
|
||||
// The test will continue once restore has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
yield promiseEndUpdateBatch();
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
|
||||
function continue_test() {
|
||||
// Check that JSON backup has been restored.
|
||||
// Notice restore from JSON notification is fired before smart bookmarks creation.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "examplejson");
|
||||
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
Assert.equal(bm.title, "examplejson");
|
||||
});
|
||||
|
@ -9,73 +9,44 @@
|
||||
* is corrupt but a JSON backup is not available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Create bookmarks.html in the profile.
|
||||
// Create our bookmarks.html from bookmarks.glue.html.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
|
||||
// Remove JSON backup from profile.
|
||||
remove_all_JSON_backups();
|
||||
|
||||
// Remove current database file.
|
||||
let db = gProfD.clone();
|
||||
db.append("places.sqlite");
|
||||
if (db.exists()) {
|
||||
db.remove(false);
|
||||
do_check_false(db.exists());
|
||||
}
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
do_register_cleanup(remove_bookmarks_html);
|
||||
|
||||
add_task(function* () {
|
||||
// Create a corrupt database.
|
||||
let corruptDB = gTestDir.clone();
|
||||
corruptDB.append("corruptDB.sqlite");
|
||||
corruptDB.copyTo(gProfD, "places.sqlite");
|
||||
do_check_true(db.exists());
|
||||
yield createCorruptDB();
|
||||
|
||||
// Initialize nsBrowserGlue before Places.
|
||||
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
// Check the database was corrupt.
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
|
||||
Assert.equal(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CORRUPT);
|
||||
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
yield promiseEndUpdateBatch();
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
|
||||
function continue_test() {
|
||||
// Check that bookmarks html has been restored.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "example");
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
Assert.equal(bm.title, "example");
|
||||
});
|
||||
|
@ -9,72 +9,42 @@
|
||||
* corrupt, nor a JSON backup nor bookmarks.html are available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Remove bookmarks.html from profile.
|
||||
remove_bookmarks_html();
|
||||
|
||||
// Remove JSON backup from profile.
|
||||
remove_all_JSON_backups();
|
||||
|
||||
// Remove current database file.
|
||||
let db = gProfD.clone();
|
||||
db.append("places.sqlite");
|
||||
if (db.exists()) {
|
||||
db.remove(false);
|
||||
do_check_false(db.exists());
|
||||
}
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
// Create a corrupt database.
|
||||
let corruptDB = gTestDir.clone();
|
||||
corruptDB.append("corruptDB.sqlite");
|
||||
corruptDB.copyTo(gProfD, "places.sqlite");
|
||||
do_check_true(db.exists());
|
||||
yield createCorruptDB();
|
||||
|
||||
// Initialize nsBrowserGlue before Places.
|
||||
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
// Check the database was corrupt.
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CORRUPT);
|
||||
Assert.equal(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CORRUPT);
|
||||
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
yield promiseEndUpdateBatch();
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
|
||||
function continue_test() {
|
||||
// Check that default bookmarks have been restored.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_true(itemId > 0);
|
||||
do_check_eq(bs.getItemTitle(itemId), "Getting Started");
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
do_check_eq(bm.title, "Getting Started");
|
||||
});
|
||||
|
@ -13,12 +13,10 @@ const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization";
|
||||
const TOPIC_CUSTOMIZATION_COMPLETE = "distribution-customization-complete";
|
||||
const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
|
||||
|
||||
function run_test()
|
||||
{
|
||||
do_test_pending();
|
||||
|
||||
function run_test() {
|
||||
// Set special pref to load distribution.ini from the profile folder.
|
||||
Services.prefs.setBoolPref("distribution.testing.loadFromProfile", true);
|
||||
|
||||
// Copy distribution.ini file to the profile dir.
|
||||
let distroDir = gProfD.clone();
|
||||
distroDir.leafName = "distribution";
|
||||
@ -28,78 +26,72 @@ function run_test()
|
||||
iniFile.remove(false);
|
||||
print("distribution.ini already exists, did some test forget to cleanup?");
|
||||
}
|
||||
|
||||
let testDistributionFile = gTestDir.clone();
|
||||
testDistributionFile.append("distribution.ini");
|
||||
testDistributionFile.copyTo(distroDir, "distribution.ini");
|
||||
do_check_true(testDistributionFile.exists());
|
||||
Assert.ok(testDistributionFile.exists());
|
||||
|
||||
// Disable Smart Bookmarks creation.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
do_check_eq(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Force distribution.
|
||||
Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_DISTRIBUTION_CUSTOMIZATION);
|
||||
|
||||
// Test will continue on customization complete notification.
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee,
|
||||
TOPIC_CUSTOMIZATION_COMPLETE,
|
||||
false);
|
||||
do_execute_soon(onCustomizationComplete);
|
||||
}, TOPIC_CUSTOMIZATION_COMPLETE, false);
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
function onCustomizationComplete()
|
||||
{
|
||||
// Check the custom bookmarks exist on menu.
|
||||
let menuItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
|
||||
do_check_neq(menuItemId, -1);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId),
|
||||
"Menu Link Before");
|
||||
menuItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
1 + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
do_check_neq(menuItemId, -1);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(menuItemId),
|
||||
"Menu Link After");
|
||||
|
||||
// Check the custom bookmarks exist on toolbar.
|
||||
let toolbarItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_neq(toolbarItemId, -1);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId),
|
||||
"Toolbar Link Before");
|
||||
toolbarItemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
1 + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_neq(toolbarItemId, -1);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(toolbarItemId),
|
||||
"Toolbar Link After");
|
||||
|
||||
// Check the bmprocessed pref has been created.
|
||||
do_check_true(Services.prefs.getBoolPref(PREF_BMPROCESSED));
|
||||
|
||||
// Check distribution prefs have been created.
|
||||
do_check_eq(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444");
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
do_register_cleanup(function() {
|
||||
do_register_cleanup(function () {
|
||||
// Remove the distribution file, even if the test failed, otherwise all
|
||||
// next tests will import it.
|
||||
let iniFile = gProfD.clone();
|
||||
iniFile.leafName = "distribution";
|
||||
iniFile.append("distribution.ini");
|
||||
if (iniFile.exists())
|
||||
if (iniFile.exists()) {
|
||||
iniFile.remove(false);
|
||||
do_check_false(iniFile.exists());
|
||||
}
|
||||
Assert.ok(!iniFile.exists());
|
||||
});
|
||||
|
||||
add_task(function* () {
|
||||
// Disable Smart Bookmarks creation.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
Assert.equal(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Force distribution.
|
||||
let glue = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver)
|
||||
glue.observe(null, TOPIC_BROWSERGLUE_TEST, TOPICDATA_DISTRIBUTION_CUSTOMIZATION);
|
||||
|
||||
// Test will continue on customization complete notification.
|
||||
yield promiseTopicObserved(TOPIC_CUSTOMIZATION_COMPLETE);
|
||||
|
||||
// Check the custom bookmarks exist on menu.
|
||||
let menuItem = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 0
|
||||
});
|
||||
Assert.equal(menuItem.title, "Menu Link Before");
|
||||
|
||||
menuItem = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 1 + DEFAULT_BOOKMARKS_ON_MENU
|
||||
});
|
||||
Assert.equal(menuItem.title, "Menu Link After");
|
||||
|
||||
// Check the custom bookmarks exist on toolbar.
|
||||
let toolbarItem = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
Assert.equal(toolbarItem.title, "Toolbar Link Before");
|
||||
|
||||
toolbarItem = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 1 + DEFAULT_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
Assert.equal(toolbarItem.title, "Toolbar Link After");
|
||||
|
||||
// Check the bmprocessed pref has been created.
|
||||
Assert.ok(Services.prefs.getBoolPref(PREF_BMPROCESSED));
|
||||
|
||||
// Check distribution prefs have been created.
|
||||
Assert.equal(Services.prefs.getCharPref(PREF_DISTRIBUTION_ID), "516444");
|
||||
});
|
||||
|
@ -10,79 +10,61 @@
|
||||
const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion";
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||
// folder. It should be ignored.
|
||||
// Create our bookmarks.html from bookmarks.glue.html.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
|
||||
// Remove current database file.
|
||||
let db = gProfD.clone();
|
||||
db.append("places.sqlite");
|
||||
if (db.exists()) {
|
||||
db.remove(false);
|
||||
do_check_false(db.exists());
|
||||
}
|
||||
clearDB();
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
do_register_cleanup(remove_bookmarks_html);
|
||||
|
||||
add_task(function* test_migrate_bookmarks() {
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
do_check_eq(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
Assert.equal(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// A migrator would run before nsBrowserGlue Places initialization, so mimic
|
||||
// that behavior adding a bookmark and notifying the migration.
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIObserver);
|
||||
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver);
|
||||
bg.observe(null, "initial-migration-will-import-default-bookmarks", null);
|
||||
|
||||
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, uri("http://mozilla.org/"),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, "migrated");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
// Check if the currently finished batch created the smart bookmarks.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (PlacesUtils.annotations
|
||||
.itemHasAnnotation(itemId, "Places/SmartBookmark")) {
|
||||
do_execute_soon(onSmartBookmarksCreation);
|
||||
}
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
// The test will continue once import has finished and smart bookmarks
|
||||
// have been created.
|
||||
PlacesUtils.bookmarks.addObserver(bookmarksObserver, false);
|
||||
yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
|
||||
url: "http://mozilla.org/",
|
||||
title: "migrated"
|
||||
});
|
||||
|
||||
let promise = promiseEndUpdateBatch();
|
||||
bg.observe(null, "initial-migration-did-import-default-bookmarks", null);
|
||||
}
|
||||
yield promise;
|
||||
|
||||
function onSmartBookmarksCreation() {
|
||||
// Check the created bookmarks still exist.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
SMART_BOOKMARKS_ON_MENU);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "migrated");
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
|
||||
// Check the created bookmark still exists.
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: SMART_BOOKMARKS_ON_MENU
|
||||
});
|
||||
Assert.equal(bm.title, "migrated");
|
||||
|
||||
// Check that we have not imported any new bookmark.
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
SMART_BOOKMARKS_ON_MENU + 1)
|
||||
do_check_eq(itemId, -1);
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_MENU)
|
||||
do_check_eq(itemId, -1);
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: SMART_BOOKMARKS_ON_MENU + 1
|
||||
})));
|
||||
|
||||
remove_bookmarks_html();
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_MENU
|
||||
})));
|
||||
});
|
||||
|
@ -15,269 +15,228 @@ const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
|
||||
const TOPICDATA_FORCE_PLACES_INIT = "force-places-init";
|
||||
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].
|
||||
getService(Ci.nsIBrowserGlue);
|
||||
getService(Ci.nsIObserver);
|
||||
|
||||
function waitForImportAndSmartBookmarks(aCallback) {
|
||||
Services.obs.addObserver(function waitImport() {
|
||||
Services.obs.removeObserver(waitImport, "bookmarks-restore-success");
|
||||
// Delay to test eventual smart bookmarks creation.
|
||||
do_execute_soon(function () {
|
||||
PlacesTestUtils.promiseAsyncUpdates().then(aCallback);
|
||||
});
|
||||
}, "bookmarks-restore-success", false);
|
||||
}
|
||||
|
||||
[
|
||||
|
||||
// This test must be the first one.
|
||||
function test_checkPreferences() {
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
do_check_eq(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Wait for Places init notification.
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee,
|
||||
"places-browser-init-complete");
|
||||
do_execute_soon(function () {
|
||||
// Ensure preferences status.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||
|
||||
try {
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_throw("importBookmarksHTML pref should not exist");
|
||||
}
|
||||
catch(ex) {}
|
||||
|
||||
try {
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
do_throw("importBookmarksHTML pref should not exist");
|
||||
}
|
||||
catch(ex) {}
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
}, "places-browser-init-complete", false);
|
||||
},
|
||||
|
||||
function test_import()
|
||||
{
|
||||
do_print("Import from bookmarks.html if importBookmarksHTML is true.");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
waitForImportAndSmartBookmarks(function () {
|
||||
// Check bookmarks.html has been imported, and a smart bookmark has been
|
||||
// created.
|
||||
itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
// Force nsBrowserGlue::_initPlaces().
|
||||
do_print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
},
|
||||
|
||||
function test_import_noSmartBookmarks()
|
||||
{
|
||||
do_print("import from bookmarks.html, but don't create smart bookmarks \
|
||||
if they are disabled");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
waitForImportAndSmartBookmarks(function () {
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
// Force nsBrowserGlue::_initPlaces().
|
||||
do_print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
},
|
||||
|
||||
function test_import_autoExport_updatedSmartBookmarks()
|
||||
{
|
||||
do_print("Import from bookmarks.html, but don't create smart bookmarks \
|
||||
if autoExportHTML is true and they are at latest version");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
waitForImportAndSmartBookmarks(function () {
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
// Check preferences have been reverted.
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
do_print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
},
|
||||
|
||||
function test_import_autoExport_oldSmartBookmarks()
|
||||
{
|
||||
do_print("Import from bookmarks.html, and create smart bookmarks if \
|
||||
autoExportHTML is true and they are not at latest version.");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
waitForImportAndSmartBookmarks(function () {
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "example");
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
// Check preferences have been reverted.
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
do_print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
},
|
||||
|
||||
function test_restore()
|
||||
{
|
||||
do_print("restore from default bookmarks.html if \
|
||||
restore_default_bookmarks is true.");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
|
||||
waitForImportAndSmartBookmarks(function () {
|
||||
// Check bookmarks.html has been restored.
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_true(itemId > 0);
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
do_print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
|
||||
},
|
||||
|
||||
function test_restore_import()
|
||||
{
|
||||
do_print("setting both importBookmarksHTML and \
|
||||
restore_default_bookmarks should restore defaults.");
|
||||
|
||||
remove_all_bookmarks();
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
let itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_eq(itemId, -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
|
||||
waitForImportAndSmartBookmarks(function () {
|
||||
// Check bookmarks.html has been restored.
|
||||
itemId =
|
||||
PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId,
|
||||
SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_true(itemId > 0);
|
||||
// Check preferences have been reverted.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
// Force nsBrowserGlue::_initPlaces()
|
||||
do_print("Simulate Places init");
|
||||
bg.QueryInterface(Ci.nsIObserver).observe(null,
|
||||
TOPIC_BROWSERGLUE_TEST,
|
||||
TOPICDATA_FORCE_PLACES_INIT);
|
||||
}
|
||||
|
||||
].forEach(add_test);
|
||||
|
||||
do_register_cleanup(function () {
|
||||
remove_all_bookmarks();
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
});
|
||||
|
||||
function run_test()
|
||||
{
|
||||
function run_test() {
|
||||
// Create our bookmarks.html from bookmarks.glue.html.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
|
||||
remove_all_JSON_backups();
|
||||
|
||||
// Create our JSON backup from bookmarks.glue.json.
|
||||
create_JSON_backup("bookmarks.glue.json");
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
do_register_cleanup(function () {
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
|
||||
return PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
function simulatePlacesInit() {
|
||||
do_print("Simulate Places init");
|
||||
let promise = waitForImportAndSmartBookmarks();
|
||||
|
||||
// Force nsBrowserGlue::_initPlaces().
|
||||
bg.observe(null, TOPIC_BROWSERGLUE_TEST, TOPICDATA_FORCE_PLACES_INIT);
|
||||
return promise;
|
||||
}
|
||||
|
||||
add_task(function* test_checkPreferences() {
|
||||
// Initialize Places through the History Service and check that a new
|
||||
// database has been created.
|
||||
Assert.equal(PlacesUtils.history.databaseStatus,
|
||||
PlacesUtils.history.DATABASE_STATUS_CREATE);
|
||||
|
||||
// Wait for Places init notification.
|
||||
yield promiseTopicObserved("places-browser-init-complete");
|
||||
|
||||
// Ensure preferences status.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||
|
||||
Assert.throws(() => Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
Assert.throws(() => Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
});
|
||||
|
||||
add_task(function* test_import() {
|
||||
do_print("Import from bookmarks.html if importBookmarksHTML is true.");
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
})));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
yield simulatePlacesInit();
|
||||
|
||||
// Check bookmarks.html has been imported, and a smart bookmark has been
|
||||
// created.
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
Assert.equal(bm.title, "example");
|
||||
|
||||
// Check preferences have been reverted.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
});
|
||||
|
||||
add_task(function* test_import_noSmartBookmarks() {
|
||||
do_print("import from bookmarks.html, but don't create smart bookmarks " +
|
||||
"if they are disabled");
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
})));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, -1);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
yield simulatePlacesInit();
|
||||
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
Assert.equal(bm.title, "example");
|
||||
|
||||
// Check preferences have been reverted.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
});
|
||||
|
||||
add_task(function* test_import_autoExport_updatedSmartBookmarks() {
|
||||
do_print("Import from bookmarks.html, but don't create smart bookmarks " +
|
||||
"if autoExportHTML is true and they are at latest version");
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
})));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 999);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
yield simulatePlacesInit();
|
||||
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
Assert.equal(bm.title, "example");
|
||||
|
||||
// Check preferences have been reverted.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
});
|
||||
|
||||
add_task(function* test_import_autoExport_oldSmartBookmarks() {
|
||||
do_print("Import from bookmarks.html, and create smart bookmarks if " +
|
||||
"autoExportHTML is true and they are not at latest version.");
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
})));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
|
||||
yield simulatePlacesInit();
|
||||
|
||||
// Check bookmarks.html has been imported, but smart bookmarks have not
|
||||
// been created.
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
Assert.equal(bm.title, "example");
|
||||
|
||||
// Check preferences have been reverted.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
Services.prefs.setBoolPref(PREF_AUTO_EXPORT_HTML, false);
|
||||
});
|
||||
|
||||
add_task(function* test_restore() {
|
||||
do_print("restore from default bookmarks.html if " +
|
||||
"restore_default_bookmarks is true.");
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
})));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
|
||||
yield simulatePlacesInit();
|
||||
|
||||
// Check bookmarks.html has been restored.
|
||||
Assert.ok(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
}));
|
||||
|
||||
// Check preferences have been reverted.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
});
|
||||
|
||||
add_task(function* test_restore_import() {
|
||||
do_print("setting both importBookmarksHTML and " +
|
||||
"restore_default_bookmarks should restore defaults.");
|
||||
|
||||
yield PlacesUtils.bookmarks.eraseEverything();
|
||||
|
||||
// Sanity check: we should not have any bookmark on the toolbar.
|
||||
Assert.ok(!(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
})));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setBoolPref(PREF_IMPORT_BOOKMARKS_HTML, true);
|
||||
Services.prefs.setBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS, true);
|
||||
|
||||
yield simulatePlacesInit();
|
||||
|
||||
// Check bookmarks.html has been restored.
|
||||
Assert.ok(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
}));
|
||||
|
||||
// Check preferences have been reverted.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
});
|
||||
|
@ -9,74 +9,54 @@
|
||||
* database has been created and one backup is available.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "bs",
|
||||
"@mozilla.org/browser/nav-bookmarks-service;1",
|
||||
"nsINavBookmarksService");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "anno",
|
||||
"@mozilla.org/browser/annotation-service;1",
|
||||
"nsIAnnotationService");
|
||||
|
||||
let bookmarksObserver = {
|
||||
onBeginUpdateBatch: function() {},
|
||||
onEndUpdateBatch: function() {
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
|
||||
continue_test();
|
||||
},
|
||||
onItemAdded: function() {},
|
||||
onItemRemoved: function(id, folder, index, itemType) {},
|
||||
onItemChanged: function() {},
|
||||
onItemVisited: function(id, visitID, time) {},
|
||||
onItemMoved: function() {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
// Create our bookmarks.html copying bookmarks.glue.html to the profile
|
||||
// folder. It will be ignored.
|
||||
// Create our bookmarks.html from bookmarks.glue.html.
|
||||
create_bookmarks_html("bookmarks.glue.html");
|
||||
|
||||
// Create our JSON backup copying bookmarks.glue.json to the profile
|
||||
// folder. It will be ignored.
|
||||
remove_all_JSON_backups();
|
||||
|
||||
// Create our JSON backup from bookmarks.glue.json.
|
||||
create_JSON_backup("bookmarks.glue.json");
|
||||
|
||||
// Remove current database file.
|
||||
let db = gProfD.clone();
|
||||
db.append("places.sqlite");
|
||||
if (db.exists()) {
|
||||
db.remove(false);
|
||||
do_check_false(db.exists());
|
||||
}
|
||||
clearDB();
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
do_register_cleanup(function () {
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
return PlacesUtils.bookmarks.eraseEverything();
|
||||
});
|
||||
|
||||
add_task(function* test_main() {
|
||||
// Initialize nsBrowserGlue before Places.
|
||||
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
|
||||
|
||||
// Initialize Places through the History Service.
|
||||
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
|
||||
// Check a new database has been created.
|
||||
// nsBrowserGlue uses databaseStatus to manage initialization.
|
||||
do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
|
||||
Assert.equal(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
|
||||
|
||||
// The test will continue once restore has finished and smart bookmarks
|
||||
// have been created.
|
||||
bs.addObserver(bookmarksObserver, false);
|
||||
}
|
||||
yield promiseEndUpdateBatch();
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
|
||||
function continue_test() {
|
||||
// Check that JSON backup has been restored.
|
||||
// Notice restore from JSON notification is fired before smart bookmarks creation.
|
||||
let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(bs.getItemTitle(itemId), "examplejson");
|
||||
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
|
||||
do_test_finished();
|
||||
}
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: SMART_BOOKMARKS_ON_TOOLBAR
|
||||
});
|
||||
Assert.equal(bm.title, "examplejson");
|
||||
});
|
||||
|
@ -14,273 +14,13 @@ const PREF_AUTO_EXPORT_HTML = "browser.bookmarks.autoExportHTML";
|
||||
const PREF_IMPORT_BOOKMARKS_HTML = "browser.places.importBookmarksHTML";
|
||||
const PREF_RESTORE_DEFAULT_BOOKMARKS = "browser.bookmarks.restore_default_bookmarks";
|
||||
|
||||
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
||||
|
||||
/**
|
||||
* Rebuilds smart bookmarks listening to console output to report any message or
|
||||
* exception generated when calling ensurePlacesDefaultQueriesInitialized().
|
||||
*/
|
||||
function rebuildSmartBookmarks() {
|
||||
let consoleListener = {
|
||||
observe: function(aMsg) {
|
||||
print("Got console message: " + aMsg.message);
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIConsoleListener
|
||||
]),
|
||||
};
|
||||
Services.console.reset();
|
||||
Services.console.registerListener(consoleListener);
|
||||
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue)
|
||||
.ensurePlacesDefaultQueriesInitialized();
|
||||
Services.console.unregisterListener(consoleListener);
|
||||
function run_test() {
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
|
||||
let tests = [];
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
tests.push({
|
||||
description: "All smart bookmarks are created if smart bookmarks version is 0.",
|
||||
exec: function() {
|
||||
// Sanity check: we should have default bookmark.
|
||||
do_check_neq(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0), -1);
|
||||
do_check_neq(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0), -1);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check version has been updated.
|
||||
do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
tests.push({
|
||||
description: "An existing smart bookmark is replaced when version changes.",
|
||||
exec: function() {
|
||||
// Sanity check: we have a smart bookmark on the toolbar.
|
||||
let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO));
|
||||
// Change its title.
|
||||
PlacesUtils.bookmarks.setItemTitle(itemId, "new title");
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "new title");
|
||||
|
||||
// Sanity check items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check smart bookmark has been replaced, itemId has changed.
|
||||
itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0);
|
||||
do_check_neq(itemId, -1);
|
||||
do_check_neq(PlacesUtils.bookmarks.getItemTitle(itemId), "new title");
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO));
|
||||
|
||||
// Check version has been updated.
|
||||
do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
tests.push({
|
||||
description: "bookmarks position is retained when version changes.",
|
||||
exec: function() {
|
||||
// Sanity check items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
let itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO));
|
||||
let firstItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId);
|
||||
|
||||
itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO));
|
||||
let secondItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check smart bookmarks are still in correct position.
|
||||
itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO));
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), firstItemTitle);
|
||||
|
||||
itemId = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId, SMART_BOOKMARKS_ANNO));
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), secondItemTitle);
|
||||
|
||||
// Check version has been updated.
|
||||
do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
tests.push({
|
||||
description: "moved bookmarks position is retained when version changes.",
|
||||
exec: function() {
|
||||
// Sanity check items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
let itemId1 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId1, SMART_BOOKMARKS_ANNO));
|
||||
let firstItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId1);
|
||||
|
||||
let itemId2 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 1);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId2, SMART_BOOKMARKS_ANNO));
|
||||
let secondItemTitle = PlacesUtils.bookmarks.getItemTitle(itemId2);
|
||||
|
||||
// Move the first smart bookmark to the end of the menu.
|
||||
PlacesUtils.bookmarks.moveItem(itemId1, PlacesUtils.bookmarksMenuFolderId,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
|
||||
do_check_eq(itemId1, PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check smart bookmarks are still in correct position.
|
||||
itemId2 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, 0);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId2, SMART_BOOKMARKS_ANNO));
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId2), secondItemTitle);
|
||||
|
||||
itemId1 = PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId,
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
do_check_true(PlacesUtils.annotations.itemHasAnnotation(itemId1, SMART_BOOKMARKS_ANNO));
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId1), firstItemTitle);
|
||||
|
||||
// Move back the smart bookmark to the original position.
|
||||
PlacesUtils.bookmarks.moveItem(itemId1, PlacesUtils.bookmarksMenuFolderId, 1);
|
||||
|
||||
// Check version has been updated.
|
||||
do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
tests.push({
|
||||
description: "An explicitly removed smart bookmark should not be recreated.",
|
||||
exec: function() {
|
||||
// Remove toolbar's smart bookmarks
|
||||
PlacesUtils.bookmarks.removeItem(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0));
|
||||
|
||||
// Sanity check items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
// We should not have recreated the smart bookmark on toolbar.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check version has been updated.
|
||||
do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
tests.push({
|
||||
description: "Even if a smart bookmark has been removed recreate it if version is 0.",
|
||||
exec: function() {
|
||||
// Sanity check items.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
// We should not have recreated the smart bookmark on toolbar.
|
||||
do_check_eq(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
do_check_eq(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check version has been updated.
|
||||
do_check_eq(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
|
||||
next_test();
|
||||
}
|
||||
});
|
||||
//------------------------------------------------------------------------------
|
||||
do_register_cleanup(() => PlacesUtils.bookmarks.eraseEverything());
|
||||
|
||||
function countFolderChildren(aFolderItemId) {
|
||||
let rootNode = PlacesUtils.getFolderContents(aFolderItemId).root;
|
||||
@ -295,57 +35,303 @@ function countFolderChildren(aFolderItemId) {
|
||||
return cc;
|
||||
}
|
||||
|
||||
function next_test() {
|
||||
if (tests.length) {
|
||||
// Execute next test.
|
||||
let test = tests.shift();
|
||||
print("\nTEST: " + test.description);
|
||||
test.exec();
|
||||
}
|
||||
else {
|
||||
// Clean up database from all bookmarks.
|
||||
remove_all_bookmarks();
|
||||
do_test_finished();
|
||||
}
|
||||
/**
|
||||
* Rebuilds smart bookmarks listening to console output to report any message or
|
||||
* exception generated when calling ensurePlacesDefaultQueriesInitialized().
|
||||
*/
|
||||
function rebuildSmartBookmarks() {
|
||||
let consoleListener = {
|
||||
observe: function(aMsg) {
|
||||
do_throw("Got console message: " + aMsg.message);
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([
|
||||
Ci.nsIConsoleListener
|
||||
]),
|
||||
};
|
||||
Services.console.reset();
|
||||
Services.console.registerListener(consoleListener);
|
||||
Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue)
|
||||
.ensurePlacesDefaultQueriesInitialized();
|
||||
Services.console.unregisterListener(consoleListener);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
|
||||
remove_bookmarks_html();
|
||||
remove_all_JSON_backups();
|
||||
|
||||
add_task(function* setup() {
|
||||
// Initialize browserGlue, but remove it's listener to places-init-complete.
|
||||
let bg = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver);
|
||||
|
||||
// Initialize Places.
|
||||
PlacesUtils.history;
|
||||
// Observes Places initialisation complete.
|
||||
Services.obs.addObserver(function waitPlaceInitComplete() {
|
||||
Services.obs.removeObserver(waitPlaceInitComplete, "places-browser-init-complete");
|
||||
|
||||
// Ensure preferences status.
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
try {
|
||||
do_check_false(Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
do_throw("importBookmarksHTML pref should not exist");
|
||||
}
|
||||
catch(ex) {}
|
||||
// Wait for Places init notification.
|
||||
yield promiseTopicObserved("places-browser-init-complete");
|
||||
|
||||
waitForImportAndSmartBookmarks(next_test);
|
||||
}, "places-browser-init-complete", false);
|
||||
// Ensure preferences status.
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
|
||||
Assert.ok(!Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
|
||||
Assert.throws(() => Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
|
||||
|
||||
// Usually places init would async notify to glue, but we want to avoid
|
||||
// randomness here, thus we fire the notification synchronously.
|
||||
bg.observe(null, "places-init-complete", null);
|
||||
}
|
||||
yield waitForImportAndSmartBookmarks();
|
||||
});
|
||||
|
||||
function waitForImportAndSmartBookmarks(aCallback) {
|
||||
Services.obs.addObserver(function waitImport() {
|
||||
Services.obs.removeObserver(waitImport, "bookmarks-restore-success");
|
||||
// Delay to test eventual smart bookmarks creation.
|
||||
do_execute_soon(function () {
|
||||
PlacesTestUtils.promiseAsyncUpdates().then(aCallback);
|
||||
});
|
||||
}, "bookmarks-restore-success", false);
|
||||
}
|
||||
add_task(function* test_version_0() {
|
||||
do_print("All smart bookmarks are created if smart bookmarks version is 0.");
|
||||
|
||||
// Sanity check: we should have default bookmark.
|
||||
Assert.ok(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
}));
|
||||
|
||||
Assert.ok(yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 0
|
||||
}));
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check version has been updated.
|
||||
Assert.equal(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
});
|
||||
|
||||
add_task(function* test_version_change() {
|
||||
do_print("An existing smart bookmark is replaced when version changes.");
|
||||
|
||||
// Sanity check: we have a smart bookmark on the toolbar.
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
|
||||
// Change its title.
|
||||
yield PlacesUtils.bookmarks.update({guid: bm.guid, title: "new title"});
|
||||
bm = yield PlacesUtils.bookmarks.fetch({guid: bm.guid});
|
||||
Assert.equal(bm.title, "new title");
|
||||
|
||||
// Sanity check items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check smart bookmark has been replaced, itemId has changed.
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
Assert.notEqual(bm.title, "new title");
|
||||
|
||||
// Check version has been updated.
|
||||
Assert.equal(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
});
|
||||
|
||||
add_task(function* test_version_change_pos() {
|
||||
do_print("bookmarks position is retained when version changes.");
|
||||
|
||||
// Sanity check items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
let firstItemTitle = bm.title;
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 1
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
let secondItemTitle = bm.title;
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check smart bookmarks are still in correct position.
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
Assert.equal(bm.title, firstItemTitle);
|
||||
|
||||
bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 1
|
||||
});
|
||||
yield checkItemHasAnnotation(bm.guid, SMART_BOOKMARKS_ANNO);
|
||||
Assert.equal(bm.title, secondItemTitle);
|
||||
|
||||
// Check version has been updated.
|
||||
Assert.equal(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
});
|
||||
|
||||
add_task(function* test_version_change_pos_moved() {
|
||||
do_print("moved bookmarks position is retained when version changes.");
|
||||
|
||||
// Sanity check items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
let bm1 = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm1.guid, SMART_BOOKMARKS_ANNO);
|
||||
let firstItemTitle = bm1.title;
|
||||
|
||||
let bm2 = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 1
|
||||
});
|
||||
yield checkItemHasAnnotation(bm2.guid, SMART_BOOKMARKS_ANNO);
|
||||
let secondItemTitle = bm2.title;
|
||||
|
||||
// Move the first smart bookmark to the end of the menu.
|
||||
yield PlacesUtils.bookmarks.update({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
guid: bm1.guid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX
|
||||
});
|
||||
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX
|
||||
});
|
||||
Assert.equal(bm.guid, bm1.guid);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check smart bookmarks are still in correct position.
|
||||
bm2 = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: 0
|
||||
});
|
||||
yield checkItemHasAnnotation(bm2.guid, SMART_BOOKMARKS_ANNO);
|
||||
Assert.equal(bm2.title, secondItemTitle);
|
||||
|
||||
bm1 = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX
|
||||
});
|
||||
yield checkItemHasAnnotation(bm1.guid, SMART_BOOKMARKS_ANNO);
|
||||
Assert.equal(bm1.title, firstItemTitle);
|
||||
|
||||
// Move back the smart bookmark to the original position.
|
||||
yield PlacesUtils.bookmarks.update({
|
||||
parentGuid: PlacesUtils.bookmarks.menuGuid,
|
||||
guid: bm1.guid,
|
||||
index: 1
|
||||
});
|
||||
|
||||
// Check version has been updated.
|
||||
Assert.equal(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
});
|
||||
|
||||
add_task(function* test_recreation() {
|
||||
do_print("An explicitly removed smart bookmark should not be recreated.");
|
||||
|
||||
// Remove toolbar's smart bookmarks
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({
|
||||
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
|
||||
index: 0
|
||||
});
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
|
||||
// Sanity check items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 1);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
// We should not have recreated the smart bookmark on toolbar.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check version has been updated.
|
||||
Assert.equal(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
});
|
||||
|
||||
add_task(function* test_recreation_version_0() {
|
||||
do_print("Even if a smart bookmark has been removed recreate it if version is 0.");
|
||||
|
||||
// Sanity check items.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Set preferences.
|
||||
Services.prefs.setIntPref(PREF_SMART_BOOKMARKS_VERSION, 0);
|
||||
|
||||
rebuildSmartBookmarks();
|
||||
|
||||
// Count items.
|
||||
// We should not have recreated the smart bookmark on toolbar.
|
||||
Assert.equal(countFolderChildren(PlacesUtils.toolbarFolderId),
|
||||
SMART_BOOKMARKS_ON_TOOLBAR + DEFAULT_BOOKMARKS_ON_TOOLBAR);
|
||||
Assert.equal(countFolderChildren(PlacesUtils.bookmarksMenuFolderId),
|
||||
SMART_BOOKMARKS_ON_MENU + DEFAULT_BOOKMARKS_ON_MENU);
|
||||
|
||||
// Check version has been updated.
|
||||
Assert.equal(Services.prefs.getIntPref(PREF_SMART_BOOKMARKS_VERSION),
|
||||
SMART_BOOKMARKS_VERSION);
|
||||
});
|
||||
|
@ -8,96 +8,42 @@
|
||||
* Tests that we build a working leftpane in various corruption situations.
|
||||
*/
|
||||
|
||||
function run_test() {
|
||||
// We want empty roots.
|
||||
remove_all_bookmarks();
|
||||
|
||||
// Sanity check.
|
||||
Assert.ok(!!PlacesUIUtils);
|
||||
|
||||
// Check getters.
|
||||
gLeftPaneFolderIdGetter = Object.getOwnPropertyDescriptor(PlacesUIUtils, "leftPaneFolderId");
|
||||
Assert.equal(typeof(gLeftPaneFolderIdGetter.get), "function");
|
||||
gAllBookmarksFolderIdGetter = Object.getOwnPropertyDescriptor(PlacesUIUtils, "allBookmarksFolderId");
|
||||
Assert.equal(typeof(gAllBookmarksFolderIdGetter.get), "function");
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
do_register_cleanup(remove_all_bookmarks);
|
||||
|
||||
// Used to store the original leftPaneFolderId getter.
|
||||
let gLeftPaneFolderIdGetter;
|
||||
let gAllBookmarksFolderIdGetter;
|
||||
// Used to store the original left Pane status as a JSON string.
|
||||
let gReferenceHierarchy;
|
||||
let gLeftPaneFolderId;
|
||||
// Third party annotated folder.
|
||||
let gFolderId;
|
||||
|
||||
// Corruption cases.
|
||||
let gTests = [
|
||||
|
||||
function test1() {
|
||||
print("1. Do nothing, checks test calibration.");
|
||||
},
|
||||
|
||||
function test2() {
|
||||
print("2. Delete the left pane folder.");
|
||||
PlacesUtils.bookmarks.removeItem(gLeftPaneFolderId);
|
||||
},
|
||||
|
||||
function test3() {
|
||||
print("3. Delete a child of the left pane folder.");
|
||||
let id = PlacesUtils.bookmarks.getIdForItemAt(gLeftPaneFolderId, 0);
|
||||
PlacesUtils.bookmarks.removeItem(id);
|
||||
},
|
||||
|
||||
function test4() {
|
||||
print("4. Delete AllBookmarks.");
|
||||
PlacesUtils.bookmarks.removeItem(PlacesUIUtils.allBookmarksFolderId);
|
||||
},
|
||||
|
||||
function test5() {
|
||||
print("5. Create a duplicated left pane folder.");
|
||||
let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
|
||||
"PlacesRoot",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, ORGANIZER_FOLDER_ANNO,
|
||||
"PlacesRoot", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
},
|
||||
|
||||
function test6() {
|
||||
print("6. Create a duplicated left pane query.");
|
||||
let id = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
|
||||
"AllBookmarks",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, ORGANIZER_QUERY_ANNO,
|
||||
"AllBookmarks", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
},
|
||||
|
||||
function test7() {
|
||||
print("7. Remove the left pane folder annotation.");
|
||||
PlacesUtils.annotations.removeItemAnnotation(gLeftPaneFolderId,
|
||||
ORGANIZER_FOLDER_ANNO);
|
||||
},
|
||||
|
||||
function test8() {
|
||||
print("8. Remove a left pane query annotation.");
|
||||
PlacesUtils.annotations.removeItemAnnotation(PlacesUIUtils.allBookmarksFolderId,
|
||||
ORGANIZER_QUERY_ANNO);
|
||||
},
|
||||
|
||||
function test9() {
|
||||
print("9. Remove a child of AllBookmarks.");
|
||||
let id = PlacesUtils.bookmarks.getIdForItemAt(PlacesUIUtils.allBookmarksFolderId, 0);
|
||||
PlacesUtils.bookmarks.removeItem(id);
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
function run_test() {
|
||||
// We want empty roots.
|
||||
remove_all_bookmarks();
|
||||
|
||||
// Sanity check.
|
||||
do_check_true(!!PlacesUIUtils);
|
||||
|
||||
// Check getters.
|
||||
gLeftPaneFolderIdGetter = PlacesUIUtils.__lookupGetter__("leftPaneFolderId");
|
||||
do_check_eq(typeof(gLeftPaneFolderIdGetter), "function");
|
||||
gAllBookmarksFolderIdGetter = PlacesUIUtils.__lookupGetter__("allBookmarksFolderId");
|
||||
do_check_eq(typeof(gAllBookmarksFolderIdGetter), "function");
|
||||
|
||||
add_task(function* () {
|
||||
// Add a third party bogus annotated item. Should not be removed.
|
||||
gFolderId = PlacesUtils.bookmarks.createFolder(PlacesUtils.unfiledBookmarksFolderId,
|
||||
"test",
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
||||
PlacesUtils.annotations.setItemAnnotation(gFolderId, ORGANIZER_QUERY_ANNO,
|
||||
let folder = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "test",
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER
|
||||
});
|
||||
|
||||
let folderId = yield PlacesUtils.promiseItemId(folder.guid);
|
||||
PlacesUtils.annotations.setItemAnnotation(folderId, ORGANIZER_QUERY_ANNO,
|
||||
"test", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
|
||||
@ -105,37 +51,101 @@ function run_test() {
|
||||
// as reference value.
|
||||
gLeftPaneFolderId = PlacesUIUtils.leftPaneFolderId;
|
||||
gReferenceHierarchy = folderIdToHierarchy(gLeftPaneFolderId);
|
||||
do_test_pending();
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
function run_next_test() {
|
||||
if (gTests.length) {
|
||||
// Create corruption.
|
||||
let test = gTests.shift();
|
||||
test();
|
||||
while (gTests.length) {
|
||||
// Run current test.
|
||||
yield Task.spawn(gTests.shift());
|
||||
|
||||
// Regenerate getters.
|
||||
PlacesUIUtils.__defineGetter__("leftPaneFolderId", gLeftPaneFolderIdGetter);
|
||||
Object.defineProperty(PlacesUIUtils, "leftPaneFolderId", gLeftPaneFolderIdGetter);
|
||||
gLeftPaneFolderId = PlacesUIUtils.leftPaneFolderId;
|
||||
PlacesUIUtils.__defineGetter__("allBookmarksFolderId", gAllBookmarksFolderIdGetter);
|
||||
Object.defineProperty(PlacesUIUtils, "allBookmarksFolderId", gAllBookmarksFolderIdGetter);
|
||||
|
||||
// Check the new left pane folder.
|
||||
Task.spawn(function() {
|
||||
let leftPaneHierarchy = folderIdToHierarchy(gLeftPaneFolderId)
|
||||
if (gReferenceHierarchy != leftPaneHierarchy) {
|
||||
do_throw("hierarchies differ!\n" + gReferenceHierarchy +
|
||||
"\n" + leftPaneHierarchy);
|
||||
}
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(gFolderId), "test");
|
||||
// Go to next test.
|
||||
run_next_test();
|
||||
let leftPaneHierarchy = folderIdToHierarchy(gLeftPaneFolderId)
|
||||
Assert.equal(gReferenceHierarchy, leftPaneHierarchy);
|
||||
|
||||
folder = yield PlacesUtils.bookmarks.fetch({guid: folder.guid});
|
||||
Assert.equal(folder.title, "test");
|
||||
}
|
||||
});
|
||||
|
||||
// Corruption cases.
|
||||
let gTests = [
|
||||
|
||||
function* test1() {
|
||||
print("1. Do nothing, checks test calibration.");
|
||||
},
|
||||
|
||||
function* test2() {
|
||||
print("2. Delete the left pane folder.");
|
||||
let guid = yield PlacesUtils.promiseItemGuid(gLeftPaneFolderId);
|
||||
yield PlacesUtils.bookmarks.remove(guid);
|
||||
},
|
||||
|
||||
function* test3() {
|
||||
print("3. Delete a child of the left pane folder.");
|
||||
let guid = yield PlacesUtils.promiseItemGuid(gLeftPaneFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({parentGuid: guid, index: 0});
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
},
|
||||
|
||||
function* test4() {
|
||||
print("4. Delete AllBookmarks.");
|
||||
let guid = yield PlacesUtils.promiseItemGuid(PlacesUIUtils.allBookmarksFolderId);
|
||||
yield PlacesUtils.bookmarks.remove(guid);
|
||||
},
|
||||
|
||||
function* test5() {
|
||||
print("5. Create a duplicated left pane folder.");
|
||||
let folder = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "PlacesRoot",
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER
|
||||
});
|
||||
|
||||
let folderId = yield PlacesUtils.promiseItemId(folder.guid);
|
||||
PlacesUtils.annotations.setItemAnnotation(folderId, ORGANIZER_FOLDER_ANNO,
|
||||
"PlacesRoot", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
},
|
||||
|
||||
function* test6() {
|
||||
print("6. Create a duplicated left pane query.");
|
||||
let folder = yield PlacesUtils.bookmarks.insert({
|
||||
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
|
||||
title: "AllBookmarks",
|
||||
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
||||
type: PlacesUtils.bookmarks.TYPE_FOLDER
|
||||
});
|
||||
|
||||
let folderId = yield PlacesUtils.promiseItemId(folder.guid);
|
||||
PlacesUtils.annotations.setItemAnnotation(folderId, ORGANIZER_QUERY_ANNO,
|
||||
"AllBookmarks", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
},
|
||||
|
||||
function* test7() {
|
||||
print("7. Remove the left pane folder annotation.");
|
||||
PlacesUtils.annotations.removeItemAnnotation(gLeftPaneFolderId,
|
||||
ORGANIZER_FOLDER_ANNO);
|
||||
},
|
||||
|
||||
function* test8() {
|
||||
print("8. Remove a left pane query annotation.");
|
||||
PlacesUtils.annotations.removeItemAnnotation(PlacesUIUtils.allBookmarksFolderId,
|
||||
ORGANIZER_QUERY_ANNO);
|
||||
},
|
||||
|
||||
function* test9() {
|
||||
print("9. Remove a child of AllBookmarks.");
|
||||
let guid = yield PlacesUtils.promiseItemGuid(PlacesUIUtils.allBookmarksFolderId);
|
||||
let bm = yield PlacesUtils.bookmarks.fetch({parentGuid: guid, index: 0});
|
||||
yield PlacesUtils.bookmarks.remove(bm.guid);
|
||||
}
|
||||
else {
|
||||
// All tests finished.
|
||||
remove_all_bookmarks();
|
||||
do_test_finished();
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* Convert a folder item id to a JSON representation of it and its contents.
|
||||
|
Loading…
Reference in New Issue
Block a user