Bug 1689565 - Part 1: Remove Notification.get() r=saschanaz

Remove Notification.get() in the code

Differential Revision: https://phabricator.services.mozilla.com/D167236
This commit is contained in:
Ho Cheung 2023-01-30 12:50:51 +00:00
Родитель 8e9b448440
Коммит c1b2ac7b4e
9 изменённых файлов: 0 добавлений и 244 удалений

Просмотреть файл

@ -112,20 +112,6 @@ interface nsINotificationStorage : nsISupports
*/
void delete(in AString origin,
in AString id);
/**
* Notifications are not supposed to be persistent, according to spec, at
* least for now. But we want to be able to have this behavior on B2G. Thus,
* this method will check if the origin sending the notifications is a valid
* registered app with a manifest or not. Hence, a webpage that has none
* will have its notification sent and available (via Notification.get())
* during the life time of the page.
*
* @param origin: Origin from which the notification is sent.
*
* @return boolean
*/
boolean canPut(in AString origin);
};
%{C++

Просмотреть файл

@ -688,11 +688,6 @@ bool Notification::PrefEnabled(JSContext* aCx, JSObject* aObj) {
return StaticPrefs::dom_webnotifications_enabled();
}
// static
bool Notification::IsGetEnabled(JSContext* aCx, JSObject* aObj) {
return NS_IsMainThread();
}
Notification::Notification(nsIGlobalObject* aGlobal, const nsAString& aID,
const nsAString& aTitle, const nsAString& aBody,
NotificationDirection aDir, const nsAString& aLang,
@ -1684,17 +1679,6 @@ already_AddRefed<Promise> Notification::Get(
return promise.forget();
}
already_AddRefed<Promise> Notification::Get(
const GlobalObject& aGlobal, const GetNotificationOptions& aFilter,
ErrorResult& aRv) {
AssertIsOnMainThread();
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
MOZ_ASSERT(global);
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global);
return Get(window, aFilter, u""_ns, aRv);
}
class WorkerGetResultRunnable final : public NotificationWorkerRunnable {
RefPtr<PromiseWorkerProxy> mPromiseProxy;
const nsTArray<NotificationStrings> mStrings;

Просмотреть файл

@ -106,8 +106,6 @@ class Notification : public DOMEventTargetHelper,
NS_DECL_NSIOBSERVER
static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
// Returns if Notification.get() is allowed for the current global.
static bool IsGetEnabled(JSContext* aCx, JSObject* aObj);
static already_AddRefed<Notification> Constructor(
const GlobalObject& aGlobal, const nsAString& aTitle,
@ -163,10 +161,6 @@ class Notification : public DOMEventTargetHelper,
const nsAString& aScope,
ErrorResult& aRv);
static already_AddRefed<Promise> Get(const GlobalObject& aGlobal,
const GetNotificationOptions& aFilter,
ErrorResult& aRv);
static already_AddRefed<Promise> WorkerGet(
WorkerPrivate* aWorkerPrivate, const GetNotificationOptions& aFilter,
const nsAString& aScope, ErrorResult& aRv);

Просмотреть файл

@ -15,7 +15,4 @@ skip-if = xorigin # Bug 1792790
fail-if = xorigin
[test_notification_permissions.html]
scheme = https
[test_notification_storage.html]
skip-if = xorigin # Bug 1792790
[test_bug931307.html]
[test_notification_tag.html]

Просмотреть файл

@ -1,34 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Bug 931307</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<pre id="test">
<script type="application/javascript"><!--
SimpleTest.waitForExplicitFinish();
var notification = new Notification("");
var promise = Notification.get();
promise.then(
function onSuccess() {
ok(true, "No error when creating a notification without title");
},
function onFailure() {
ok(false, "Should not throw error when creating a notification without title");
}
).then(() => {
notification.close();
}).then(() => {
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -24,7 +24,6 @@
ok(Notification, "Notification constructor exists");
ok(Notification.permission, "Notification.permission exists");
ok(Notification.requestPermission, "Notification.requestPermission exists");
ok(Notification.get, "Notification.get exists");
},
function() {

Просмотреть файл

@ -1,158 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Notification Basics</title>
<script type="text/javascript" src="MockServices.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="NotificationTest.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"></pre>
<script type="text/javascript">
SimpleTest.requestFlakyTimeout("untriaged");
function deleteAllNotifications(done) {
var promise = Notification.get();
promise.then(function(notifications) {
notifications.forEach(function(notification) {
notification.close();
});
done();
});
}
var info = NotificationTest.info;
var steps = [
function(done) {
info("Test that Notifcation.get fulfills the promise");
var promise = Notification.get();
ok(promise.then, "should return a promise");
// Create a new notification to make sure
// Notification.get() works while creating
new Notification("this is a test");
promise.then(function() {
ok(true, "promise should be fulfilled");
done();
});
},
deleteAllNotifications,
function(done) {
info("Test adding a notification, and making sure get returns it");
NotificationTest.allowNotifications();
var options = NotificationTest.payload;
var notification = new Notification("This is a title", options);
var promise = Notification.get();
promise.then(function(notifications) {
ok(notifications.length, "should return notifications");
for (var i = 0; i < notifications.length; i++) {
var currentNotification = notifications[i];
if (currentNotification.tag === options.tag) {
ok(true, "should contain newly created notification");
for (var key in options) {
if (key === "data") {
ok(NotificationTest.customDataMatches(currentNotification.data),
"data property should match");
continue;
}
is(currentNotification[key], options[key], key + " property should match");
}
currentNotification.close();
return;
}
}
ok(false, "should contain newly created notification");
notification.close();
});
notification.onclose = done;
},
function(done) {
info("Testing fetching notification by tag filter");
var n1 = new Notification("title1", {tag: "tag1"});
var n2 = new Notification("title2", {tag: "tag2"});
var n3 = new Notification("title3", {tag: "tag3"});
var promise = Notification.get({tag: "tag3"});
promise.then(function(notifications) {
var notification = notifications[0];
is(notifications.length, 1, "should return 1 notification");
is(notification.title, "title3", "titles should match");
is(notification.tag, "tag3", "tags should match");
var closeCount = 0;
var waitForAll = function() {
if (++closeCount >= 3) {
done();
}
};
n1.onclose = waitForAll;
n2.onclose = waitForAll;
n3.onclose = waitForAll;
n1.close();
n2.close();
n3.close();
});
},
deleteAllNotifications,
function(done) {
info("Testing fetching no notifications");
var promise = Notification.get();
promise.then(function(notifications) {
is(notifications.length, 0, "should return 0 notifications");
done();
});
},
function(done) {
info("Testing fetching multiple notifications");
var n1 = new Notification("title1");
var n2 = new Notification("title2");
var n3 = new Notification("title3");
var promise = Notification.get();
promise.then(function(notifications) {
is(notifications.length, 3, "should return 3 notifications");
n1.close();
n2.close();
n3.close();
done();
});
},
deleteAllNotifications,
function(done) {
info("Testing 'alertfinished' removes the notification from DB");
var n = new Notification("test-title" + Math.random());
n.onclose = function() {
Notification.get().then(function(notifications) {
is(notifications.length, 0, "should return 0 notifications");
done();
});
};
info("Installing 'onshow' for " + n.title);
n.onshow = function() {
info("Triggered 'onshow' for " + n.title);
window.setTimeout(function() {
NotificationTest.fireCloseEvent(n.title);
}, 100);
};
},
];
MockServices.register();
NotificationTest.run(steps, function() {
MockServices.unregister();
});
</script>
</body>
</html>

Просмотреть файл

@ -23,9 +23,6 @@ interface Notification : EventTarget {
[NewObject, Func="mozilla::dom::Notification::RequestPermissionEnabledForScope"]
static Promise<NotificationPermission> requestPermission(optional NotificationPermissionCallback permissionCallback);
[NewObject, Func="mozilla::dom::Notification::IsGetEnabled"]
static Promise<sequence<Notification>> get(optional GetNotificationOptions filter = {});
attribute EventHandler onclick;
attribute EventHandler onshow;

Просмотреть файл

@ -1,9 +0,0 @@
[historical.any.worker.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[historical.any.html]
expected:
if (os == "android") and fission: [TIMEOUT, OK]
[Notification.get is obsolete]
expected: FAIL