Use a batch in head_queries.js and dump table in case of failures (test_redirectsMode.js failure).
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 22 Oct 2010 18:43:12 +0200
changeset 59315 45655fe19c7fe27e3332ce904527bc5f5ee7bcc3
parent 59314 debf742b72653a995a3c53f2332135cafd9ab024
child 59316 b836e83fe06134853c6120c9380bde0fd696ba15
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
milestone2.0b8pre
Use a batch in head_queries.js and dump table in case of failures (test_redirectsMode.js failure). a=perma-orange
toolkit/components/places/tests/queries/head_queries.js
--- a/toolkit/components/places/tests/queries/head_queries.js
+++ b/toolkit/components/places/tests/queries/head_queries.js
@@ -64,195 +64,201 @@ const futureday = today + (DAY_MICROSEC 
 
 
 /**
  * Generalized function to pull in an array of objects of data and push it into
  * the database. It does NOT do any checking to see that the input is
  * appropriate.
  */
 function populateDB(aArray) {
-  aArray.forEach(function(data) {
-    dump_table("moz_bookmarks");
-    try {
-      // make the data object into a query data object in order to create proper
-      // default values for anything left unspecified
-      var qdata = new queryData(data);
-      if (qdata.isVisit) {
-        // Then we should add a visit for this node
-        var referrer = qdata.referrer ? uri(qdata.referrer) : null;
-        var visitId = PlacesUtils.history.addVisit(uri(qdata.uri), qdata.lastVisit,
-                                                   referrer, qdata.transType,
-                                                   qdata.isRedirect, qdata.sessionID);
-        do_check_true(visitId > 0);
-        if (qdata.title && !qdata.isDetails) {
-          // Set the page title synchronously, otherwise setPageTitle is LAZY.
-          let stmt = DBConn().createStatement(
-            "UPDATE moz_places SET title = :title WHERE url = :url"
-          );
-          stmt.params.title = qdata.title;
-          stmt.params.url = qdata.uri;
-          try {
-            stmt.execute();
-            // Force a notification so results are updated.
-            PlacesUtils.history.runInBatchMode({runBatched: function(){}}, null);
-          }
-          finally {
-            stmt.finalize();
-          }
-        }
-        if (qdata.visitCount && !qdata.isDetails) {
-          // Set a fake visit_count, this is not a real count but can be used
-          // to test sorting by visit_count.
-          let stmt = DBConn().createStatement(
-            "UPDATE moz_places SET visit_count = :vc WHERE url = :url");
-          stmt.params.vc = qdata.visitCount;
-          stmt.params.url = qdata.uri;
-          try {
-            stmt.execute();
-            // Force a notification so results are updated.
-            PlacesUtils.history.runInBatchMode({runBatched: function(){}}, null);
+  PlacesUtils.history.runInBatchMode({
+    runBatched: function (aUserData)
+    {
+      aArray.forEach(function (data)
+      {
+        try {
+          // make the data object into a query data object in order to create proper
+          // default values for anything left unspecified
+          var qdata = new queryData(data);
+          if (qdata.isVisit) {
+            // Then we should add a visit for this node
+            var referrer = qdata.referrer ? uri(qdata.referrer) : null;
+            var visitId = PlacesUtils.history.addVisit(uri(qdata.uri), qdata.lastVisit,
+                                                       referrer, qdata.transType,
+                                                       qdata.isRedirect, qdata.sessionID);
+            if (qdata.title && !qdata.isDetails) {
+              // Set the page title synchronously, otherwise setPageTitle is LAZY.
+              let stmt = DBConn().createStatement(
+                "UPDATE moz_places SET title = :title WHERE url = :url"
+              );
+              stmt.params.title = qdata.title;
+              stmt.params.url = qdata.uri;
+              try {
+                stmt.execute();
+              }
+              catch (ex) {
+                print("Error while setting title.");
+              }
+              finally {
+                stmt.finalize();
+              }
+            }
+            if (qdata.visitCount && !qdata.isDetails) {
+              // Set a fake visit_count, this is not a real count but can be used
+              // to test sorting by visit_count.
+              let stmt = DBConn().createStatement(
+                "UPDATE moz_places SET visit_count = :vc WHERE url = :url");
+              stmt.params.vc = qdata.visitCount;
+              stmt.params.url = qdata.uri;
+              try {
+                stmt.execute();
+              }
+              catch (ex) {
+                print("Error while setting visit_count.");
+              }
+              finally {
+                stmt.finalize();
+              }
+            }
           }
-          finally {
-            stmt.finalize();
+
+          if (qdata.isDetails) {
+            // Then we add extraneous page details for testing
+            PlacesUtils.history.addPageWithDetails(uri(qdata.uri),
+                                                   qdata.title, qdata.lastVisit);
           }
-        }
-      }
 
-      if (qdata.isDetails) {
-        // Then we add extraneous page details for testing
-        PlacesUtils.history.addPageWithDetails(uri(qdata.uri),
-                                               qdata.title, qdata.lastVisit);
-      }
+          if (qdata.markPageAsTyped){
+            PlacesUtils.bhistory.markPageAsTyped(uri(qdata.uri));
+          }
 
-      if (qdata.markPageAsTyped){
-        PlacesUtils.bhistory.markPageAsTyped(uri(qdata.uri));
-      }
-
-      if (qdata.hidePage){
-        PlacesUtils.bhistory.hidePage(uri(qdata.uri));
-      }
+          if (qdata.hidePage){
+            PlacesUtils.bhistory.hidePage(uri(qdata.uri));
+          }
 
-      if (qdata.isPageAnnotation) {
-        if (qdata.removeAnnotation) 
-          PlacesUtils.annotations.removePageAnnotation(uri(qdata.uri),
-                                                       qdata.annoName);
-        else {
-          PlacesUtils.annotations.setPageAnnotation(uri(qdata.uri),
-                                                    qdata.annoName,
-                                                    qdata.annoVal,
-                                                    qdata.annoFlags,
-                                                    qdata.annoExpiration);
-        }
-      }
+          if (qdata.isPageAnnotation) {
+            if (qdata.removeAnnotation) 
+              PlacesUtils.annotations.removePageAnnotation(uri(qdata.uri),
+                                                           qdata.annoName);
+            else {
+              PlacesUtils.annotations.setPageAnnotation(uri(qdata.uri),
+                                                        qdata.annoName,
+                                                        qdata.annoVal,
+                                                        qdata.annoFlags,
+                                                        qdata.annoExpiration);
+            }
+          }
 
-      if (qdata.isItemAnnotation) {
-        if (qdata.removeAnnotation)
-          PlacesUtils.annotations.removeItemAnnotation(qdata.itemId,
-                                                       qdata.annoName);
-        else {
-          PlacesUtils.annotations.setItemAnnotation(qdata.itemId,
-                                                    qdata.annoName,
-                                                    qdata.annoVal,
-                                                    qdata.annoFlags,
-                                                    qdata.annoExpiration);
-        }
-      }
+          if (qdata.isItemAnnotation) {
+            if (qdata.removeAnnotation)
+              PlacesUtils.annotations.removeItemAnnotation(qdata.itemId,
+                                                           qdata.annoName);
+            else {
+              PlacesUtils.annotations.setItemAnnotation(qdata.itemId,
+                                                        qdata.annoName,
+                                                        qdata.annoVal,
+                                                        qdata.annoFlags,
+                                                        qdata.annoExpiration);
+            }
+          }
 
-      if (qdata.isPageBinaryAnnotation) {
-        if (qdata.removeAnnotation)
-          PlacesUtils.annotations.removePageAnnotation(uri(qdata.uri),
-                                                       qdata.annoName);
-        else {
-          PlacesUtils.annotations.setPageAnnotationBinary(uri(qdata.uri),
-                                                          qdata.annoName,
-                                                          qdata.binarydata,
-                                                          qdata.binaryDataLength,
-                                                          qdata.annoMimeType,
-                                                          qdata.annoFlags,
-                                                          qdata.annoExpiration);
-        }
-      }
+          if (qdata.isPageBinaryAnnotation) {
+            if (qdata.removeAnnotation)
+              PlacesUtils.annotations.removePageAnnotation(uri(qdata.uri),
+                                                           qdata.annoName);
+            else {
+              PlacesUtils.annotations.setPageAnnotationBinary(uri(qdata.uri),
+                                                              qdata.annoName,
+                                                              qdata.binarydata,
+                                                              qdata.binaryDataLength,
+                                                              qdata.annoMimeType,
+                                                              qdata.annoFlags,
+                                                              qdata.annoExpiration);
+            }
+          }
 
-      if (qdata.isItemBinaryAnnotation) {
-        if (qdata.removeAnnotation)
-          PlacesUtils.annotations.removeItemAnnotation(qdata.itemId,
-                                                       qdata.annoName);
-        else {
-          PlacesUtils.annotations.setItemAnnotationBinary(qdata.itemId,
-                                                          qdata.annoName,
-                                                          qdata.binaryData,
-                                                          qdata.binaryDataLength,
-                                                          qdata.annoMimeType,
-                                                          qdata.annoFlags,
-                                                          qdata.annoExpiration);
-        }
-      }
+          if (qdata.isItemBinaryAnnotation) {
+            if (qdata.removeAnnotation)
+              PlacesUtils.annotations.removeItemAnnotation(qdata.itemId,
+                                                           qdata.annoName);
+            else {
+              PlacesUtils.annotations.setItemAnnotationBinary(qdata.itemId,
+                                                              qdata.annoName,
+                                                              qdata.binaryData,
+                                                              qdata.binaryDataLength,
+                                                              qdata.annoMimeType,
+                                                              qdata.annoFlags,
+                                                              qdata.annoExpiration);
+            }
+          }
 
-      if (qdata.isFavicon) {
-        // Not planning on doing deep testing of favIcon service so these two
-        // calls should be sufficient to get favicons into the database
-        try {
-          PlacesUtils.favicons.setFaviconData(uri(qdata.faviconURI),
-                                              qdata.favicon,
-                                              qdata.faviconLen,
-                                              qdata.faviconMimeType,
-                                              qdata.faviconExpiration);
-        } catch (ex) {}
-        PlacesUtils.favicons.setFaviconUrlForPage(uri(qdata.uri),
-                                                  uri(qdata.faviconURI));
-      }
+          if (qdata.isFavicon) {
+            // Not planning on doing deep testing of favIcon service so these two
+            // calls should be sufficient to get favicons into the database
+            try {
+              PlacesUtils.favicons.setFaviconData(uri(qdata.faviconURI),
+                                                  qdata.favicon,
+                                                  qdata.faviconLen,
+                                                  qdata.faviconMimeType,
+                                                  qdata.faviconExpiration);
+            } catch (ex) {}
+            PlacesUtils.favicons.setFaviconUrlForPage(uri(qdata.uri),
+                                                      uri(qdata.faviconURI));
+          }
 
-      if (qdata.isFolder) {
-        let folderId = PlacesUtils.bookmarks.createFolder(qdata.parentFolder,
-                                                          qdata.title,
-                                                          qdata.index);
-        if (qdata.readOnly)
-          PlacesUtils.bookmarks.setFolderReadonly(folderId, true);
-      }
+          if (qdata.isFolder) {
+            let folderId = PlacesUtils.bookmarks.createFolder(qdata.parentFolder,
+                                                              qdata.title,
+                                                              qdata.index);
+            if (qdata.readOnly)
+              PlacesUtils.bookmarks.setFolderReadonly(folderId, true);
+          }
 
-      if (qdata.isLivemark) {
-        PlacesUtils.livemarks.createLivemark(qdata.parentFolder,
-                                             qdata.title,
-                                             uri(qdata.uri),
-                                             uri(qdata.feedURI),
-                                             qdata.index);
-      }
+          if (qdata.isLivemark) {
+            PlacesUtils.livemarks.createLivemark(qdata.parentFolder,
+                                                 qdata.title,
+                                                 uri(qdata.uri),
+                                                 uri(qdata.feedURI),
+                                                 qdata.index);
+          }
 
-      if (qdata.isBookmark) {
-        let itemId = PlacesUtils.bookmarks.insertBookmark(qdata.parentFolder,
-                                                          uri(qdata.uri),
-                                                          qdata.index,
-                                                          qdata.title);
-        if (qdata.keyword)
-          PlacesUtils.bookmarks.setKeywordForBookmark(itemId, qdata.keyword);
-        if (qdata.dateAdded)
-          PlacesUtils.bookmarks.setItemDateAdded(itemId, qdata.dateAdded);
-        if (qdata.lastModified)
-          PlacesUtils.bookmarks.setItemLastModified(itemId, qdata.lastModified);
-      }
+          if (qdata.isBookmark) {
+            let itemId = PlacesUtils.bookmarks.insertBookmark(qdata.parentFolder,
+                                                              uri(qdata.uri),
+                                                              qdata.index,
+                                                              qdata.title);
+            if (qdata.keyword)
+              PlacesUtils.bookmarks.setKeywordForBookmark(itemId, qdata.keyword);
+            if (qdata.dateAdded)
+              PlacesUtils.bookmarks.setItemDateAdded(itemId, qdata.dateAdded);
+            if (qdata.lastModified)
+              PlacesUtils.bookmarks.setItemLastModified(itemId, qdata.lastModified);
+          }
+
+          if (qdata.isTag) {
+            PlacesUtils.tagging.tagURI(uri(qdata.uri), qdata.tagArray);
+          }
 
-      if (qdata.isTag) {
-        PlacesUtils.tagging.tagURI(uri(qdata.uri), qdata.tagArray);
-      }
+          if (qdata.isDynContainer) {
+            PlacesUtils.bookmarks.createDynamicContainer(qdata.parentFolder,
+                                                         qdata.title,
+                                                         qdata.contractId,
+                                                         qdata.index);
+          }
 
-      if (qdata.isDynContainer) {
-        PlacesUtils.bookmarks.createDynamicContainer(qdata.parentFolder,
-                                                     qdata.title,
-                                                     qdata.contractId,
-                                                     qdata.index);
-      }
-
-      if (qdata.isSeparator)
-        PlacesUtils.bookmarks.insertSeparator(qdata.parentFolder, qdata.index);
-    } catch (ex) {
-      // use the data object here in case instantiation of qdata failed
-      LOG("Problem with this URI: " + data.uri);
-      do_throw("Error creating database: " + ex + "\n");
+          if (qdata.isSeparator)
+            PlacesUtils.bookmarks.insertSeparator(qdata.parentFolder, qdata.index);
+        } catch (ex) {
+          // use the data object here in case instantiation of qdata failed
+          LOG("Problem with this URI: " + data.uri);
+          do_throw("Error creating database: " + ex + "\n");
+        }
+      }); // End of function and array
     }
-  }); // End of function and array
+  }, null);
 }
 
 
 /**
  * The Query Data Object - this object encapsulates data for our queries and is
  * used to parameterize our calls to the Places APIs to put data into the
  * database. It also has some interesting meta functions to determine which APIs
  * should be called, and to determine if this object should show up in the
@@ -340,18 +346,20 @@ function compareArrayToResult(aArray, aR
 
   var inQueryIndex = 0;
   for (var i = 0; i < aArray.length; i++) {
     if (aArray[i].isInQuery) {
       var child = aRoot.getChild(inQueryIndex);
       LOG("testing testData[" + i + "] vs result[" + inQueryIndex + "]");
       if (!aArray[i].isFolder && !aArray[i].isSeparator) {
         LOG("testing testData[" + aArray[i].uri + "] vs result[" + child.uri + "]");
-        if (aArray[i].uri != child.uri)
+        if (aArray[i].uri != child.uri) {
+          dump_table("moz_places");
           do_throw("Expected " + aArray[i].uri + " found " + child.uri);
+        }
       }
       if (!aArray[i].isSeparator && aArray[i].title != child.title)
         do_throw("Expected " + aArray[i].title + " found " + child.title);
       if (aArray[i].hasOwnProperty("lastVisit") &&
           aArray[i].lastVisit != child.time)
         do_throw("Expected " + aArray[i].lastVisit + " found " + child.time);
       if (aArray[i].hasOwnProperty("index") &&
           aArray[i].index != PlacesUtils.bookmarks.DEFAULT_INDEX &&