Bug 1724026 - Add a new xpcshell-serviceworker.ini manifest and include all alarms API tests in it. r=mixedpuppy

This patch includes:

- a new xpcshell-serviceworker.ini manifest, all tests included in this manifest will also run in the
  "background service worker mode", initially including all `alarms` API xpcshell tests

- some small changes to test_ext_alarms.js to temporarily skip test case that can't yet pass
  while running in "background service worker mode" (until fixed in separate followups)

- some small tweaks to head_service_worker.js to avoid failure due to an existing ExtensionCommon
  const bindings being redefined while running a test for the xpcshell-remote.ini manifest

Differential Revision: https://phabricator.services.mozilla.com/D135125
This commit is contained in:
Luca Greco 2022-01-12 11:33:13 +00:00
parent 63324905ef
commit bc9802e70b
12 changed files with 105 additions and 85 deletions

View file

@ -609,6 +609,18 @@ class ExternallyInstalledWrapper extends AOMExtensionWrapper {
var ExtensionTestUtils = {
BASE_MANIFEST,
// Shortcut to more easily access WebExtensionPolicy.backgroundServiceWorkerEnabled
// from mochitest-plain tests.
getBackgroundServiceWorkerEnabled() {
return ExtensionTestCommon.getBackgroundServiceWorkerEnabled();
},
// A test helper used to check if the pref "extension.backgroundServiceWorker.forceInTestExtension"
// is set to true.
isInBackgroundServiceWorkerTests() {
return ExtensionTestCommon.isInBackgroundServiceWorkerTests();
},
async normalizeManifest(
manifest,
manifestType = "manifest.WebExtensionManifest",

View file

@ -126,7 +126,10 @@ XPCSHELL_TESTS_MANIFESTS += [
# Only include tests that requires the WebExtensions WebIDL API bindings
# in builds where they are enabled (currently only on Nightly builds).
if CONFIG["MOZ_WEBEXT_WEBIDL_ENABLED"]:
XPCSHELL_TESTS_MANIFESTS += ["test/xpcshell/webidl-api/xpcshell.ini"]
XPCSHELL_TESTS_MANIFESTS += [
"test/xpcshell/webidl-api/xpcshell.ini",
"test/xpcshell/xpcshell-serviceworker.ini",
]
MOCHITEST_MANIFESTS += ["test/mochitest/mochitest-serviceworker.ini"]

View file

@ -1,7 +1,7 @@
"use strict";
/* exported createHttpServer, cleanupDir, clearCache, optionalPermissionsPromptHandler, promiseConsoleOutput,
promiseQuotaManagerServiceReset, promiseQuotaManagerServiceClear,
/* exported createHttpServer, cleanupDir, clearCache, isInBackgroundServiceWorkerTests,
promiseConsoleOutput, promiseQuotaManagerServiceReset, promiseQuotaManagerServiceClear,
runWithPrefs, testEnv, withHandlingUserInput, resetHandlingUserInput */
var { AppConstants } = ChromeUtils.import(

View file

@ -4,8 +4,20 @@
/* exported TestWorkerWatcher */
const { ExtensionCommon } = ChromeUtils.import(
"resource://gre/modules/ExtensionCommon.jsm"
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionCommon: "resource://gre/modules/ExtensionCommon.jsm",
});
// Ensure that the profile-after-change message has been notified,
// so that ServiceWokerRegistrar is going to be initialized,
// otherwise tests using a background service worker will fail.
// in debug builds because of an assertion failure triggered
// by ServiceWorkerRegistrar.cpp (due to not being initialized
// automatically on startup as in a real Firefox instance).
Services.obs.notifyObservers(
null,
"profile-after-change",
"force-serviceworkerrestart-init"
);
// A test utility class used in the test case to watch for a given extension

View file

@ -3,26 +3,32 @@
/* eslint-disable mozilla/no-arbitrary-setTimeout */
"use strict";
add_task(async function test_alarm_without_permissions() {
function backgroundScript() {
browser.test.assertTrue(
!browser.alarms,
"alarm API is not available when the alarm permission is not required"
);
browser.test.notifyPass("alarms_permission");
add_task(
{
// TODO(Bug 1725478): remove the skip if once webidl API bindings will be hidden based on permissions.
skip_if: () => ExtensionTestUtils.isInBackgroundServiceWorkerTests(),
},
async function test_alarm_without_permissions() {
function backgroundScript() {
browser.test.assertTrue(
!browser.alarms,
"alarm API is not available when the alarm permission is not required"
);
browser.test.notifyPass("alarms_permission");
}
let extension = ExtensionTestUtils.loadExtension({
background: `(${backgroundScript})()`,
manifest: {
permissions: [],
},
});
await extension.startup();
await extension.awaitFinish("alarms_permission");
await extension.unload();
}
let extension = ExtensionTestUtils.loadExtension({
background: `(${backgroundScript})()`,
manifest: {
permissions: [],
},
});
await extension.startup();
await extension.awaitFinish("alarms_permission");
await extension.unload();
});
);
add_task(async function test_alarm_clear_non_matching_name() {
async function backgroundScript() {
@ -50,33 +56,39 @@ add_task(async function test_alarm_clear_non_matching_name() {
await extension.unload();
});
add_task(async function test_alarm_get_and_clear_single_argument() {
async function backgroundScript() {
browser.alarms.create({ when: Date.now() + 2000000 });
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 });
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();
}
let extension = ExtensionTestUtils.loadExtension({
background: `(${backgroundScript})()`,
manifest: {
permissions: ["alarms"],
},
});
await extension.startup();
await extension.awaitFinish("alarm-single-arg");
await extension.unload();
});
);
add_task(async function test_get_get_all_clear_all_alarms() {
async function backgroundScript() {

View file

@ -32,13 +32,6 @@ add_task(async function setup() {
);
await AddonTestUtils.promiseStartupManager();
// Ensure that the profile-after-change message has been notified,
// so that ServiceWokerRegistrar is going to be initialized.
Services.obs.notifyObservers(
null,
"profile-after-change",
"force-serviceworkerrestart-init"
);
// Make sure background-delayed-startup is set to true (in some builds,
// in particular Thunderbird, it is set to false) otherwise the extension

View file

@ -12,13 +12,6 @@ AddonTestUtils.createAppInfo(
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
// Ensure that the profile-after-change message has been notified,
// so that ServiceWokerRegistrar is going to be initialized.
Services.obs.notifyObservers(
null,
"profile-after-change",
"force-serviceworkerrestart-init"
);
});
add_task(async function test_ext_context_does_have_webidl_bindings() {

View file

@ -14,13 +14,6 @@ AddonTestUtils.createAppInfo(
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
// Ensure that the profile-after-change message has been notified,
// so that ServiceWokerRegistrar is going to be initialized.
Services.obs.notifyObservers(
null,
"profile-after-change",
"force-serviceworkerrestart-init"
);
});
add_task(async function test_api_event_manager_methods() {

View file

@ -12,13 +12,6 @@ AddonTestUtils.createAppInfo(
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
// Ensure that the profile-after-change message has been notified,
// so that ServiceWokerRegistrar is going to be initialized.
Services.obs.notifyObservers(
null,
"profile-after-change",
"force-serviceworkerrestart-init"
);
});
// Verify ExtensionAPIRequestHandler handling API requests for

View file

@ -12,13 +12,6 @@ AddonTestUtils.createAppInfo(
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
// Ensure that the profile-after-change message has been notified,
// so that ServiceWokerRegistrar is going to be initialized.
Services.obs.notifyObservers(
null,
"profile-after-change",
"force-serviceworkerrestart-init"
);
});
add_task(async function test_method_return_runtime_port() {

View file

@ -28,7 +28,3 @@ skip-if = tsan
[test_WebExtensionContentScript.js]
[test_ext_ipcBlob.js]
skip-if = os == 'android' && processor == 'x86_64'
[test_ext_background_service_worker.js]
head = head.js head_remote.js head_service_worker.js
prefs =
extensions.backgroundServiceWorker.enabled=true

View file

@ -0,0 +1,20 @@
[DEFAULT]
head = head.js head_remote.js head_e10s.js head_telemetry.js head_sync.js head_storage.js head_service_worker.js
tail =
firefox-appdir = browser
skip-if = os == "android"
dupe-manifest = true
support-files =
data/**
tags = webextensions sw-webextensions
prefs =
extensions.backgroundServiceWorker.enabled=true
extensions.backgroundServiceWorker.forceInTestExtension=true
extensions.webextensions.remote=true
[test_ext_background_service_worker.js]
[test_ext_alarms.js]
[test_ext_alarms_does_not_fire.js]
[test_ext_alarms_periodic.js]
[test_ext_alarms_replaces.js]