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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/favicons/test_getFaviconDataForPage.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     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 getFaviconDataForPage.
     1.9 + */
    1.10 +
    1.11 +////////////////////////////////////////////////////////////////////////////////
    1.12 +/// Globals
    1.13 +
    1.14 +const FAVICON_URI = NetUtil.newURI(do_get_file("favicon-normal32.png"));
    1.15 +const FAVICON_DATA = readFileData(do_get_file("favicon-normal32.png"));
    1.16 +const FAVICON_MIMETYPE = "image/png";
    1.17 +
    1.18 +////////////////////////////////////////////////////////////////////////////////
    1.19 +/// Tests
    1.20 +
    1.21 +function run_test()
    1.22 +{
    1.23 +  // Check that the favicon loaded correctly before starting the actual tests.
    1.24 +  do_check_eq(FAVICON_DATA.length, 344);
    1.25 +  run_next_test();
    1.26 +}
    1.27 +
    1.28 +add_test(function test_normal()
    1.29 +{
    1.30 +  let pageURI = NetUtil.newURI("http://example.com/normal");
    1.31 +
    1.32 +  promiseAddVisits(pageURI).then(function () {
    1.33 +    PlacesUtils.favicons.setAndFetchFaviconForPage(
    1.34 +      pageURI, FAVICON_URI, true,
    1.35 +        PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
    1.36 +        function () {
    1.37 +        PlacesUtils.favicons.getFaviconDataForPage(pageURI,
    1.38 +          function (aURI, aDataLen, aData, aMimeType) {
    1.39 +            do_check_true(aURI.equals(FAVICON_URI));
    1.40 +            do_check_eq(FAVICON_DATA.length, aDataLen);
    1.41 +            do_check_true(compareArrays(FAVICON_DATA, aData));
    1.42 +            do_check_eq(FAVICON_MIMETYPE, aMimeType);
    1.43 +            run_next_test();
    1.44 +          });
    1.45 +      });
    1.46 +  });
    1.47 +});
    1.48 +
    1.49 +add_test(function test_missing()
    1.50 +{
    1.51 +  let pageURI = NetUtil.newURI("http://example.com/missing");
    1.52 +
    1.53 +  PlacesUtils.favicons.getFaviconDataForPage(pageURI,
    1.54 +    function (aURI, aDataLen, aData, aMimeType) {
    1.55 +      // Check also the expected data types.
    1.56 +      do_check_true(aURI === null);
    1.57 +      do_check_true(aDataLen === 0);
    1.58 +      do_check_true(aData.length === 0);
    1.59 +      do_check_true(aMimeType === "");
    1.60 +      run_next_test();
    1.61 +    });
    1.62 +});

mercurial