Bug 1234020: Part 2c - [webext] Return promises from the idle API. r?rpl
--- a/toolkit/components/extensions/ext-idle.js
+++ b/toolkit/components/extensions/ext-idle.js
@@ -1,11 +1,11 @@
"use strict";
extensions.registerSchemaAPI("idle", "idle", (extension, context) => {
return {
idle: {
- queryState: function(detectionIntervalInSeconds, callback) {
- runSafe(context, callback, "active");
+ queryState: function(detectionIntervalInSeconds) {
+ return Promise.resolve("active");
},
},
};
});
--- a/toolkit/components/extensions/schemas/idle.json
+++ b/toolkit/components/extensions/schemas/idle.json
@@ -13,16 +13,17 @@
"enum": ["active", "idle", "locked"]
}
],
"functions": [
{
"name": "queryState",
"type": "function",
"description": "Returns \"locked\" if the system is locked, \"idle\" if the user has not generated any input for a specified number of seconds, or \"active\" otherwise.",
+ "async": "callback",
"parameters": [
{
"name": "detectionIntervalInSeconds",
"type": "integer",
"minimum": 15,
"description": "The system is considered idle if detectionIntervalInSeconds seconds have elapsed since the last user input detected."
},
{
--- a/toolkit/components/extensions/test/mochitest/mochitest.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest.ini
@@ -27,16 +27,17 @@ support-files =
[test_ext_schema.html]
[test_ext_geturl.html]
[test_ext_contentscript.html]
skip-if = buildapp == 'b2g' # runat != document_idle is not supported.
[test_ext_contentscript_create_iframe.html]
[test_ext_contentscript_api_injection.html]
[test_ext_i18n_css.html]
[test_ext_generate.html]
+[test_ext_idle.html]
[test_ext_localStorage.html]
[test_ext_onmessage_removelistener.html]
[test_ext_notifications.html]
[test_ext_permission_xhr.html]
skip-if = buildapp == 'b2g' # JavaScript error: jar:remoteopenfile:///data/local/tmp/generated-extension.xpi!/content.js, line 46: NS_ERROR_ILLEGAL_VALUE:
[test_ext_runtime_connect.html]
skip-if = buildapp == 'b2g' # port.sender.tab is undefined on b2g.
[test_ext_runtime_connect2.html]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_idle.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>WebExtension idle API test</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <script type="text/javascript" src="head.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+add_task(function* testIdle() {
+ function background() {
+ browser.idle.queryState(15).then(status => {
+ browser.test.assertEq("active", status, "Expected status");
+ browser.test.notifyPass("idle");
+ },
+ e => {
+ browser.test.fail(`Error: ${e} :: ${e.stack}`);
+ browser.test.notifyFail("idle");
+ });
+ }
+
+ let extension = ExtensionTestUtils.loadExtension({
+ background: `(${background})()`,
+
+ manifest: {
+ permissions: ["idle"],
+ },
+ });
+
+ yield extension.startup();
+
+ yield extension.awaitFinish("idle");
+
+ yield extension.unload();
+});
+</script>
+</body>