B2G/gecko/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
/*
 * Check for imported bookmarks correctness
 *
 * @param aCallback
 *        Called when the checks are finished.
 */
Check for imported bookmarks correctness
@param aCallback
Called when the checks are finished.
Check for imported bookmarks correctness @param aCallback Called when the checks are finished .
function database_check(aCallback) {
  var query = hs.getNewQuery();
  query.setFolders([bs.bookmarksMenuFolder], 1);
  var options = hs.getNewQueryOptions();
  options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
  var result = hs.executeQuery(query, options);
  var rootNode = result.root;
  rootNode.containerOpen = true;
  do_check_eq(rootNode.childCount, 2);
  var testFolder = rootNode.getChild(1);
  do_check_eq(testFolder.type, testFolder.RESULT_TYPE_FOLDER);
  do_check_eq(testFolder.title, "test");
  do_check_eq(bs.getItemDateAdded(testFolder.itemId)/1000000, 1177541020);
  do_check_eq(bs.getItemLastModified(testFolder.itemId)/1000000, 1177541050);
  testFolder = testFolder.QueryInterface(Ci.nsINavHistoryQueryResultNode);
  do_check_eq(testFolder.hasChildren, true);
  do_check_true(as.itemHasAnnotation(testFolder.itemId,
                                          DESCRIPTION_ANNO));
  do_check_eq("folder test comment",
              as.getItemAnnotation(testFolder.itemId, DESCRIPTION_ANNO));
  testFolder.containerOpen = true;
  var cc = testFolder.childCount;
  do_check_eq(cc, 1);
  var testBookmark1 = testFolder.getChild(0);
  do_check_eq("http://test/post", testBookmark1.uri);
  do_check_eq("test post keyword", testBookmark1.title);
  do_check_eq("test", bs.getKeywordForBookmark(testBookmark1.itemId));
  do_check_true(as.itemHasAnnotation(testBookmark1.itemId,
                                          LOAD_IN_SIDEBAR_ANNO));
  do_check_eq(testBookmark1.dateAdded/1000000, 1177375336);
  do_check_eq(testBookmark1.lastModified/1000000, 1177375423);
  do_check_true(as.itemHasAnnotation(testBookmark1.itemId,
                                          POST_DATA_ANNO));
  do_check_eq("hidden1%3Dbar&text1%3D%25s",
              as.getItemAnnotation(testBookmark1.itemId, POST_DATA_ANNO));
  var testURI = uri(testBookmark1.uri);
  do_check_eq("ISO-8859-1", hs.getCharsetForURI(testURI));
  do_check_true(as.itemHasAnnotation(testBookmark1.itemId,
                                          DESCRIPTION_ANNO));
  do_check_eq("item description",
              as.getItemAnnotation(testBookmark1.itemId,
                                        DESCRIPTION_ANNO));
  testFolder.containerOpen = false;
  rootNode.containerOpen = false;
  query.setFolders([bs.toolbarFolder], 1);
  result = hs.executeQuery(query, hs.getNewQueryOptions());
  var toolbar = result.root;
  toolbar.containerOpen = true;
  do_check_eq(toolbar.childCount, 3);
  var livemark = toolbar.getChild(1);
  do_check_eq("Latest Headlines", livemark.title);
  PlacesUtils.livemarks.getLivemark(
    { id: livemark.itemId },
    function (aStatus, aLivemark) {
      do_check_true(Components.isSuccessCode(aStatus));
      do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
                  aLivemark.siteURI.spec);
      do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
                  aLivemark.feedURI.spec);
    }
  );
  toolbar.containerOpen = false;
  query.setFolders([bs.unfiledBookmarksFolder], 1);
  result = hs.executeQuery(query, hs.getNewQueryOptions());
  var unfiledBookmarks = result.root;
  unfiledBookmarks.containerOpen = true;
  do_check_eq(unfiledBookmarks.childCount, 1);
  unfiledBookmarks.containerOpen = false;
  icos.getFaviconDataForPage(uri(TEST_FAVICON_PAGE_URL),
    function DC_onComplete(aURI, aDataLen, aData, aMimeType) {
      do_check_neq(aURI, null);
      do_check_eq(TEST_FAVICON_DATA_SIZE, aDataLen);
      aCallback();
    });
}
function database_check ( aCallback ) { var query = hs . getNewQuery ( ) ; query . setFolders ( [ bs . bookmarksMenuFolder ] , 1 ) ; var options = hs . getNewQueryOptions ( ) ; options . queryType = Ci . nsINavHistoryQueryOptions . QUERY_TYPE_BOOKMARKS ; var result = hs . executeQuery ( query , options ) ; var rootNode = result . root ; rootNode . containerOpen = true ; do_check_eq ( rootNode . childCount , 2 ) ; var testFolder = rootNode . getChild ( 1 ) ; do_check_eq ( testFolder . type , testFolder . RESULT_TYPE_FOLDER ) ; do_check_eq ( testFolder . title , "test" ) ; do_check_eq ( bs . getItemDateAdded ( testFolder . itemId ) / 1000000 , 1177541020 ) ; do_check_eq ( bs . getItemLastModified ( testFolder . itemId ) / 1000000 , 1177541050 ) ; testFolder = testFolder . QueryInterface ( Ci . nsINavHistoryQueryResultNode ) ; do_check_eq ( testFolder . hasChildren , true ) ; do_check_true ( as . itemHasAnnotation ( testFolder . itemId , DESCRIPTION_ANNO ) ) ; do_check_eq ( "folder test comment" , as . getItemAnnotation ( testFolder . itemId , DESCRIPTION_ANNO ) ) ; testFolder . containerOpen = true ; var cc = testFolder . childCount ; do_check_eq ( cc , 1 ) ; var testBookmark1 = testFolder . getChild ( 0 ) ; do_check_eq ( "http://test/post" , testBookmark1 . uri ) ; do_check_eq ( "test post keyword" , testBookmark1 . title ) ; do_check_eq ( "test" , bs . getKeywordForBookmark ( testBookmark1 . itemId ) ) ; do_check_true ( as . itemHasAnnotation ( testBookmark1 . itemId , LOAD_IN_SIDEBAR_ANNO ) ) ; do_check_eq ( testBookmark1 . dateAdded / 1000000 , 1177375336 ) ; do_check_eq ( testBookmark1 . lastModified / 1000000 , 1177375423 ) ; do_check_true ( as . itemHasAnnotation ( testBookmark1 . itemId , POST_DATA_ANNO ) ) ; do_check_eq ( "hidden1%3Dbar&text1%3D%25s" , as . getItemAnnotation ( testBookmark1 . itemId , POST_DATA_ANNO ) ) ; var testURI = uri ( testBookmark1 . uri ) ; do_check_eq ( "ISO-8859-1" , hs . getCharsetForURI ( testURI ) ) ; do_check_true ( as . itemHasAnnotation ( testBookmark1 . itemId , DESCRIPTION_ANNO ) ) ; do_check_eq ( "item description" , as . getItemAnnotation ( testBookmark1 . itemId , DESCRIPTION_ANNO ) ) ; testFolder . containerOpen = false ; rootNode . containerOpen = false ; query . setFolders ( [ bs . toolbarFolder ] , 1 ) ; result = hs . executeQuery ( query , hs . getNewQueryOptions ( ) ) ; var toolbar = result . root ; toolbar . containerOpen = true ; do_check_eq ( toolbar . childCount , 3 ) ; var livemark = toolbar . getChild ( 1 ) ; do_check_eq ( "Latest Headlines" , livemark . title ) ; PlacesUtils . livemarks . getLivemark ( { id : livemark . itemId } , function ( aStatus , aLivemark ) { do_check_true ( Components . isSuccessCode ( aStatus ) ) ; do_check_eq ( "http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/" , aLivemark . siteURI . spec ) ; do_check_eq ( "http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml" , aLivemark . feedURI . spec ) ; } ) ; toolbar . containerOpen = false ; query . setFolders ( [ bs . unfiledBookmarksFolder ] , 1 ) ; result = hs . executeQuery ( query , hs . getNewQueryOptions ( ) ) ; var unfiledBookmarks = result . root ; unfiledBookmarks . containerOpen = true ; do_check_eq ( unfiledBookmarks . childCount , 1 ) ; unfiledBookmarks . containerOpen = false ; icos . getFaviconDataForPage ( uri ( TEST_FAVICON_PAGE_URL ) , function DC_onComplete ( aURI , aDataLen , aData , aMimeType ) { do_check_neq ( aURI , null ) ; do_check_eq ( TEST_FAVICON_DATA_SIZE , aDataLen ) ; aCallback ( ) ; } ) ; }
Check for imported bookmarks correctness
 @param aCallback
        Called when the checks are finished.
Check for imported bookmarks correctness @param aCallback Called when the checks are finished .
// BOOKMARKS MENU // get test folder // add date // last modified // folder description // open test folder, and test the children // test bookmark 1 // url // title // keyword // sidebar // add date // last modified // post data // last charset // description // clean up // BOOKMARKS TOOLBAR // livemark // title // cleanup // UNFILED BOOKMARKS // favicons // aURI should never be null when aDataLen > 0. // Favicon data is stored in the bookmarks file as a "data:" URI.  For // simplicity, instead of converting the data we receive to a "data:" URI // and comparing it, we just check the data size.