summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_PlacesUtils_invalidateCachedGuidFor.js
blob: 31f3891b2bf80e4616105a61c752b1e807225316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
add_task(async function() {
  info("Add a bookmark.");
  let bm = await PlacesUtils.bookmarks.insert({
    url: "http://example.com/",
    parentGuid: PlacesUtils.bookmarks.unfiledGuid,
  });
  let id = await PlacesUtils.promiseItemId(bm.guid);
  Assert.equal(await PlacesUtils.promiseItemGuid(id), bm.guid);

  // Ensure invalidating a non-existent itemId doesn't throw.
  PlacesUtils.invalidateCachedGuidFor(null);
  PlacesUtils.invalidateCachedGuidFor(9999);

  info("Change the GUID.");
  await PlacesUtils.withConnectionWrapper("test", async function(db) {
    await db.execute("UPDATE moz_bookmarks SET guid = :guid WHERE id = :id", {
      guid: "123456789012",
      id,
    });
  });
  // The cache should still point to the wrong id.
  Assert.equal(await PlacesUtils.promiseItemGuid(id), bm.guid);

  info("Invalidate the cache.");
  PlacesUtils.invalidateCachedGuidFor(id);
  Assert.equal(await PlacesUtils.promiseItemGuid(id), "123456789012");
  Assert.equal(await PlacesUtils.promiseItemId("123456789012"), id);
  await Assert.rejects(
    PlacesUtils.promiseItemId(bm.guid),
    /no item found for the given GUID/
  );
});