From e26e5ee5d4a766ef270e56848738cc8b706521bc Mon Sep 17 00:00:00 2001 From: Ferenc Nagy Date: Sat, 16 Feb 2019 14:15:43 +0000 Subject: [PATCH] Bug 1509042 - Enable Eslint for dom/notification (manual changes) r=Ehsan Depends on D12815 Differential Revision: https://phabricator.services.mozilla.com/D12816 --HG-- extra : moz-landing-system : lando --- .eslintignore | 3 --- dom/notification/NotificationDB.jsm | 14 +++++--------- .../test/mochitest/MockServices.js | 9 ++++++++- .../test/mochitest/NotificationTest.js | 5 +++-- .../mochitest/test_notification_storage.html | 18 +++++++++--------- .../test/mochitest/test_notification_tag.html | 1 + 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.eslintignore b/.eslintignore index 597ce9ebe4ef..dd0755fe7b68 100644 --- a/.eslintignore +++ b/.eslintignore @@ -189,9 +189,6 @@ dom/media/webspeech/** dom/messagechannel/** dom/midi/** dom/network/** -dom/notification/Notification*.* -dom/notification/test/browser/** -dom/notification/test/mochitest/** dom/payments/** dom/performance/** dom/permission/** diff --git a/dom/notification/NotificationDB.jsm b/dom/notification/NotificationDB.jsm index ad950e4ffb8f..83651f0594e1 100644 --- a/dom/notification/NotificationDB.jsm +++ b/dom/notification/NotificationDB.jsm @@ -9,16 +9,11 @@ var EXPORTED_SYMBOLS = []; const DEBUG = false; function debug(s) { dump("-*- NotificationDB component: " + s + "\n"); } -const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); ChromeUtils.defineModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); -XPCOMUtils.defineLazyServiceGetter(this, "notificationStorage", - "@mozilla.org/notificationStorage;1", - "nsINotificationStorage"); - const NOTIFICATION_STORE_DIR = OS.Constants.Path.profileDir; const NOTIFICATION_STORE_PATH = OS.Path.join(NOTIFICATION_STORE_DIR, "notificationstore.json"); @@ -258,15 +253,16 @@ var NotificationDB = { switch (task.operation) { case "getall": return this.taskGetAll(task.data); - break; case "save": return this.taskSave(task.data); - break; case "delete": return this.taskDelete(task.data); - break; + + default: + return Promise.reject( + new Error(`Found a task with unknown operation ${task.operation}`)); } }) .then(payload => { @@ -279,7 +275,7 @@ var NotificationDB = { if (DEBUG) { debug("Error while running " + this.runningTask.operation + ": " + err); } - this.runningTask.defer.reject(new String(err)); + this.runningTask.defer.reject(err); }) .then(() => { this.runNextTask(); diff --git a/dom/notification/test/mochitest/MockServices.js b/dom/notification/test/mochitest/MockServices.js index a40192508a4f..9b06417807c4 100644 --- a/dom/notification/test/mochitest/MockServices.js +++ b/dom/notification/test/mochitest/MockServices.js @@ -1,3 +1,4 @@ +/* eslint-disable mozilla/use-chromeutils-generateqi */ var MockServices = (function() { "use strict"; @@ -76,7 +77,13 @@ var MockServices = (function() { } }, - QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]), + QueryInterface(aIID) { + if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) || + SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService)) { + return this; + } + throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; + }, createInstance(aOuter, aIID) { if (aOuter != null) { diff --git a/dom/notification/test/mochitest/NotificationTest.js b/dom/notification/test/mochitest/NotificationTest.js index 0ea77ad91186..1076afa65f34 100644 --- a/dom/notification/test/mochitest/NotificationTest.js +++ b/dom/notification/test/mochitest/NotificationTest.js @@ -22,7 +22,8 @@ var NotificationTest = (function() { (function executeRemainingTests(remainingTests) { if (!remainingTests.length) { - return callback(); + callback(); + return; } var nextTest = remainingTests.shift(); @@ -45,7 +46,7 @@ var NotificationTest = (function() { var fakeCustomData = (function() { var buffer = new ArrayBuffer(2); - var dv = new DataView(buffer).setInt16(0, 42, true); + new DataView(buffer).setInt16(0, 42, true); var canvas = document.createElement("canvas"); canvas.width = canvas.height = 100; var context = canvas.getContext("2d"); diff --git a/dom/notification/test/mochitest/test_notification_storage.html b/dom/notification/test/mochitest/test_notification_storage.html index c6ef3c54c641..c695b94c67c6 100644 --- a/dom/notification/test/mochitest/test_notification_storage.html +++ b/dom/notification/test/mochitest/test_notification_storage.html @@ -2,8 +2,8 @@ Notification Basics - + @@ -35,7 +35,7 @@ // Create a new notification to make sure // Notification.get() works while creating - var notification = new Notification("this is a test"); + new Notification("this is a test"); promise.then(function() { ok(true, "promise should be fulfilled"); @@ -55,18 +55,18 @@ promise.then(function(notifications) { ok(notifications.length, "should return notifications"); for (var i = 0; i < notifications.length; i++) { - var notification = notifications[i]; - if (notification.tag === options.tag) { + 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(notification.data), + ok(NotificationTest.customDataMatches(currentNotification.data), "data property should match"); continue; } - is(notification[key], options[key], key + " property should match"); + is(currentNotification[key], options[key], key + " property should match"); } - notification.close(); + currentNotification.close(); return; } } @@ -85,8 +85,8 @@ promise.then(function(notifications) { var notification = notifications[0]; is(notifications.length, 1, "should return 1 notification"); - is(notifications[0].title, "title3", "titles should match"); - is(notifications[0].tag, "tag3", "tags should match"); + is(notification.title, "title3", "titles should match"); + is(notification.tag, "tag3", "tags should match"); var closeCount = 0; var waitForAll = function() { if (++closeCount >= 3) { diff --git a/dom/notification/test/mochitest/test_notification_tag.html b/dom/notification/test/mochitest/test_notification_tag.html index 5809e6ccc822..7c63893f1219 100644 --- a/dom/notification/test/mochitest/test_notification_tag.html +++ b/dom/notification/test/mochitest/test_notification_tag.html @@ -19,6 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=782211