Bug 636924 - Part 2: test updates; r=mano
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 22 Mar 2011 10:56:19 -0400
changeset 63631 8a61e8610d6684005e3db4ec97bf9c9e9779d82e
parent 63630 b6d89aa5c8c4610c6f970e99de844adbe18293f7
child 63632 e4a1143ddbdf9d587d396e6e38640d8c6ea1d934
push id19248
push usereakhgari@mozilla.com
push dateWed, 23 Mar 2011 23:19:35 +0000
treeherdermozilla-central@ab95ab9e389b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmano
bugs636924
milestone2.0b13pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 636924 - Part 2: test updates; r=mano
browser/components/places/tests/browser/browser_library_views_liveupdate.js
browser/components/places/tests/browser/browser_views_liveupdate.js
--- a/browser/components/places/tests/browser/browser_library_views_liveupdate.js
+++ b/browser/components/places/tests/browser/browser_library_views_liveupdate.js
@@ -73,18 +73,19 @@ function test() {
                 null);
 }
 
 /**
  * Adds bookmarks observer, and executes a bunch of bookmarks operations.
  */
 function startTest() {
   var bs = PlacesUtils.bookmarks;
-  // Add bookmarks observer.
+  // Add observers.
   bs.addObserver(bookmarksObserver, false);
+  PlacesUtils.annotations.addObserver(bookmarksObserver, false);
   var addedBookmarks = [];
 
   // MENU
   ok(true, "*** Acting on menu bookmarks");
   var id = bs.insertBookmark(bs.bookmarksMenuFolder,
                              PlacesUtils._uri("http://bm1.mozilla.org/"),
                              bs.DEFAULT_INDEX,
                              "bm1");
@@ -103,16 +104,21 @@ function startTest() {
   bs.setItemTitle(id, "bmf_edited");
   addedBookmarks.push(id);
   id = bs.insertBookmark(id,
                          PlacesUtils._uri("http://bmf1.mozilla.org/"),
                          bs.DEFAULT_INDEX,
                          "bmf1");
   addedBookmarks.push(id);
   bs.moveItem(id, bs.bookmarksMenuFolder, 0);
+  id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+    bs.bookmarksMenuFolder, "bml",
+    PlacesUtils._uri("http://bml.siteuri.mozilla.org/"),
+    PlacesUtils._uri("http://bml.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+  addedBookmarks.push(id);
 
   // TOOLBAR
   ok(true, "*** Acting on toolbar bookmarks");
   bs.insertBookmark(bs.toolbarFolder,
                     PlacesUtils._uri("http://tb1.mozilla.org/"),
                     bs.DEFAULT_INDEX,
                     "tb1");
   bs.setItemTitle(id, "tb1_edited");
@@ -131,16 +137,20 @@ function startTest() {
   bs.setItemTitle(id, "tbf_edited");
   addedBookmarks.push(id);
   id = bs.insertBookmark(id,
                          PlacesUtils._uri("http://tbf1.mozilla.org/"),
                          bs.DEFAULT_INDEX,
                          "bmf1");
   addedBookmarks.push(id);
   bs.moveItem(id, bs.toolbarFolder, 0);
+  id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+    bs.toolbarFolder, "tbl", PlacesUtils._uri("http://tbl.siteuri.mozilla.org/"),
+    PlacesUtils._uri("http://tbl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+  addedBookmarks.push(id);
 
   // UNSORTED
   ok(true, "*** Acting on unsorted bookmarks");
   id = bs.insertBookmark(bs.unfiledBookmarksFolder,
                          PlacesUtils._uri("http://ub1.mozilla.org/"),
                          bs.DEFAULT_INDEX,
                          "ub1");
   bs.setItemTitle(id, "ub1_edited");
@@ -159,28 +169,34 @@ function startTest() {
   bs.setItemTitle(id, "ubf_edited");
   addedBookmarks.push(id);
   id = bs.insertBookmark(id,
                          PlacesUtils._uri("http://ubf1.mozilla.org/"),
                          bs.DEFAULT_INDEX,
                          "ubf1");
   addedBookmarks.push(id);
   bs.moveItem(id, bs.unfiledBookmarksFolder, 0);
+  id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+    bs.unfiledBookmarksFolder, "bubl",
+    PlacesUtils._uri("http://bubl.siteuri.mozilla.org/"),
+    PlacesUtils._uri("http://bubl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+  addedBookmarks.push(id);
 
   // Remove all added bookmarks.
   addedBookmarks.forEach(function (aItem) {
     // If we remove an item after its containing folder has been removed,
     // this will throw, but we can ignore that.
     try {
       bs.removeItem(aItem);
     } catch (ex) {}
   });
 
-  // Remove bookmarks observer.
+  // Remove observers.
   bs.removeObserver(bookmarksObserver);
+  PlacesUtils.annotations.removeObserver(bookmarksObserver);
   finishTest();
 }
 
 /**
  * Restores browser state and calls finish.
  */
 function finishTest() {
   // Close Library window.
@@ -188,22 +204,46 @@ function finishTest() {
   finish();
 }
 
 /**
  * The observer is where magic happens, for every change we do it will look for
  * nodes positions in the affected views.
  */
 var bookmarksObserver = {
-  QueryInterface: function PSB_QueryInterface(aIID) {
-    if (aIID.equals(Ci.nsINavBookmarkObserver) ||
-        aIID.equals(Ci.nsISupports))
-      return this;
-    throw Cr.NS_NOINTERFACE;
+  QueryInterface: XPCOMUtils.generateQI([
+    Ci.nsINavBookmarkObserver
+  , Ci.nsIAnnotationObserver
+  ]),
+
+  // nsIAnnotationObserver
+  onItemAnnotationSet: function(aItemId, aAnnotationName) {
+    if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
+      // Check that item is recognized as a livemark.
+      let validator = function(aTreeRowIndex) {
+        let tree = gLibrary.PlacesOrganizer._places;
+        let livemarkAtom = Cc["@mozilla.org/atom-service;1"].
+                           getService(Ci.nsIAtomService).
+                           getAtom("livemark");
+        let properties = Cc["@mozilla.org/supports-array;1"].
+                         createInstance(Ci.nsISupportsArray);
+        tree.view.getCellProperties(aTreeRowIndex,
+                                    tree.columns.getColumnAt(0),
+                                    properties);
+        return properties.GetIndexOf(livemarkAtom) != -1;
+      };
+
+      var [node, index, valid] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places, validator);
+      isnot(node, null, "Found new Places node in left pane at " + index);
+      ok(valid, "Node is recognized as a livemark");
+    }
   },
+  onItemAnnotationRemoved: function() {},
+  onPageAnnotationSet: function() {},
+  onPageAnnotationRemoved: function() {},
 
   // nsINavBookmarkObserver
   onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex, aItemType,
                                         aURI) {
     var node = null;
     var index = null;
     [node, index] = getNodeForTreeItem(aItemId, gLibrary.PlacesOrganizer._places);
     // Left pane should not be updated for normal bookmarks or separators.
--- a/browser/components/places/tests/browser/browser_views_liveupdate.js
+++ b/browser/components/places/tests/browser/browser_views_liveupdate.js
@@ -80,18 +80,19 @@ function fakeOpenPopup(aPopup) {
   aPopup.dispatchEvent(popupEvent);  
 }
 
 /**
  * Adds bookmarks observer, and executes a bunch of bookmarks operations.
  */
 function startTest() {
   var bs = PlacesUtils.bookmarks;
-  // Add bookmarks observer.
+  // Add observers.
   bs.addObserver(bookmarksObserver, false);
+  PlacesUtils.annotations.addObserver(bookmarksObserver, false);
   var addedBookmarks = [];
 
   // MENU
   info("*** Acting on menu bookmarks");
   var id = bs.insertBookmark(bs.bookmarksMenuFolder,
                              PlacesUtils._uri("http://bm1.mozilla.org/"),
                              bs.DEFAULT_INDEX,
                              "bm1");
@@ -112,16 +113,21 @@ function startTest() {
   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);
+  id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+    bs.bookmarksMenuFolder, "bml",
+    PlacesUtils._uri("http://bml.siteuri.mozilla.org/"),
+    PlacesUtils._uri("http://bml.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+  addedBookmarks.push(id);
 
   // TOOLBAR
   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");
@@ -143,16 +149,20 @@ function startTest() {
   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);
+  id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+    bs.toolbarFolder, "tbl", PlacesUtils._uri("http://tbl.siteuri.mozilla.org/"),
+    PlacesUtils._uri("http://tbl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+  addedBookmarks.push(id);
 
   // UNSORTED
   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");
@@ -172,28 +182,34 @@ function startTest() {
   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);
+  id = PlacesUtils.livemarks.createLivemarkFolderOnly(
+    bs.unfiledBookmarksFolder, "bubl",
+    PlacesUtils._uri("http://bubl.siteuri.mozilla.org/"),
+    PlacesUtils._uri("http://bubl.feeduri.mozilla.org/"), bs.DEFAULT_INDEX);
+  addedBookmarks.push(id);
 
   // Remove all added bookmarks.
   addedBookmarks.forEach(function (aItem) {
     // If we remove an item after its containing folder has been removed,
     // this will throw, but we can ignore that.
     try {
       bs.removeItem(aItem);
     } catch (ex) {}
   });
 
-  // Remove bookmarks observer.
+  // Remove observers.
   bs.removeObserver(bookmarksObserver);
+  PlacesUtils.annotations.removeObserver(bookmarksObserver);
   finishTest();
 }
 
 /**
  * Restores browser state and calls finish.
  */
 function finishTest() {
   // Close bookmarks sidebar.
@@ -206,22 +222,57 @@ function finishTest() {
   finish();
 }
 
 /**
  * The observer is where magic happens, for every change we do it will look for
  * nodes positions in the affected views.
  */
 var bookmarksObserver = {
-  QueryInterface: function PSB_QueryInterface(aIID) {
-    if (aIID.equals(Ci.nsINavBookmarkObserver) ||
-        aIID.equals(Ci.nsISupports))
-      return this;
-    throw Cr.NS_NOINTERFACE;
+  QueryInterface: XPCOMUtils.generateQI([
+    Ci.nsINavBookmarkObserver
+  , Ci.nsIAnnotationObserver
+  ]),
+
+  // nsIAnnotationObserver
+  onItemAnnotationSet: function(aItemId, aAnnotationName) {
+    if (aAnnotationName == PlacesUtils.LMANNO_FEEDURI) {
+      var views = getViewsForFolder(PlacesUtils.bookmarks.getFolderIdForItem(aItemId));
+      ok(views.length > 0, "Found affected views (" + views.length + "): " + views);
+
+      // Check that item is recognized as a livemark.
+      let validator = function(aElementOrTreeIndex) {
+        if (typeof(aElementOrTreeIndex) == "number") {
+          var sidebar = document.getElementById("sidebar");
+          var tree = sidebar.contentDocument.getElementById("bookmarks-view");
+          let livemarkAtom = Cc["@mozilla.org/atom-service;1"].
+                             getService(Ci.nsIAtomService).
+                             getAtom("livemark");
+          let properties = Cc["@mozilla.org/supports-array;1"].
+                           createInstance(Ci.nsISupportsArray);
+          tree.view.getCellProperties(aElementOrTreeIndex,
+                                      tree.columns.getColumnAt(0),
+                                      properties);
+          return properties.GetIndexOf(livemarkAtom) != -1;
+        }
+        else {
+          return aElementOrTreeIndex.hasAttribute("livemark");
+        }
+      };
+
+      for (var i = 0; i < views.length; i++) {
+        var [node, index, valid] = searchItemInView(aItemId, views[i], validator);
+        isnot(node, null, "Found new Places node in " + views[i] + " at " + index);
+        ok(valid, "Node is recognized as a livemark");
+      }
+    }
   },
+  onItemAnnotationRemoved: function() {},
+  onPageAnnotationSet: function() {},
+  onPageAnnotationRemoved: function() {},
 
   // nsINavBookmarkObserver
   onItemAdded: function PSB_onItemAdded(aItemId, aFolderId, aIndex,
                                         aItemType, aURI) {
     var views = getViewsForFolder(aFolderId);
     ok(views.length > 0, "Found affected views (" + views.length + "): " + views);
 
     // Check that item has been added in the correct position.