Bug 1371919 - Fix Intermittent browser/components/extensions/test/browser/browser_ext_browsingData_history.js, r?mixedpuppy draft
authorBob Silverberg <bsilverberg@mozilla.com>
Mon, 30 Oct 2017 11:37:31 -0400
changeset 688723 b1f8f6b2e89ffab26904c2375f76c2caafed1a2c
parent 688663 1c618b1a13662de7cec429f606367db3827b6dc7
child 738147 94b83ce6e54647949f098b8ce1f6da028e8d976f
push id86832
push userbmo:bob.silverberg@gmail.com
push dateMon, 30 Oct 2017 15:38:00 +0000
reviewersmixedpuppy
bugs1371919
milestone58.0a1
Bug 1371919 - Fix Intermittent browser/components/extensions/test/browser/browser_ext_browsingData_history.js, r?mixedpuppy I spoke to Marco about this and it turns out the problem is due to using PlacesUtils.history.insertMany together with PlacesTestUtils.visitsInDB. Calling the former to insert the visits and then immediately calling the latter to verify them can result in the latter reading a snapshot of the places DB that is not up to date. The fix is to call PlacesTestUtils.addVisits which will not return until everything is finished up and will therefore not cause PlacesTestUtils.visitsInDB to possibly read an old snapshot. MozReview-Commit-ID: GebqORQI0Co
browser/components/extensions/test/browser/browser_ext_browsingData_history.js
--- a/browser/components/extensions/test/browser/browser_ext_browsingData_history.js
+++ b/browser/components/extensions/test/browser/browser_ext_browsingData_history.js
@@ -6,38 +6,38 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://testing-common/PlacesTestUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
 
 const OLD_URL = "http://example.com/";
 const RECENT_URL = "http://example.com/2/";
 const REFERENCE_DATE = new Date();
 
-// pages/visits to add via History.insert
-const PAGE_INFOS = [
+// Visits to add via addVisits
+const PLACEINFO = [
   {
-    url: RECENT_URL,
+    uri: RECENT_URL,
     title: `test visit for ${RECENT_URL}`,
-    visits: [
-      {date: REFERENCE_DATE},
-    ],
+    visitDate: REFERENCE_DATE,
   },
   {
-    url: OLD_URL,
+    uri: OLD_URL,
     title: `test visit for ${OLD_URL}`,
-    visits: [
-      {date: new Date(Number(REFERENCE_DATE) - 1000)},
-      {date: new Date(Number(REFERENCE_DATE) - 2000)},
-    ],
+    visitDate: new Date(Number(REFERENCE_DATE) - 1000),
+  },
+  {
+    uri: OLD_URL,
+    title: `test visit for ${OLD_URL}`,
+    visitDate: new Date(Number(REFERENCE_DATE) - 2000),
   },
 ];
 
 async function setupHistory() {
-  await PlacesTestUtils.clearHistory();
-  await PlacesUtils.history.insertMany(PAGE_INFOS);
+  await PlacesUtils.history.clear();
+  await PlacesTestUtils.addVisits(PLACEINFO);
   is((await PlacesTestUtils.visitsInDB(RECENT_URL)), 1, "Expected number of visits found in history database.");
   is((await PlacesTestUtils.visitsInDB(OLD_URL)), 2, "Expected number of visits found in history database.");
 }
 
 add_task(async function testHistory() {
   function background() {
     browser.test.onMessage.addListener(async (msg, options) => {
       if (msg == "removeHistory") {