B2G/gecko/toolkit/components/places/tests/queries/test_querySerialization.js
/**
 * Serializes the nsINavHistoryQuery objects in aQueryArr and the
 * nsINavHistoryQueryOptions object aQueryOptions, de-serializes the
 * serialization, and ensures (using do_check_* functions) that the
 * de-serialized objects equal the originals.
 *
 * @param aQueryArr
 *        an array containing nsINavHistoryQuery objects
 * @param aQueryOptions
 *        an nsINavHistoryQueryOptions object
 */
Serializes the nsINavHistoryQuery objects in aQueryArr and the
nsINavHistoryQueryOptions object aQueryOptions, de-serializes the
serialization, and ensures (using do_check_* functions) that the
de-serialized objects equal the originals.


Serializes the nsINavHistoryQuery objects in aQueryArr and the nsINavHistoryQueryOptions object aQueryOptions de - serializes the serialization and ensures ( using do_check_ * functions ) that the de - serialized objects equal the originals .
function serializeDeserialize(aQueryArr, aQueryOptions)
{
  var queryStr = PlacesUtils.history.queriesToQueryString(aQueryArr,
                                                        aQueryArr.length,
                                                        aQueryOptions);
  print("  " + queryStr);
  var queryArr2 = {};
  var opts2 = {};
  PlacesUtils.history.queryStringToQueries(queryStr, queryArr2, {}, opts2);
  queryArr2 = queryArr2.value;
  opts2 = opts2.value;
  do_check_eq(aQueryArr.length, queryArr2.length);
  for (let i = 0; i < aQueryArr.length; i++) {
    let j = 0;
    for (; j < queryArr2.length; j++) {
      if (queryObjsEqual(querySwitches, aQueryArr[i], queryArr2[j]))
        break;
    }
    if (j < queryArr2.length)
      queryArr2.splice(j, 1);
  }
  do_check_eq(queryArr2.length, 0);
  do_check_true(queryObjsEqual(queryOptionSwitches, aQueryOptions, opts2));
}
function serializeDeserialize ( aQueryArr , aQueryOptions ) { var queryStr = PlacesUtils . history . queriesToQueryString ( aQueryArr , aQueryArr . length , aQueryOptions ) ; print ( "  " + queryStr ) ; var queryArr2 = { } ; var opts2 = { } ; PlacesUtils . history . queryStringToQueries ( queryStr , queryArr2 , { } , opts2 ) ; queryArr2 = queryArr2 . value ; opts2 = opts2 . value ; do_check_eq ( aQueryArr . length , queryArr2 . length ) ; for ( let i = 0 ; i < aQueryArr . length ; i ++ ) { let j = 0 ; for ( ; j < queryArr2 . length ; j ++ ) { if ( queryObjsEqual ( querySwitches , aQueryArr [ i ] , queryArr2 [ j ] ) ) break ; } if ( j < queryArr2 . length ) queryArr2 . splice ( j , 1 ) ; } do_check_eq ( queryArr2 . length , 0 ) ; do_check_true ( queryObjsEqual ( queryOptionSwitches , aQueryOptions , opts2 ) ) ; }
Serializes the nsINavHistoryQuery objects in aQueryArr and the
 nsINavHistoryQueryOptions object aQueryOptions, de-serializes the
 serialization, and ensures (using do_check_* functions) that the
 de-serialized objects equal the originals.
Serializes the nsINavHistoryQuery objects in aQueryArr and the nsINavHistoryQueryOptions object aQueryOptions de - serializes the serialization and ensures ( using do_check_ * functions ) that the de - serialized objects equal the originals .
// The two sets of queries cannot be the same if their lengths differ. // Although the query serialization code as it is written now practically // ensures that queries appear in the query string in the same order they // appear in both the array to be serialized and the array resulting from // de-serialization, the interface does not guarantee any ordering.  So, for // each query in aQueryArr, find its equivalent in queryArr2 and delete it // from queryArr2.  If queryArr2 is empty after looping through aQueryArr, // the two sets of queries are equal. // Finally check the query options objects.