Skip to content

Commit

Permalink
Bug 1753696 - move common setup/init tasks in head.js files to use ad…
Browse files Browse the repository at this point in the history
…d_setup, r=Standard8

Without this, changing to add_setup in individual test files causes the tasks to be reordered, which causes tests to fail.

I also had to adjust an enterprise policy test that was expecting setup tests to run inbetween tasks.

Differential Revision: https://phabricator.services.mozilla.com/D142457
  • Loading branch information
gijsk committed Mar 30, 2022
1 parent b76ad61 commit 7298feb
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 32 deletions.
2 changes: 1 addition & 1 deletion browser/base/content/test/webextensions/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ async function interactiveUpdateTest(autoUpdate, checkFn) {
// Individual tests can store a cleanup function in the testCleanup global
// to ensure it gets called before the final check is performed.
let testCleanup;
add_task(async function() {
add_setup(async function head_setup() {
let addons = await AddonManager.getAllAddons();
let existingAddons = new Set(addons.map(a => a.id));

Expand Down
2 changes: 1 addition & 1 deletion browser/components/aboutlogins/tests/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function addLogin(login) {

let EXPECTED_BREACH = null;
let EXPECTED_ERROR_MESSAGE = null;
add_task(async function setup_head() {
add_setup(async function setup_head() {
const db = await RemoteSettings(LoginBreaches.REMOTE_SETTINGS_COLLECTION).db;
if (EXPECTED_BREACH) {
await db.create(EXPECTED_BREACH, {
Expand Down
2 changes: 1 addition & 1 deletion browser/components/downloads/test/unit/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function run_test() {
run_next_test();
}

add_task(async function test_common_initialize() {
add_setup(async function test_common_initialize() {
gDownloadDir = await setDownloadDir();
Services.prefs.setCharPref("browser.download.loglevel", "Debug");
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ add_task(async function test_menu_shown() {
await BrowserTestUtils.closeWindow(newWin);
});

add_setup(async function() {
add_task(async function test_menu_shown() {
await setupPolicyEngineWithJson({
policies: {
SearchBar: "unified",
},
});
});

add_task(async function test_menu_shown() {
let newWin = await BrowserTestUtils.openNewBrowserWindow();
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement, null, "Search bar has no placement");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ async function check_homepage({
await BrowserTestUtils.removeTab(tab);
}

add_task(async function policies_headjs_startWithCleanSlate() {
add_setup(async function policies_headjs_startWithCleanSlate() {
if (Services.policies.status != Ci.nsIEnterprisePolicies.INACTIVE) {
await setupPolicyEngineWithJson("");
}
Expand Down
10 changes: 4 additions & 6 deletions browser/components/urlbar/tests/browser-tips/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ const SEARCH_STRINGS = {
UPDATE: "firefox update",
};

add_task(async function init() {
registerCleanupFunction(() => {
// We need to reset the provider's appUpdater.status between tests so that
// each test doesn't interfere with the next.
UrlbarProviderInterventions.resetAppUpdater();
});
registerCleanupFunction(() => {
// We need to reset the provider's appUpdater.status between tests so that
// each test doesn't interfere with the next.
UrlbarProviderInterventions.resetAppUpdater();
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ XPCOMUtils.defineLazyGetter(this, "UrlbarTestUtils", () => {
return module;
});

add_task(async function headInit() {
add_setup(async function headInit() {
await PlacesUtils.history.clear();
await PlacesUtils.bookmarks.eraseEverything();

Expand Down
2 changes: 1 addition & 1 deletion browser/components/urlbar/tests/ext/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const SCRIPT_PATH = getTestFilePath(SCRIPT_BASENAME);
let schemaSource;
let scriptSource;

add_task(async function loadSource() {
add_setup(async function loadSource() {
schemaSource = await (await fetch("file://" + SCHEMA_PATH)).text();
scriptSource = await (await fetch("file://" + SCRIPT_PATH)).text();
});
Expand Down
2 changes: 1 addition & 1 deletion browser/components/urlbar/tests/unit/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ AddonTestUtils.createAppInfo(
const SUGGESTIONS_ENGINE_NAME = "Suggestions";
const TAIL_SUGGESTIONS_ENGINE_NAME = "Tail Suggestions";

add_task(async function initXPCShellDependencies() {
add_setup(async function initXPCShellDependencies() {
await UrlbarTestUtils.initXPCShellDependencies();
});

Expand Down
4 changes: 2 additions & 2 deletions browser/extensions/formautofill/test/unit/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function objectMatches(object, fields) {
return ObjectUtils.deepEqual(actual, fields);
}

add_task(async function head_initialize() {
add_setup(async function head_initialize() {
Services.prefs.setBoolPref("extensions.experiments.enabled", true);
Services.prefs.setBoolPref(
"extensions.formautofill.heuristics.enabled",
Expand Down Expand Up @@ -338,7 +338,7 @@ add_task(async function head_initialize() {
});

let OSKeyStoreTestUtils;
add_task(async function os_key_store_setup() {
add_setup(async function os_key_store_setup() {
({ OSKeyStoreTestUtils } = ChromeUtils.import(
"resource://testing-common/OSKeyStoreTestUtils.jsm"
));
Expand Down
2 changes: 1 addition & 1 deletion browser/extensions/screenshots/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async function getImageSizeFromClipboard(browser) {
});
}

add_task(async function common_initialize() {
add_setup(async function common_initialize() {
// Ensure Screenshots is initially enabled for all tests
const addon = await AddonManager.getAddonByID("[email protected]");
const isEnabled = addon.enabled;
Expand Down
2 changes: 1 addition & 1 deletion browser/tools/mozscreenshots/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ function shouldCapture() {
return true;
}

add_task(setup);
add_setup(setup);
2 changes: 1 addition & 1 deletion services/sync/tests/unit/head_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ChromeUtils.defineModuleGetter(
"resource://gre/modules/AddonManager.jsm"
);

add_task(async function head_setup() {
add_setup(async function head_setup() {
// Initialize logging. This will sometimes be reset by a pref reset,
// so it's also called as part of SyncTestingInfrastructure().
syncTestLogging();
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/downloads/test/unit/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ var gMostRecentFirstBytePos;

// Initialization functions common to all tests

add_task(function test_common_initialize() {
add_setup(function test_common_initialize() {
// Start the HTTP server.
gHttpServer = new HttpServer();
gHttpServer.registerDirectory("/", do_get_file("../data"));
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/extensions/test/xpcshell/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const testEnv = {
expectRemote: false,
};

add_task(function check_remote() {
add_setup(function check_remote() {
Assert.equal(
WebExtensionPolicy.useRemoteWebExtensions,
testEnv.expectRemote,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionTestCommon: "resource://testing-common/ExtensionTestCommon.jsm",
});

add_task(function checkExtensionsWebIDLEnabled() {
add_setup(function checkExtensionsWebIDLEnabled() {
equal(
AppConstants.MOZ_WEBEXT_WEBIDL_ENABLED,
true,
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/httpsonlyerror/tests/browser/head.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mozilla/frame-script */

// Enable HTTPS-Only Mode
add_task(async function() {
add_setup(async function() {
await SpecialPowers.pushPrefEnv({
set: [["dom.security.https_only_mode", true]],
});
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/passwordmgr/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { PromptTestUtils } = ChromeUtils.import(
"resource://testing-common/PromptTestUtils.jsm"
);

add_task(async function common_initialize() {
add_setup(async function common_initialize() {
await SpecialPowers.pushPrefEnv({
set: [
["signon.rememberSignons", true],
Expand Down
4 changes: 2 additions & 2 deletions toolkit/components/passwordmgr/test/unit/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const RecipeHelpers = {

// Initialization functions common to all tests

add_task(async function test_common_initialize() {
add_setup(async function test_common_initialize() {
// Before initializing the service for the first time, we should copy the key
// file required to decrypt the logins contained in the SQLite databases used
// by migration tests. This file is not required for the other tests.
Expand All @@ -100,7 +100,7 @@ add_task(async function test_common_initialize() {
}
});

add_task(async function test_common_prefs() {
add_setup(async function test_common_prefs() {
Services.prefs.setStringPref(NEW_PASSWORD_HEURISTIC_ENABLED_PREF, "0.75");
});

Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/places/tests/unit/head_bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ AddonTestUtils.createAppInfo(
"42"
);

add_task(async function setup() {
add_setup(async function() {
await AddonTestUtils.promiseStartupManager();
});
2 changes: 1 addition & 1 deletion toolkit/mozapps/update/tests/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ requestLongerTimeout(10);
/**
* Common tasks to perform for all tests before each one has started.
*/
add_task(async function setupTestCommon() {
add_setup(async function setupTestCommon() {
await SpecialPowers.pushPrefEnv({
set: [
[PREF_APP_UPDATE_BADGEWAITTIME, 1800],
Expand Down
2 changes: 1 addition & 1 deletion uriloader/exthandler/tests/mochitest/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ async function setDownloadDir() {
return tmpDir;
}

add_task(async function test_common_initialize() {
add_setup(async function test_common_initialize() {
gDownloadDir = await setDownloadDir();
Services.prefs.setCharPref("browser.download.loglevel", "Debug");
registerCleanupFunction(function() {
Expand Down

0 comments on commit 7298feb

Please sign in to comment.