diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/protocolhandler/test | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/protocolhandler/test')
4 files changed, 165 insertions, 0 deletions
diff --git a/browser/components/protocolhandler/test/browser/browser.toml b/browser/components/protocolhandler/test/browser/browser.toml new file mode 100644 index 0000000000..73a0ad72d2 --- /dev/null +++ b/browser/components/protocolhandler/test/browser/browser.toml @@ -0,0 +1,5 @@ +[DEFAULT] + +["browser_registerProtocolHandler_notification.js"] +support-files = ["browser_registerProtocolHandler_notification.html"] +skip-if = ["verify"] diff --git a/browser/components/protocolhandler/test/browser/browser_registerProtocolHandler_notification.html b/browser/components/protocolhandler/test/browser/browser_registerProtocolHandler_notification.html new file mode 100644 index 0000000000..6ffacd2e85 --- /dev/null +++ b/browser/components/protocolhandler/test/browser/browser_registerProtocolHandler_notification.html @@ -0,0 +1,15 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html> + <head> + <title>Protocol registrar page</title> + <meta content="text/html;charset=utf-8" http-equiv="Content-Type"> + <meta content="utf-8" http-equiv="encoding"> + </head> + <body> + <script type="text/javascript"> + navigator.registerProtocolHandler("web+testprotocol", + "https://example.com/foobar?uri=%s", + "Test Protocol"); + </script> + </body> +</html> diff --git a/browser/components/protocolhandler/test/browser/browser_registerProtocolHandler_notification.js b/browser/components/protocolhandler/test/browser/browser_registerProtocolHandler_notification.js new file mode 100644 index 0000000000..e2598ae281 --- /dev/null +++ b/browser/components/protocolhandler/test/browser/browser_registerProtocolHandler_notification.js @@ -0,0 +1,57 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const TEST_PATH = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content", + "https://example.com" +); +add_task(async function () { + let notificationValue = "Protocol Registration: web+testprotocol"; + let testURI = TEST_PATH + "browser_registerProtocolHandler_notification.html"; + + BrowserTestUtils.startLoadingURIString( + window.gBrowser.selectedBrowser, + testURI + ); + await TestUtils.waitForCondition( + function () { + // Do not start until the notification is up + let notificationBox = window.gBrowser.getNotificationBox(); + let notification = + notificationBox.getNotificationWithValue(notificationValue); + return notification; + }, + "Still can not get notification after retrying 100 times.", + 100, + 100 + ); + + let notificationBox = window.gBrowser.getNotificationBox(); + let notification = + notificationBox.getNotificationWithValue(notificationValue); + ok(notification, "Notification box should be displayed"); + if (notification == null) { + finish(); + return; + } + is( + notification.getAttribute("type"), + "info", + "We expect this notification to have the type of 'info'." + ); + is( + notification.messageImage.getAttribute("src"), + "chrome://global/skin/icons/info-filled.svg", + "We expect this notification to have an icon." + ); + + let buttons = notification.buttonContainer.getElementsByClassName( + "notification-button" + ); + is(buttons.length, 1, "We expect see one button."); + + let button = buttons[0]; + isnot(button.label, null, "We expect the add button to have a label."); + todo(button.accesskey, "We expect the add button to have a accesskey."); +}); diff --git a/browser/components/protocolhandler/test/test_registerHandler.html b/browser/components/protocolhandler/test/test_registerHandler.html new file mode 100644 index 0000000000..2eb4f7dbdc --- /dev/null +++ b/browser/components/protocolhandler/test/test_registerHandler.html @@ -0,0 +1,88 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=402788 +--> +<head> + <title>Test for Bug 402788</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402788">Mozilla Bug 402788</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +/** Test for Bug 402788 */ + SimpleTest.waitForExplicitFinish(); + + // return false if an exception has been catched, true otherwise + function testRegisterHandler(aIsProtocol, aTxt, aUri, aTitle) { + try { + navigator.registerProtocolHandler(aTxt, aUri, aTitle); + } catch (e) { + return false; + } + + return true; + } + + // helper function to build URLs since hostname differs + // based on whether the test is running in a cross-origin iframe + function buildUrl(protocol="http", addFormat=true) { + return `${protocol}://${window.location.hostname}:${window.location.port}${addFormat ? "/%s" : "/"}`; + } + + async function tests() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["dom.registerProtocolHandler.insecure.enabled", true], + ], + }); + + // testing a generic case + is(testRegisterHandler(true, "web+foo", buildUrl(), "Foo handler"), true, "registering a web+foo protocol handler should work"); + + // testing with wrong uris + is(testRegisterHandler(true, "web+foo", buildUrl("http", false), "Foo handler"), false, "a protocol handler uri should contain %s"); + + // the spec explicitly allows relative urls to be passed + is(testRegisterHandler(true, "web+foo", "foo/%s", "Foo handler"), true, "a protocol handler uri should be valid"); + + // we should only accept to register when the handler has the same host as the current page (bug 402287) + is(testRegisterHandler(true, "fweb+oo", "http://remotehost:8888/%s", "Foo handler"), false, "registering a web+foo protocol handler with a different host should not work"); + + // restriction to http(s) for the uri of the handler (bug 401343) + // http is already tested in the generic case + // ftp should not work + is(testRegisterHandler(true, "web+foo", buildUrl("ftp"), "Foo handler"), false, "registering a web+foo protocol handler with ftp scheme should not work"); + // chrome should not work + is(testRegisterHandler(true, "web+foo", buildUrl("chrome"), "Foo handler"), false, "registering a web+foo protocol handler with chrome scheme should not work"); + // foo should not work + is(testRegisterHandler(true, "web+foo", buildUrl("foo"), "Foo handler"), false, "registering a web+foo protocol handler with foo scheme should not work"); + + // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788) + is(testRegisterHandler(true, "chrome", buildUrl(), "chrome handler"), false, "registering a chrome protocol handler should not work"); + is(testRegisterHandler(true, "vbscript", buildUrl(), "vbscript handler"), false, "registering a vbscript protocol handler should not work"); + is(testRegisterHandler(true, "javascript", buildUrl(), "javascript handler"), false, "registering a javascript protocol handler should not work"); + is(testRegisterHandler(true, "moz-icon", buildUrl(), "moz-icon handler"), false, "registering a moz-icon protocol handler should not work"); + + // registering anything not on the list of safe schemes and unprefixed by web+ shouldn't work + is(testRegisterHandler(true, "foo", buildUrl(), "chrome handler"), false, "registering a foo protocol handler should not work"); + is(testRegisterHandler(true, "web+", buildUrl(), "chrome handler"), false, "registering a 'web+' protocol handler should not work"); + is(testRegisterHandler(true, "web+1", buildUrl(), "chrome handler"), false, "registering a 'web+1' protocol handler should not work"); + + + SimpleTest.finish(); + } + + tests(); + +</script> +</pre> +</body> +</html> |