summaryrefslogtreecommitdiffstats
path: root/dom/notification/test/mochitest/test_notification_insecure_context.html
diff options
context:
space:
mode:
Diffstat (limited to 'dom/notification/test/mochitest/test_notification_insecure_context.html')
-rw-r--r--dom/notification/test/mochitest/test_notification_insecure_context.html47
1 files changed, 47 insertions, 0 deletions
diff --git a/dom/notification/test/mochitest/test_notification_insecure_context.html b/dom/notification/test/mochitest/test_notification_insecure_context.html
new file mode 100644
index 0000000000..cd3a22bc7f
--- /dev/null
+++ b/dom/notification/test/mochitest/test_notification_insecure_context.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Tests that Notification permissions are denied in insecure context.
+https://bugzilla.mozilla.org/show_bug.cgi?id=1429432
+-->
+<head>
+ <title>Notification permission in insecure context</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+ <p id="display"></p>
+ <div id="content" style="display: none">
+ </div>
+ <pre id="test">
+ <script class="testbody" type="text/javascript">
+ SimpleTest.waitForExplicitFinish();
+
+ // Add an allow permission for the mochitest origin to test this.
+ let script = SpecialPowers.loadChromeScript(function() {
+ /* eslint-env mozilla/chrome-script */
+ let principal = Services.scriptSecurityManager.createContentPrincipalFromOrigin("http://mochi.test:8888");
+ Services.perms.addFromPrincipal(principal, "desktop-notification", Services.perms.ALLOW_ACTION);
+ addMessageListener("destroy", function() {
+ Services.perms.removeFromPrincipal(principal, "desktop-notification");
+ });
+ });
+
+ (async function runTest() {
+ let response = await Notification.requestPermission();
+ is(response, "denied", "Denied permission in insecure context");
+
+ await SpecialPowers.pushPrefEnv({"set": [["dom.webnotifications.allowinsecure", true]]});
+
+ response = await Notification.requestPermission();
+ is(response, "granted", "Granted permission in insecure context with pref set");
+
+ script.sendAsyncMessage("destroy");
+ script.destroy();
+
+ SimpleTest.finish();
+ })();
+ </script>
+ </pre>
+</body>
+</html>