From d651053da276f336b24984b65fa59c877cde97aa Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Mon, 14 Mar 2022 13:27:20 +0000 Subject: [PATCH] Bug 1748714 - Regenerate ExtensionAlarms.webidl and remove skip on test_alarms_get_and_clear_single_argument. r=mixedpuppy,webidl,peterv Differential Revision: https://phabricator.services.mozilla.com/D135420 --- dom/webidl/ExtensionAlarms.webidl | 12 +++- .../test/xpcshell/test_ext_alarms.js | 71 +++++++++++++------ 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/dom/webidl/ExtensionAlarms.webidl b/dom/webidl/ExtensionAlarms.webidl index adfa9cb7dff6..4d3cf01a6e77 100644 --- a/dom/webidl/ExtensionAlarms.webidl +++ b/dom/webidl/ExtensionAlarms.webidl @@ -26,16 +26,22 @@ interface ExtensionAlarms { // API methods. [Throws, WebExtensionStub="NoReturn"] - void create(optional DOMString name, any alarmInfo); + void create(DOMString name, any alarmInfo); + [Throws, WebExtensionStub="NoReturn"] + void create(any alarmInfo); [Throws, WebExtensionStub="Async"] - any get(optional DOMString name, optional Function callback); + any get(DOMString name, optional Function callback); + [Throws, WebExtensionStub="Async"] + any get(optional Function callback); [Throws, WebExtensionStub="Async"] any getAll(optional Function callback); [Throws, WebExtensionStub="Async"] - any clear(optional DOMString name, optional Function callback); + any clear(DOMString name, optional Function callback); + [Throws, WebExtensionStub="Async"] + any clear(optional Function callback); [Throws, WebExtensionStub="Async"] any clearAll(optional Function callback); diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js b/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js index c6986d0039b5..34cd2daada4d 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_alarms.js @@ -65,39 +65,67 @@ add_task(async function test_alarm_clear_non_matching_name() { await extension.unload(); }); -add_task( - { - // TODO(Bug 1748714): remove once alarms.create accepts also a single parameter. - skip_if: () => ExtensionTestUtils.isInBackgroundServiceWorkerTests(), - }, - async function test_alarm_get_and_clear_single_argument() { - async function backgroundScript() { - browser.alarms.create({ when: Date.now() + 2000000 }); +add_task(async function test_alarm_get_and_clear_single_argument() { + async function backgroundScript() { + browser.alarms.create({ when: Date.now() + 2000000 }); - let alarm = await browser.alarms.get(); - browser.test.assertEq("", alarm.name, "expected alarm returned"); + let alarm = await browser.alarms.get(); + browser.test.assertEq("", alarm.name, "expected alarm returned"); - let wasCleared = await browser.alarms.clear(); - browser.test.assertTrue(wasCleared, "alarm was cleared"); + let wasCleared = await browser.alarms.clear(); + browser.test.assertTrue(wasCleared, "alarm was cleared"); - let alarms = await browser.alarms.getAll(); - browser.test.assertEq(0, alarms.length, "alarm was removed"); + let alarms = await browser.alarms.getAll(); + browser.test.assertEq(0, alarms.length, "alarm was removed"); - browser.test.notifyPass("alarm-single-arg"); - } + browser.test.notifyPass("alarm-single-arg"); + } + let extension = ExtensionTestUtils.loadExtension({ + background: `(${backgroundScript})()`, + manifest: { + permissions: ["alarms"], + }, + }); + + await extension.startup(); + await extension.awaitFinish("alarm-single-arg"); + await extension.unload(); +}); + +// This test case covers the behavior of browser.alarms.create when the +// first optional argument (the alarm name) is passed explicitly as null +// or undefined instead of being omitted. +add_task(async function test_alarm_name_arg_null_or_undefined() { + async function backgroundScript(alarmName) { + browser.alarms.create(alarmName, { when: Date.now() + 2000000 }); + + let alarm = await browser.alarms.get(); + browser.test.assertTrue(alarm, "got an alarm"); + browser.test.assertEq("", alarm.name, "expected alarm returned"); + + let wasCleared = await browser.alarms.clear(); + browser.test.assertTrue(wasCleared, "alarm was cleared"); + + let alarms = await browser.alarms.getAll(); + browser.test.assertEq(0, alarms.length, "alarm was removed"); + + browser.test.notifyPass("alarm-test-done"); + } + + for (const alarmName of [null, undefined]) { + info(`Test alarm.create with alarm name ${alarmName}`); let extension = ExtensionTestUtils.loadExtension({ - background: `(${backgroundScript})()`, + background: `(${backgroundScript})(${alarmName})`, manifest: { permissions: ["alarms"], }, }); - await extension.startup(); - await extension.awaitFinish("alarm-single-arg"); + await extension.awaitFinish("alarm-test-done"); await extension.unload(); } -); +}); add_task(async function test_get_get_all_clear_all_alarms() { async function backgroundScript() { @@ -257,7 +285,8 @@ function trackEvents(wrapper) { add_task( { - // TODO(Bug 1725478): remove the skip if once webidl API bindings will be hidden based on permissions. + // TODO(Bug 1748665): remove the skip once background service worker is also + // woken up by persistent listeners. skip_if: () => ExtensionTestUtils.isInBackgroundServiceWorkerTests(), pref_set: [ ["privacy.resistFingerprinting.reduceTimerPrecision.jitter", false],