diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/components/thumbnails/test/test_thumbnails_interfaces.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/thumbnails/test/test_thumbnails_interfaces.js')
-rw-r--r-- | toolkit/components/thumbnails/test/test_thumbnails_interfaces.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/toolkit/components/thumbnails/test/test_thumbnails_interfaces.js b/toolkit/components/thumbnails/test/test_thumbnails_interfaces.js new file mode 100644 index 0000000000..f7e5850702 --- /dev/null +++ b/toolkit/components/thumbnails/test/test_thumbnails_interfaces.js @@ -0,0 +1,50 @@ +"use strict"; + +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); + +// need profile so that PageThumbsStorageService can resolve the path to the underlying file +do_get_profile(); + +function run_test() { + // check the protocol handler implements the correct interface + let handler = Services.io.getProtocolHandler("moz-page-thumb"); + ok( + handler instanceof Ci.nsIProtocolHandler, + "moz-page-thumb handler provides a protocol handler interface" + ); + + // create a dummy loadinfo which we can hand to newChannel. + let dummyURI = Services.io.newURI("https://www.example.com/1"); + let dummyChannel = NetUtil.newChannel({ + uri: dummyURI, + loadUsingSystemPrincipal: true, + }); + let dummyLoadInfo = dummyChannel.loadInfo; + + // and check that the error cases work as specified + let badhost = Services.io.newURI( + "moz-page-thumb://wronghost/?url=http%3A%2F%2Fwww.mozilla.org%2F" + ); + Assert.throws( + () => handler.newChannel(badhost, dummyLoadInfo), + /NS_ERROR_NOT_AVAILABLE/i, + "moz-page-thumb object with wrong host must not resolve to a file path" + ); + + let badQuery = Services.io.newURI( + "moz-page-thumb://thumbnail/http%3A%2F%2Fwww.mozilla.org%2F" + ); + Assert.throws( + () => handler.newChannel(badQuery, dummyLoadInfo), + /NS_ERROR_NOT_AVAILABLE/i, + "moz-page-thumb object with malformed query parameters must not resolve to a file path" + ); + + let noURL = Services.io.newURI("moz-page-thumb://thumbnail/?badStuff"); + Assert.throws( + () => handler.newChannel(noURL, dummyLoadInfo), + /NS_ERROR_NOT_AVAILABLE/i, + "moz-page-thumb object without a URL parameter must not resolve to a file path" + ); +} |