summaryrefslogtreecommitdiffstats
path: root/dom/notification/test/chrome
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/notification/test/chrome
parentInitial commit. (diff)
downloadfirefox-upstream/124.0.1.tar.xz
firefox-upstream/124.0.1.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/notification/test/chrome')
-rw-r--r--dom/notification/test/chrome/chrome.toml3
-rw-r--r--dom/notification/test/chrome/test_notification_system_principal.xhtml76
2 files changed, 79 insertions, 0 deletions
diff --git a/dom/notification/test/chrome/chrome.toml b/dom/notification/test/chrome/chrome.toml
new file mode 100644
index 0000000000..d4027438d2
--- /dev/null
+++ b/dom/notification/test/chrome/chrome.toml
@@ -0,0 +1,3 @@
+[DEFAULT]
+
+["test_notification_system_principal.xhtml"]
diff --git a/dom/notification/test/chrome/test_notification_system_principal.xhtml b/dom/notification/test/chrome/test_notification_system_principal.xhtml
new file mode 100644
index 0000000000..0700d59338
--- /dev/null
+++ b/dom/notification/test/chrome/test_notification_system_principal.xhtml
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=874090
+-->
+<window title="Mozilla Bug 874090" onload="runTests()"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+ <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+
+ <!-- test results are displayed in the html:body -->
+ <body xmlns="http://www.w3.org/1999/xhtml">
+ <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=874090"
+ target="_blank">Mozilla Bug 874090</a>
+ </body>
+
+ <!-- test code goes here -->
+ <script type="application/javascript">
+ <![CDATA[
+ /** Test for Bug 874090 **/
+ const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}");
+ const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
+
+ var mockAlertsService = {
+ showAlert(alert, alertListener) {
+ ok(true, "System principal was granted permission and is able to call showAlert.");
+ unregisterMock();
+ SimpleTest.finish();
+ },
+
+ showAlertNotification(imageUrl, title, text, textClickable,
+ cookie, alertListener, name, dir, lang, data) {
+ this.showAlert();
+ },
+
+ QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]),
+
+ createInstance(aIID) {
+ return this.QueryInterface(aIID);
+ }
+ };
+
+ function registerMock() {
+ Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
+ registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
+ }
+
+ function unregisterMock() {
+ Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
+ unregisterFactory(MOCK_CID, mockAlertsService);
+ }
+
+ function runTests() {
+ registerMock();
+
+ is(Notification.permission, "granted", "System principal should be automatically granted permission.");
+
+ Notification.requestPermission(function(permission) {
+ is(permission, "granted", "System principal should be granted permission when calling requestPermission.");
+
+ if (permission == "granted") {
+ // Create a notification and make sure that it is able to call into
+ // the mock alert service to show the notification.
+ new Notification("Hello");
+ } else {
+ unregisterMock();
+ SimpleTest.finish();
+ }
+ });
+ }
+
+ SimpleTest.waitForExplicitFinish();
+ ]]>
+ </script>
+</window>