Bug 1094909 - Convert xpcshell-tests in toolkit/components/places/tests/expiration to Bookmarks.jsm API r=mak

This commit is contained in:
Tim Taubert 2015-03-13 15:51:07 +01:00
parent d0edf6a669
commit 1c3086f994
9 changed files with 80 additions and 70 deletions

View File

@ -12,8 +12,7 @@ const TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING = "autocomplete-will-enter-text";
/**
* Ensures that we have no data in the tables created by ANALYZE.
*/
function clearAnalyzeData()
{
function clearAnalyzeData() {
let db = DBConn();
if (!db.tableExists("sqlite_stat1")) {
return;
@ -29,8 +28,7 @@ function clearAnalyzeData()
* @param aRan
* True if it was expected to run, false otherwise
*/
function do_check_analyze_ran(aTableName, aRan)
{
function do_check_analyze_ran(aTableName, aRan) {
let db = DBConn();
do_check_true(db.tableExists("sqlite_stat1"));
let stmt = db.createStatement("SELECT idx FROM sqlite_stat1 WHERE tbl = :table");
@ -52,18 +50,19 @@ function do_check_analyze_ran(aTableName, aRan)
////////////////////////////////////////////////////////////////////////////////
//// Tests
function run_test()
{
function run_test() {
run_next_test();
}
add_task(function init_tests()
{
add_task(function* init_tests() {
const TEST_URI = NetUtil.newURI("http://mozilla.org/");
const TEST_TITLE = "This is a test";
let bs = PlacesUtils.bookmarks;
bs.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, TEST_URI,
bs.DEFAULT_INDEX, TEST_TITLE);
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: TEST_TITLE,
url: TEST_URI
});
yield PlacesTestUtils.addVisits(TEST_URI);
let thing = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput,
@ -80,8 +79,7 @@ add_task(function init_tests()
null);
});
add_task(function test_timed()
{
add_task(function* test_timed() {
clearAnalyzeData();
// Set a low interval and wait for the timed expiration to start.
@ -96,8 +94,7 @@ add_task(function test_timed()
do_check_analyze_ran("moz_inputhistory", true);
});
add_task(function test_debug()
{
add_task(function* test_debug() {
clearAnalyzeData();
yield promiseForceExpirationStep(1);
@ -108,8 +105,7 @@ add_task(function test_debug()
do_check_analyze_ran("moz_inputhistory", true);
});
add_task(function test_clear_history()
{
add_task(function* test_clear_history() {
clearAnalyzeData();
let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED);

View File

@ -12,8 +12,6 @@
* This expiration policy is only valid for page annotations.
*/
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let as = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
@ -47,8 +45,11 @@ add_task(function test_annos_expire_history() {
let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
// We also add a visit before bookmarking.
yield PlacesTestUtils.addVisits({ uri: pageURI, visitDate: now++ });
let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
bs.DEFAULT_INDEX, null);
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: pageURI,
title: null
});
// Notice we use page annotations here, items annotations can't use this
// kind of expiration policy.
as.setPageAnnotation(pageURI, "item_persist1", "test", 0, as.EXPIRE_WITH_HISTORY);

View File

@ -15,8 +15,6 @@
* the item is removed, thus expiration won't handle this case at all.
*/
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let as = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
@ -50,8 +48,12 @@ add_task(function test_annos_expire_never() {
let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
// We also add a visit before bookmarking.
yield PlacesTestUtils.addVisits({ uri: pageURI, visitDate: now++ });
let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
bs.DEFAULT_INDEX, null);
let bm = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: pageURI,
title: null
});
let id = yield PlacesUtils.promiseItemId(bm.guid);
as.setItemAnnotation(id, "item_persist1", "test", 0, as.EXPIRE_NEVER);
as.setItemAnnotation(id, "item_persist2", "test", 0, as.EXPIRE_NEVER);
}

View File

@ -14,8 +14,6 @@
* - EXPIRE_MONTHS: annotation would be expired after 180 days
*/
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let as = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
@ -89,8 +87,12 @@ add_task(function test_annos_expire_policy() {
for (let i = 0; i < 5; i++) {
let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
yield PlacesTestUtils.addVisits({ uri: pageURI, visitDate: now++ });
let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
bs.DEFAULT_INDEX, null);
let bm = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: pageURI,
title: null
});
let id = yield PlacesUtils.promiseItemId(bm.guid);
// Add a 6 days old anno.
add_old_anno(id, "persist_days", "test", as.EXPIRE_DAYS, 6);
// Add a 8 days old anno, modified 5 days ago.

View File

@ -10,8 +10,6 @@
* Session annotations should be expired when browsing session ends.
*/
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let as = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
@ -35,8 +33,12 @@ add_task(function test_annos_expire_session() {
// Add some bookmarked page and a couple session annotations for each.
for (let i = 0; i < 10; i++) {
let pageURI = uri("http://session_item_anno." + i + ".mozilla.org/");
let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
bs.DEFAULT_INDEX, null);
let bm = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: pageURI,
title: null
});
let id = yield PlacesUtils.promiseItemId(bm.guid);
as.setItemAnnotation(id, "test1", "test", 0, as.EXPIRE_SESSION);
as.setItemAnnotation(id, "test2", "test", 0, as.EXPIRE_SESSION);
}

View File

@ -12,7 +12,6 @@
*/
let hs = PlacesUtils.history;
let bs = PlacesUtils.bookmarks;
let as = PlacesUtils.annotations;
/**
@ -94,8 +93,12 @@ add_task(function test_historyClear() {
let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
// This visit will be expired.
yield PlacesTestUtils.addVisits({ uri: pageURI });
let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
bs.DEFAULT_INDEX, null);
let bm = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: pageURI,
title: null
});
let id = yield PlacesUtils.promiseItemId(bm.guid);
// Will persist because it's an EXPIRE_NEVER item anno.
as.setItemAnnotation(id, "persist", "test", 0, as.EXPIRE_NEVER);
// Will persist because the page is bookmarked.
@ -140,17 +143,15 @@ add_task(function test_historyClear() {
do_check_eq(items.length, 0);
});
["persist"].forEach(function(aAnno) {
let pages = as.getPagesWithAnnotation(aAnno);
do_check_eq(pages.length, 5);
});
let pages = as.getPagesWithAnnotation("persist");
do_check_eq(pages.length, 5);
["persist"].forEach(function(aAnno) {
let items = as.getItemsWithAnnotation(aAnno);
do_check_eq(items.length, 5);
items.forEach(function(aItemId) {
// Check item exists.
bs.getItemIndex(aItemId);
});
});
let items = as.getItemsWithAnnotation("persist");
do_check_eq(items.length, 5);
for (let itemId of items) {
// Check item exists.
let guid = yield PlacesUtils.promiseItemGuid(itemId);
do_check_true((yield PlacesUtils.bookmarks.fetch({guid})), "item exists");
}
});

View File

@ -10,7 +10,7 @@
let gNow = getExpirablePRTime();
add_task(function test_expire_orphans()
add_task(function* test_expire_orphans()
{
// Add visits to 2 pages and force a orphan expiration. Visits should survive.
yield PlacesTestUtils.addVisits({
@ -22,10 +22,12 @@ add_task(function test_expire_orphans()
visitDate: gNow++
});
// Create a orphan place.
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://page3.mozilla.org/"),
PlacesUtils.bookmarks.DEFAULT_INDEX, "");
PlacesUtils.bookmarks.removeItem(id);
let bm = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://page3.mozilla.org/",
title: ""
});
yield PlacesUtils.bookmarks.remove(bm);
// Expire now.
yield promiseForceExpirationStep(0);
@ -39,7 +41,7 @@ add_task(function test_expire_orphans()
yield PlacesTestUtils.clearHistory();
});
add_task(function test_expire_orphans_optionalarg()
add_task(function* test_expire_orphans_optionalarg()
{
// Add visits to 2 pages and force a orphan expiration. Visits should survive.
yield PlacesTestUtils.addVisits({
@ -51,10 +53,12 @@ add_task(function test_expire_orphans_optionalarg()
visitDate: gNow++
});
// Create a orphan place.
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://page3.mozilla.org/"),
PlacesUtils.bookmarks.DEFAULT_INDEX, "");
PlacesUtils.bookmarks.removeItem(id);
let bm = yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://page3.mozilla.org/",
title: ""
});
yield PlacesUtils.bookmarks.remove(bm);
// Expire now.
yield promiseForceExpirationStep();

View File

@ -12,8 +12,6 @@
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let tests = [
@ -70,8 +68,11 @@ add_task(function test_notifications_onDeleteURI() {
currentTest.bookmarks = [];
for (let i = 0; i < currentTest.addBookmarks; i++) {
let page = "http://" + testIndex + "." + i + ".mozilla.org/";
bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page),
bs.DEFAULT_INDEX, null);
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: null,
url: page
});
currentTest.bookmarks.push(page);
}
@ -103,11 +104,11 @@ add_task(function test_notifications_onDeleteURI() {
currentTest.expectedNotifications);
// Clean up.
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
yield PlacesUtils.bookmarks.eraseEverything();
yield PlacesTestUtils.clearHistory();
}
clearMaxPages();
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
yield PlacesUtils.bookmarks.eraseEverything();
yield PlacesTestUtils.clearHistory();
});

View File

@ -13,8 +13,6 @@
let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
let tests = [
@ -89,8 +87,11 @@ add_task(function test_notifications_onDeleteVisits() {
currentTest.bookmarks = [];
for (let i = 0; i < currentTest.addBookmarks; i++) {
let page = "http://" + testIndex + "." + i + ".mozilla.org/";
bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page),
bs.DEFAULT_INDEX, null);
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.unfiledGuid,
title: null,
url: page
});
currentTest.bookmarks.push(page);
}
@ -125,11 +126,11 @@ add_task(function test_notifications_onDeleteVisits() {
currentTest.expectedNotifications);
// Clean up.
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
yield PlacesUtils.bookmarks.eraseEverything();
yield PlacesTestUtils.clearHistory();
}
clearMaxPages();
bs.removeFolderChildren(bs.unfiledBookmarksFolder);
yield PlacesUtils.bookmarks.eraseEverything();
yield PlacesTestUtils.clearHistory();
});