summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit/test_PlacesObservers_counts.js
blob: 3eb7c2d2a9756747914ff936c05b320bb25eb643 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test PlacesObservers.counts.

add_task(async function test_counts() {
  const url = "http://example.com/title";
  await PlacesUtils.history.insertMany([
    {
      title: "will change",
      url,
      visits: [{ transition: TRANSITION_LINK }],
    },
    {
      title: "changed",
      url,
      referrer: url,
      visits: [{ transition: TRANSITION_LINK }],
    },
    {
      title: "another",
      url: "http://example.com/another",
      visits: [{ transition: TRANSITION_LINK }],
    },
  ]);
  await PlacesUtils.bookmarks.insert({
    url,
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
  });
  await PlacesUtils.history.clear();
  await PlacesUtils.bookmarks.eraseEverything;

  Assert.strictEqual(
    PlacesObservers.counts.get("non-existing"),
    undefined,
    "Check non existing event returns undefined"
  );
  Assert.strictEqual(
    PlacesObservers.counts.get("page-removed"),
    0,
    "Check non fired event returns 0"
  );
  Assert.strictEqual(
    PlacesObservers.counts.get("page-visited"),
    3,
    "Check fired event `page-visited`"
  );
  Assert.strictEqual(
    PlacesObservers.counts.get("history-cleared"),
    1,
    "Check fired event `history-cleared`"
  );
  Assert.strictEqual(
    PlacesObservers.counts.get("bookmark-added"),
    1,
    "Check fired event `bookmark-added`"
  );
});