B2G/gecko/toolkit/mozapps/extensions/test/xpcshell/test_AddonRepository_cache.js
/*
 * Check the add-ons in the cache. This function also tests
 * AddonRepository.getCachedAddonByID()
 *
 * @param  aExpectedToFind
 *         An array of booleans representing which REPOSITORY_ADDONS are
 *         expected to be found in the cache
 * @param  aExpectedImmediately
 *         A boolean representing if results from the cache are expected
 *         immediately. Results are not immediate if the cache has not been
 *         initialized yet.
 * @param  aCallback
 *         A callback to call once the checks are complete
 */
Check the add-ons in the cache.

@param  aExpectedToFind
An array of booleans representing which REPOSITORY_ADDONS are
expected to be found in the cache
@param  aExpectedImmediately
A boolean representing if results from the cache are expected
immediately. Results are not immediate if the cache has not been
initialized yet.
@param  aCallback
A callback to call once the checks are complete
Check the add - ons in the cache . @param aExpectedToFind An array of booleans representing which REPOSITORY_ADDONS are expected to be found in the cache @param aExpectedImmediately A boolean representing if results from the cache are expected immediately . Results are not immediate if the cache has not been initialized yet . @param aCallback A callback to call once the checks are complete
function check_cache(aExpectedToFind, aExpectedImmediately, aCallback) {
  do_check_eq(aExpectedToFind.length, REPOSITORY_ADDONS.length);
  let pendingAddons = REPOSITORY_ADDONS.length;
  let immediatelyFound = true;
  for (let i = 0; i < REPOSITORY_ADDONS.length; i++) {
    let expected = aExpectedToFind[i] ? REPOSITORY_ADDONS[i] : null;
    AddonRepository.getCachedAddonByID(REPOSITORY_ADDONS[i].id, function(aAddon) {
      do_check_eq(immediatelyFound, aExpectedImmediately);
      if (expected == null)
        do_check_eq(aAddon, null);
      else
        check_results([aAddon], [expected], true);
      if (--pendingAddons == 0)
        aCallback();
    });
  }
  immediatelyFound = false;
}
function check_cache ( aExpectedToFind , aExpectedImmediately , aCallback ) { do_check_eq ( aExpectedToFind . length , REPOSITORY_ADDONS . length ) ; let pendingAddons = REPOSITORY_ADDONS . length ; let immediatelyFound = true ; for ( let i = 0 ; i < REPOSITORY_ADDONS . length ; i ++ ) { let expected = aExpectedToFind [ i ] ? REPOSITORY_ADDONS [ i ] : null ; AddonRepository . getCachedAddonByID ( REPOSITORY_ADDONS [ i ] . id , function ( aAddon ) { do_check_eq ( immediatelyFound , aExpectedImmediately ) ; if ( expected == null ) do_check_eq ( aAddon , null ) ; else check_results ( [ aAddon ] , [ expected ] , true ) ; if ( -- pendingAddons == 0 ) aCallback ( ) ; } ) ; } immediatelyFound = false ; }
Check the add-ons in the cache.
Check the add - ons in the cache .