B2G/gecko/browser/components/places/tests/browser/browser_views_liveupdate.js
/**
 * Adds bookmarks observer, and executes a bunch of bookmarks operations.
 */
Adds bookmarks observer, and executes a bunch of bookmarks operations.
Adds bookmarks observer and executes a bunch of bookmarks operations .
function startTest() {
  var bs = PlacesUtils.bookmarks;
  bs.addObserver(bookmarksObserver, false);
  PlacesUtils.annotations.addObserver(bookmarksObserver, false);
  var addedBookmarks = [];
  info("*** Acting on menu bookmarks");
  var id = bs.insertBookmark(bs.bookmarksMenuFolder,
                             PlacesUtils._uri("http://bm1.mozilla.org/"),
                             bs.DEFAULT_INDEX,
                             "bm1");
  bs.setItemTitle(id, "bm1_edited");
  addedBookmarks.push(id);
  id = bs.insertBookmark(bs.bookmarksMenuFolder,
                         PlacesUtils._uri("place:"),
                         bs.DEFAULT_INDEX,
                         "bm2");
  bs.setItemTitle(id, "");
  addedBookmarks.push(id);
  id = bs.insertSeparator(bs.bookmarksMenuFolder, bs.DEFAULT_INDEX);
  addedBookmarks.push(id);
  id = bs.createFolder(bs.bookmarksMenuFolder,
                       "bmf",
                       bs.DEFAULT_INDEX);
  bs.setItemTitle(id, "bmf_edited");
  addedBookmarks.push(id);
  id = bs.insertBookmark(id,
                         PlacesUtils._uri("http://bmf1.mozilla.org/"),
                         bs.DEFAULT_INDEX,
                         "bmf1");
  bs.setItemTitle(id, "bmf1_edited");
  addedBookmarks.push(id);
  bs.moveItem(id, bs.bookmarksMenuFolder, 0);
  info("*** Acting on toolbar bookmarks");
  id = bs.insertBookmark(bs.toolbarFolder,
                         PlacesUtils._uri("http://tb1.mozilla.org/"),
                         bs.DEFAULT_INDEX,
                         "tb1");
  bs.setItemTitle(id, "tb1_edited");
  addedBookmarks.push(id);
  bs.setItemTitle(id, "tb1_edited");
  id = bs.insertBookmark(bs.toolbarFolder,
                         PlacesUtils._uri("place:"),
                         bs.DEFAULT_INDEX,
                         "tb2");
  bs.setItemTitle(id, "");
  addedBookmarks.push(id);
  id = bs.insertSeparator(bs.toolbarFolder, bs.DEFAULT_INDEX);
  addedBookmarks.push(id);
  id = bs.createFolder(bs.toolbarFolder,
                       "tbf",
                       bs.DEFAULT_INDEX);
  bs.setItemTitle(id, "tbf_edited");
  addedBookmarks.push(id);
  id = bs.insertBookmark(id,
                         PlacesUtils._uri("http://tbf1.mozilla.org/"),
                         bs.DEFAULT_INDEX,
                         "tbf1");
  bs.setItemTitle(id, "tbf1_edited");
  addedBookmarks.push(id);
  bs.moveItem(id, bs.toolbarFolder, 0);
  info("*** Acting on unsorted bookmarks");
  id = bs.insertBookmark(bs.unfiledBookmarksFolder,
                         PlacesUtils._uri("http://ub1.mozilla.org/"),
                         bs.DEFAULT_INDEX,
                         "ub1");
  bs.setItemTitle(id, "ub1_edited");
  addedBookmarks.push(id);
  id = bs.insertBookmark(bs.unfiledBookmarksFolder,
                         PlacesUtils._uri("place:"),
                         bs.DEFAULT_INDEX,
                         "ub2");
  bs.setItemTitle(id, "ub2_edited");
  addedBookmarks.push(id);
  id = bs.insertSeparator(bs.unfiledBookmarksFolder, bs.DEFAULT_INDEX);
  addedBookmarks.push(id);
  id = bs.createFolder(bs.unfiledBookmarksFolder,
                       "ubf",
                       bs.DEFAULT_INDEX);
  bs.setItemTitle(id, "ubf_edited");
  addedBookmarks.push(id);
  id = bs.insertBookmark(id,
                         PlacesUtils._uri("http://ubf1.mozilla.org/"),
                         bs.DEFAULT_INDEX,
                         "bubf1");
  bs.setItemTitle(id, "bubf1_edited");
  addedBookmarks.push(id);
  bs.moveItem(id, bs.unfiledBookmarksFolder, 0);
  addedBookmarks.forEach(function (aItem) {
    try {
      bs.removeItem(aItem);
    } catch (ex) {}
  });
  bs.removeObserver(bookmarksObserver);
  PlacesUtils.annotations.removeObserver(bookmarksObserver);
  finishTest();
}
function startTest ( ) { var bs = PlacesUtils . bookmarks ; bs . addObserver ( bookmarksObserver , false ) ; PlacesUtils . annotations . addObserver ( bookmarksObserver , false ) ; var addedBookmarks = [ ] ; info ( "*** Acting on menu bookmarks" ) ; var id = bs . insertBookmark ( bs . bookmarksMenuFolder , PlacesUtils . _uri ( "http://bm1.mozilla.org/" ) , bs . DEFAULT_INDEX , "bm1" ) ; bs . setItemTitle ( id , "bm1_edited" ) ; addedBookmarks . push ( id ) ; id = bs . insertBookmark ( bs . bookmarksMenuFolder , PlacesUtils . _uri ( "place:" ) , bs . DEFAULT_INDEX , "bm2" ) ; bs . setItemTitle ( id , "" ) ; addedBookmarks . push ( id ) ; id = bs . insertSeparator ( bs . bookmarksMenuFolder , bs . DEFAULT_INDEX ) ; addedBookmarks . push ( id ) ; id = bs . createFolder ( bs . bookmarksMenuFolder , "bmf" , bs . DEFAULT_INDEX ) ; bs . setItemTitle ( id , "bmf_edited" ) ; addedBookmarks . push ( id ) ; id = bs . insertBookmark ( id , PlacesUtils . _uri ( "http://bmf1.mozilla.org/" ) , bs . DEFAULT_INDEX , "bmf1" ) ; bs . setItemTitle ( id , "bmf1_edited" ) ; addedBookmarks . push ( id ) ; bs . moveItem ( id , bs . bookmarksMenuFolder , 0 ) ; info ( "*** Acting on toolbar bookmarks" ) ; id = bs . insertBookmark ( bs . toolbarFolder , PlacesUtils . _uri ( "http://tb1.mozilla.org/" ) , bs . DEFAULT_INDEX , "tb1" ) ; bs . setItemTitle ( id , "tb1_edited" ) ; addedBookmarks . push ( id ) ; bs . setItemTitle ( id , "tb1_edited" ) ; id = bs . insertBookmark ( bs . toolbarFolder , PlacesUtils . _uri ( "place:" ) , bs . DEFAULT_INDEX , "tb2" ) ; bs . setItemTitle ( id , "" ) ; addedBookmarks . push ( id ) ; id = bs . insertSeparator ( bs . toolbarFolder , bs . DEFAULT_INDEX ) ; addedBookmarks . push ( id ) ; id = bs . createFolder ( bs . toolbarFolder , "tbf" , bs . DEFAULT_INDEX ) ; bs . setItemTitle ( id , "tbf_edited" ) ; addedBookmarks . push ( id ) ; id = bs . insertBookmark ( id , PlacesUtils . _uri ( "http://tbf1.mozilla.org/" ) , bs . DEFAULT_INDEX , "tbf1" ) ; bs . setItemTitle ( id , "tbf1_edited" ) ; addedBookmarks . push ( id ) ; bs . moveItem ( id , bs . toolbarFolder , 0 ) ; info ( "*** Acting on unsorted bookmarks" ) ; id = bs . insertBookmark ( bs . unfiledBookmarksFolder , PlacesUtils . _uri ( "http://ub1.mozilla.org/" ) , bs . DEFAULT_INDEX , "ub1" ) ; bs . setItemTitle ( id , "ub1_edited" ) ; addedBookmarks . push ( id ) ; id = bs . insertBookmark ( bs . unfiledBookmarksFolder , PlacesUtils . _uri ( "place:" ) , bs . DEFAULT_INDEX , "ub2" ) ; bs . setItemTitle ( id , "ub2_edited" ) ; addedBookmarks . push ( id ) ; id = bs . insertSeparator ( bs . unfiledBookmarksFolder , bs . DEFAULT_INDEX ) ; addedBookmarks . push ( id ) ; id = bs . createFolder ( bs . unfiledBookmarksFolder , "ubf" , bs . DEFAULT_INDEX ) ; bs . setItemTitle ( id , "ubf_edited" ) ; addedBookmarks . push ( id ) ; id = bs . insertBookmark ( id , PlacesUtils . _uri ( "http://ubf1.mozilla.org/" ) , bs . DEFAULT_INDEX , "bubf1" ) ; bs . setItemTitle ( id , "bubf1_edited" ) ; addedBookmarks . push ( id ) ; bs . moveItem ( id , bs . unfiledBookmarksFolder , 0 ) ; addedBookmarks . forEach ( function ( aItem ) { try { bs . removeItem ( aItem ) ; } catch ( ex ) { } } ) ; bs . removeObserver ( bookmarksObserver ) ; PlacesUtils . annotations . removeObserver ( bookmarksObserver ) ; finishTest ( ) ; }
Adds bookmarks observer, and executes a bunch of bookmarks operations.
Adds bookmarks observer and executes a bunch of bookmarks operations .
// Add observers. // MENU // TOOLBAR // Test live update of title. // UNSORTED // Remove all added bookmarks. // If we remove an item after its containing folder has been removed, // this will throw, but we can ignore that. // Remove observers.