summaryrefslogtreecommitdiffstats
path: root/toolkit/components/places/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/places/tests/unit')
-rw-r--r--toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js4
-rw-r--r--toolkit/components/places/tests/unit/test_async_transactions.js2
-rw-r--r--toolkit/components/places/tests/unit/test_bookmark_list.js115
-rw-r--r--toolkit/components/places/tests/unit/test_bookmarks_html.js2
-rw-r--r--toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js2
-rw-r--r--toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js2
-rw-r--r--toolkit/components/places/tests/unit/test_frecency_decay.js2
-rw-r--r--toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js8
-rw-r--r--toolkit/components/places/tests/unit/test_origins.js79
-rw-r--r--toolkit/components/places/tests/unit/test_origins_parsing.js11
-rw-r--r--toolkit/components/places/tests/unit/test_tag_autocomplete_search.js2
-rw-r--r--toolkit/components/places/tests/unit/xpcshell.toml2
12 files changed, 186 insertions, 45 deletions
diff --git a/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js b/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js
index 084415fb37..02577f159e 100644
--- a/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js
+++ b/toolkit/components/places/tests/unit/test_asyncExecuteLegacyQueries.js
@@ -30,7 +30,7 @@ add_task(async function test_history_query() {
"Async execution error (" + aError.result + "): " + aError.message
);
},
- handleCompletion(aReason) {
+ handleCompletion() {
cleanupTest().then(resolve);
},
});
@@ -69,7 +69,7 @@ add_task(async function test_bookmarks_query() {
"Async execution error (" + aError.result + "): " + aError.message
);
},
- handleCompletion(aReason) {
+ handleCompletion() {
cleanupTest().then(resolve);
},
});
diff --git a/toolkit/components/places/tests/unit/test_async_transactions.js b/toolkit/components/places/tests/unit/test_async_transactions.js
index b0e9b292f3..9f96a9c040 100644
--- a/toolkit/components/places/tests/unit/test_async_transactions.js
+++ b/toolkit/components/places/tests/unit/test_async_transactions.js
@@ -1485,7 +1485,7 @@ add_task(async function test_edit_specific_keyword() {
url: "http://test.edit.keyword/",
};
bm_info.guid = await PT.NewBookmark(bm_info).transact();
- function ensureKeywordChange(aCurrentKeyword = "", aPreviousKeyword = "") {
+ function ensureKeywordChange(aCurrentKeyword = "") {
ensureItemsKeywordChanged({
guid: bm_info.guid,
keyword: aCurrentKeyword,
diff --git a/toolkit/components/places/tests/unit/test_bookmark_list.js b/toolkit/components/places/tests/unit/test_bookmark_list.js
new file mode 100644
index 0000000000..b743a1281d
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_bookmark_list.js
@@ -0,0 +1,115 @@
+/* Any copyright is dedicated to the Public Domain.
+http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { sinon } = ChromeUtils.importESModule(
+ "resource://testing-common/Sinon.sys.mjs"
+);
+const { BookmarkList } = ChromeUtils.importESModule(
+ "resource://gre/modules/BookmarkList.sys.mjs"
+);
+
+registerCleanupFunction(
+ async () => await PlacesUtils.bookmarks.eraseEverything()
+);
+
+add_task(async function test_url_tracking() {
+ const firstBookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "https://www.example.com/",
+ });
+ const secondBookmark = await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "https://www.reddit.com/",
+ });
+
+ let deferredUpdate;
+ const bookmarkList = new BookmarkList(
+ [
+ "https://www.example.com/",
+ "https://www.reddit.com/",
+ "https://www.youtube.com/",
+ ],
+ () => deferredUpdate?.resolve()
+ );
+
+ async function waitForUpdateBookmarksTask(updateTask) {
+ deferredUpdate = Promise.withResolvers();
+ await updateTask();
+ return deferredUpdate.promise;
+ }
+
+ info("Check bookmark status of tracked URLs.");
+ equal(await bookmarkList.isBookmark("https://www.example.com/"), true);
+ equal(await bookmarkList.isBookmark("https://www.reddit.com/"), true);
+ equal(await bookmarkList.isBookmark("https://www.youtube.com/"), false);
+
+ info("Add a bookmark.");
+ await waitForUpdateBookmarksTask(() =>
+ PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "https://www.youtube.com/",
+ })
+ );
+ equal(await bookmarkList.isBookmark("https://www.youtube.com/"), true);
+
+ info("Remove a bookmark.");
+ await waitForUpdateBookmarksTask(() =>
+ PlacesUtils.bookmarks.remove(firstBookmark.guid)
+ );
+ equal(await bookmarkList.isBookmark("https://www.example.com/"), false);
+
+ info("Update a bookmark's URL.");
+ await waitForUpdateBookmarksTask(() =>
+ PlacesUtils.bookmarks.update({
+ guid: secondBookmark.guid,
+ url: "https://www.wikipedia.org/",
+ })
+ );
+ equal(await bookmarkList.isBookmark("https://www.reddit.com/"), false);
+
+ info("Add a bookmark after removing listeners.");
+ bookmarkList.removeListeners();
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "https://www.example.com/",
+ });
+
+ info("Reinitialize the list and validate bookmark status.");
+ bookmarkList.setTrackedUrls(["https://www.example.com/"]);
+ bookmarkList.addListeners();
+ equal(await bookmarkList.isBookmark("https://www.example.com/"), true);
+
+ info("Cleanup.");
+ bookmarkList.removeListeners();
+ await PlacesUtils.bookmarks.eraseEverything();
+});
+
+add_task(async function test_no_unnecessary_observer_notifications() {
+ const spy = sinon.spy();
+ const bookmarkList = new BookmarkList(
+ ["https://www.example.com/"],
+ spy,
+ 0,
+ 0
+ );
+
+ info("Add a bookmark with an untracked URL.");
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "https://www.reddit.com/",
+ });
+ await new Promise(resolve => ChromeUtils.idleDispatch(resolve));
+ ok(spy.notCalled, "Observer was not notified.");
+ equal(await bookmarkList.isBookmark("https://www.reddit.com"), undefined);
+
+ info("Add a bookmark after removing listeners.");
+ bookmarkList.removeListeners();
+ await PlacesUtils.bookmarks.insert({
+ parentGuid: PlacesUtils.bookmarks.toolbarGuid,
+ url: "https://www.example.com/",
+ });
+ await new Promise(resolve => ChromeUtils.idleDispatch(resolve));
+ ok(spy.notCalled, "Observer was not notified.");
+});
diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html.js b/toolkit/components/places/tests/unit/test_bookmarks_html.js
index 4b3f04b444..f1f8caa354 100644
--- a/toolkit/components/places/tests/unit/test_bookmarks_html.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html.js
@@ -246,7 +246,7 @@ add_task(async function test_import_chromefavicon() {
let data = await new Promise(resolve => {
PlacesUtils.favicons.getFaviconDataForPage(
PAGE_URI,
- (uri, dataLen, faviconData, mimeType) => resolve(faviconData)
+ (uri, dataLen, faviconData) => resolve(faviconData)
);
});
diff --git a/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js b/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
index 061c8c0c5f..f7b366b309 100644
--- a/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html_corrupt.js
@@ -112,7 +112,7 @@ var database_check = async function () {
await new Promise(resolve => {
PlacesUtils.favicons.getFaviconDataForPage(
uri(TEST_FAVICON_PAGE_URL),
- (aURI, aDataLen, aData, aMimeType) => {
+ (aURI, aDataLen) => {
// aURI should never be null when aDataLen > 0.
Assert.notEqual(aURI, null);
// Favicon data is stored in the bookmarks file as a "data:" URI. For
diff --git a/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js b/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js
index 892b2d1d04..75b52aafc7 100644
--- a/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_restore_notification.js
@@ -115,7 +115,7 @@ async function checkObservers(expectPromises, expectedData) {
/**
* Run after every test cases.
*/
-async function teardown(file, begin, success, fail) {
+async function teardown(file) {
// On restore failed, file may not exist, so wrap in try-catch.
await IOUtils.remove(file, { ignoreAbsent: true });
diff --git a/toolkit/components/places/tests/unit/test_frecency_decay.js b/toolkit/components/places/tests/unit/test_frecency_decay.js
index 8fbb08aecc..a9762209c1 100644
--- a/toolkit/components/places/tests/unit/test_frecency_decay.js
+++ b/toolkit/components/places/tests/unit/test_frecency_decay.js
@@ -78,5 +78,5 @@ add_task(async function test_frecency_decay() {
);
let snapshot = histogram.snapshot();
- Assert.greater(snapshot.sum, 0);
+ Assert.greater(Object.values(snapshot.values).length, 0);
});
diff --git a/toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js b/toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js
index e98cdbac79..2cdcba60aa 100644
--- a/toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js
+++ b/toolkit/components/places/tests/unit/test_nsINavHistoryViewer.js
@@ -6,11 +6,11 @@
var resultObserver = {
insertedNode: null,
- nodeInserted(parent, node, newIndex) {
+ nodeInserted(parent, node) {
this.insertedNode = node;
},
removedNode: null,
- nodeRemoved(parent, node, oldIndex) {
+ nodeRemoved(parent, node) {
this.removedNode = node;
},
@@ -24,14 +24,14 @@ var resultObserver = {
newAccessCount: 0,
newTime: 0,
nodeChangedByHistoryDetails: null,
- nodeHistoryDetailsChanged(node, oldVisitDate, oldVisitCount) {
+ nodeHistoryDetailsChanged(node) {
this.nodeChangedByHistoryDetails = node;
this.newTime = node.time;
this.newAccessCount = node.accessCount;
},
movedNode: null,
- nodeMoved(node, oldParent, oldIndex, newParent, newIndex) {
+ nodeMoved(node) {
this.movedNode = node;
},
openedContainer: null,
diff --git a/toolkit/components/places/tests/unit/test_origins.js b/toolkit/components/places/tests/unit/test_origins.js
index 67b6d59c7d..f74313a125 100644
--- a/toolkit/components/places/tests/unit/test_origins.js
+++ b/toolkit/components/places/tests/unit/test_origins.js
@@ -1005,6 +1005,33 @@ add_task(async function moreOriginFrecencyStats() {
await cleanUp();
});
+add_task(async function test_cutoff() {
+ // Add first page with visit.
+ await PlacesTestUtils.addVisits([{ uri: "http://example.com/0" }]);
+ // Add a second page last visited before the cutoff, it should be ignored.
+ let visitDate = PlacesUtils.toPRTime(
+ new Date(
+ new Date().setDate(
+ -Services.prefs.getIntPref("places.frecency.originsCutOffDays", 90)
+ )
+ )
+ );
+ await PlacesTestUtils.addVisits([{ uri: "http://example.com/1", visitDate }]);
+ // Add a third page with visit both before and after the cutoff, should count.
+ await PlacesTestUtils.addVisits([
+ { uri: "http://example.com/2" },
+ { uri: "http://example.com/2", visitDate },
+ ]);
+ await checkDB([
+ [
+ "http://",
+ "example.com",
+ ["http://example.com/0", "http://example.com/2"],
+ ],
+ ]);
+ await cleanUp();
+});
+
/**
* Returns the expected frecency of the origin of the given URLs, i.e., the sum
* of their frecencies. Each URL is expected to have the same origin.
@@ -1017,12 +1044,15 @@ async function expectedOriginFrecency(urls) {
let value = 0;
for (let url of urls) {
let v = Math.max(
- await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", { url }),
+ (await PlacesTestUtils.getDatabaseValue("moz_places", "frecency", {
+ url,
+ last_visit_date: [">", 0],
+ })) ?? 0,
0
);
value += v;
}
- return value;
+ return value || 1.0;
}
/**
@@ -1064,49 +1094,34 @@ async function checkDB(expectedOrigins) {
}
Assert.deepEqual(actualOrigins, expected);
if (checkFrecencies) {
- await checkStats(expected.map(o => o[2]).filter(o => o > 0));
+ info("Checking threshold");
+ await PlacesTestUtils.dumpTable({ db, table: "moz_origins" });
+ await checkThreshold(expected.map(o => o[2]));
}
}
/**
- * Asserts that the origin frecency stats are correct.
+ * Asserts that the origin frecency threshold is correct.
*
* @param expectedOriginFrecencies
* An array of expected origin frecencies.
*/
-async function checkStats(expectedOriginFrecencies) {
- let stats = await promiseStats();
- Assert.equal(stats.count, expectedOriginFrecencies.length);
- Assert.equal(
- stats.sum,
- expectedOriginFrecencies.reduce((sum, f) => sum + f, 0)
+async function checkThreshold(expectedOriginFrecencies) {
+ const DEFAULT_THRESHOLD = 2.0;
+ let threshold = await PlacesUtils.metadata.get(
+ "origin_frecency_threshold",
+ DEFAULT_THRESHOLD
);
+
Assert.equal(
- stats.squares,
- expectedOriginFrecencies.reduce((squares, f) => squares + f * f, 0)
+ threshold,
+ expectedOriginFrecencies.length
+ ? expectedOriginFrecencies.reduce((a, b) => a + b, 0) /
+ expectedOriginFrecencies.length
+ : DEFAULT_THRESHOLD
);
}
-/**
- * Returns the origin frecency stats.
- *
- * @return An object: { count, sum, squares }
- */
-async function promiseStats() {
- let db = await PlacesUtils.promiseDBConnection();
- let rows = await db.execute(`
- SELECT
- IFNULL((SELECT value FROM moz_meta WHERE key = 'origin_frecency_count'), 0),
- IFNULL((SELECT value FROM moz_meta WHERE key = 'origin_frecency_sum'), 0),
- IFNULL((SELECT value FROM moz_meta WHERE key = 'origin_frecency_sum_of_squares'), 0)
- `);
- return {
- count: rows[0].getResultByIndex(0),
- sum: rows[0].getResultByIndex(1),
- squares: rows[0].getResultByIndex(2),
- };
-}
-
async function cleanUp() {
await PlacesUtils.bookmarks.eraseEverything();
await PlacesUtils.history.clear();
diff --git a/toolkit/components/places/tests/unit/test_origins_parsing.js b/toolkit/components/places/tests/unit/test_origins_parsing.js
index 35ba8bdd0d..bdeabce271 100644
--- a/toolkit/components/places/tests/unit/test_origins_parsing.js
+++ b/toolkit/components/places/tests/unit/test_origins_parsing.js
@@ -65,7 +65,16 @@ add_task(async function parsing() {
// in the database are correct.
for (let i = 0; i < uris.length; i++) {
await PlacesUtils.history.remove(uris[i]);
- await checkDB(expectedOrigins.slice(i + 1, expectedOrigins.length));
+
+ let uri = Services.io.newURI(uris[i]);
+ if (uri.hasUserPass) {
+ // The history cannot be deleted at a URL with a user path.
+ } else {
+ expectedOrigins = expectedOrigins.filter(
+ ([prefix, hostPort]) => !prefix.startsWith(uri.scheme + ":")
+ );
+ }
+ await checkDB(expectedOrigins);
}
await cleanUp();
}
diff --git a/toolkit/components/places/tests/unit/test_tag_autocomplete_search.js b/toolkit/components/places/tests/unit/test_tag_autocomplete_search.js
index 43f899c237..06182b6dd3 100644
--- a/toolkit/components/places/tests/unit/test_tag_autocomplete_search.js
+++ b/toolkit/components/places/tests/unit/test_tag_autocomplete_search.js
@@ -33,7 +33,7 @@ AutoCompleteInput.prototype = {
popupOpen: false,
popup: {
- setSelectedIndex(aIndex) {},
+ setSelectedIndex() {},
invalidate() {},
// nsISupports implementation
diff --git a/toolkit/components/places/tests/unit/xpcshell.toml b/toolkit/components/places/tests/unit/xpcshell.toml
index 750e8ad9ea..8a56fcc370 100644
--- a/toolkit/components/places/tests/unit/xpcshell.toml
+++ b/toolkit/components/places/tests/unit/xpcshell.toml
@@ -78,6 +78,8 @@ skip-if = ["os == 'linux'"] # Bug 821781
["test_bookmark-tags-changed_frequency.js"]
+["test_bookmark_list.js"]
+
["test_bookmarks_html.js"]
["test_bookmarks_html_corrupt.js"]