Bug 613588 (Tests) - Load-on-demand livemarks.

r=dietrich
This commit is contained in:
Marco Bonardo 2012-02-24 13:42:30 +01:00
Родитель 53a27445a1
Коммит 3f265f4b54
30 изменённых файлов: 541 добавлений и 1528 удалений

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

@ -41,7 +41,7 @@ function test() {
ok(PlacesUIUtils, "checking PlacesUIUtils, running in chrome context?");
/*
- create, a test folder, add bookmark, separator, livemark to it
- create, a test folder, add bookmark, separator to it
- fetch guids for all
- copy the folder
- test that guids are all different
@ -66,10 +66,6 @@ function test() {
PlacesUtils.bookmarks.insertBookmark(folderAId, PlacesUtils._uri("http://foo"),
-1, "test bookmark");
PlacesUtils.bookmarks.insertSeparator(folderAId, -1);
PlacesUtils.livemarks.createLivemarkFolderOnly(folderAId, "test livemark",
PlacesUtils._uri("http://test"),
PlacesUtils._uri("http://test"), -1);
var folderANode = testRootNode.getChild(0);
var folderAGUIDs = getGUIDs(folderANode);
@ -125,8 +121,7 @@ function getGUIDs(aNode) {
var GUIDs = {
folder: PlacesUtils.bookmarks.getItemGUID(aNode.itemId),
bookmark: PlacesUtils.bookmarks.getItemGUID(aNode.getChild(0).itemId),
separator: PlacesUtils.bookmarks.getItemGUID(aNode.getChild(1).itemId),
livemark: PlacesUtils.bookmarks.getItemGUID(aNode.getChild(2).itemId)
separator: PlacesUtils.bookmarks.getItemGUID(aNode.getChild(1).itemId)
};
aNode.containerOpen = false;
return GUIDs;
@ -144,8 +139,7 @@ function checkGUIDs(aFolderNode, aGUIDs, aShouldMatch) {
var allMatch = check(aFolderNode, aGUIDs.folder, aShouldMatch) &&
check(aFolderNode.getChild(0), aGUIDs.bookmark, aShouldMatch) &&
check(aFolderNode.getChild(1), aGUIDs.separator, aShouldMatch) &&
check(aFolderNode.getChild(2), aGUIDs.livemark, aShouldMatch);
check(aFolderNode.getChild(1), aGUIDs.separator, aShouldMatch)
aFolderNode.containerOpen = false;
return allMatch;

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

@ -95,11 +95,6 @@ function startTest() {
"bmf1");
addedBookmarks.push(id);
bs.moveItem(id, bs.bookmarksMenuFolder, 0);
id = PlacesUtils.livemarks.createLivemarkFolderOnly(
bs.bookmarksMenuFolder, "bml",
PlacesUtils._uri("http://bml.siteuri.mozilla.org/"),
PlacesUtils._uri("http://bml.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
addedBookmarks.push(id);
// TOOLBAR
ok(true, "*** Acting on toolbar bookmarks");
@ -128,10 +123,6 @@ function startTest() {
"bmf1");
addedBookmarks.push(id);
bs.moveItem(id, bs.toolbarFolder, 0);
id = PlacesUtils.livemarks.createLivemarkFolderOnly(
bs.toolbarFolder, "tbl", PlacesUtils._uri("http://tbl.siteuri.mozilla.org/"),
PlacesUtils._uri("http://tbl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
addedBookmarks.push(id);
// UNSORTED
ok(true, "*** Acting on unsorted bookmarks");
@ -160,11 +151,6 @@ function startTest() {
"ubf1");
addedBookmarks.push(id);
bs.moveItem(id, bs.unfiledBookmarksFolder, 0);
id = PlacesUtils.livemarks.createLivemarkFolderOnly(
bs.unfiledBookmarksFolder, "bubl",
PlacesUtils._uri("http://bubl.siteuri.mozilla.org/"),
PlacesUtils._uri("http://bubl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
addedBookmarks.push(id);
// Remove all added bookmarks.
addedBookmarks.forEach(function (aItem) {
@ -201,27 +187,7 @@ var bookmarksObserver = {
]),
// nsIAnnotationObserver
onItemAnnotationSet: function(aItemId, aAnnotationName) {
if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
// Check that item is recognized as a livemark.
let validator = function(aTreeRowIndex) {
let tree = gLibrary.PlacesOrganizer._places;
let livemarkAtom = Cc["@mozilla.org/atom-service;1"].
getService(Ci.nsIAtomService).
getAtom("livemark");
let properties = Cc["@mozilla.org/supports-array;1"].
createInstance(Ci.nsISupportsArray);
tree.view.getCellProperties(aTreeRowIndex,
tree.columns.getColumnAt(0),
properties);
return properties.GetIndexOf(livemarkAtom) != -1;
};
var [node, index, valid] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places, validator);
isnot(node, null, "Found new Places node in left pane at " + index);
ok(valid, "Node is recognized as a livemark");
}
},
onItemAnnotationSet: function() {},
onItemAnnotationRemoved: function() {},
onPageAnnotationSet: function() {},
onPageAnnotationRemoved: function() {},

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

@ -118,11 +118,6 @@ function startTest() {
bs.setItemTitle(id, "bmf1_edited");
addedBookmarks.push(id);
bs.moveItem(id, bs.bookmarksMenuFolder, 0);
id = PlacesUtils.livemarks.createLivemarkFolderOnly(
bs.bookmarksMenuFolder, "bml",
PlacesUtils._uri("http://bml.siteuri.mozilla.org/"),
PlacesUtils._uri("http://bml.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
addedBookmarks.push(id);
// TOOLBAR
info("*** Acting on toolbar bookmarks");
@ -154,10 +149,6 @@ function startTest() {
bs.setItemTitle(id, "tbf1_edited");
addedBookmarks.push(id);
bs.moveItem(id, bs.toolbarFolder, 0);
id = PlacesUtils.livemarks.createLivemarkFolderOnly(
bs.toolbarFolder, "tbl", PlacesUtils._uri("http://tbl.siteuri.mozilla.org/"),
PlacesUtils._uri("http://tbl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
addedBookmarks.push(id);
// UNSORTED
info("*** Acting on unsorted bookmarks");
@ -187,11 +178,6 @@ function startTest() {
bs.setItemTitle(id, "bubf1_edited");
addedBookmarks.push(id);
bs.moveItem(id, bs.unfiledBookmarksFolder, 0);
id = PlacesUtils.livemarks.createLivemarkFolderOnly(
bs.unfiledBookmarksFolder, "bubl",
PlacesUtils._uri("http://bubl.siteuri.mozilla.org/"),
PlacesUtils._uri("http://bubl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
addedBookmarks.push(id);
// Remove all added bookmarks.
addedBookmarks.forEach(function (aItem) {
@ -233,38 +219,7 @@ var bookmarksObserver = {
]),
// nsIAnnotationObserver
onItemAnnotationSet: function(aItemId, aAnnotationName) {
if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
var views = getViewsForFolder(PlacesUtils.bookmarks.getFolderIdForItem(aItemId));
ok(views.length > 0, "Found affected views (" + views.length + "): " + views);
// Check that item is recognized as a livemark.
let validator = function(aElementOrTreeIndex) {
if (typeof(aElementOrTreeIndex) == "number") {
var sidebar = document.getElementById("sidebar");
var tree = sidebar.contentDocument.getElementById("bookmarks-view");
let livemarkAtom = Cc["@mozilla.org/atom-service;1"].
getService(Ci.nsIAtomService).
getAtom("livemark");
let properties = Cc["@mozilla.org/supports-array;1"].
createInstance(Ci.nsISupportsArray);
tree.view.getCellProperties(aElementOrTreeIndex,
tree.columns.getColumnAt(0),
properties);
return properties.GetIndexOf(livemarkAtom) != -1;
}
else {
return aElementOrTreeIndex.hasAttribute("livemark");
}
};
for (var i = 0; i < views.length; i++) {
var [node, index, valid] = searchItemInView(aItemId, views[i], validator);
isnot(node, null, "Found new Places node in " + views[i] + " at " + index);
ok(valid, "Node is recognized as a livemark");
}
}
},
onItemAnnotationSet: function() {},
onItemAnnotationRemoved: function() {},
onPageAnnotationSet: function() {},
onPageAnnotationRemoved: function() {},

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

@ -36,11 +36,6 @@
*
* ***** END LICENSE BLOCK ***** */
// The following components need to be initialized to perform tests without
// asserting in debug builds (Bug 448804).
Cc["@mozilla.org/browser/livemark-service;2"].getService(Ci.nsILivemarkService);
Cc["@mozilla.org/feed-processor;1"].createInstance(Ci.nsIFeedProcessor);
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
const DESCRIPTION_ANNO = "bookmarkProperties/description";
const POST_DATA_ANNO = "bookmarkProperties/POSTData";
@ -49,6 +44,7 @@ do_check_eq(typeof PlacesUtils, "object");
// main
function run_test() {
do_test_pending();
/*
HTML+FEATURES SUMMARY:
- import legacy bookmarks
@ -92,21 +88,25 @@ function run_test() {
populate();
validate();
// Test exporting a Places canonical json file.
// 1. export to bookmarks.exported.json
// 2. empty bookmarks db
// 3. import bookmarks.exported.json
// 4. run the test-suite
try {
PlacesUtils.backups.saveBookmarksToJSONFile(jsonFile);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
LOG("exported json");
try {
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
LOG("imported json");
validate();
LOG("validated import");
waitForAsyncUpdates(function () {
// Test exporting a Places canonical json file.
// 1. export to bookmarks.exported.json
// 2. empty bookmarks db
// 3. import bookmarks.exported.json
// 4. run the test-suite
try {
PlacesUtils.backups.saveBookmarksToJSONFile(jsonFile);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
LOG("exported json");
try {
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
LOG("imported json");
validate();
LOG("validated import");
waitForAsyncUpdates(do_test_finished);
});
}
var tagData = [
@ -243,14 +243,17 @@ function testToolbarFolder() {
var livemark = toolbar.getChild(1);
// title
do_check_eq("Latest Headlines", livemark.title);
// livemark check
do_check_true(PlacesUtils.livemarks.isLivemark(livemark.itemId));
// site url
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
PlacesUtils.livemarks.getSiteURI(livemark.itemId).spec);
// feed url
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
PlacesUtils.livemarks.getFeedURI(livemark.itemId).spec);
PlacesUtils.livemarks.getLivemark(
{ id: livemark.itemId },
function (aStatus, aLivemark) {
do_check_true(Components.isSuccessCode(aStatus));
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
aLivemark.siteURI.spec);
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
aLivemark.feedURI.spec);
}
);
// test added bookmark data
var child = toolbar.getChild(2);

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

@ -49,8 +49,6 @@ var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var as = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var lms = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
var icos = Cc["@mozilla.org/browser/favicon-service;1"].
getService(Ci.nsIFaviconService);
var ps = Cc["@mozilla.org/preferences-service;1"].
@ -65,8 +63,9 @@ const POST_DATA_ANNO = "bookmarkProperties/POSTData";
const TEST_FAVICON_PAGE_URL = "http://en-US.www.mozilla.com/en-US/firefox/central/";
const TEST_FAVICON_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==";
// main
function run_test() {
do_test_pending();
// avoid creating the places smart folder during tests
ps.setIntPref("browser.places.smartBookmarksVersion", -1);
@ -79,38 +78,41 @@ function run_test() {
// Check that every bookmark is correct
// Corrupt bookmarks should not have been imported
database_check();
waitForAsyncUpdates(function() {
// Create corruption in database
var corruptItemId = bs.insertBookmark(bs.toolbarFolder,
uri("http://test.mozilla.org"),
bs.DEFAULT_INDEX, "We love belugas");
var stmt = dbConn.createStatement("UPDATE moz_bookmarks SET fk = NULL WHERE id = :itemId");
stmt.params.itemId = corruptItemId;
stmt.execute();
stmt.finalize();
// Create corruption in database
var corruptItemId = bs.insertBookmark(bs.toolbarFolder,
uri("http://test.mozilla.org"),
bs.DEFAULT_INDEX, "We love belugas");
var stmt = dbConn.createStatement("UPDATE moz_bookmarks SET fk = NULL WHERE id = :itemId");
stmt.params.itemId = corruptItemId;
stmt.execute();
stmt.finalize();
// Export bookmarks
var bookmarksFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
bookmarksFile.append("bookmarks.exported.html");
if (bookmarksFile.exists())
bookmarksFile.remove(false);
bookmarksFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600);
if (!bookmarksFile.exists())
do_throw("couldn't create file: bookmarks.exported.html");
try {
ies.exportHTMLToFile(bookmarksFile);
} catch(ex) { do_throw("couldn't export to bookmarks.exported.html: " + ex); }
// Export bookmarks
var bookmarksFile = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
bookmarksFile.append("bookmarks.exported.html");
if (bookmarksFile.exists())
bookmarksFile.remove(false);
bookmarksFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600);
if (!bookmarksFile.exists())
do_throw("couldn't create file: bookmarks.exported.html");
try {
ies.exportHTMLToFile(bookmarksFile);
} catch(ex) { do_throw("couldn't export to bookmarks.exported.html: " + ex); }
// Clear all bookmarks
remove_all_bookmarks();
// Clear all bookmarks
remove_all_bookmarks();
// Import bookmarks
try {
ies.importHTMLFromFile(bookmarksFile, true);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
// Import bookmarks
try {
ies.importHTMLFromFile(bookmarksFile, true);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
// Check that every bookmark is correct
database_check();
// Check that every bookmark is correct
database_check();
waitForAsyncUpdates(do_test_finished);
});
}
/*
@ -192,14 +194,16 @@ function database_check() {
var livemark = toolbar.getChild(1);
// title
do_check_eq("Latest Headlines", livemark.title);
// livemark check
do_check_true(lms.isLivemark(livemark.itemId));
// site url
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
lms.getSiteURI(livemark.itemId).spec);
// feed url
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
lms.getFeedURI(livemark.itemId).spec);
PlacesUtils.livemarks.getLivemark(
{ id: livemark.itemId },
function (aStatus, aLivemark) {
do_check_true(Components.isSuccessCode(aStatus));
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
aLivemark.siteURI.spec);
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
aLivemark.feedURI.spec);
}
);
// cleanup
toolbar.containerOpen = false;

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

@ -83,7 +83,6 @@ let test_bookmarks = {
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg=="
},
{ title: "Latest Headlines",
description: "Livemark test comment",
url: "http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
feedUrl: "http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
}
@ -105,6 +104,10 @@ let importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
function run_test()
{
run_next_test();
}
add_test(function setup() {
// Avoid creating smart bookmarks during the test.
Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1);
@ -131,16 +134,20 @@ function run_test()
importer.importHTMLFromFile(gBookmarksFileOld, true);
} catch(ex) { do_throw("couldn't import legacy bookmarks file: " + ex); }
testImportedBookmarks();
waitForAsyncUpdates(function () {
testImportedBookmarks();
// Prepare for next tests.
try {
importer.exportHTMLToFile(gBookmarksFileNew);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
// Prepare for next tests.
try {
importer.exportHTMLToFile(gBookmarksFileNew);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
remove_all_bookmarks();
run_next_test();
}
waitForAsyncUpdates(function () {
remove_all_bookmarks();
run_next_test();
});
});
});
add_test(function test_import_new()
{
@ -152,10 +159,14 @@ add_test(function test_import_new()
importer.importHTMLFromFile(gBookmarksFileNew, true);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
testImportedBookmarks();
waitForAsyncUpdates(function () {
testImportedBookmarks();
remove_all_bookmarks();
run_next_test();
waitForAsyncUpdates(function () {
remove_all_bookmarks();
run_next_test();
});
});
});
add_test(function test_emptytitle_export()
@ -189,18 +200,22 @@ add_test(function test_emptytitle_export()
importer.importHTMLFromFile(gBookmarksFileNew, true);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
testImportedBookmarks();
waitForAsyncUpdates(function () {
testImportedBookmarks();
// Cleanup.
test_bookmarks.unfiled.pop();
PlacesUtils.bookmarks.removeItem(id);
// Cleanup.
test_bookmarks.unfiled.pop();
PlacesUtils.bookmarks.removeItem(id);
try {
importer.exportHTMLToFile(gBookmarksFileNew);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
try {
importer.exportHTMLToFile(gBookmarksFileNew);
} catch(ex) { do_throw("couldn't export to file: " + ex); }
remove_all_bookmarks();
run_next_test();
waitForAsyncUpdates(function () {
remove_all_bookmarks();
run_next_test();
});
});
});
add_test(function test_import_preplaces_to_folder()
@ -218,11 +233,15 @@ add_test(function test_import_preplaces_to_folder()
importer.importHTMLFromFileToFolder(gBookmarksFileOld, testFolder, false);
} catch(ex) { do_throw("couldn't import the exported file to folder: " + ex); }
// Import-to-folder creates subfolders for toolbar and unfiled.
testImportedBookmarksToFolder(testFolder);
waitForAsyncUpdates(function () {
// Import-to-folder creates subfolders for toolbar and unfiled.
testImportedBookmarksToFolder(testFolder);
remove_all_bookmarks();
run_next_test();
waitForAsyncUpdates(function () {
remove_all_bookmarks();
run_next_test();
});
});
});
add_test(function test_import_to_folder()
@ -240,11 +259,15 @@ add_test(function test_import_to_folder()
importer.importHTMLFromFileToFolder(gBookmarksFileNew, testFolder, false);
} catch(ex) { do_throw("couldn't import the exported file to folder: " + ex); }
// Import-to-folder creates subfolders for toolbar and unfiled.
testImportedBookmarksToFolder(testFolder);
waitForAsyncUpdates(function () {
// Import-to-folder creates subfolders for toolbar and unfiled.
testImportedBookmarksToFolder(testFolder);
remove_all_bookmarks();
run_next_test();
waitForAsyncUpdates(function () {
remove_all_bookmarks();
run_next_test();
});
});
});
add_test(function test_import_ontop()
@ -267,10 +290,14 @@ add_test(function test_import_ontop()
importer.importHTMLFromFile(gBookmarksFileNew, true);
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
testImportedBookmarks();
waitForAsyncUpdates(function () {
testImportedBookmarks();
remove_all_bookmarks();
run_next_test();
waitForAsyncUpdates(function () {
remove_all_bookmarks();
run_next_test();
});
});
});
function testImportedBookmarks()
@ -350,8 +377,14 @@ function checkItem(aExpected, aNode)
aExpected.lastModified);
break;
case "url":
if (!PlacesUtils.livemarks.isLivemark(id))
do_check_eq(aNode.uri, aExpected.url);
PlacesUtils.livemarks.getLivemark(
{ id: id },
function (aStatus, aLivemark) {
if (!Components.isSuccessCode(aStatus)) {
do_check_eq(aNode.uri, aExpected.url);
}
}
);
break;
case "icon":
let faviconURI = PlacesUtils.favicons.getFaviconForPage(
@ -378,11 +411,14 @@ function checkItem(aExpected, aNode)
aExpected.charset);
break;
case "feedUrl":
do_check_true(PlacesUtils.livemarks.isLivemark(id));
do_check_eq(PlacesUtils.livemarks.getSiteURI(id).spec,
aExpected.url);
do_check_eq(PlacesUtils.livemarks.getFeedURI(id).spec,
aExpected.feedUrl);
PlacesUtils.livemarks.getLivemark(
{ id: id },
function (aStatus, aLivemark) {
do_check_true(Components.isSuccessCode(aStatus));
do_check_eq(aLivemark.siteURI.spec, aExpected.url);
do_check_eq(aLivemark.feedURI.spec, Expected.feedUrl);
}
);
break;
case "children":
let folder = aNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);

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

@ -39,7 +39,6 @@
* ***** END LICENSE BLOCK ***** */
var bmsvc = PlacesUtils.bookmarks;
var lmsvc = PlacesUtils.livemarks;
var ptSvc = PlacesUIUtils.ptm;
var tagssvc = PlacesUtils.tagging;
var annosvc = PlacesUtils.annotations;
@ -419,84 +418,6 @@ function run_test() {
do_check_eq(observer._itemChangedProperty, "keyword");
do_check_eq(observer._itemChangedValue, "");
// Testing create livemark
var txn12 = ptSvc.createLivemark(uri("http://feeduri.com"),
uri("http://siteuri.com"),
"Livemark1", root);
txn12.doTransaction();
var lvmkId = observer._itemAddedId;
do_check_true(lmsvc.isLivemark(lvmkId));
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://siteuri.com/");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://feeduri.com/");
txn12.undoTransaction();
do_check_false(lmsvc.isLivemark(lvmkId));
txn12.redoTransaction();
lvmkId = observer._itemAddedId;
do_check_true(lmsvc.isLivemark(lvmkId));
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://siteuri.com/");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://feeduri.com/");
// editLivemarkSiteURI
var txn13 = ptSvc.editLivemarkSiteURI(lvmkId, uri("http://new-siteuri.com/"));
txn13.doTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/siteURI");
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://new-siteuri.com/");
txn13.undoTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/siteURI");
do_check_eq(observer._itemChangedValue, "");
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://siteuri.com/");
txn13.redoTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/siteURI");
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://new-siteuri.com/");
txn13.undoTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/siteURI");
do_check_eq(observer._itemChangedValue, "");
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://siteuri.com/");
// editLivemarkFeedURI
var txn14 = ptSvc.editLivemarkFeedURI(lvmkId, uri("http://new-feeduri.com/"));
txn14.doTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/feedURI");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://new-feeduri.com/");
txn14.undoTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/feedURI");
do_check_eq(observer._itemChangedValue, "");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://feeduri.com/");
txn14.redoTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/feedURI");
do_check_eq(observer._itemChangedValue, "");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://new-feeduri.com/");
txn14.undoTransaction();
do_check_eq(observer._itemChangedId, lvmkId);
do_check_eq(observer._itemChangedProperty, "livemark/feedURI");
do_check_eq(observer._itemChangedValue, "");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://feeduri.com/");
// Testing remove livemark
// Set an annotation and check that we don't lose it on undo
annosvc.setItemAnnotation(lvmkId, "livemark/testAnno", "testAnno",
0, annosvc.EXPIRE_NEVER);
var txn15 = ptSvc.removeItem(lvmkId);
txn15.doTransaction();
do_check_false(lmsvc.isLivemark(lvmkId));
do_check_eq(observer._itemRemovedId, lvmkId);
txn15.undoTransaction();
lvmkId = observer._itemAddedId;
do_check_true(lmsvc.isLivemark(lvmkId));
do_check_eq(lmsvc.getSiteURI(lvmkId).spec, "http://siteuri.com/");
do_check_eq(lmsvc.getFeedURI(lvmkId).spec, "http://feeduri.com/");
do_check_eq(annosvc.getItemAnnotation(lvmkId, "livemark/testAnno"), "testAnno");
txn15.redoTransaction();
do_check_false(lmsvc.isLivemark(lvmkId));
do_check_eq(observer._itemRemovedId, lvmkId);
// Test LoadInSidebar transaction.
var txn16 = ptSvc.setLoadInSidebar(bkmk1Id, true);
txn16.doTransaction();

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

@ -41,47 +41,65 @@
* This test will ensure any transactions service that is going to create
* a new item, won't replace the GUID when undoing and redoing the action.
*/
var bmsvc = PlacesUtils.bookmarks;
var txnsvc = PlacesUIUtils.ptm;
function test_GUID_persistance(aTxn) {
aTxn.doTransaction();
var itemId = bmsvc.getIdForItemAt(bmsvc.unfiledBookmarksFolder, 0);
var GUID = bmsvc.getItemGUID(itemId);
aTxn.undoTransaction();
aTxn.redoTransaction();
do_check_eq(GUID, bmsvc.getItemGUID(itemId));
aTxn.undoTransaction();
waitForAsyncUpdates(function () {
let itemId = PlacesUtils.bookmarks
.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
let GUID = PlacesUtils.bookmarks.getItemGUID(itemId);
aTxn.undoTransaction();
aTxn.redoTransaction();
waitForAsyncUpdates(function() {
let itemId = PlacesUtils.bookmarks
.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0);
do_check_eq(GUID, PlacesUtils.bookmarks.getItemGUID(itemId));
aTxn.undoTransaction();
waitForAsyncUpdates(run_next_test);
});
});
}
function run_test() {
// Create folder.
var createFolderTxn = txnsvc.createFolder("Test folder",
bmsvc.unfiledBookmarksFolder,
bmsvc.DEFAULT_INDEX);
test_GUID_persistance(createFolderTxn);
// Create bookmark.
var createBookmarkTxn = txnsvc.createItem(uri("http://www.example.com"),
bmsvc.unfiledBookmarksFolder,
bmsvc.DEFAULT_INDEX,
"Test bookmark");
test_GUID_persistance(createBookmarkTxn);
// Create separator.
var createSeparatorTxn = txnsvc.createSeparator(bmsvc.unfiledBookmarksFolder,
bmsvc.DEFAULT_INDEX);
test_GUID_persistance(createFolderTxn);
// Create livemark.
var createLivemarkTxn = txnsvc.createLivemark(uri("http://feeduri.com"),
uri("http://siteuri.com"),
"Test livemark",
bmsvc.unfiledBookmarksFolder,
bmsvc.DEFAULT_INDEX);
test_GUID_persistance(createLivemarkTxn);
// Tag URI.
var tagURITxn = txnsvc.tagURI(uri("http://www.example.com"), ["foo"]);
test_GUID_persistance(tagURITxn);
run_next_test();
}
add_test(function create_folder() {
let createFolderTxn = new PlacesCreateFolderTransaction(
"Test folder", PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX
);
test_GUID_persistance(createFolderTxn);
});
add_test(function create_bookmark() {
let createBookmarkTxn = new PlacesCreateBookmarkTransaction(
NetUtil.newURI("http://www.example.com"), PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX, "Test bookmark"
);
test_GUID_persistance(createBookmarkTxn);
});
add_test(function create_separator() {
let createSeparatorTxn = new PlacesCreateSeparatorTransaction(
PlacesUtils.unfiledBookmarksFolderId, PlacesUtils.bookmarks.DEFAULT_INDEX
);
test_GUID_persistance(createSeparatorTxn);
});
add_test(function tag_uri() {
let tagURITxn = new PlacesTagURITransaction(
NetUtil.newURI("http://www.example.com"), ["foo"]
);
test_GUID_persistance(tagURITxn);
});
add_test(function create_livemark() {
let createLivemarkTxn = new PlacesCreateLivemarkTransaction(
NetUtil.newURI("http://feeduri.com"), NetUtil.newURI("http://siteuri.com"),
"Test livemark", PlacesUtils.unfiledBookmarksFolderId,
PlacesUtils.bookmarks.DEFAULT_INDEX
);
test_GUID_persistance(createLivemarkTxn);
});

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

@ -187,77 +187,12 @@ var iosvc = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
// Some date not too long ago
let gDate = new Date(Date.now() - 1000 * 60 * 60) * 1000;
// Store the page info for each uri
let gPages = [];
/**
* Adds a livemark container with a single child, and creates various properties
* for it depending on the parameters passed in.
*
* @param aContainerSiteURI
* An index into kURIs that holds the string for the URI of site of the
* livemark container we are to add.
* @param aContainerFeedURI
* An index into kURIs that holds the string for the URI of feed of the
* livemark container we are to add.
* @param aContainerTitle
* An index into kTitles that holds the string for the title we are to
* associate with the livemark container.
* @param aChildURI
* An index into kURIs that holds the string for the URI of single
* livemark child we are to add.
* @param aChildTitle
* An index into kTitles that holds the string for the title we are to
* associate with the single livemark child.
* @param aTransitionType [optional]
* The transition type to use when adding the visit. The default is
* nsINavHistoryService::TRANSITION_LINK.
* @param aNoChildVisit [optional]
* If true, no visit is added for the child's URI. If false or
* undefined, a visit is added.
*/
function addLivemark(aContainerSiteURI, aContainerFeedURI, aContainerTitle,
aChildURI, aChildTitle, aTransitionType, aNoChildVisit)
{
// Add a page entry for the child uri
gPages[aChildURI] = [aChildURI, aChildTitle, null];
let out = [aChildURI, aChildTitle];
out.push("\nchild uri=" + kURIs[aChildURI]);
out.push("\nchild title=" + kTitles[aChildTitle]);
// Create the container
let containerSiteURI = toURI(kURIs[aContainerSiteURI]);
let containerFeedURI = toURI(kURIs[aContainerFeedURI]);
let containerTitle = kTitles[aContainerTitle];
let containerId = lmsvc.createLivemarkFolderOnly(bmsvc.unfiledBookmarksFolder,
containerTitle,
containerSiteURI,
containerFeedURI,
bmsvc.DEFAULT_INDEX);
// Insert the child
let childURI = toURI(kURIs[aChildURI]);
let childTitle = kTitles[aChildTitle];
bmsvc.insertBookmark(containerId, childURI, bmsvc.DEFAULT_INDEX, childTitle);
// Add a visit to the child if we need to
if (!aNoChildVisit) {
let tt = aTransitionType || TRANSITION_LINK;
let isRedirect = tt == TRANSITION_REDIRECT_PERMANENT ||
tt == TRANSITION_REDIRECT_TEMPORARY;
histsvc.addVisit(childURI, gDate, null, tt, isRedirect, 0);
out.push("\nwith visit");
}
print("\nAdding livemark: " + out.join(", "));
}
/**
* Adds a page, and creates various properties for it depending on the
* parameters passed in. This function will also add one visit, unless

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

@ -1,109 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
vim:set ts=2 sw=2 sts=2 et:
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Places Test code.
*
* The Initial Developer of the Original Code is the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Drew Willcoxon <adw@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* Bug 479082
* https://bugzilla.mozilla.org/show_bug.cgi?id=479082
*
* Ensures that unvisited livemarks that are not bookmarked elsewhere do not
* show up in AutoComplete results. Also does some related checking that
* visited and/or separately bookmarked livemarks *do* show up.
*/
let kURIs = [
"http://example.com/",
"http://example.com/container",
// URIs that themselves should match our searches
"http://example.com/unvisited-not-bookmarked-elsewhere/vy-__--D",
"http://example.com/visited-not-bookmarked-elsewhere/_0YlX-9L",
"http://example.com/unvisited-bookmarked-elsewhere/X132H20w",
"http://example.com/visited-bookmarked-elsewhere/n_6D_Pw5",
// URIs whose titles should match our searches
"http://example.com/unvisited-not-bookmarked-elsewhere",
"http://example.com/visited-not-bookmarked-elsewhere",
"http://example.com/unvisited-bookmarked-elsewhere",
"http://example.com/visited-bookmarked-elsewhere",
];
let kTitles = [
"container title",
// titles for URIs that should match our searches
"unvisited not-bookmarked-elsewhere child title",
"visited not-bookmarked-elsewhere child title",
"unvisited bookmarked-elsewhere child title",
"visited bookmarked-elsewhere child title",
// titles that themselves should match our searches
"unvisited not-bookmarked-elsewhere child title P-13U-z-",
"visited not-bookmarked-elsewhere child title _3-X4_Qd",
"unvisited bookmarked-elsewhere child title I4jOt6o4",
"visited bookmarked-elsewhere child title 9-RVT4D5",
];
// our searches will match URIs on these livemarks
addLivemark(0, 1, 0, 2, 1, null, true);
addLivemark(0, 1, 0, 3, 2, null, false);
addLivemark(0, 1, 0, 4, 3, null, true);
addPageBook(4, 3, 3, null, null, null, true);
addLivemark(0, 1, 0, 5, 4, null, false);
// we'll match titles on these livemarks
addLivemark(0, 1, 0, 6, 5, null, true);
addLivemark(0, 1, 0, 7, 6, null, false);
addLivemark(0, 1, 0, 8, 7, null, true);
addPageBook(8, 7, 7, null, null, null, true);
addLivemark(0, 1, 0, 9, 8, null, false);
let gTests = [
// URIs should match these searches
["0: unvisited not-bookmarked-elsewhere livemark child (should be empty)",
"vy-__--D", []],
["1: visited not-bookmarked-elsewhere livemark child (should not be empty)",
"_0YlX-9L", [3]],
["2: unvisited bookmarked-elsewhere livemark child (should not be empty)",
"X132H20w", [4]],
["3: visited bookmarked-elsewhere livemark child (should not be empty)",
"n_6D_Pw5", [5]],
// titles should match these
["4: unvisited not-bookmarked-elsewhere livemark child (should be empty)",
"P-13U-z-", []],
["5: visited not-bookmarked-elsewhere livemark child (should not be empty)",
"_3-X4_Qd", [7]],
["6: unvisited bookmarked-elsewhere livemark child (should not be empty)",
"I4jOt6o4", [8]],
["7: visited bookmarked-elsewhere livemark child (should not be empty)",
"9-RVT4D5", [9]],
];

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

@ -20,7 +20,6 @@ fail-if = os == "android"
[test_escape_self.js]
[test_ignore_protocol.js]
[test_keyword_search.js]
[test_livemarks.js]
[test_match_beginning.js]
[test_multi_word_search.js]
[test_special_search.js]

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

@ -37,58 +37,45 @@
*
* ***** END LICENSE BLOCK ***** */
// Get livemark service
try {
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
} catch(ex) {
do_throw("Could not get livemark-service\n");
}
// This tests the deprecated livemarks interface.
// Get bookmark service
try {
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
} catch(ex) {
do_throw("Could not get nav-bookmarks-service\n");
}
function run_test()
{
let livemarkId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.bookmarksMenuFolderId, "foo", uri("http://example.com/"),
uri("http://example.com/rss.xml"), PlacesUtils.bookmarks.DEFAULT_INDEX
);
// get bookmarks root index
var root = bmsvc.bookmarksMenuFolder;
// main
function run_test() {
var livemarkId =
lmsvc.createLivemarkFolderOnly(root, "foo",
uri("http://example.com/"),
uri("http://example.com/rss.xml"), -1);
do_check_true(lmsvc.isLivemark(livemarkId));
do_check_true(lmsvc.getSiteURI(livemarkId).spec == "http://example.com/");
do_check_true(lmsvc.getFeedURI(livemarkId).spec == "http://example.com/rss.xml");
do_check_true(bmsvc.getFolderReadonly(livemarkId));
lmsvc.setSiteURI(livemarkId, uri("http://foo.example.com/"));
do_check_true(lmsvc.getSiteURI(livemarkId).spec == "http://foo.example.com/");
lmsvc.setFeedURI(livemarkId, uri("http://foo.example.com/rss.xml"));
do_check_true(lmsvc.getFeedURI(livemarkId).spec == "http://foo.example.com/rss.xml");
do_check_true(PlacesUtils.livemarks.isLivemark(livemarkId));
do_check_eq(PlacesUtils.livemarks.getSiteURI(livemarkId).spec, "http://example.com/");
do_check_eq(PlacesUtils.livemarks.getFeedURI(livemarkId).spec, "http://example.com/rss.xml");
do_check_true(PlacesUtils.bookmarks.getFolderReadonly(livemarkId));
// Make sure we can't add a livemark to a livemark
var livemarkId2 = null;
let livemarkId2 = null;
try {
var livemarkId2 = lmsvc.createLivemark(livemarkId, "foo", uri("http://example.com/"),
uri("http://example.com/rss.xml"), -1);
let livemarkId2 = PlacesUtils.livemarks.createLivemark(
livemarkId, "foo", uri("http://example.com/"),
uri("http://example.com/rss.xml"), PlacesUtils.bookmarks.DEFAULT_INDEX
);
} catch (ex) {
livemarkId2 = null;
}
do_check_true(livemarkId2 == null);
// make sure it didn't screw up the first one
do_check_true(lmsvc.isLivemark(livemarkId));
do_check_true(PlacesUtils.livemarks.isLivemark(livemarkId));
do_check_eq(
PlacesUtils.livemarks.getLivemarkIdForFeedURI(uri("http://example.com/rss.xml")),
livemarkId
);
// make sure folders don't get counted as bookmarks
// create folder
var randomFolder = bmsvc.createFolder(root, "Random", -1);
do_check_true(!lmsvc.isLivemark(randomFolder));
let randomFolder = PlacesUtils.bookmarks.createFolder(
PlacesUtils.bookmarksMenuFolderId, "Random",
PlacesUtils.bookmarks.DEFAULT_INDEX
);
do_check_true(!PlacesUtils.livemarks.isLivemark(randomFolder));
}

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

@ -54,10 +54,10 @@ _HTTP_FILES = \
$(NULL)
_CHROME_FILES = \
test_329534.xul \
test_371798.xul \
test_342484.xul \
test_341972a.xul \
test_341972b.xul \
test_favicon_annotations.xul \
test_303567.xul \
test_381357.xul \

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

@ -4,7 +4,8 @@
href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Add Bad Livemarks"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTest()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
@ -12,10 +13,10 @@
<script type="application/javascript">
<![CDATA[
// Test that for feeds with items that have no link:
// * the link-less items are present in the database.
// * the feed's site URI is substituted for each item's link.
// Test that for feeds with items that have no link:
// * the link-less items are present in the database.
// * the feed's site URI is substituted for each item's link.
SimpleTest.waitForExplicitFinish();
const Cc = Components.classes;
const Ci = Components.interfaces;
@ -25,7 +26,6 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
// Create livemarks.
const LIVEMARKS = [
{ feedURI: NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/link-less-items.rss"),
siteURI: NetUtil.newURI("http://mochi.test:8888/"),
@ -48,72 +48,75 @@ const LIVEMARKS = [
function runTest()
{
SimpleTest.waitForExplicitFinish();
function testLivemark(aLivemarkData) {
PlacesUtils.livemarks.addLivemark(
{ title: "foo"
, parentId: PlacesUtils.toolbarFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: aLivemarkData.feedURI
, siteURI: aLivemarkData.siteURI
},
function (aStatus, aLivemark) {
ok(Components.isSuccessCode(aStatus), "Get livemark");
// Add bookmarks observer.
let observer = {
QueryInterface: XPCOMUtils.generateQI([
Ci.nsINavBookmarkObserver,
]),
is (aLivemark.feedURI.spec, aLivemarkData.feedURI.spec,
"Get correct feedURI");
if (aLivemarkData.siteURI) {
is (aLivemark.siteURI.spec, aLivemarkData.siteURI.spec,
"Get correct siteURI");
}
else {
is (aLivemark.siteURI, null, "Get correct siteURI");
}
onBeginUpdateBatch: function () {},
onEndUpdateBatch: function () {},
onItemAdded: function (aItemId, aParentId, aIndex, aItemType) {
// Wait for the addition of all children in the expected livemark.
if (PlacesUtils.livemarks.isLivemark(aParentId) &&
this.expectedFeedURI &&
PlacesUtils.livemarks.getFeedURI(aParentId).equals(this.expectedFeedURI) &&
--this.expectedChildren == 0) {
setTimeout(function () step(), 0);
waitForLivemarkLoad(aLivemark, function (aLivemark) {
let nodes = aLivemark.getNodesForContainer({});
is(nodes.length, aLivemarkData.urls.length,
"Ensure all the livemark items were created.");
aLivemarkData.urls.forEach(function (aUrl, aIndex) {
let node = nodes[aIndex];
is(node.uri, aUrl, aLivemarkData.message);
});
PlacesUtils.bookmarks.removeItem(aLivemark.id);
if (aLivemark.feedURI.equals(LIVEMARKS[LIVEMARKS.length - 1].feedURI)) {
SimpleTest.finish();
}
});
}
},
onBeforeItemRemoved: function () {},
onItemRemoved: function () {},
onItemChanged: function () {},
onItemVisited: function () {},
onItemMoved: function () {},
};
PlacesUtils.bookmarks.addObserver(observer, false);
for (let i = 0; i < LIVEMARKS.length; i++) {
let livemark = LIVEMARKS[i];
observer.expectedFeedURI = livemark.feedURI;
observer.expectedChildren = livemark.urls.length;
livemark.id = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.toolbarFolderId, "foo", livemark.siteURI, livemark.feedURI,
PlacesUtils.bookmarks.DEFAULT_INDEX
);
PlacesUtils.livemarks.reloadLivemarkFolder(livemark.id);
yield;
// Validate livemark's contents.
let root = PlacesUtils.getFolderContents(livemark.id).root;
let cc = root.childCount;
is(cc, livemark.urls.length, "Eensure the livemark item was created.");
livemark.urls.forEach(function (aUrl, aIndex) {
let node = root.getChild(aIndex);
is(node.uri, aUrl, livemark.message);
});
root.containerOpen = false;
PlacesUtils.bookmarks.removeItem(livemark.id);
)
}
PlacesUtils.bookmarks.removeObserver(observer);
SimpleTest.finish();
LIVEMARKS.forEach(testLivemark);
}
let gTestRunner = runTest();
function step()
{
try {
gTestRunner.next();
} catch (ex) {}
function waitForLivemarkLoad(aLivemark, aCallback) {
// Don't need a real node here.
let node = {};
let resultObserver = {
nodeInserted: function() {},
nodeRemoved: function() {},
nodeAnnotationChanged: function() {},
nodeTitleChanged: function() {},
nodeHistoryDetailsChanged: function() {},
nodeReplaced: function() {},
nodeMoved: function() {},
ontainerStateChanged: function () {},
sortingChanged: function() {},
batching: function() {},
invalidateContainer: function(node) {
isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
"Loading livemark should success");
if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
aLivemark.unregisterForUpdates(node, resultObserver);
aCallback(aLivemark);
}
}
};
aLivemark.registerForUpdates(node, resultObserver);
aLivemark.reload();
}
// Kick-off test.
step();
]]>
</script>

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

@ -1,174 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet
href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Distribute to loading Livemark"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml" />
<script type="application/javascript">
<![CDATA[
/*
Test distribute the load of livemark update
*/
SimpleTest.waitForExplicitFinish();
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
function uri(spec) {
return iosvc.newURI(spec, null, null);
}
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var toolbarFolderId = bmsvc.toolbarFolder;
var status = 0;
var secondFolderId = 0;
var firstLoadTime = 0;
var firstURL = "";
var secondURL = "";
// stop updating livemarks
lmsvc.stopUpdateLivemarks();
// add 2 feeds
const FEED1 = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/rss_as_html.rss";
gLivemarkId1 = lmsvc.createLivemarkFolderOnly( toolbarFolderId, "foo",
uri("http:/mochi.test:8888/"),
uri(FEED1), -1);
const FEED2 = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom";
gLivemarkId2 = lmsvc.createLivemarkFolderOnly( toolbarFolderId, "bar",
uri("http:/mochi.test:8888/"),
uri(FEED2), -1);
var observer =
{
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavBookmarkObserver) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsINavBookmarkObserver
onBeginUpdateBatch: function(){},
onEndUpdateBatch: function(){},
onItemAdded: function(bookmarkId, folderId, index, itemType, uri) {
if ( status == 0 ) {
runTest1( folderId );
} else {
runTest2( folderId );
if ( status == 2 ) {
bmsvc.removeObserver(this);
bmsvc.removeItem(gLivemarkId1);
bmsvc.removeItem(gLivemarkId2);
SimpleTest.finish();
}
}
},
onBeforeItemRemoved: function(){},
onItemRemoved: function() {},
onItemChanged: function() {},
onItemVisited: function() {},
onItemMoved: function() {}
};
bmsvc.addObserver(observer, false);
// start updating livemarks
firstLoadTime = Date.now();
lmsvc.reloadAllLivemarks();
// First
function runTest1( folderId ) {
if ( folderId == gLivemarkId1 ) {
secondFolderId = gLivemarkId2;
firstURL = "http://www.example.com/index.html";
secondURL = "http://example.org/2003/12/13/atom03";
} else if ( folderId == gLivemarkId2 ) {
secondFolderId = gLivemarkId1;
firstURL = "http://example.org/2003/12/13/atom03";
secondURL = "http://www.example.com/index.html";
}
if ( secondFolderId != 0 ) {
status++;
/* first folder is loading now */
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
query.setFolders([folderId], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
ok( cc == 1, "first livemark is empty" );
var node = rootNode.getChild( 0 );
ok( node.uri == firstURL,
"first livemark item is invalid value "+node.uri);
rootNode.containerOpen = false;
/* second folder has no item */
options = histsvc.getNewQueryOptions();
query = histsvc.getNewQuery();
query.setFolders([secondFolderId], 1);
result = histsvc.executeQuery(query, options);
rootNode = result.root;
rootNode.containerOpen = true;
cc = rootNode.childCount;
ok( cc == 0, "second livemark is not empty" );
rootNode.containerOpen = false;
}
}
// Second
function runTest2( folderId ) {
if ( folderId == secondFolderId ) {
status++;
var secondLoadTime = Date.now();
/* second folder is loading now */
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
query.setFolders([folderId], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
ok( cc == 1, "second livemark is empty" );
var node = rootNode.getChild( 0 );
ok( node.uri == secondURL,
"second livemark item is invalid value "+node.uri);
rootNode.containerOpen = false;
/* Check passed 2sec.
We should check for 3s but are relaxing request to accomplish possible
VM timing bugs.
For the same reason if time elapsed is 0 we have catched an interval
where VM has not updated timers, we will still consider the test valid
to avoid random test failures.
*/
t = parseInt( (secondLoadTime - firstLoadTime) / 1000 );
if (t > 0)
ok( t >= 2, "not passed 2sec when second livemark loading" );
}
}
]]>
</script>
</window>

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

@ -4,7 +4,8 @@
href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Update Livemark SiteURI"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTest()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
@ -21,58 +22,64 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
function uri(spec) {
return iosvc.newURI(spec, null, null);
function runTest() {
const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom";
const INITIALSITESPEC = "http://mochi.test:8888/";
const FEEDSITESPEC = "http://example.org/";
PlacesUtils.livemarks.addLivemark(
{ title: "foo"
, parentId: PlacesUtils.toolbarFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: NetUtil.newURI(FEEDSPEC)
, siteURI: NetUtil.newURI(INITIALSITESPEC)
},
function (aStatus, aLivemark) {
ok(Components.isSuccessCode(aStatus), "Get livemark");
is(aLivemark.siteURI.spec, INITIALSITESPEC,
"Has correct initial livemark site URI");
waitForLivemarkLoad(aLivemark, function (aLivemark) {
is(aLivemark.siteURI.spec, FEEDSITESPEC,
"livemark site URI set to value in feed");
PlacesUtils.bookmarks.removeItem(aLivemark.id);
SimpleTest.finish();
});
}
);
}
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var toolbarFolderId = bmsvc.toolbarFolder;
var observer =
{
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIAnnotationObserver) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsIAnnotationObserver
onItemAnnotationSet: function(aItemId, aAnnotationName) {
if (aAnnotationName == "livemark/siteURI" &&
aItemId == gLivemarkId) {
var newSiteURI = annosvc.getItemAnnotation(aItemId, aAnnotationName);
ok(newSiteURI == FEEDSITESPEC,
"livemark site URI changed to " + newSiteURI + " not to value in feed");
annosvc.removeObserver(this);
bmsvc.removeItem(gLivemarkId);
SimpleTest.finish();
function waitForLivemarkLoad(aLivemark, aCallback) {
// Don't need a real node here.
let node = {};
let resultObserver = {
nodeInserted: function() {},
nodeRemoved: function() {},
nodeAnnotationChanged: function() {},
nodeTitleChanged: function() {},
nodeHistoryDetailsChanged: function() {},
nodeReplaced: function() {},
nodeMoved: function() {},
ontainerStateChanged: function () {},
sortingChanged: function() {},
batching: function() {},
invalidateContainer: function(node) {
isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
"Loading livemark should success");
if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
aLivemark.unregisterForUpdates(node, resultObserver);
aCallback(aLivemark);
}
}
},
onItemAnnotationRemoved: function(aItemId, aAnnotationName) {},
onPageAnnotationSet: function(aUri, aAnnotationName) {},
onPageAnnotationRemoved: function(aUri, aAnnotationName) {}
};
const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom";
const INITIALSITESPEC = "http://mochi.test:8888/";
const FEEDSITESPEC = "http://example.org/";
gLivemarkId = lmsvc.createLivemarkFolderOnly(toolbarFolderId, "foo",
uri(INITIALSITESPEC),
uri(FEEDSPEC), -1);
annosvc.addObserver(observer, false);
lmsvc.reloadLivemarkFolder(gLivemarkId);
};
aLivemark.registerForUpdates(node, resultObserver);
aLivemark.reload();
}
]]>
</script>

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

@ -4,7 +4,8 @@
href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Update Livemark SiteURI, null to start"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTest()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
@ -14,7 +15,6 @@
<![CDATA[
/*
Test updating livemark siteURI to the value from the feed, when it's null
to start
*/
SimpleTest.waitForExplicitFinish();
@ -22,55 +22,61 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
function uri(spec) {
return iosvc.newURI(spec, null, null);
function runTest() {
const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom";
const FEEDSITESPEC = "http://example.org/";
PlacesUtils.livemarks.addLivemark(
{ title: "foo"
, parentId: PlacesUtils.toolbarFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: NetUtil.newURI(FEEDSPEC)
},
function (aStatus, aLivemark) {
ok(Components.isSuccessCode(aStatus), "Get livemark");
is(aLivemark.siteURI, null, "Has null livemark site URI");
waitForLivemarkLoad(aLivemark, function (aLivemark) {
is(aLivemark.siteURI.spec, FEEDSITESPEC,
"livemark site URI set to value in feed");
PlacesUtils.bookmarks.removeItem(aLivemark.id);
SimpleTest.finish();
});
}
);
}
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].
getService(Ci.nsIAnnotationService);
var toolbarFolderId = bmsvc.toolbarFolder;
var observer =
{
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIAnnotationObserver) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsIAnnotationObserver
onItemAnnotationSet: function(aItemId, aAnnotationName) {
if (aAnnotationName == "livemark/siteURI") {
var newSiteURI = annosvc.getItemAnnotation(aItemId, aAnnotationName);
ok(newSiteURI == FEEDSITESPEC,
"livemark site URI not set to value in feed");
annosvc.removeObserver(this);
bmsvc.removeFolder(gLivemarkId);
SimpleTest.finish();
function waitForLivemarkLoad(aLivemark, aCallback) {
// Don't need a real node here.
let node = {};
let resultObserver = {
nodeInserted: function() {},
nodeRemoved: function() {},
nodeAnnotationChanged: function() {},
nodeTitleChanged: function() {},
nodeHistoryDetailsChanged: function() {},
nodeReplaced: function() {},
nodeMoved: function() {},
ontainerStateChanged: function () {},
sortingChanged: function() {},
batching: function() {},
invalidateContainer: function(node) {
isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
"Loading livemark should success");
if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
aLivemark.unregisterForUpdates(node, resultObserver);
aCallback(aLivemark);
}
}
},
onItemAnnotationRemoved: function(aItemId, aAnnotationName) {},
onPageAnnotationSet: function(aUri, aAnnotationName) {},
onPageAnnotationRemoved: function(aUri, aAnnotationName) {}
};
const FEEDSPEC = "http://localhost:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom";
const FEEDSITESPEC = "http://example.org/";
gLivemarkId = lmsvc.createLivemarkFolderOnly(toolbarFolderId, "foo",
null, uri(FEEDSPEC), -1);
annosvc.addObserver(observer, false);
lmsvc.reloadLivemarkFolder(gLivemarkId);
};
aLivemark.registerForUpdates(node, resultObserver);
aLivemark.reload();
}
]]>
</script>

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

@ -26,61 +26,61 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
let gLivemarkId = -1;
function runTest() {
const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/bad_links.atom";
let bookmarksObserver = {
QueryInterface: XPCOMUtils.generateQI([
Ci.nsINavBookmarkObserver
]),
onItemAdded: function (aItemId, aParentId, aIndex, aItemType, aURI) {
if (aURI.spec == "http://example.org/last")
this._updateFinished = true;
},
onEndUpdateBatch: function () {
if (this._updateFinished) {
PlacesUtils.bookmarks.removeObserver(this);
setTimeout(continueTest, 0);
}
},
onBeginUpdateBatch: function () {},
onBeforeItemRemoved: function () {},
onItemRemoved: function () {},
onItemChanged: function () {},
onItemVisited: function () {},
onItemMoved: function () {},
};
gLivemarkId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.toolbarFolderId, "foo", NetUtil.newURI("http://mochi.test/"),
NetUtil.newURI(FEEDSPEC), PlacesUtils.bookmarks.DEFAULT_INDEX
);
PlacesUtils.bookmarks.addObserver(bookmarksObserver, false);
PlacesUtils.livemarks.reloadLivemarkFolder(gLivemarkId);
}
function continueTest() {
const GOOD_URLS = ["http://example.org/first", "http://example.org/last"];
let options = PlacesUtils.history.getNewQueryOptions();
let query = PlacesUtils.history.getNewQuery();
query.setFolders([gLivemarkId], 1);
let root = PlacesUtils.history.executeQuery(query, options).root;
root.containerOpen = true;
PlacesUtils.livemarks.addLivemark(
{ title: "foo"
, parentId: PlacesUtils.toolbarFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: NetUtil.newURI(FEEDSPEC)
, siteURI: NetUtil.newURI("http:/mochi.test/")
},
function (aStatus, aLivemark) {
ok(Components.isSuccessCode(aStatus), "Get livemark");
let cc = root.childCount;
is(cc, 2, "failed to create the two good livemark items");
for (let i = 0; i < cc; ++i) {
let node = root.getChild(i);
ok(GOOD_URLS.indexOf(node.uri) != -1, "livemark item created with bad uri " + node.uri);
}
waitForLivemarkLoad(aLivemark, function (aLivemark) {
let nodes = aLivemark.getNodesForContainer({});
root.containerOpen = false;
PlacesUtils.bookmarks.removeItem(gLivemarkId);
SimpleTest.finish();
is(nodes.length, 2, "Created the two good livemark items");
for (let i = 0; i < nodes.length; ++i) {
let node = nodes[i];
ok(GOOD_URLS.indexOf(node.uri) != -1, "livemark item created with bad uri " + node.uri);
}
PlacesUtils.bookmarks.removeItem(aLivemark.id);
SimpleTest.finish();
});
}
);
}
function waitForLivemarkLoad(aLivemark, aCallback) {
// Don't need a real node here.
let node = {};
let resultObserver = {
nodeInserted: function() {},
nodeRemoved: function() {},
nodeAnnotationChanged: function() {},
nodeTitleChanged: function() {},
nodeHistoryDetailsChanged: function() {},
nodeReplaced: function() {},
nodeMoved: function() {},
ontainerStateChanged: function () {},
sortingChanged: function() {},
batching: function() {},
invalidateContainer: function(node) {
isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
"Loading livemark should success");
if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
aLivemark.unregisterForUpdates(node, resultObserver);
aCallback(aLivemark);
}
}
};
aLivemark.registerForUpdates(node, resultObserver);
aLivemark.reload();
}
]]>

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

@ -4,7 +4,8 @@
href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<window title="Add Livemarks from RSS feed served as text/html"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTest()">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
@ -21,56 +22,64 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
function uri(spec) {
return iosvc.newURI(spec, null, null);
function runTest() {
const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/rss_as_html.rss";
PlacesUtils.livemarks.addLivemark(
{ title: "foo"
, parentId: PlacesUtils.toolbarFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, feedURI: NetUtil.newURI(FEEDSPEC)
, siteURI: NetUtil.newURI("http:/mochi.test/")
},
function (aStatus, aLivemark) {
ok(Components.isSuccessCode(aStatus), "Get livemark");
waitForLivemarkLoad(aLivemark, function (aLivemark) {
let nodes = aLivemark.getNodesForContainer({});
ok(Components.isSuccessCode(aStatus), "Get livemark entries");
is(nodes[0].title, "The First Title",
"livemark site URI set to value in feed");
PlacesUtils.bookmarks.removeItem(aLivemark.id);
SimpleTest.finish();
});
}
);
}
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var toolbarFolderId = bmsvc.toolbarFolder;
var observer =
{
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavBookmarkObserver) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsINavBookmarkObserve
onBeginUpdateBatch: function(){},
onEndUpdateBatch: function(){
},
onItemAdded: function(itemId, folder, index, itemType, uri, title) {
if (title == "The First Title") {
ok(true, "Item with title loaded");
bmsvc.removeObserver(this);
SimpleTest.finish();
function waitForLivemarkLoad(aLivemark, aCallback) {
// Don't need a real node here.
let node = {};
let resultObserver = {
nodeInserted: function() {},
nodeRemoved: function() {},
nodeAnnotationChanged: function() {},
nodeTitleChanged: function() {},
nodeHistoryDetailsChanged: function() {},
nodeReplaced: function() {},
nodeMoved: function() {},
ontainerStateChanged: function () {},
sortingChanged: function() {},
batching: function() {},
invalidateContainer: function(node) {
isnot(aLivemark.status, Ci.mozILivemark.STATUS_FAILED,
"Loading livemark should success");
if (aLivemark.status == Ci.mozILivemark.STATUS_READY) {
aLivemark.unregisterForUpdates(node, resultObserver);
aCallback(aLivemark);
}
}
},
onBeforeItemRemoved: function(){},
onItemRemoved: function(){},
onItemChanged: function(){},
onItemVisited: function(){},
onItemMoved: function(){},
};
aLivemark.registerForUpdates(node, resultObserver);
aLivemark.reload();
}
};
const FEEDSPEC = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/rss_as_html.rss";
gLivemarkId = lmsvc.createLivemarkFolderOnly(toolbarFolderId, "foo",
uri("http:/mochi.test/"),
uri(FEEDSPEC), -1);
bmsvc.addObserver(observer, false);
lmsvc.reloadLivemarkFolder(gLivemarkId);
]]>
</script>

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

@ -35,7 +35,7 @@
*
* ***** END LICENSE BLOCK ***** */
const CURRENT_SCHEMA_VERSION = 18;
const CURRENT_SCHEMA_VERSION = 19;
const NS_APP_USER_PROFILE_50_DIR = "ProfD";
const NS_APP_PROFILE_DIR_STARTUP = "ProfDS";
@ -74,11 +74,7 @@ XPCOMUtils.defineLazyGetter(this, "FileUtils", function() {
return FileUtils;
});
XPCOMUtils.defineLazyGetter(this, "PlacesUtils", function() {
Cu.import("resource://gre/modules/PlacesUtils.jsm");
return PlacesUtils;
});
Cu.import("resource://gre/modules/PlacesUtils.jsm");
function LOG(aMsg) {
aMsg = ("*** PLACES TESTS: " + aMsg);
@ -86,7 +82,6 @@ function LOG(aMsg) {
print(aMsg);
}
let gTestDir = do_get_cwd();
// Ensure history is enabled.

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

@ -200,11 +200,12 @@ function populateDB(aArray) {
}
if (qdata.isLivemark) {
PlacesUtils.livemarks.createLivemark(qdata.parentFolder,
qdata.title,
uri(qdata.uri),
uri(qdata.feedURI),
qdata.index);
PlacesUtils.livemarks.addLivemark({ title: qdata.title
, parentId: qdata.parentFolder
, index: qdata.index
, feedURI: uri(qdata.feedURI)
, siteURI: uri(qdata.uri)
});
}
if (qdata.isBookmark) {

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

@ -44,70 +44,6 @@
* https://bugzilla.mozilla.org/show_bug.cgi?id=412132
*/
add_test(function unvisited_bookmarked_livemarkItem()
{
do_log_info("Frecency of unvisited, separately bookmarked livemark item's " +
"URI should be zero after bookmark's URI changed.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0.");
do_check_neq(frecencyForUrl(TEST_URI), 0);
PlacesUtils.bookmarks.changeBookmarkURI(id, NetUtil.newURI("http://example.com/new-uri"));
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function visited_bookmarked_livemarkItem()
{
do_log_info("Frecency of visited, separately bookmarked livemark item's " +
"URI should not be zero after bookmark's URI changed.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(TEST_URI);
PlacesUtils.bookmarks.changeBookmarkURI(id, uri("http://example.com/new-uri"));
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function changeuri_unvisited_bookmark()
{
do_log_info("After changing URI of bookmark, frecency of bookmark's " +
@ -232,25 +168,6 @@ add_test(function changeuri_nonexistent_bookmark()
///////////////////////////////////////////////////////////////////////////////
/**
* Creates a livemark with a single child item.
*
* @param aChildURI
* the URI of the livemark's single child item
* @return the item ID of the single child item
*/
function createLivemark(aChildURI)
{
let livemarkId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.unfiledBookmarksFolderId, "livemark title",
uri("http://example.com/"), uri("http://example.com/rdf"), -1
);
return PlacesUtils.bookmarks.insertBookmark(livemarkId,
aChildURI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"livemark item title");
}
/**
* Adds a visit for aURI.
*

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

@ -13,12 +13,14 @@ function run_test()
{
if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
PlacesUtils.annotations.removeObserver(this);
do_check_true(PlacesUtils.livemarks.isLivemark(aItemId));
do_execute_soon(function () {
PlacesUtils.bookmarks.removeItem(aItemId);
do_check_false(PlacesUtils.livemarks.isLivemark(aItemId));
do_test_finished();
});
PlacesUtils.livemarks.getLivemark(
{ id: aItemId },
function (aStatus, aLivemark) {
do_check_true(Components.isSuccessCode(aStatus));
PlacesUtils.bookmarks.removeItem(aItemId);
do_test_finished();
}
);
}
},
@ -30,11 +32,12 @@ function run_test()
]),
}
PlacesUtils.annotations.addObserver(annoObserver, false);
PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.unfiledBookmarksFolderId,
"livemark title",
uri("http://example.com/"),
uri("http://example.com/rdf"),
PlacesUtils.bookmarks.DEFAULT_INDEX
PlacesUtils.livemarks.addLivemark(
{ title: "livemark title"
, parentId: PlacesUtils.unfiledBookmarksFolderId
, index: PlacesUtils.bookmarks.DEFAULT_INDEX
, siteURI: uri("http://example.com/")
, feedURI: uri("http://example.com/rdf")
}
);
}

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

@ -1,114 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Google Inc.
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Darin Fisher <darin@meer.net>
* Dietrich Ayala <dietrich@mozilla.com>
* Seth Spitzer <sspitzer@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Get livemark service
try {
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
} catch(ex) {
do_throw("Could not get livemark-service\n");
}
// Get bookmark service
try {
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
getService(Ci.nsINavBookmarksService);
} catch(ex) {
do_throw("Could not get nav-bookmarks-service\n");
}
// Get history service
try {
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
} catch(ex) {
do_throw("Could not get history service\n");
}
// get bookmarks root index
var root = bmsvc.bookmarksMenuFolder;
// main
function run_test() {
var livemarkId =
lmsvc.createLivemarkFolderOnly(root, "foo",
uri("http://example.com/"),
uri("http://example.com/rss.xml"), -1);
do_check_true(lmsvc.isLivemark(livemarkId));
do_check_true(lmsvc.getSiteURI(livemarkId).spec == "http://example.com/");
do_check_true(lmsvc.getFeedURI(livemarkId).spec == "http://example.com/rss.xml");
var livemarkItem = bmsvc.insertBookmark(livemarkId, uri("http://example.com/item1.html"), bmsvc.DEFAULT_INDEX, "item 1");
// create a folder
var parent = bmsvc.createFolder(root, "test", bmsvc.DEFAULT_INDEX);
// create a non livemark item under the folder
var nonLivemarkItem = bmsvc.insertBookmark(parent, uri("http://example.com/item2.html"), bmsvc.DEFAULT_INDEX, "item 2");
// don't exclude livemark items, search for "item", should get two results
var options = histsvc.getNewQueryOptions();
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
var query = histsvc.getNewQuery();
query.searchTerms = "item";
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
do_check_eq(cc, 2);
var node = rootNode.getChild(0);
do_check_eq(node.itemId, livemarkItem);
node = rootNode.getChild(1);
do_check_eq(node.itemId, nonLivemarkItem);
rootNode.containerOpen = false;
// exclude livemark items, search for "item", should get one result
options = histsvc.getNewQueryOptions();
options.excludeItemIfParentHasAnnotation = "livemark/feedURI";
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
query = histsvc.getNewQuery();
query.searchTerms = "item";
result = histsvc.executeQuery(query, options);
rootNode = result.root;
rootNode.containerOpen = true;
cc = rootNode.childCount;
do_check_eq(cc, 1);
var node = rootNode.getChild(0);
do_check_eq(node.itemId, nonLivemarkItem);
rootNode.containerOpen = false;
}

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

@ -39,28 +39,6 @@
let mDBConn = DBConn();
function add_fake_livemark() {
let lmId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.toolbarFolderId, "Livemark",
uri("http://www.mozilla.org/"), uri("http://www.mozilla.org/test.xml"),
PlacesUtils.bookmarks.DEFAULT_INDEX
);
// Add a visited child.
PlacesUtils.bookmarks.insertBookmark(lmId,
uri("http://visited.livemark.com/"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"visited");
PlacesUtils.history.addVisit(uri("http://visited.livemark.com/"),
Date.now(), null,
Ci.nsINavHistoryService.TRANSITION_BOOKMARK,
false, 0);
// Add an unvisited child.
PlacesUtils.bookmarks.insertBookmark(lmId,
uri("http://unvisited.livemark.com/"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"unvisited");
}
let historyObserver = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
@ -143,17 +121,6 @@ let historyObserver = {
do_check_false(stmt.executeStep());
stmt.finalize();
// Check that livemarks children don't have frecency <> 0
stmt = mDBConn.createStatement(
"SELECT h.id FROM moz_places h " +
"JOIN moz_bookmarks b ON h.id = b.fk " +
"JOIN moz_bookmarks bp ON bp.id = b.parent " +
"JOIN moz_items_annos t ON t.item_id = bp.id " +
"JOIN moz_anno_attributes n ON t.anno_attribute_id = n.id " +
"WHERE n.name = 'livemark/feedURI' AND h.frecency <> 0 LIMIT 1");
do_check_false(stmt.executeStep());
stmt.finalize();
do_test_finished();
});
}, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);
@ -178,8 +145,6 @@ function run_test() {
}
function continue_test() {
// Add a livemark with a visited and an unvisited child
add_fake_livemark();
PlacesUtils.history.addVisit(uri("http://typed.mozilla.org/"), Date.now(),
null, Ci.nsINavHistoryService.TRANSITION_TYPED,
false, 0);

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

@ -1,98 +0,0 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Places unit test code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Marco Bonardo <mak77@bonardo.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const LMANNO_FEEDURI = "livemark/feedURI";
var PU = PlacesUtils;
var bs = PU.bookmarks;
var as = PU.annotations;
/**
* Creates a fake livemark without using the livemark service.
*
* @param aParentId
* folder where we will create the livemark.
* @param aTitle
* title for the livemark.
* @param aSiteURI
* siteURI, currently unused.
* @param aFeedURI
* feed URI for the livemark.
* @param aIndex
* index of the new folder inside parent.
*
* @returns the new folder id.
*/
function createFakeLivemark(aParentId, aTitle, aSiteURI, aFeedURI, aIndex) {
var folderId = bs.createFolder(aParentId, aTitle, aIndex);
bs.setFolderReadonly(folderId, true);
// Add an annotation to map the folder id to the livemark feed URI.
as.setItemAnnotation(folderId, LMANNO_FEEDURI, aFeedURI.spec,
0, as.EXPIRE_NEVER);
return folderId;
}
// main
function run_test() {
var feedURI = uri("http://example.com/rss.xml");
// Create a fake livemark, and use getMostRecentFolderForFeedURI before
// livemark service is initialized.
var fakeLivemarkId = createFakeLivemark(bs.bookmarksMenuFolder, "foo",
uri("http://example.com/"),
feedURI, bs.DEFAULT_INDEX);
do_check_eq(PU.getMostRecentFolderForFeedURI(feedURI), fakeLivemarkId);
bs.removeItem(fakeLivemarkId);
do_check_eq(PU.getMostRecentFolderForFeedURI(feedURI), -1);
// Create livemark service and repeat the test.
var ls = PU.livemarks;
var livemarkId = ls.createLivemarkFolderOnly(bs.bookmarksMenuFolder, "foo",
uri("http://example.com/"),
feedURI, bs.DEFAULT_INDEX);
do_check_eq(ls.getLivemarkIdForFeedURI(feedURI), livemarkId);
do_check_eq(PU.getMostRecentFolderForFeedURI(feedURI), livemarkId);
bs.removeItem(livemarkId);
do_check_eq(ls.getLivemarkIdForFeedURI(feedURI), -1);
do_check_eq(PU.getMostRecentFolderForFeedURI(feedURI), -1);
}

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

@ -56,6 +56,7 @@ let testServices = [
["browser/nav-bookmarks-service;1","nsINavBookmarksService",
["createFolder", "getItemIdForGUID"]],
["browser/livemark-service;2","nsILivemarkService", []],
["browser/livemark-service;2","mozIAsyncLivemarks", []],
["browser/annotation-service;1","nsIAnnotationService", []],
["browser/favicon-service;1","nsIFaviconService", []],
["browser/tagging-service;1","nsITaggingService", []],

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

@ -728,49 +728,6 @@ tests.push({
//------------------------------------------------------------------------------
tests.push({
name: "D.11",
desc: "Remove old livemarks status items",
_bookmarkId: null,
_livemarkLoadingStatusId: null,
_livemarkFailedStatusId: null,
_placeId: null,
_lmLoadingPlaceId: null,
_lmFailedPlaceId: null,
setup: function() {
// Add a place to ensure place_id = 1 is valid
this._placeId = addPlace();
// Insert a bookmark
this._bookmarkId = addBookmark(this._placeId);
// Add livemark status item
this._lmLoadingPlaceId = addPlace("about:livemark-loading");
this._lmFailedPlaceId = addPlace("about:livemark-failed");
// Bookmark it
this._livemarkLoadingStatusId = addBookmark(this._lmLoadingPlaceId);
this._livemarkFailedStatusId = addBookmark(this._lmFailedPlaceId);
},
check: function() {
// Check that valid bookmark is still there
let stmt = mDBConn.createStatement("SELECT id FROM moz_bookmarks WHERE id = :item_id");
stmt.params["item_id"] = this._bookmarkId;
do_check_true(stmt.executeStep());
stmt.reset();
// Check that livemark status items have been removed
stmt.params["item_id"] = this._livemarkLoadingStatusId;
do_check_false(stmt.executeStep());
stmt.reset();
stmt.params["item_id"] = this._livemarkFailedStatusId;
do_check_false(stmt.executeStep());
stmt.finalize();
}
});
//------------------------------------------------------------------------------
tests.push({
name: "D.12",
desc: "Fix empty-named tags",

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

@ -45,67 +45,6 @@
* bookmark is deleted.
*/
add_test(function unvisited_bookmarked_livemarkItem()
{
do_log_info("Frecency of unvisited, separately bookmarked livemark item's " +
"URI should be zero after bookmark removed.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
PlacesUtils.bookmarks.removeItem(id);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function visited_bookmarked_livemarkItem()
{
do_log_info("Frecency of visited, separately bookmarked livemark item's " +
"URI should not be zero after bookmark removed.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(TEST_URI);
PlacesUtils.bookmarks.removeItem(id);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function removed_bookmark()
{
do_log_info("After removing bookmark, frecency of bookmark's URI should be " +
@ -192,98 +131,6 @@ add_test(function remove_bookmark_still_bookmarked()
});
});
add_test(function cleared_parent_of_unvisited_bookmark_to_livemarkItem()
{
do_log_info("Frecency of unvisited, separately bookmarked livemark item's " +
"URI should be zero after all children removed from bookmark's " +
"parent.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now unvisited livemark item => frecency = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_visited_bookmark_to_livemarkItem()
{
do_log_info("Frecency of visited, separately bookmarked livemark item's " +
"URI should not be zero after all children removed from " +
"bookmark's parent.");
// Add livemark and bookmark. Bookmark's URI is the URI of the livemark's
// only item.
const TEST_URI = NetUtil.newURI("http://example.com/livemark-item");
createLivemark(TEST_URI);
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
visit(TEST_URI);
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForAsyncUpdates(function ()
{
do_log_info("URI's only bookmark is now *visited* livemark item => frecency != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_unvisited_unbookmarked_livemarkItem()
{
do_log_info("After removing all children from bookmark's parent, frecency " +
"of bookmark's URI should be zero if URI is unvisited and no " +
"longer bookmarked.");
const TEST_URI = NetUtil.newURI("http://example.com/1");
let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
TEST_URI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"bookmark title");
waitForAsyncUpdates(function ()
{
do_log_info("Bookmarked => frecency of URI should be != 0");
do_check_neq(frecencyForUrl(TEST_URI), 0);
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
waitForAsyncUpdates(function ()
{
do_log_info("Unvisited URI no longer bookmarked => frecency should = 0");
do_check_eq(frecencyForUrl(TEST_URI), 0);
remove_all_bookmarks();
waitForClearHistory(run_next_test);
});
});
});
add_test(function cleared_parent_of_visited_bookmark()
{
do_log_info("After removing all children from bookmark's parent, frecency " +
@ -347,25 +194,6 @@ add_test(function cleared_parent_of_bookmark_still_bookmarked()
///////////////////////////////////////////////////////////////////////////////
/**
* Creates a livemark with a single child item.
*
* @param aChildURI
* the URI of the livemark's single child item
* @return the item ID of the single child item
*/
function createLivemark(aChildURI)
{
let livemarkId = PlacesUtils.livemarks.createLivemarkFolderOnly(
PlacesUtils.unfiledBookmarksFolderId, "livemark title",
uri("http://example.com/"), uri("http://example.com/rdf"), -1
);
return PlacesUtils.bookmarks.insertBookmark(livemarkId,
aChildURI,
PlacesUtils.bookmarks.DEFAULT_INDEX,
"livemark item title");
}
/**
* Adds a visit for aURI.
*

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

@ -71,7 +71,6 @@ fail-if = os == "android"
[test_download_history.js]
# Bug 676989: test fails consistently on Android
fail-if = os == "android"
[test_exclude_livemarks.js]
[test_faviconService_expireAllFavicons.js]
[test_favicons.js]
# Bug 676989: test fails consistently on Android
@ -93,7 +92,6 @@ skip-if = os == "android"
[test_isURIVisited.js]
[test_isvisited.js]
[test_lastModified.js]
[test_livemarkService_getLivemarkIdForFeedURI.js]
[test_markpageas.js]
[test_mozIAsyncLivemarks.js]
[test_moz-anno_favicon_mime_type.js]