diff --git a/toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini b/toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini index a6fc7b3b5543..109d5a381f2e 100644 --- a/toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini +++ b/toolkit/components/telemetry/tests/marionette/tests/client/manifest.ini @@ -10,8 +10,6 @@ skip-if = true # See Bug 1753034, disabled due to network access when using `sea [test_subsession_management.py] [test_fog_deletion_request_ping.py] skip-if = true # See Bug 1753034, disabled due to network access when using `search` helper -[test_fog_background_update_ping.py] -skip-if = (os != "win" && os != "mac") || (cc_type == "clang" && os == 'win') # MOZ_UPDATE_AGENT is Windows (non MinGW) and macOS only right now. [test_fog_custom_ping.py] [test_fog_user_activity.py] [test_dynamic_probes.py] diff --git a/toolkit/components/telemetry/tests/marionette/tests/client/test_fog_background_update_ping.py b/toolkit/components/telemetry/tests/marionette/tests/client/test_fog_background_update_ping.py deleted file mode 100644 index 5aa73b0a37c2..000000000000 --- a/toolkit/components/telemetry/tests/marionette/tests/client/test_fog_background_update_ping.py +++ /dev/null @@ -1,136 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -from telemetry_harness.fog_ping_filters import FOG_BACKGROUND_UPDATE_PING -from telemetry_harness.fog_testcase import FOGTestCase - -import os -import subprocess - - -class TestBackgroundUpdatePing(FOGTestCase): - """Tests for the "background-update" FOG custom ping. - - This test is subtle. We launch Firefox to prepare a profile and to _disable_ - the background update setting. We exit Firefox, leaving the (unlocked) profile - to be used as the default profile for the background update task (and not having - multiple instances running). The task will not try to update, but it will send - a ping. Then we restart Firefox to unwind the background update setting and - allow shutdown to proceed cleanly.""" - - def test_background_update_ping(self): - - with self.marionette.using_context(self.marionette.CONTEXT_CHROME): - update_agent = self.marionette.execute_script( - "return AppConstants.MOZ_UPDATE_AGENT;" - ) - - if not update_agent: - # Before we skip this test, we need to quit marionette and the ping - # server created in TelemetryTestCase by running tearDown. - self.tearDown() - self.skipTest("background update task is not enabled.") - return - - def readUpdateConfigSetting(marionette, prefName): - with marionette.using_context(marionette.CONTEXT_CHROME): - return marionette.execute_async_script( - """ - let [prefName, resolve] = arguments; - const { UpdateUtils } = ChromeUtils.import( - "resource://gre/modules/UpdateUtils.jsm" - ); - UpdateUtils.readUpdateConfigSetting(prefName) - .then(resolve); - """, - script_args=[prefName], - ) - - def writeUpdateConfigSetting(marionette, prefName, value, options=None): - with marionette.using_context(marionette.CONTEXT_CHROME): - marionette.execute_async_script( - """ - let [prefName, value, options, resolve] = arguments; - const { UpdateUtils } = ChromeUtils.import( - "resource://gre/modules/UpdateUtils.jsm" - ); - UpdateUtils.writeUpdateConfigSetting(prefName, value, options) - .then(() => Services.prefs.savePrefFile(null)) // Ensure flushed to disk! - .then(resolve); - """, - script_args=[prefName, value, options], - ) - - def send_ping(marionette): - env = dict(os.environ) - env["MOZ_BACKGROUNDTASKS_DEFAULT_PROFILE_PATH"] = marionette.profile - cmd = marionette.instance.runner.command[0] - - enabled = None - with marionette.using_context(marionette.CONTEXT_CHROME): - enabled = readUpdateConfigSetting( - marionette, "app.update.background.enabled" - ) - writeUpdateConfigSetting( - marionette, "app.update.background.enabled", False - ) - - marionette.quit() - try: - subprocess.check_call( - [cmd, "--backgroundtask", "backgroundupdate"], env=env - ) - - finally: - # Restart to reset our per-installation pref, which is on disk - # on Windows and shared across profiles, so must be reset. - # Also, this test needs a Marionette session in order to tear - # itself down cleanly. - marionette.start_session() - if enabled is not None: - writeUpdateConfigSetting( - marionette, "app.update.background.enabled", enabled - ) - - ping1 = self.wait_for_ping( - lambda: send_ping(self.marionette), - FOG_BACKGROUND_UPDATE_PING, - ping_server=self.fog_ping_server, - ) - - # Check some background update details. - self.assertEqual( - True, - ping1["payload"]["metrics"]["boolean"][ - "background_update.exit_code_success" - ], - ) - self.assertNotIn( - "background_update.exit_code_exception", - ping1["payload"]["metrics"]["boolean"], - ) - self.assertEqual( - "NEVER_CHECKED", - ping1["payload"]["metrics"]["string"]["background_update.final_state"], - ) - self.assertIn( - "background_update.client_id", ping1["payload"]["metrics"]["uuid"] - ) - self.assertEqual( - "NEVER_CHECKED", - ping1["payload"]["metrics"]["string"]["background_update.final_state"], - ) - self.assertListEqual( - ["NEVER_CHECKED"], - ping1["payload"]["metrics"]["string_list"]["background_update.states"], - ) - self.assertIn( - "app.update.background.enabled=false", - ping1["payload"]["metrics"]["string_list"]["background_update.reasons"], - ) - - # And make sure that the general update stuff is present. - self.assertEqual( - False, ping1["payload"]["metrics"]["boolean"]["update.background_update"] - ) diff --git a/toolkit/mozapps/update/BackgroundTask_backgroundupdate.jsm b/toolkit/mozapps/update/BackgroundTask_backgroundupdate.jsm index 9d53d275b025..6cad5d61ccc4 100644 --- a/toolkit/mozapps/update/BackgroundTask_backgroundupdate.jsm +++ b/toolkit/mozapps/update/BackgroundTask_backgroundupdate.jsm @@ -5,7 +5,11 @@ "use strict"; -var EXPORTED_SYMBOLS = ["backgroundTaskTimeoutSec", "runBackgroundTask"]; +var EXPORTED_SYMBOLS = [ + "backgroundTaskTimeoutSec", + "maybeSubmitBackgroundUpdatePing", + "runBackgroundTask", +]; const { EXIT_CODE } = ChromeUtils.import( "resource://gre/modules/BackgroundUpdate.jsm" diff --git a/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_glean.js b/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_glean.js index feb12449f761..65b5f7813261 100644 --- a/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_glean.js +++ b/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_glean.js @@ -10,6 +10,10 @@ const { BackgroundUpdate } = ChromeUtils.import( "resource://gre/modules/BackgroundUpdate.jsm" ); +const { maybeSubmitBackgroundUpdatePing } = ChromeUtils.import( + "resource://gre/modules/backgroundtasks/BackgroundTask_backgroundupdate.jsm" +); + XPCOMUtils.defineLazyServiceGetter( this, "UpdateService", @@ -28,41 +32,57 @@ add_task(function test_setup() { add_task(async function test_record_update_environment() { await BackgroundUpdate.recordUpdateEnvironment(); - Assert.equal( - Services.prefs.getBoolPref("app.update.service.enabled", false), - Glean.update.serviceEnabled.testGetValue() + let pingSubmitted = false; + let appUpdateAutoEnabled = await UpdateUtils.getAppUpdateAutoEnabled(); + let backgroundUpdateEnabled = await UpdateUtils.readUpdateConfigSetting( + "app.update.background.enabled" ); + GleanPings.backgroundUpdate.testBeforeNextSubmit(reason => { + pingSubmitted = true; + Assert.equal( + Services.prefs.getBoolPref("app.update.service.enabled", false), + Glean.update.serviceEnabled.testGetValue() + ); - Assert.equal( - await UpdateUtils.getAppUpdateAutoEnabled(), - Glean.update.autoDownload.testGetValue() - ); + Assert.equal( + appUpdateAutoEnabled, + Glean.update.autoDownload.testGetValue() + ); - Assert.equal( - await UpdateUtils.readUpdateConfigSetting("app.update.background.enabled"), - Glean.update.backgroundUpdate.testGetValue() - ); + Assert.equal( + backgroundUpdateEnabled, + Glean.update.backgroundUpdate.testGetValue() + ); - Assert.equal(UpdateUtils.UpdateChannel, Glean.update.channel.testGetValue()); - Assert.equal( - !Services.policies || Services.policies.isAllowed("appUpdate"), - Glean.update.enabled.testGetValue() - ); + Assert.equal( + UpdateUtils.UpdateChannel, + Glean.update.channel.testGetValue() + ); + Assert.equal( + !Services.policies || Services.policies.isAllowed("appUpdate"), + Glean.update.enabled.testGetValue() + ); - Assert.equal( - UpdateService.canUsuallyApplyUpdates, - Glean.update.canUsuallyApplyUpdates.testGetValue() - ); - Assert.equal( - UpdateService.canUsuallyCheckForUpdates, - Glean.update.canUsuallyCheckForUpdates.testGetValue() - ); - Assert.equal( - UpdateService.canUsuallyStageUpdates, - Glean.update.canUsuallyStageUpdates.testGetValue() - ); - Assert.equal( - UpdateService.canUsuallyUseBits, - Glean.update.canUsuallyUseBits.testGetValue() - ); + Assert.equal( + UpdateService.canUsuallyApplyUpdates, + Glean.update.canUsuallyApplyUpdates.testGetValue() + ); + Assert.equal( + UpdateService.canUsuallyCheckForUpdates, + Glean.update.canUsuallyCheckForUpdates.testGetValue() + ); + Assert.equal( + UpdateService.canUsuallyStageUpdates, + Glean.update.canUsuallyStageUpdates.testGetValue() + ); + Assert.equal( + UpdateService.canUsuallyUseBits, + Glean.update.canUsuallyUseBits.testGetValue() + ); + }); + + // There's nothing async in this function atm, but it's annotated async, so.. + await maybeSubmitBackgroundUpdatePing(); + + ok(pingSubmitted, "'background-update' ping was submitted"); });