summaryrefslogtreecommitdiffstats
path: root/browser/components/places/tests/browser/browser_library_bookmark_clear_visits.js
blob: fab8b4c3b0f526da4ce0d2b0d32df6831d7776eb (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/*
 * Test whether or not that Most Recent Visit of bookmark in library window will
 * update properly when removing the history.
 */

const TEST_URLS = ["https://example.com/", "https://example.org/"];

add_setup(async function () {
  await PlacesUtils.bookmarks.eraseEverything();
  await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    url: TEST_URLS[0],
  });
  await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    url: TEST_URLS[1],
  });
  await PlacesUtils.bookmarks.insert({
    parentGuid: PlacesUtils.bookmarks.toolbarGuid,
    url: TEST_URLS[1],
  });
  PlacesUtils.tagging.tagURI(makeURI(TEST_URLS[0]), ["test"]);
  PlacesUtils.tagging.tagURI(makeURI(TEST_URLS[1]), ["test"]);

  registerCleanupFunction(async () => {
    PlacesUtils.tagging.untagURI(makeURI(TEST_URLS[0]), ["test"]);
    PlacesUtils.tagging.untagURI(makeURI(TEST_URLS[1]), ["test"]);
    await PlacesUtils.bookmarks.eraseEverything();
    await PlacesUtils.history.clear();
  });
});

add_task(async function folder() {
  info("Open bookmarked urls to update most recent visit time");
  await updateMostRecentVisitTime();

  info("Open library for bookmarks toolbar");
  const library = await promiseLibrary("BookmarksToolbar");

  info("Add Most Recent Visit column");
  await showLibraryColumn(library, "placesContentDate");

  info("Check the initial content");
  const tree = library.document.getElementById("placeContent");
  Assert.equal(tree.view.rowCount, 3, "All bookmarks are shown");
  assertRow(tree, 0, TEST_URLS[0], true);
  assertRow(tree, 1, TEST_URLS[1], true);
  assertRow(tree, 2, TEST_URLS[1], true);

  info("Clear all visits data");
  await PlacesUtils.history.remove(TEST_URLS);

  info("Check whether or not the content are updated");
  assertRow(tree, 0, TEST_URLS[0], false);
  assertRow(tree, 1, TEST_URLS[1], false);
  assertRow(tree, 2, TEST_URLS[1], false);

  info("Close library window");
  await promiseLibraryClosed(library);
});

add_task(async function tags() {
  info("Open bookmarked urls to update most recent visit time");
  await updateMostRecentVisitTime();

  info("Open library for bookmarks toolbar");
  const library = await promiseLibrary("BookmarksToolbar");

  info("Add Most Recent Visit column");
  await showLibraryColumn(library, "placesContentDate");

  info("Open test tag");
  const PO = library.PlacesOrganizer;
  PO.selectLeftPaneBuiltIn("Tags");
  const tagsNode = PO._places.selectedNode;
  PlacesUtils.asContainer(tagsNode).containerOpen = true;
  const tag = tagsNode.getChild(0);
  PO._places.selectNode(tag);

  info("Check the initial content");
  const tree = library.ContentTree.view;
  Assert.equal(tree.view.rowCount, 3, "All bookmarks are shown");
  assertRow(tree, 0, TEST_URLS[0], true);
  assertRow(tree, 1, TEST_URLS[1], true);
  assertRow(tree, 2, TEST_URLS[1], true);

  info("Clear all visits data");
  await PlacesUtils.history.remove(TEST_URLS);

  info("Check whether or not the content are updated");
  assertRow(tree, 0, TEST_URLS[0], false);
  assertRow(tree, 1, TEST_URLS[1], false);
  assertRow(tree, 2, TEST_URLS[1], false);

  info("Close library window");
  await promiseLibraryClosed(library);
});

async function updateMostRecentVisitTime() {
  for (const url of TEST_URLS) {
    const onLoaded = BrowserTestUtils.browserLoaded(gBrowser, false, url);
    BrowserTestUtils.startLoadingURIString(gBrowser, url);
    await onLoaded;
  }
}

function assertRow(tree, targeRow, expectedUrl, expectMostRecentVisitHasValue) {
  const url = tree.view.getCellText(targeRow, tree.columns.placesContentUrl);
  Assert.equal(url, expectedUrl, "URL is correct");
  const mostRecentVisit = tree.view.getCellText(
    targeRow,
    tree.columns.placesContentDate
  );
  Assert.equal(
    !!mostRecentVisit,
    expectMostRecentVisitHasValue,
    "Most Recent Visit data is in the cell correctly"
  );
}