toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * This file tests getFaviconDataForPage.
michael@0 6 */
michael@0 7
michael@0 8 ////////////////////////////////////////////////////////////////////////////////
michael@0 9 /// Globals
michael@0 10
michael@0 11 const FAVICON_URI = NetUtil.newURI(do_get_file("favicon-normal32.png"));
michael@0 12 const FAVICON_DATA = readFileData(do_get_file("favicon-normal32.png"));
michael@0 13 const FAVICON_MIMETYPE = "image/png";
michael@0 14
michael@0 15 ////////////////////////////////////////////////////////////////////////////////
michael@0 16 /// Tests
michael@0 17
michael@0 18 function run_test()
michael@0 19 {
michael@0 20 // Check that the favicon loaded correctly before starting the actual tests.
michael@0 21 do_check_eq(FAVICON_DATA.length, 344);
michael@0 22 run_next_test();
michael@0 23 }
michael@0 24
michael@0 25 add_test(function test_normal()
michael@0 26 {
michael@0 27 let pageURI = NetUtil.newURI("http://example.com/normal");
michael@0 28
michael@0 29 promiseAddVisits(pageURI).then(function () {
michael@0 30 PlacesUtils.favicons.setAndFetchFaviconForPage(
michael@0 31 pageURI, FAVICON_URI, true,
michael@0 32 PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
michael@0 33 function () {
michael@0 34 PlacesUtils.favicons.getFaviconDataForPage(pageURI,
michael@0 35 function (aURI, aDataLen, aData, aMimeType) {
michael@0 36 do_check_true(aURI.equals(FAVICON_URI));
michael@0 37 do_check_eq(FAVICON_DATA.length, aDataLen);
michael@0 38 do_check_true(compareArrays(FAVICON_DATA, aData));
michael@0 39 do_check_eq(FAVICON_MIMETYPE, aMimeType);
michael@0 40 run_next_test();
michael@0 41 });
michael@0 42 });
michael@0 43 });
michael@0 44 });
michael@0 45
michael@0 46 add_test(function test_missing()
michael@0 47 {
michael@0 48 let pageURI = NetUtil.newURI("http://example.com/missing");
michael@0 49
michael@0 50 PlacesUtils.favicons.getFaviconDataForPage(pageURI,
michael@0 51 function (aURI, aDataLen, aData, aMimeType) {
michael@0 52 // Check also the expected data types.
michael@0 53 do_check_true(aURI === null);
michael@0 54 do_check_true(aDataLen === 0);
michael@0 55 do_check_true(aData.length === 0);
michael@0 56 do_check_true(aMimeType === "");
michael@0 57 run_next_test();
michael@0 58 });
michael@0 59 });

mercurial