gecko/toolkit/components/places/tests/bookmarks/test_async_observers.js
Paolo Amadini 3ee0f44360 Bug 728143 - Replace old synchronous favicons calls in Places tests. r=mak
--HG--
rename : toolkit/components/places/tests/unit/expected-favicon-big16.ico.png => toolkit/components/places/tests/favicons/expected-favicon-big16.ico.png
rename : toolkit/components/places/tests/unit/expected-favicon-big32.jpg.png => toolkit/components/places/tests/favicons/expected-favicon-big32.jpg.png
rename : toolkit/components/places/tests/unit/expected-favicon-big4.jpg.png => toolkit/components/places/tests/favicons/expected-favicon-big4.jpg.png
rename : toolkit/components/places/tests/unit/expected-favicon-big48.ico.png => toolkit/components/places/tests/favicons/expected-favicon-big48.ico.png
rename : toolkit/components/places/tests/unit/expected-favicon-big64.png.png => toolkit/components/places/tests/favicons/expected-favicon-big64.png.png
rename : toolkit/components/places/tests/unit/expected-favicon-scale160x3.jpg.png => toolkit/components/places/tests/favicons/expected-favicon-scale160x3.jpg.png
rename : toolkit/components/places/tests/unit/expected-favicon-scale3x160.jpg.png => toolkit/components/places/tests/favicons/expected-favicon-scale3x160.jpg.png
rename : toolkit/components/places/tests/unit/favicon-big16.ico => toolkit/components/places/tests/favicons/favicon-big16.ico
rename : toolkit/components/places/tests/unit/favicon-big32.jpg => toolkit/components/places/tests/favicons/favicon-big32.jpg
rename : toolkit/components/places/tests/unit/favicon-big4.jpg => toolkit/components/places/tests/favicons/favicon-big4.jpg
rename : toolkit/components/places/tests/unit/favicon-big48.ico => toolkit/components/places/tests/favicons/favicon-big48.ico
rename : toolkit/components/places/tests/unit/favicon-big64.png => toolkit/components/places/tests/favicons/favicon-big64.png
rename : toolkit/components/places/tests/unit/favicon-normal16.png => toolkit/components/places/tests/favicons/favicon-normal16.png
rename : toolkit/components/places/tests/unit/favicon-normal32.png => toolkit/components/places/tests/favicons/favicon-normal32.png
rename : toolkit/components/places/tests/unit/favicon-scale160x3.jpg => toolkit/components/places/tests/favicons/favicon-scale160x3.jpg
rename : toolkit/components/places/tests/unit/favicon-scale3x160.jpg => toolkit/components/places/tests/favicons/favicon-scale3x160.jpg
rename : toolkit/components/places/tests/unit/head_bookmarks.js => toolkit/components/places/tests/favicons/head_favicons.js
rename : toolkit/components/places/tests/unit/test_favicons.js => toolkit/components/places/tests/favicons/test_favicons.js
rename : toolkit/components/places/tests/unit/test_moz-anno_favicon_mime_type.js => toolkit/components/places/tests/favicons/test_moz-anno_favicon_mime_type.js
rename : toolkit/components/places/tests/unit/test_doReplaceFaviconData.js => toolkit/components/places/tests/favicons/test_replaceFaviconData.js
rename : toolkit/components/places/tests/unit/test_doReplaceFaviconDataFromDataURL.js => toolkit/components/places/tests/favicons/test_replaceFaviconDataFromDataURL.js
2012-03-19 20:24:21 +01:00

110 lines
3.4 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* This test checks that bookmarks service is correctly forwarding async
* events like visit or favicon additions. */
const NOW = Date.now() * 1000;
let observer = {
bookmarks: [],
observedBookmarks: 0,
visitId: 0,
reset: function ()
{
this.observedBookmarks = 0;
},
onBeginUpdateBatch: function () {},
onEndUpdateBatch: function () {},
onItemAdded: function () {},
onBeforeItemRemoved: function () {},
onItemRemoved: function () {},
onItemMoved: function () {},
onItemChanged: function(aItemId, aProperty, aIsAnnotation, aNewValue,
aLastModified, aItemType)
{
do_log_info("Check that we got the correct change information.");
do_check_neq(this.bookmarks.indexOf(aItemId), -1);
if (aProperty == "favicon") {
do_check_false(aIsAnnotation);
do_check_eq(aNewValue, SMALLPNG_DATA_URI.spec);
do_check_eq(aLastModified, 0);
do_check_eq(aItemType, PlacesUtils.bookmarks.TYPE_BOOKMARK);
}
else if (aProperty == "cleartime") {
do_check_false(aIsAnnotation);
do_check_eq(aNewValue, "");
do_check_eq(aLastModified, 0);
do_check_eq(aItemType, PlacesUtils.bookmarks.TYPE_BOOKMARK);
}
else {
do_throw("Unexpected property change " + aProperty);
}
if (++this.observedBookmarks == this.bookmarks.length) {
run_next_test();
}
},
onItemVisited: function(aItemId, aVisitId, aTime)
{
do_log_info("Check that we got the correct visit information.");
do_check_neq(this.bookmarks.indexOf(aItemId), -1);
do_check_eq(aVisitId, this.visitId);
do_check_eq(aTime, NOW);
if (++this.observedBookmarks == this.bookmarks.length) {
run_next_test();
}
},
QueryInterface: XPCOMUtils.generateQI([
Ci.nsINavBookmarkObserver,
])
};
PlacesUtils.bookmarks.addObserver(observer, false);
let gTests = [
function add_visit_test()
{
observer.reset();
// Add a visit to the bookmark and wait for the observer.
observer.visitId =
PlacesUtils.history.addVisit(NetUtil.newURI("http://book.ma.rk/"), NOW, null,
PlacesUtils.history.TRANSITION_TYPED, false, 0);
},
function add_icon_test()
{
observer.reset();
PlacesUtils.favicons.setAndFetchFaviconForPage(NetUtil.newURI("http://book.ma.rk/"),
SMALLPNG_DATA_URI, true);
},
function remove_page_test()
{
observer.reset();
PlacesUtils.history.removePage(NetUtil.newURI("http://book.ma.rk/"));
},
function cleanup()
{
PlacesUtils.bookmarks.removeObserver(observer, false);
run_next_test();
},
];
function run_test()
{
// Add multiple bookmarks to the same uri.
observer.bookmarks.push(
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://book.ma.rk/"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"Bookmark")
);
observer.bookmarks.push(
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.toolbarFolderId,
NetUtil.newURI("http://book.ma.rk/"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"Bookmark")
);
run_next_test();
}