Bug 1299846 - Complete the implementation of chrome.idle.queryState, r=kmag
authorBob Silverberg <bsilverberg@mozilla.com>
Thu, 01 Sep 2016 09:28:56 -0400
changeset 312588 bf2af823492c9a451e0cf92f38cfbfc6c557507a
parent 312587 73e11489018d57a94c02a6f2808554b54ae7692d
child 312589 90644e264b8351f8c280284ae838bfacef90f69b
push id30647
push userphilringnalda@gmail.com
push dateSun, 04 Sep 2016 04:50:54 +0000
treeherdermozilla-central@d61bbdd0b155 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1299846
milestone51.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 1299846 - Complete the implementation of chrome.idle.queryState, r=kmag MozReview-Commit-ID: jYsePeTluZ
toolkit/components/extensions/ext-idle.js
toolkit/components/extensions/test/xpcshell/test_ext_idle.js
--- a/toolkit/components/extensions/ext-idle.js
+++ b/toolkit/components/extensions/ext-idle.js
@@ -1,11 +1,18 @@
 "use strict";
 
+XPCOMUtils.defineLazyServiceGetter(this, "idleService",
+                                   "@mozilla.org/widget/idleservice;1",
+                                   "nsIIdleService");
+
 extensions.registerSchemaAPI("idle", "addon_parent", context => {
   return {
     idle: {
       queryState: function(detectionIntervalInSeconds) {
-        return Promise.resolve("active");
+        if (idleService.idleTime < detectionIntervalInSeconds * 1000) {
+          return Promise.resolve("active");
+        }
+        return Promise.resolve("idle");
       },
     },
   };
 });
--- a/toolkit/components/extensions/test/xpcshell/test_ext_idle.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_idle.js
@@ -1,30 +1,65 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
-add_task(function* testIdle() {
+Cu.import("resource://testing-common/MockRegistrar.jsm");
+
+let idleService = {
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIIdleService]),
+  idleTime: 19999,
+};
+
+add_task(function* setup() {
+  let fakeIdleService = MockRegistrar.register("@mozilla.org/widget/idleservice;1", idleService);
+  do_register_cleanup(() => {
+    MockRegistrar.unregister(fakeIdleService);
+  });
+});
+
+add_task(function* testIdleActive() {
   function background() {
-    browser.idle.queryState(15).then(status => {
-      browser.test.assertEq("active", status, "Expected status");
+    browser.idle.queryState(20).then(status => {
+      browser.test.assertEq("active", status, "Idle status is active");
       browser.test.notifyPass("idle");
     },
-    e => {
-      browser.test.fail(`Error: ${e} :: ${e.stack}`);
+    err => {
+      browser.test.fail(`Error: ${err} :: ${err.stack}`);
       browser.test.notifyFail("idle");
     });
   }
 
   let extension = ExtensionTestUtils.loadExtension({
     background,
-
     manifest: {
       permissions: ["idle"],
     },
   });
 
   yield extension.startup();
-
   yield extension.awaitFinish("idle");
-
   yield extension.unload();
 });
+
+add_task(function* testIdleIdle() {
+  function background() {
+    browser.idle.queryState(15).then(status => {
+      browser.test.assertEq("idle", status, "Idle status is idle");
+      browser.test.notifyPass("idle");
+    },
+    err => {
+      browser.test.fail(`Error: ${err} :: ${err.stack}`);
+      browser.test.notifyFail("idle");
+    });
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    background,
+    manifest: {
+      permissions: ["idle"],
+    },
+  });
+
+  yield extension.startup();
+  yield extension.awaitFinish("idle");
+  yield extension.unload();
+});