B2G/gecko/toolkit/components/places/tests/favicons/test_favicons_conversions.js
/**
 * Checks the conversion of the given test image file.
 *
 * @param aFileName
 *        File that contains the favicon image, located in the test folder.
 * @param aFileMimeType
 *        MIME type of the image contained in the file.
 * @param aFileLength
 *        Expected length of the file.
 * @param aExpectConversion
 *        If false, the icon should be stored as is.  If true, the expected data
 *        is loaded from a file named "expected-" + aFileName + ".png".
 * @param aVaryOnWindows
 *        Indicates that the content of the converted image can be different on
 *        Windows and should not be checked on that platform.
 * @param aCallback
 *        This function is called after the check finished.
 */
Checks the conversion of the given test image file.
@param aFileName
File that contains the favicon image, located in the test folder.
@param aFileMimeType
MIME type of the image contained in the file.
@param aFileLength
Expected length of the file.
@param aExpectConversion
If false, the icon should be stored as is.  If true, the expected data
is loaded from a file named "expected-" + aFileName + ".png".
@param aVaryOnWindows
Indicates that the content of the converted image can be different on
Windows and should not be checked on that platform.
@param aCallback
This function is called after the check finished.
Checks the conversion of the given test image file . @param aFileName File that contains the favicon image located in the test folder . @param aFileMimeType MIME type of the image contained in the file . @param aFileLength Expected length of the file . @param aExpectConversion If false the icon should be stored as is . If true the expected data is loaded from a file named " expected - " + aFileName + " . png " . @param aVaryOnWindows Indicates that the content of the converted image can be different on Windows and should not be checked on that platform . @param aCallback This function is called after the check finished .
function checkFaviconDataConversion(aFileName, aFileMimeType, aFileLength,
                                    aExpectConversion, aVaryOnWindows,
                                    aCallback) {
  let pageURI = NetUtil.newURI("http://places.test/page/" + aFileName);
  addVisits({ uri: pageURI, transition: TRANSITION_TYPED }, function () {
    let faviconURI = NetUtil.newURI("http://places.test/icon/" + aFileName);
    let fileData = readFileOfLength(aFileName, aFileLength);
    PlacesUtils.favicons.replaceFaviconData(faviconURI, fileData, fileData.length,
                                            aFileMimeType);
    PlacesUtils.favicons.setAndFetchFaviconForPage(pageURI, faviconURI, true,
      PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE,
      function CFDC_verify(aURI, aDataLen, aData, aMimeType) {
        if (!aExpectConversion) {
          do_check_true(compareArrays(aData, fileData));
          do_check_eq(aMimeType, aFileMimeType);
        } else {
          if (!aVaryOnWindows || !isWindows) {
            let expectedFile = do_get_file("expected-" + aFileName + ".png");
            do_check_true(compareArrays(aData, readFileData(expectedFile)));
          }
          do_check_eq(aMimeType, "image/png");
        }
        aCallback();
      });
  });
}
function checkFaviconDataConversion ( aFileName , aFileMimeType , aFileLength , aExpectConversion , aVaryOnWindows , aCallback ) { let pageURI = NetUtil . newURI ( "http://places.test/page/" + aFileName ) ; addVisits ( { uri : pageURI , transition : TRANSITION_TYPED } , function ( ) { let faviconURI = NetUtil . newURI ( "http://places.test/icon/" + aFileName ) ; let fileData = readFileOfLength ( aFileName , aFileLength ) ; PlacesUtils . favicons . replaceFaviconData ( faviconURI , fileData , fileData . length , aFileMimeType ) ; PlacesUtils . favicons . setAndFetchFaviconForPage ( pageURI , faviconURI , true , PlacesUtils . favicons . FAVICON_LOAD_NON_PRIVATE , function CFDC_verify ( aURI , aDataLen , aData , aMimeType ) { if ( ! aExpectConversion ) { do_check_true ( compareArrays ( aData , fileData ) ) ; do_check_eq ( aMimeType , aFileMimeType ) ; } else { if ( ! aVaryOnWindows || ! isWindows ) { let expectedFile = do_get_file ( "expected-" + aFileName + ".png" ) ; do_check_true ( compareArrays ( aData , readFileData ( expectedFile ) ) ) ; } do_check_eq ( aMimeType , "image/png" ) ; } aCallback ( ) ; } ) ; } ) ; }
Checks the conversion of the given test image file.
Checks the conversion of the given test image file .