Bug 1724156 - Replace Background Update ping tt(c) test with xpcshell r=nalexander

Differential Revision: https://phabricator.services.mozilla.com/D138841
This commit is contained in:
Chris H-C 2022-02-16 19:34:44 +00:00
Родитель 08d9d265ac
Коммит a7c37dca26
4 изменённых файлов: 57 добавлений и 171 удалений

Просмотреть файл

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

Просмотреть файл

@ -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"]
)

Просмотреть файл

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

Просмотреть файл

@ -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");
});