Bug 1388149 - Make PlacesUtils.history.insertMany respect provided GUIDs r?markh
MozReview-Commit-ID: 7g6uABtHKg2
--- a/services/sync/tests/unit/test_history_store.js
+++ b/services/sync/tests/unit/test_history_store.js
@@ -132,16 +132,17 @@ add_task(async function test_store_creat
{id: tbguid,
histUri: tburi.spec,
title: "The bird is the word!",
visits: [{date: TIMESTAMP3,
type: Ci.nsINavHistoryService.TRANSITION_TYPED}]}
]);
await onVisitObserved;
try {
+ do_check_true((await store.itemExists(tbguid)));
do_check_attribute_count(await store.getAllIDs(), 2);
let queryres = queryHistoryVisits(tburi);
do_check_eq(queryres.length, 1);
do_check_eq(queryres[0].time, TIMESTAMP3);
do_check_eq(queryres[0].title, "The bird is the word!");
} catch (ex) {
PlacesTestUtils.clearHistory();
do_throw(ex);
--- a/toolkit/components/places/History.jsm
+++ b/toolkit/components/places/History.jsm
@@ -705,16 +705,17 @@ this.History = Object.freeze({
* Note: this assumes that the PageInfo object has already been validated
* via PlacesUtils.validatePageInfo.
*
* @param pageInfo: (PageInfo)
* @return (info)
*/
function convertForUpdatePlaces(pageInfo) {
let info = {
+ guid: pageInfo.guid,
uri: PlacesUtils.toURI(pageInfo.url),
title: pageInfo.title,
visits: [],
};
for (let inVisit of pageInfo.visits) {
let visit = {
visitDate: PlacesUtils.toPRTime(inVisit.date),
--- a/toolkit/components/places/tests/history/test_insertMany.js
+++ b/toolkit/components/places/tests/history/test_insertMany.js
@@ -140,8 +140,56 @@ add_task(async function test_transitions
await PlacesUtils.history.insertMany(places);
// Check callbacks.
let count = 0;
await PlacesUtils.history.insertMany(places, pageInfo => {
++count;
});
Assert.equal(count, Object.keys(PlacesUtils.history.TRANSITIONS).length);
});
+
+add_task(async function test_guid() {
+ const guidA = "aaaaaaaaaaaa";
+ const guidB = "bbbbbbbbbbbb";
+ const guidC = "cccccccccccc";
+
+ await PlacesUtils.history.insertMany([
+ {
+ title: "foo",
+ url: "http://example.com/foo",
+ guid: guidA,
+ visits: [
+ { transition: TRANSITION_LINK, date: new Date() }
+ ]
+ }
+ ]);
+
+ Assert.ok(await PlacesUtils.history.fetch(guidA),
+ "Record is inserted with correct GUID");
+
+ let expectedGuids = new Set([guidB, guidC]);
+ await PlacesUtils.history.insertMany([
+ {
+ title: "bar",
+ url: "http://example.com/bar",
+ guid: guidB,
+ visits: [
+ { transition: TRANSITION_LINK, date: new Date() }
+ ]
+ },
+ {
+ title: "baz",
+ url: "http://example.com/baz",
+ guid: guidC,
+ visits: [
+ { transition: TRANSITION_LINK, date: new Date() }
+ ]
+ }
+ ], pageInfo => {
+ Assert.ok(expectedGuids.has(pageInfo.guid));
+ expectedGuids.delete(pageInfo.guid);
+ });
+ Assert.equal(expectedGuids.size, 0);
+
+
+ Assert.ok(await PlacesUtils.history.fetch(guidB), "Record B is fetchable after insertMany");
+ Assert.ok(await PlacesUtils.history.fetch(guidC), "Record C is fetchable after insertMany");
+});