michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * This file tests getFaviconDataForPage. michael@0: */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: /// Globals michael@0: michael@0: const FAVICON_URI = NetUtil.newURI(do_get_file("favicon-normal32.png")); michael@0: const FAVICON_DATA = readFileData(do_get_file("favicon-normal32.png")); michael@0: const FAVICON_MIMETYPE = "image/png"; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: /// Tests michael@0: michael@0: function run_test() michael@0: { michael@0: // Check that the favicon loaded correctly before starting the actual tests. michael@0: do_check_eq(FAVICON_DATA.length, 344); michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_normal() michael@0: { michael@0: let pageURI = NetUtil.newURI("http://example.com/normal"); michael@0: michael@0: promiseAddVisits(pageURI).then(function () { michael@0: PlacesUtils.favicons.setAndFetchFaviconForPage( michael@0: pageURI, FAVICON_URI, true, michael@0: PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, michael@0: function () { michael@0: PlacesUtils.favicons.getFaviconDataForPage(pageURI, michael@0: function (aURI, aDataLen, aData, aMimeType) { michael@0: do_check_true(aURI.equals(FAVICON_URI)); michael@0: do_check_eq(FAVICON_DATA.length, aDataLen); michael@0: do_check_true(compareArrays(FAVICON_DATA, aData)); michael@0: do_check_eq(FAVICON_MIMETYPE, aMimeType); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: add_test(function test_missing() michael@0: { michael@0: let pageURI = NetUtil.newURI("http://example.com/missing"); michael@0: michael@0: PlacesUtils.favicons.getFaviconDataForPage(pageURI, michael@0: function (aURI, aDataLen, aData, aMimeType) { michael@0: // Check also the expected data types. michael@0: do_check_true(aURI === null); michael@0: do_check_true(aDataLen === 0); michael@0: do_check_true(aData.length === 0); michael@0: do_check_true(aMimeType === ""); michael@0: run_next_test(); michael@0: }); michael@0: });