Bug 682443 - dump the bookmark list on bookmark test failure, a=testonly, DONTBUILD
authorJonathan Griffin <jgriffin@mozilla.com>
Wed, 07 Sep 2011 17:34:27 -0700
changeset 76751 05c913f50c3e967da2acdcceb13013795627114c
parent 76750 cd782e4f3a1bddcacd16113cf4c1336b6f4de382
child 76752 41a6dc9025cb67e258aa2cb9f2238d4a9ae98873
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerstestonly, DONTBUILD
bugs682443
milestone9.0a1
Bug 682443 - dump the bookmark list on bookmark test failure, a=testonly, DONTBUILD
services/sync/tps/extensions/tps/modules/bookmarks.jsm
services/sync/tps/extensions/tps/modules/tps.jsm
--- a/services/sync/tps/extensions/tps/modules/bookmarks.jsm
+++ b/services/sync/tps/extensions/tps/modules/bookmarks.jsm
@@ -36,26 +36,46 @@
  * ***** END LICENSE BLOCK ***** */
 
  /* This is a JavaScript module (JSM) to be imported via 
   * Components.utils.import() and acts as a singleton. Only the following 
   * listed symbols will exposed on import, and only when and where imported.
   */
 
 var EXPORTED_SYMBOLS = ["PlacesItem", "Bookmark", "Separator", "Livemark",
-                        "BookmarkFolder"];
+                        "BookmarkFolder", "DumpBookmarks"];
 
 const CC = Components.classes;
 const CI = Components.interfaces;
 const CU = Components.utils;
 
 CU.import("resource://tps/logger.jsm");
 CU.import("resource://gre/modules/Services.jsm");
 CU.import("resource://gre/modules/PlacesUtils.jsm");
 
+
+var DumpBookmarks = function TPS_Bookmarks__DumpBookmarks() {
+  let writer = {
+    value: "",
+    write: function PlacesItem__dump__write(aStr, aLen) {
+      this.value += aStr;
+    }
+  };
+
+  let options = PlacesUtils.history.getNewQueryOptions();
+  options.queryType = options.QUERY_TYPE_BOOKMARKS;
+  let query = PlacesUtils.history.getNewQuery();
+  query.setFolders([PlacesUtils.placesRootId], 1);
+  let root = PlacesUtils.history.executeQuery(query, options).root;
+  root.containerOpen = true;
+  PlacesUtils.serializeNodeAsJSONToOutputStream(root, writer, true, false);
+  let value = JSON.parse(writer.value);
+  Logger.logInfo("dumping bookmarks\n\n" + JSON.stringify(value, null, ' ') + "\n\n");
+};
+
 /**
  * extend, causes a child object to inherit from a parent
  */
 function extend(child, supertype)
 {
    child.prototype.__proto__ = supertype.prototype;
 }
 
--- a/services/sync/tps/extensions/tps/modules/tps.jsm
+++ b/services/sync/tps/extensions/tps/modules/tps.jsm
@@ -337,74 +337,80 @@ var TPS =
           Logger.AssertTrue(false, "invalid action: " + action);
       } 
     }
     Logger.logPass("executing action " + action.toUpperCase() + 
                    " on passwords");
   },
 
   HandleBookmarks: function (bookmarks, action) {
-    let items = [];
-    for (folder in bookmarks) {
-      let last_item_pos = -1;
-      for each (bookmark in bookmarks[folder]) {
-        Logger.clearPotentialError();
-        let placesItem;
-        bookmark['location'] = folder;
-        if (last_item_pos != -1)
-          bookmark['last_item_pos'] = last_item_pos;
-        let item_id = -1;
-        if (action != ACTION_MODIFY && action != ACTION_DELETE)
-          Logger.logInfo("executing action " + action.toUpperCase() + 
-                         " on bookmark " + JSON.stringify(bookmark));
-        if ("uri" in bookmark)
-          placesItem = new Bookmark(bookmark);
-        else if ("folder" in bookmark)
-          placesItem = new BookmarkFolder(bookmark);
-        else if ("livemark" in bookmark)
-          placesItem = new Livemark(bookmark);
-        else if ("separator" in bookmark)
-          placesItem = new Separator(bookmark);
-        if (action == ACTION_ADD) {
-          item_id = placesItem.Create();
-        }
-        else {
-          item_id = placesItem.Find();
-          if (action == ACTION_VERIFY_NOT) {
-            Logger.AssertTrue(item_id == -1,
-              "places item exists but it shouldn't: " +
-              JSON.stringify(bookmark));
+    try {
+      let items = [];
+      for (folder in bookmarks) {
+        let last_item_pos = -1;
+        for each (bookmark in bookmarks[folder]) {
+          Logger.clearPotentialError();
+          let placesItem;
+          bookmark['location'] = folder;
+          if (last_item_pos != -1)
+            bookmark['last_item_pos'] = last_item_pos;
+          let item_id = -1;
+          if (action != ACTION_MODIFY && action != ACTION_DELETE)
+            Logger.logInfo("executing action " + action.toUpperCase() + 
+                           " on bookmark " + JSON.stringify(bookmark));
+          if ("uri" in bookmark)
+            placesItem = new Bookmark(bookmark);
+          else if ("folder" in bookmark)
+            placesItem = new BookmarkFolder(bookmark);
+          else if ("livemark" in bookmark)
+            placesItem = new Livemark(bookmark);
+          else if ("separator" in bookmark)
+            placesItem = new Separator(bookmark);
+          if (action == ACTION_ADD) {
+            item_id = placesItem.Create();
           }
-          else
-            Logger.AssertTrue(item_id != -1, "places item not found", true);
-        }
-        
-        last_item_pos = placesItem.GetItemIndex();
-        items.push(placesItem);
-      }
-    }
-
-    if (action == ACTION_DELETE || action == ACTION_MODIFY) {
-      for each (item in items) {
-        Logger.logInfo("executing action " + action.toUpperCase() + 
-                       " on bookmark " + JSON.stringify(item));
-        switch(action) {
-          case ACTION_DELETE:
-            item.Remove();
-            break;
-          case ACTION_MODIFY:
-            if (item.updateProps != null)
-              item.Update();
-            break;
+          else {
+            item_id = placesItem.Find();
+            if (action == ACTION_VERIFY_NOT) {
+              Logger.AssertTrue(item_id == -1,
+                "places item exists but it shouldn't: " +
+                JSON.stringify(bookmark));
+            }
+            else
+              Logger.AssertTrue(item_id != -1, "places item not found", true);
+          }
+          
+          last_item_pos = placesItem.GetItemIndex();
+          items.push(placesItem);
         }
       }
-    }
 
-    Logger.logPass("executing action " + action.toUpperCase() +
-      " on bookmarks");
+      if (action == ACTION_DELETE || action == ACTION_MODIFY) {
+        for each (item in items) {
+          Logger.logInfo("executing action " + action.toUpperCase() + 
+                         " on bookmark " + JSON.stringify(item));
+          switch(action) {
+            case ACTION_DELETE:
+              item.Remove();
+              break;
+            case ACTION_MODIFY:
+              if (item.updateProps != null)
+                item.Update();
+              break;
+          }
+        }
+      }
+
+      Logger.logPass("executing action " + action.toUpperCase() +
+        " on bookmarks");
+    }
+    catch(e) {
+      DumpBookmarks();
+      throw(e);
+    }
   },
 
   MozmillEndTestListener: function TPS__MozmillEndTestListener(obj) {
     Logger.logInfo("mozmill endTest: " + JSON.stringify(obj));
     if (obj.failed > 0) {
       this.DumpError('mozmill test failed, name: ' + obj.name + ', reason: ' + JSON.stringify(obj.fails));
       return;
     }