summaryrefslogtreecommitdiffstats
path: root/toolkit/components/webextensions/test/xpcshell/test_ext_idle.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@wolfbeast.com>2019-03-06 12:30:20 +0100
committerwolfbeast <mcwerewolf@wolfbeast.com>2019-03-06 12:30:20 +0100
commite25ad543952b5afc13181aaebef9c5951fc27be0 (patch)
tree456a1359b3e5f810319edd423dd5cc5a1e22ada5 /toolkit/components/webextensions/test/xpcshell/test_ext_idle.js
parent74533a843277c3687c749989ed1522354d1054d2 (diff)
parent5dba1ebe8498286762873fff0016f35f3e14d2d5 (diff)
downloadUXP-e25ad543952b5afc13181aaebef9c5951fc27be0.tar
UXP-e25ad543952b5afc13181aaebef9c5951fc27be0.tar.gz
UXP-e25ad543952b5afc13181aaebef9c5951fc27be0.tar.lz
UXP-e25ad543952b5afc13181aaebef9c5951fc27be0.tar.xz
UXP-e25ad543952b5afc13181aaebef9c5951fc27be0.zip
Merge branch 'master' into Basilisk-releasev2019.03.08
Diffstat (limited to 'toolkit/components/webextensions/test/xpcshell/test_ext_idle.js')
-rw-r--r--toolkit/components/webextensions/test/xpcshell/test_ext_idle.js202
1 files changed, 0 insertions, 202 deletions
diff --git a/toolkit/components/webextensions/test/xpcshell/test_ext_idle.js b/toolkit/components/webextensions/test/xpcshell/test_ext_idle.js
deleted file mode 100644
index 89bcac217..000000000
--- a/toolkit/components/webextensions/test/xpcshell/test_ext_idle.js
+++ /dev/null
@@ -1,202 +0,0 @@
-/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
-/* vim: set sts=2 sw=2 et tw=80: */
-"use strict";
-
-Cu.import("resource://testing-common/MockRegistrar.jsm");
-
-let idleService = {
- _observers: new Set(),
- _activity: {
- addCalls: [],
- removeCalls: [],
- observerFires: [],
- },
- _reset: function() {
- this._observers.clear();
- this._activity.addCalls = [];
- this._activity.removeCalls = [];
- this._activity.observerFires = [];
- },
- _fireObservers: function(state) {
- for (let observer of this._observers.values()) {
- observer.observe(observer, state, null);
- this._activity.observerFires.push(state);
- }
- },
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIIdleService]),
- idleTime: 19999,
- addIdleObserver: function(observer, time) {
- this._observers.add(observer);
- this._activity.addCalls.push(time);
- },
- removeIdleObserver: function(observer, time) {
- this._observers.delete(observer);
- this._activity.removeCalls.push(time);
- },
-};
-
-function checkActivity(expectedActivity) {
- let {expectedAdd, expectedRemove, expectedFires} = expectedActivity;
- let {addCalls, removeCalls, observerFires} = idleService._activity;
- equal(expectedAdd.length, addCalls.length, "idleService.addIdleObserver was called the expected number of times");
- equal(expectedRemove.length, removeCalls.length, "idleService.removeIdleObserver was called the expected number of times");
- equal(expectedFires.length, observerFires.length, "idle observer was fired the expected number of times");
- deepEqual(addCalls, expectedAdd, "expected interval passed to idleService.addIdleObserver");
- deepEqual(removeCalls, expectedRemove, "expected interval passed to idleService.removeIdleObserver");
- deepEqual(observerFires, expectedFires, "expected topic passed to idle observer");
-}
-
-add_task(function* setup() {
- let fakeIdleService = MockRegistrar.register("@mozilla.org/widget/idleservice;1", idleService);
- do_register_cleanup(() => {
- MockRegistrar.unregister(fakeIdleService);
- });
-});
-
-add_task(function* testQueryStateActive() {
- function background() {
- browser.idle.queryState(20).then(status => {
- browser.test.assertEq("active", status, "Idle status is active");
- 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();
-});
-
-add_task(function* testQueryStateIdle() {
- 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();
-});
-
-add_task(function* testOnlySetDetectionInterval() {
- function background() {
- browser.idle.setDetectionInterval(99);
- browser.test.sendMessage("detectionIntervalSet");
- }
-
- let extension = ExtensionTestUtils.loadExtension({
- background,
- manifest: {
- permissions: ["idle"],
- },
- });
-
- idleService._reset();
- yield extension.startup();
- yield extension.awaitMessage("detectionIntervalSet");
- idleService._fireObservers("idle");
- checkActivity({expectedAdd: [], expectedRemove: [], expectedFires: []});
- yield extension.unload();
-});
-
-add_task(function* testSetDetectionIntervalBeforeAddingListener() {
- function background() {
- browser.idle.setDetectionInterval(99);
- browser.idle.onStateChanged.addListener(newState => {
- browser.test.assertEq("idle", newState, "listener fired with the expected state");
- browser.test.sendMessage("listenerFired");
- });
- browser.test.sendMessage("listenerAdded");
- }
-
- let extension = ExtensionTestUtils.loadExtension({
- background,
- manifest: {
- permissions: ["idle"],
- },
- });
-
- idleService._reset();
- yield extension.startup();
- yield extension.awaitMessage("listenerAdded");
- idleService._fireObservers("idle");
- yield extension.awaitMessage("listenerFired");
- checkActivity({expectedAdd: [99], expectedRemove: [], expectedFires: ["idle"]});
- yield extension.unload();
-});
-
-add_task(function* testSetDetectionIntervalAfterAddingListener() {
- function background() {
- browser.idle.onStateChanged.addListener(newState => {
- browser.test.assertEq("idle", newState, "listener fired with the expected state");
- browser.test.sendMessage("listenerFired");
- });
- browser.idle.setDetectionInterval(99);
- browser.test.sendMessage("detectionIntervalSet");
- }
-
- let extension = ExtensionTestUtils.loadExtension({
- background,
- manifest: {
- permissions: ["idle"],
- },
- });
-
- idleService._reset();
- yield extension.startup();
- yield extension.awaitMessage("detectionIntervalSet");
- idleService._fireObservers("idle");
- yield extension.awaitMessage("listenerFired");
- checkActivity({expectedAdd: [60, 99], expectedRemove: [60], expectedFires: ["idle"]});
- yield extension.unload();
-});
-
-add_task(function* testOnlyAddingListener() {
- function background() {
- browser.idle.onStateChanged.addListener(newState => {
- browser.test.assertEq("active", newState, "listener fired with the expected state");
- browser.test.sendMessage("listenerFired");
- });
- browser.test.sendMessage("listenerAdded");
- }
-
- let extension = ExtensionTestUtils.loadExtension({
- background,
- manifest: {
- permissions: ["idle"],
- },
- });
-
- idleService._reset();
- yield extension.startup();
- yield extension.awaitMessage("listenerAdded");
- idleService._fireObservers("active");
- yield extension.awaitMessage("listenerFired");
- // check that "idle-daily" topic does not cause a listener to fire
- idleService._fireObservers("idle-daily");
- checkActivity({expectedAdd: [60], expectedRemove: [], expectedFires: ["active", "idle-daily"]});
- yield extension.unload();
-});