From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test_backgroundupdate_reason.js | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_reason.js (limited to 'toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_reason.js') diff --git a/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_reason.js b/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_reason.js new file mode 100644 index 0000000000..71ce7f0361 --- /dev/null +++ b/toolkit/mozapps/update/tests/unit_background_update/test_backgroundupdate_reason.js @@ -0,0 +1,66 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- + * vim: sw=2 ts=2 sts=2 et + * 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/. */ + +"use strict"; + +const { BackgroundUpdate } = ChromeUtils.importESModule( + "resource://gre/modules/BackgroundUpdate.sys.mjs" +); + +// These tests use per-installation prefs, and those are a shared resource, so +// they require some non-trivial setup. +setupTestCommon(null); +standardInit(); + +add_setup(function test_setup() { + // FOG needs a profile directory to put its data in. + do_get_profile(); + + // We need to initialize it once, otherwise operations will be stuck in the + // pre-init queue. + Services.fog.initializeFOG(); +}); + +// Because we want to use the keys from REASON as strings and send these with +// Glean, we have to make sure, that they meet the requirements for `String +// Lists` and are not too long. +add_task(async function test_reasons_length() { + for (const key of Object.keys(BackgroundUpdate.REASON)) { + Glean.backgroundUpdate.reasonsToNotUpdate.add(key); + // No exception means success. + Assert.ok( + Array.isArray(Glean.backgroundUpdate.reasonsToNotUpdate.testGetValue()), + "Glean allows the name of the reason to be '" + key + "'" + ); + } +}); + +// The string list in Glean can overflow and has a hard limit of 20 entries. +// This test toggles a switch to reach this limit and fails if this causes an +// exception, because we want to avoid that statistical data collection can have +// an negative impact on the success rate of background updates. +add_task(async function test_reasons_overflow() { + let prev = await UpdateUtils.getAppUpdateAutoEnabled(); + try { + for (let i = 1; i <= 21; i++) { + await UpdateUtils.setAppUpdateAutoEnabled(false); + await BackgroundUpdate._reasonsToNotUpdateInstallation(); + await UpdateUtils.setAppUpdateAutoEnabled(true); + await BackgroundUpdate._reasonsToNotUpdateInstallation(); + Assert.ok(true, "Overflow test successful for run #" + i); + } + } finally { + ok(true, "resetting AppUpdateAutoEnabled to " + prev); + await UpdateUtils.setAppUpdateAutoEnabled(prev); + } +}); + +add_task(() => { + // `setupTestCommon()` calls `do_test_pending()`; this calls + // `do_test_finish()`. The `add_task` schedules this to run after all the + // other tests have completed. + doTestFinish(); +}); -- cgit v1.2.3