B2G/gecko/browser/components/places/tests/browser/browser_sort_in_library.js
/**
 * Tests sorting aPlaceContentTree by column only and then by both column
 * and direction.
 *
 * @param aOrganizerWin
 *        the Places window
 * @param aPlaceContentTree
 *        the placeContent tree in aOrganizerWin
 * @param aUnsortFirst
 *        true if, before each sort we try, we should sort to SORT_BY_NONE
 */
Tests sorting aPlaceContentTree by column only and then by both column
and direction.

@param aOrganizerWin
the Places window
@param aPlaceContentTree
the placeContent tree in aOrganizerWin
@param aUnsortFirst
true if, before each sort we try, we should sort to SORT_BY_NONE
Tests sorting aPlaceContentTree by column only and then by both column and direction . @param aOrganizerWin the Places window @param aPlaceContentTree the placeContent tree in aOrganizerWin @param aUnsortFirst true if before each sort we try we should sort to SORT_BY_NONE
function testSortByColAndDir(aOrganizerWin, aPlaceContentTree, aUnsortFirst) {
  let cols = aPlaceContentTree.getElementsByTagName("treecol");
  ok(cols.length > 0, "sanity check: placeContent should contain columns");
  for (let i = 0; i < cols.length; i++) {
    let col = cols.item(i);
    ok(col.hasAttribute("anonid"),
       "sanity check: column " + col.id + " should have anonid");
    let colId = col.getAttribute("anonid");
    ok(colId in SORT_LOOKUP_TABLE,
       "sanity check: unexpected placeContent column anonid");
    let sortConst =
      "SORT_BY_" + SORT_LOOKUP_TABLE[colId].key + "_" +
      (aUnsortFirst ? SORT_LOOKUP_TABLE[colId].dir : prevSortDir);
    let expectedSortMode = Ci.nsINavHistoryQueryOptions[sortConst];
    let expectedAnno = SORT_LOOKUP_TABLE[colId].anno || "";
    setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, col);
    checkSort(aPlaceContentTree, expectedSortMode, expectedAnno);
    ["ascending", "descending"].forEach(function (dir) {
      let sortConst =
        "SORT_BY_" + SORT_LOOKUP_TABLE[colId].key + "_" + dir.toUpperCase();
      let expectedSortMode = Ci.nsINavHistoryQueryOptions[sortConst];
      setSort(aOrganizerWin, aPlaceContentTree, aUnsortFirst, false, col, dir);
      checkSort(aPlaceContentTree, expectedSortMode, expectedAnno);
    });
  }
}
function testSortByColAndDir ( aOrganizerWin , aPlaceContentTree , aUnsortFirst ) { let cols = aPlaceContentTree . getElementsByTagName ( "treecol" ) ; ok ( cols . length > 0 , "sanity check: placeContent should contain columns" ) ; for ( let i = 0 ; i < cols . length ; i ++ ) { let col = cols . item ( i ) ; ok ( col . hasAttribute ( "anonid" ) , "sanity check: column " + col . id + " should have anonid" ) ; let colId = col . getAttribute ( "anonid" ) ; ok ( colId in SORT_LOOKUP_TABLE , "sanity check: unexpected placeContent column anonid" ) ; let sortConst = "SORT_BY_" + SORT_LOOKUP_TABLE [ colId ] . key + "_" + ( aUnsortFirst ? SORT_LOOKUP_TABLE [ colId ] . dir : prevSortDir ) ; let expectedSortMode = Ci . nsINavHistoryQueryOptions [ sortConst ] ; let expectedAnno = SORT_LOOKUP_TABLE [ colId ] . anno || "" ; setSort ( aOrganizerWin , aPlaceContentTree , aUnsortFirst , false , col ) ; checkSort ( aPlaceContentTree , expectedSortMode , expectedAnno ) ; [ "ascending" , "descending" ] . forEach ( function ( dir ) { let sortConst = "SORT_BY_" + SORT_LOOKUP_TABLE [ colId ] . key + "_" + dir . toUpperCase ( ) ; let expectedSortMode = Ci . nsINavHistoryQueryOptions [ sortConst ] ; setSort ( aOrganizerWin , aPlaceContentTree , aUnsortFirst , false , col , dir ) ; checkSort ( aPlaceContentTree , expectedSortMode , expectedAnno ) ; } ) ; } }
Tests sorting aPlaceContentTree by column only and then by both column
 and direction.
Tests sorting aPlaceContentTree by column only and then by both column and direction .
// Test sorting by only a column. // Test sorting by both a column and a direction.