From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../places/tests/unit/test_isURIVisited.js | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 toolkit/components/places/tests/unit/test_isURIVisited.js (limited to 'toolkit/components/places/tests/unit/test_isURIVisited.js') diff --git a/toolkit/components/places/tests/unit/test_isURIVisited.js b/toolkit/components/places/tests/unit/test_isURIVisited.js new file mode 100644 index 0000000000..ac40e5fba6 --- /dev/null +++ b/toolkit/components/places/tests/unit/test_isURIVisited.js @@ -0,0 +1,73 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Tests functionality of the isURIVisited API. + +const SCHEMES = { + "http://": true, + "https://": true, + "ftp://": true, + "file:///": true, + "about:": false, + // nsIIOService.newURI() can throw if e.g. the app knows about imap:// + // but the account is not set up and so the URL is invalid for it. + // "imap://": false, + "news://": false, + "mailbox:": false, + "cached-favicon:http://": false, + "view-source:http://": false, + "chrome://browser/content/browser.xhtml?": false, + "resource://": false, + "data:,": false, + "javascript:": false, +}; + +add_task(async function test_isURIVisited() { + let history = Cc["@mozilla.org/browser/history;1"].getService( + Ci.mozIAsyncHistory + ); + + function visitsPromise(uri) { + return new Promise(resolve => { + history.isURIVisited(uri, (receivedURI, visited) => { + resolve([receivedURI, visited]); + }); + }); + } + + for (let scheme in SCHEMES) { + info("Testing scheme " + scheme); + for (let t in PlacesUtils.history.TRANSITIONS) { + if (t == "EMBED") { + continue; + } + info("With transition " + t); + let aTransition = PlacesUtils.history.TRANSITIONS[t]; + + let aURI = Services.io.newURI(scheme + "mozilla.org/"); + + let [receivedURI1, visited1] = await visitsPromise(aURI); + Assert.ok(aURI.equals(receivedURI1)); + Assert.ok(!visited1); + + if (PlacesUtils.history.canAddURI(aURI)) { + await PlacesTestUtils.addVisits([ + { + uri: aURI, + transition: aTransition, + }, + ]); + info("Added visit for " + aURI.spec); + } + + let [receivedURI2, visited2] = await visitsPromise(aURI); + Assert.ok(aURI.equals(receivedURI2)); + Assert.equal(SCHEMES[scheme], visited2); + + await PlacesUtils.history.clear(); + let [receivedURI3, visited3] = await visitsPromise(aURI); + Assert.ok(aURI.equals(receivedURI3)); + Assert.ok(!visited3); + } + } +}); -- cgit v1.2.3