Bug 1234020: Part 2c - [webext] Return promises from the idle API. r=rpl

This commit is contained in:
Kris Maglione 2016-02-02 19:35:31 -08:00
parent 2d769cdaa7
commit 6500b66487
4 changed files with 47 additions and 2 deletions

View File

@ -3,8 +3,8 @@
extensions.registerSchemaAPI("idle", "idle", (extension, context) => {
return {
idle: {
queryState: function(detectionIntervalInSeconds, callback) {
runSafe(context, callback, "active");
queryState: function(detectionIntervalInSeconds) {
return Promise.resolve("active");
},
},
};

View File

@ -18,6 +18,7 @@
"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",

View File

@ -32,6 +32,7 @@ skip-if = buildapp == 'b2g' # runat != document_idle is not supported.
[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]

View File

@ -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>