Bug 737846 - Ensure favicons service doesn't add unwanted pages to history.
authorMarco Bonardo <mbonardo@mozilla.com>
Tue, 27 Mar 2012 15:28:14 +0200
changeset 26414 402bd042872310b6cd5f943f3d631a8e17826cf7
parent 26413 18bdca83f0373277586500bf86aa1ab57aa98e75
child 26415 fc967da87da352b957e0d96286bdd9c7944dc241
push id1834
push userclokep@gmail.com
push dateMon, 23 Jan 2017 21:48:40 +0000
treeherdercomm-beta@293cffe83e59 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs737846
Bug 737846 - Ensure favicons service doesn't add unwanted pages to history. r=dietrich
suite/common/places/tests/head_common.js
--- a/suite/common/places/tests/head_common.js
+++ b/suite/common/places/tests/head_common.js
@@ -865,8 +865,66 @@ NavHistoryResultObserver.prototype = {
   nodeTagsChanged: function () {},
   nodeTitleChanged: function () {},
   nodeURIChanged: function () {},
   sortingChanged: function () {},
   QueryInterface: XPCOMUtils.generateQI([
     Ci.nsINavHistoryResultObserver,
   ])
 };
+
+/**
+ * Asynchronously adds visits to a page, invoking a callback function when done.
+ *
+ * @param aPlaceInfo
+ *        Can be an nsIURI, in such a case a single LINK visit will be added.
+ *        Otherwise can be an object describing the visit to add, or an array
+ *        of these objects:
+ *          { uri: nsIURI of the page,
+ *            transition: one of the TRANSITION_* from nsINavHistoryService,
+ *            [optional] title: title of the page,
+ *            [optional] visitDate: visit date in microseconds from the epoch
+ *          }
+ * @param [optional] aCallback
+ *        Function to be invoked on completion.
+ * @param [optional] aStack
+ *        The stack frame used to report errors.
+ */
+function addVisits(aPlaceInfo, aCallback, aStack)
+{
+  let stack = aStack || Components.stack.caller;
+  let places = [];
+  if (aPlaceInfo instanceof Ci.nsIURI) {
+    places.push({ uri: aPlaceInfo });
+  }
+  else if (Array.isArray(aPlaceInfo)) {
+    places = places.concat(aPlaceInfo);
+  } else {
+    places.push(aPlaceInfo)
+  }
+
+  // Create mozIVisitInfo for each entry.
+  let now = Date.now();
+  for (let i = 0; i < places.length; i++) {
+    if (!places[i].title) {
+      places[i].title = "test visit for " + places[i].uri.spec;
+    }
+    places[i].visits = [{
+      transitionType: places[i].transition === undefined ? TRANSITION_LINK
+                                                         : places[i].transition,
+      visitDate: places[i].visitDate || (now++) * 1000
+    }];
+  }
+
+  PlacesUtils.asyncHistory.updatePlaces(
+    places,
+    {
+      handleError: function AAV_handleError() {
+        do_throw("Unexpected error in adding visit.", stack);
+      },
+      handleResult: function () {},
+      handleCompletion: function UP_handleCompletion() {
+        if (aCallback)
+          aCallback();
+      }
+    }
+  );
+}