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
--- 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") {