1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/favicons/test_expireAllFavicons.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * This file tests that favicons are correctly expired by expireAllFavicons. 1.9 + */ 1.10 + 1.11 +//////////////////////////////////////////////////////////////////////////////// 1.12 +/// Globals 1.13 + 1.14 +const TEST_PAGE_URI = NetUtil.newURI("http://example.com/"); 1.15 +const BOOKMARKED_PAGE_URI = NetUtil.newURI("http://example.com/bookmarked"); 1.16 + 1.17 +//////////////////////////////////////////////////////////////////////////////// 1.18 +/// Tests 1.19 + 1.20 +function run_test() { 1.21 + run_next_test(); 1.22 +} 1.23 + 1.24 +add_test(function test_expireAllFavicons() { 1.25 + // Set up an observer to wait for favicons expiration to finish. 1.26 + Services.obs.addObserver(function EAF_observer(aSubject, aTopic, aData) { 1.27 + Services.obs.removeObserver(EAF_observer, aTopic); 1.28 + 1.29 + // Check that the favicons for the pages we added were removed. 1.30 + checkFaviconMissingForPage(TEST_PAGE_URI, function () { 1.31 + checkFaviconMissingForPage(BOOKMARKED_PAGE_URI, function () { 1.32 + run_next_test(); 1.33 + }); 1.34 + }); 1.35 + }, PlacesUtils.TOPIC_FAVICONS_EXPIRED, false); 1.36 + 1.37 + // Add a visited page. 1.38 + promiseAddVisits({ uri: TEST_PAGE_URI, transition: TRANSITION_TYPED }).then( 1.39 + function () { 1.40 + PlacesUtils.favicons.setAndFetchFaviconForPage(TEST_PAGE_URI, 1.41 + SMALLPNG_DATA_URI, true, 1.42 + PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE); 1.43 + 1.44 + // Add a page with a bookmark. 1.45 + PlacesUtils.bookmarks.insertBookmark( 1.46 + PlacesUtils.toolbarFolderId, BOOKMARKED_PAGE_URI, 1.47 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.48 + "Test bookmark"); 1.49 + PlacesUtils.favicons.setAndFetchFaviconForPage( 1.50 + BOOKMARKED_PAGE_URI, SMALLPNG_DATA_URI, true, 1.51 + PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, 1.52 + function () { 1.53 + // Start expiration only after data has been saved in the database. 1.54 + PlacesUtils.favicons.expireAllFavicons(); 1.55 + }); 1.56 + }); 1.57 +});