diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/places/tests/history/test_fetchMany.js | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/places/tests/history/test_fetchMany.js')
-rw-r--r-- | toolkit/components/places/tests/history/test_fetchMany.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/toolkit/components/places/tests/history/test_fetchMany.js b/toolkit/components/places/tests/history/test_fetchMany.js new file mode 100644 index 0000000000..5ed053c10b --- /dev/null +++ b/toolkit/components/places/tests/history/test_fetchMany.js @@ -0,0 +1,90 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +add_task(async function test_fetchMany() { + await PlacesUtils.history.clear(); + await PlacesUtils.bookmarks.eraseEverything(); + + let pages = [ + { + url: "https://mozilla.org/test1/", + title: "test 1", + }, + { + url: "https://mozilla.org/test2/", + title: "test 2", + }, + { + url: "https://mozilla.org/test3/", + title: "test 3", + }, + ]; + await PlacesTestUtils.addVisits(pages); + + // Add missing page info from the database. + for (let page of pages) { + page.guid = await PlacesTestUtils.fieldInDB(page.url, "guid"); + page.frecency = await PlacesTestUtils.fieldInDB(page.url, "frecency"); + } + + info("Fetch by url"); + let fetched = await PlacesUtils.history.fetchMany(pages.map(p => p.url)); + Assert.equal(fetched.size, 3, "Map should contain same number of entries"); + for (let page of pages) { + Assert.deepEqual(page, fetched.get(page.url)); + } + info("Fetch by GUID"); + fetched = await PlacesUtils.history.fetchMany(pages.map(p => p.guid)); + Assert.equal(fetched.size, 3, "Map should contain same number of entries"); + for (let page of pages) { + Assert.deepEqual(page, fetched.get(page.guid)); + } + info("Fetch mixed"); + let keys = pages.map((p, i) => (i % 2 == 0 ? p.guid : p.url)); + fetched = await PlacesUtils.history.fetchMany(keys); + Assert.equal(fetched.size, 3, "Map should contain same number of entries"); + for (let key of keys) { + let page = pages.find(p => p.guid == key || p.url == key); + Assert.deepEqual(page, fetched.get(key)); + Assert.ok(URL.isInstance(fetched.get(key).url)); + } +}); + +add_task(async function test_fetch_empty() { + await PlacesUtils.history.clear(); + await PlacesUtils.bookmarks.eraseEverything(); + + let fetched = await PlacesUtils.history.fetchMany([]); + Assert.equal(fetched.size, 0, "Map should contain no entries"); +}); + +add_task(async function test_fetch_nonexistent() { + await PlacesUtils.history.clear(); + await PlacesUtils.bookmarks.eraseEverything(); + + let uri = NetUtil.newURI("http://doesntexist.in.db"); + let fetched = await PlacesUtils.history.fetchMany([uri]); + Assert.equal(fetched.size, 0, "Map should contain no entries"); +}); + +add_task(async function test_error_cases() { + Assert.throws( + () => PlacesUtils.history.fetchMany("3"), + /TypeError: Input is not an array/ + ); + Assert.throws( + () => PlacesUtils.history.fetchMany([{ not: "a valid string or guid" }]), + /TypeError: Invalid url or guid/ + ); + Assert.throws( + () => + PlacesUtils.history.fetchMany(["http://valid.uri.com", "not an object"]), + /TypeError: URL constructor/ + ); + Assert.throws( + () => PlacesUtils.history.fetchMany(["http://valid.uri.com", null]), + /TypeError: Invalid url or guid/ + ); +}); |