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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * This file tests the image conversions done by the favicon service.
     6  */
     8 ////////////////////////////////////////////////////////////////////////////////
     9 /// Globals
    11 // The pixel values we get on Windows are sometimes +/- 1 value compared to
    12 // other platforms, so we need to skip some image content tests.
    13 let isWindows = ("@mozilla.org/windows-registry-key;1" in Cc);
    15 /**
    16  * Checks the conversion of the given test image file.
    17  *
    18  * @param aFileName
    19  *        File that contains the favicon image, located in the test folder.
    20  * @param aFileMimeType
    21  *        MIME type of the image contained in the file.
    22  * @param aFileLength
    23  *        Expected length of the file.
    24  * @param aExpectConversion
    25  *        If false, the icon should be stored as is.  If true, the expected data
    26  *        is loaded from a file named "expected-" + aFileName + ".png".
    27  * @param aVaryOnWindows
    28  *        Indicates that the content of the converted image can be different on
    29  *        Windows and should not be checked on that platform.
    30  * @param aCallback
    31  *        This function is called after the check finished.
    32  */
    33 function checkFaviconDataConversion(aFileName, aFileMimeType, aFileLength,
    34                                     aExpectConversion, aVaryOnWindows,
    35                                     aCallback) {
    36   let pageURI = NetUtil.newURI("http://places.test/page/" + aFileName);
    37   promiseAddVisits({ uri: pageURI, transition: TRANSITION_TYPED }).then(
    38     function () {
    39       let faviconURI = NetUtil.newURI("http://places.test/icon/" + aFileName);
    40       let fileData = readFileOfLength(aFileName, aFileLength);
    42       PlacesUtils.favicons.replaceFaviconData(faviconURI, fileData, fileData.length,
    43                                               aFileMimeType);
    44       PlacesUtils.favicons.setAndFetchFaviconForPage(pageURI, faviconURI, true,
    45         PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
    46         function CFDC_verify(aURI, aDataLen, aData, aMimeType) {
    47           if (!aExpectConversion) {
    48             do_check_true(compareArrays(aData, fileData));
    49             do_check_eq(aMimeType, aFileMimeType);
    50           } else {
    51             if (!aVaryOnWindows || !isWindows) {
    52               let expectedFile = do_get_file("expected-" + aFileName + ".png");
    53               do_check_true(compareArrays(aData, readFileData(expectedFile)));
    54             }
    55             do_check_eq(aMimeType, "image/png");
    56           }
    58           aCallback();
    59         });
    60     });
    61 }
    63 ////////////////////////////////////////////////////////////////////////////////
    64 /// Tests
    66 function run_test() {
    67   run_next_test();
    68 }
    70 add_test(function test_storing_a_normal_16x16_icon() {
    71   // 16x16 png, 286 bytes.
    72   checkFaviconDataConversion("favicon-normal16.png", "image/png", 286,
    73                              false, false, run_next_test);
    74 });
    76 add_test(function test_storing_a_normal_32x32_icon() {
    77   // 32x32 png, 344 bytes.
    78   checkFaviconDataConversion("favicon-normal32.png", "image/png", 344,
    79                              false, false, run_next_test);
    80 });
    82 add_test(function test_storing_an_oversize_16x16_icon() {
    83   //  in: 16x16 ico, 1406 bytes.
    84   // out: 16x16 png
    85   checkFaviconDataConversion("favicon-big16.ico", "image/x-icon", 1406,
    86                              true, false, run_next_test);
    87 });
    89 add_test(function test_storing_an_oversize_4x4_icon() {
    90   //  in: 4x4 jpg, 4751 bytes.
    91   // out: 16x16 png
    92   checkFaviconDataConversion("favicon-big4.jpg", "image/jpeg", 4751,
    93                              true, false, run_next_test);
    94 });
    96 add_test(function test_storing_an_oversize_32x32_icon() {
    97   //  in: 32x32 jpg, 3494 bytes.
    98   // out: 16x16 png
    99   checkFaviconDataConversion("favicon-big32.jpg", "image/jpeg", 3494,
   100                              true, true, run_next_test);
   101 });
   103 add_test(function test_storing_an_oversize_48x48_icon() {
   104   //  in: 48x48 ico, 56646 bytes.
   105   // (howstuffworks.com icon, contains 13 icons with sizes from 16x16 to
   106   // 48x48 in varying depths)
   107   // out: 16x16 png
   108   checkFaviconDataConversion("favicon-big48.ico", "image/x-icon", 56646,
   109                              true, false, run_next_test);
   110 });
   112 add_test(function test_storing_an_oversize_64x64_icon() {
   113   //  in: 64x64 png, 10698 bytes.
   114   // out: 16x16 png
   115   checkFaviconDataConversion("favicon-big64.png", "image/png", 10698,
   116                              true, false, run_next_test);
   117 });
   119 add_test(function test_scaling_an_oversize_160x3_icon() {
   120   //  in: 160x3 jpg, 5095 bytes.
   121   // out: 16x16 png
   122   checkFaviconDataConversion("favicon-scale160x3.jpg", "image/jpeg", 5095,
   123                              true, false, run_next_test);
   124 });
   126 add_test(function test_scaling_an_oversize_3x160_icon() {
   127   //  in: 3x160 jpg, 5059 bytes.
   128   // out: 16x16 png
   129   checkFaviconDataConversion("favicon-scale3x160.jpg", "image/jpeg", 5059,
   130                              true, false, run_next_test);
   131 });

mercurial