Bug 1509042 - Enable Eslint for dom/notification (manual changes) r=Ehsan
authorFerenc Nagy <nagy.ferenc.jr@gmail.com>
Sat, 16 Feb 2019 14:15:43 +0000
changeset 459681 b1463424f116029d24eb87845ad9ddec68eb10a1
parent 459680 677240cf51405d6473d02f5ed3af4f8e2ddb7d94
child 459682 be1132e03145abe7cf1b325fb5772127e1135e7d
push id35565
push userncsoregi@mozilla.com
push dateSat, 16 Feb 2019 21:45:13 +0000
treeherdermozilla-central@bf8ca7933ead [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1509042
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1509042 - Enable Eslint for dom/notification (manual changes) r=Ehsan Depends on D12815 Differential Revision: https://phabricator.services.mozilla.com/D12816
.eslintignore
dom/notification/NotificationDB.jsm
dom/notification/test/mochitest/MockServices.js
dom/notification/test/mochitest/NotificationTest.js
dom/notification/test/mochitest/test_notification_storage.html
dom/notification/test/mochitest/test_notification_tag.html
--- a/.eslintignore
+++ b/.eslintignore
@@ -184,19 +184,16 @@ dom/html/**
 dom/jsurl/**
 dom/media/test/**
 dom/media/tests/**
 dom/media/webaudio/**
 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/**
 dom/plugins/test/mochitest/**
 dom/plugins/test/unit/**
 dom/promise/**
 dom/push/**
 dom/quota/**
--- a/dom/notification/NotificationDB.jsm
+++ b/dom/notification/NotificationDB.jsm
@@ -4,26 +4,21 @@
 
 "use strict";
 
 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");
 
 const kMessages = [
   "Notification:Save",
   "Notification:Delete",
   "Notification:GetAll",
@@ -253,38 +248,39 @@ var NotificationDB = {
     // Always make sure we are loaded before performing any read/write tasks.
     this.ensureLoaded()
     .then(() => {
       var task = this.runningTask;
 
       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 => {
       if (DEBUG) {
         debug("Finishing task: " + this.runningTask.operation);
       }
       this.runningTask.defer.resolve(payload);
     })
     .catch(err => {
       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();
     });
   },
 
   taskGetAll(data) {
     if (DEBUG) { debug("Task, getting all"); }
--- a/dom/notification/test/mochitest/MockServices.js
+++ b/dom/notification/test/mochitest/MockServices.js
@@ -1,8 +1,9 @@
+/* eslint-disable mozilla/use-chromeutils-generateqi */
 var MockServices = (function() {
   "use strict";
 
   const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components)
                           .ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}");
   const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
 
   const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components)
@@ -71,17 +72,23 @@ var MockServices = (function() {
       }
 
       var appNotification = activeAppNotifications[name];
       if (appNotification) {
         delete activeAppNotifications[name];
       }
     },
 
-    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) {
         throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION;
       }
       return this.QueryInterface(aIID);
     },
   };
--- a/dom/notification/test/mochitest/NotificationTest.js
+++ b/dom/notification/test/mochitest/NotificationTest.js
@@ -17,17 +17,18 @@ var NotificationTest = (function() {
 
   function executeTests(tests, callback) {
     // context is `this` object in test functions
     // it can be used to track data between tests
     var context = {};
 
     (function executeRemainingTests(remainingTests) {
       if (!remainingTests.length) {
-        return callback();
+        callback();
+        return;
       }
 
       var nextTest = remainingTests.shift();
       var finishTest = executeRemainingTests.bind(null, remainingTests);
       var startTest = nextTest.call.bind(nextTest, context, finishTest);
 
       try {
         startTest();
@@ -40,17 +41,17 @@ var NotificationTest = (function() {
         ok(false, "Test threw exception!");
         finishTest();
       }
     })(tests);
   }
 
   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");
 
     var map = new Map();
     var set = new Set();
     map.set("test", 42);
     set.add(4); set.add(2);
--- a/dom/notification/test/mochitest/test_notification_storage.html
+++ b/dom/notification/test/mochitest/test_notification_storage.html
@@ -1,14 +1,14 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Notification Basics</title>
+  <script type="text/javascript" src="MockServices.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="MockServices.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">
@@ -30,17 +30,17 @@
   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
-      var notification = new Notification("this is a test");
+      new Notification("this is a test");
 
       promise.then(function() {
         ok(true, "promise should be fulfilled");
         done();
       });
     },
 
     deleteAllNotifications,
@@ -50,28 +50,28 @@
       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 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;
           }
         }
         ok(false, "should contain newly created notification");
         notification.close();
       });
       notification.onclose = done;
     },
@@ -80,18 +80,18 @@
       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(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) {
             done();
           }
         };
         n1.onclose = waitForAll;
         n2.onclose = waitForAll;
--- a/dom/notification/test/mochitest/test_notification_tag.html
+++ b/dom/notification/test/mochitest/test_notification_tag.html
@@ -14,16 +14,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <iframe name="sameDomain"></iframe>
 <iframe name="anotherSameDomain"></iframe>
 <iframe name="crossDomain"></iframe>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 </pre>
 <script type="text/javascript">
+  /* eslint-disable mozilla/use-chromeutils-generateqi */
   const MOCK_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{dbe37e64-d9a3-402c-8d8a-0826c619f7ad}");
   const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
 
   var mockAlertsService = {
     showAlert(alert, alertListener) {
       notificationsCreated.push(alert.name);
       if (notificationsCreated.length == 3) {
         checkNotifications();