B2G/gecko/toolkit/components/places/tests/queries/head_queries.js
/**
 * Helper function to compare an array of query objects with a result set.
 * It assumes the array of query objects contains the SAME SORT as the result
 * set.  It checks the the uri, title, time, and bookmarkIndex properties of
 * the results, where appropriate.
 */
Helper function to compare an array of query objects with a result set.
It assumes the array of query objects contains the SAME SORT as the result
set.  It checks the the uri, title, time, and bookmarkIndex properties of
the results, where appropriate.
Helper function to compare an array of query objects with a result set . It assumes the array of query objects contains the SAME SORT as the result set . It checks the the uri title time and bookmarkIndex properties of the results where appropriate .
function compareArrayToResult(aArray, aRoot) {
  LOG("Comparing Array to Results");
  var wasOpen = aRoot.containerOpen;
  if (!wasOpen)
    aRoot.containerOpen = true;
  var expectedResultCount = aArray.filter(function(aEl) { return aEl.isInQuery; }).length;
  if (expectedResultCount != aRoot.childCount) {
    dump_table("moz_places");
    dump_table("moz_historyvisits");
    LOG("Found children:");
    for (let i = 0; i < aRoot.childCount; i++) {
      LOG(aRoot.getChild(i).uri);
    }
    LOG("Expected:");
    for (let i = 0; i < aArray.length; i++) {
      if (aArray[i].isInQuery)
        LOG(aArray[i].uri);
    }
  }
  do_check_eq(expectedResultCount, aRoot.childCount);
  var inQueryIndex = 0;
  for (var i = 0; i < aArray.length; i++) {
    if (aArray[i].isInQuery) {
      var child = aRoot.getChild(inQueryIndex);
      if (!aArray[i].isFolder && !aArray[i].isSeparator) {
        LOG("testing testData[" + aArray[i].uri + "] vs result[" + child.uri + "]");
        if (aArray[i].uri != child.uri) {
          dump_table("moz_places");
          do_throw("Expected " + aArray[i].uri + " found " + child.uri);
        }
      }
      if (!aArray[i].isSeparator && aArray[i].title != child.title)
        do_throw("Expected " + aArray[i].title + " found " + child.title);
      if (aArray[i].hasOwnProperty("lastVisit") &&
          aArray[i].lastVisit != child.time)
        do_throw("Expected " + aArray[i].lastVisit + " found " + child.time);
      if (aArray[i].hasOwnProperty("index") &&
          aArray[i].index != PlacesUtils.bookmarks.DEFAULT_INDEX &&
          aArray[i].index != child.bookmarkIndex)
        do_throw("Expected " + aArray[i].index + " found " + child.bookmarkIndex);
      inQueryIndex++;
    }
  }
  if (!wasOpen)
    aRoot.containerOpen = false;
  LOG("Comparing Array to Results passes");
}
function compareArrayToResult ( aArray , aRoot ) { LOG ( "Comparing Array to Results" ) ; var wasOpen = aRoot . containerOpen ; if ( ! wasOpen ) aRoot . containerOpen = true ; var expectedResultCount = aArray . filter ( function ( aEl ) { return aEl . isInQuery ; } ) . length ; if ( expectedResultCount != aRoot . childCount ) { dump_table ( "moz_places" ) ; dump_table ( "moz_historyvisits" ) ; LOG ( "Found children:" ) ; for ( let i = 0 ; i < aRoot . childCount ; i ++ ) { LOG ( aRoot . getChild ( i ) . uri ) ; } LOG ( "Expected:" ) ; for ( let i = 0 ; i < aArray . length ; i ++ ) { if ( aArray [ i ] . isInQuery ) LOG ( aArray [ i ] . uri ) ; } } do_check_eq ( expectedResultCount , aRoot . childCount ) ; var inQueryIndex = 0 ; for ( var i = 0 ; i < aArray . length ; i ++ ) { if ( aArray [ i ] . isInQuery ) { var child = aRoot . getChild ( inQueryIndex ) ; if ( ! aArray [ i ] . isFolder && ! aArray [ i ] . isSeparator ) { LOG ( "testing testData[" + aArray [ i ] . uri + "] vs result[" + child . uri + "]" ) ; if ( aArray [ i ] . uri != child . uri ) { dump_table ( "moz_places" ) ; do_throw ( "Expected " + aArray [ i ] . uri + " found " + child . uri ) ; } } if ( ! aArray [ i ] . isSeparator && aArray [ i ] . title != child . title ) do_throw ( "Expected " + aArray [ i ] . title + " found " + child . title ) ; if ( aArray [ i ] . hasOwnProperty ( "lastVisit" ) && aArray [ i ] . lastVisit != child . time ) do_throw ( "Expected " + aArray [ i ] . lastVisit + " found " + child . time ) ; if ( aArray [ i ] . hasOwnProperty ( "index" ) && aArray [ i ] . index != PlacesUtils . bookmarks . DEFAULT_INDEX && aArray [ i ] . index != child . bookmarkIndex ) do_throw ( "Expected " + aArray [ i ] . index + " found " + child . bookmarkIndex ) ; inQueryIndex ++ ; } } if ( ! wasOpen ) aRoot . containerOpen = false ; LOG ( "Comparing Array to Results passes" ) ; }
Helper function to compare an array of query objects with a result set.
Helper function to compare an array of query objects with a result set .
// check expected number of results against actual // Debugging code for failures. //LOG("testing testData[" + i + "] vs result[" + inQueryIndex + "]");