Bug 1856104 - Remove useless version checks from JavaScript code. r=Gijs,webcompat-reviewers,settings-reviewers,search-reviewers,Standard8,twisniewski

Differential Revision: https://phabricator.services.mozilla.com/D189696
This commit is contained in:
Masatoshi Kimura
2023-10-02 17:36:27 +00:00
parent 01540b090c
commit 89e9a36583
28 changed files with 83 additions and 228 deletions

View File

@@ -4671,12 +4671,8 @@ let gShareUtils = {
return;
}
// We only support "share URL" on macOS and on Windows 10:
if (
AppConstants.platform != "macosx" &&
// Windows 10's internal NT version number was initially 6.4
!AppConstants.isPlatformAndVersionAtLeast("win", "6.4")
) {
// We only support "share URL" on macOS and on Windows:
if (AppConstants.platform != "macosx" && AppConstants.platform != "win") {
return;
}
@@ -6624,7 +6620,7 @@ var TabletModeUpdater = {
var gTabletModePageCounter = {
enabled: false,
inc() {
this.enabled = AppConstants.isPlatformAndVersionAtLeast("win", "10.0");
this.enabled = AppConstants.platform == "win";
if (!this.enabled) {
this.inc = () => {};
return;

View File

@@ -41,12 +41,6 @@ add_task(async function test_contextmenu_share_win() {
"hidden"
);
let itemCreated = contextMenu.querySelector(".share-tab-url-item");
if (!AppConstants.isPlatformAndVersionAtLeast("win", "6.4")) {
Assert.ok(!itemCreated, "We only expose share on windows 10 and above");
contextMenu.hidePopup();
await contextMenuClosedPromise;
return;
}
ok(itemCreated, "Got Share item on Windows 10");

View File

@@ -34,9 +34,9 @@ async function openAndCheckContextMenu(contextMenu, target) {
contextMenu.hidePopup();
}
// Ensure that we can run touch events properly for windows [10]
// Ensure that we can run touch events properly for windows
add_setup(async function () {
let isWindows = AppConstants.isPlatformAndVersionAtLeast("win", "10.0");
let isWindows = AppConstants.platform == "win";
await SpecialPowers.pushPrefEnv({
set: [["apz.test.fails_with_native_injection", isWindows]],
});

View File

@@ -793,7 +793,7 @@ add_task(async function test_scrollbar_props() {
BrowserTestUtils.removeTab(tab);
});
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
if (AppConstants.platform == "win") {
add_task(async function test_darkmode() {
let lightSelectColor = rgbaToString(
InspectorUtils.colorToRGBA("MenuText", document)

View File

@@ -111,9 +111,9 @@ async function openAndCheckCustomizationUIMenu(target) {
menu.hidePopup();
}
// Ensure that we can run touch events properly for windows [10]
// Ensure that we can run touch events properly for windows
add_setup(async function () {
let isWindows = AppConstants.isPlatformAndVersionAtLeast("win", "10.0");
let isWindows = AppConstants.platform == "win";
await SpecialPowers.pushPrefEnv({
set: [["apz.test.fails_with_native_injection", isWindows]],
});

View File

@@ -1463,9 +1463,8 @@ CustomizeMode.prototype = {
}
}
// Add menu items for automatically switching to Touch mode in Windows Tablet Mode,
// which is only available in Windows 10.
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
// Add menu items for automatically switching to Touch mode in Windows Tablet Mode.
if (AppConstants.platform == "win") {
let spacer = doc.getElementById("customization-uidensity-touch-spacer");
let checkbox = doc.getElementById(
"customization-uidensity-autotouchmode-checkbox"

View File

@@ -175,8 +175,8 @@ add_task(async function test_touch_mode_menuitem() {
await testModeMenuitem("touch", window.gUIDensity.MODE_TOUCH);
// Test the checkbox for automatic Touch Mode transition
// in Windows 10 Tablet Mode.
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
// in Windows Tablet Mode.
if (AppConstants.platform == "win") {
await startCustomizing();
let popupButton = document.getElementById("customization-uidensity-button");

View File

@@ -13,7 +13,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
PlacesUIUtils: "resource:///modules/PlacesUIUtils.sys.mjs",
PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
Sqlite: "resource://gre/modules/Sqlite.sys.mjs",
WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
setTimeout: "resource://gre/modules/Timer.sys.mjs",
MigrationWizardConstants:
"chrome://browser/content/migration/migration-wizard-constants.mjs",
@@ -23,7 +22,6 @@ var gMigrators = null;
var gFileMigrators = null;
var gProfileStartup = null;
var gL10n = null;
var gPreviousDefaultBrowserKey = "";
var gHasOpenedLegacyWizard = false;
let gForceExitSpinResolve = false;
@@ -500,51 +498,6 @@ class MigrationUtils {
console.error("Could not detect default browser: ", ex);
}
// "firefox" is the least useful entry here, and might just be because we've set
// ourselves as the default (on Windows 7 and below). In that case, check if we
// have a registry key that tells us where to go:
if (
key == "firefox" &&
AppConstants.isPlatformAndVersionAtMost("win", "6.2")
) {
// Because we remove the registry key, reading the registry key only works once.
// We save the value for subsequent calls to avoid hard-to-trace bugs when multiple
// consumers ask for this key.
if (gPreviousDefaultBrowserKey) {
key = gPreviousDefaultBrowserKey;
} else {
// We didn't have a saved value, so check the registry.
const kRegPath = "Software\\Mozilla\\Firefox";
let oldDefault = lazy.WindowsRegistry.readRegKey(
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
kRegPath,
"OldDefaultBrowserCommand"
);
if (oldDefault) {
// Remove the key:
lazy.WindowsRegistry.removeRegKey(
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
kRegPath,
"OldDefaultBrowserCommand"
);
try {
let file = Cc["@mozilla.org/file/local;1"].createInstance(
Ci.nsILocalFileWin
);
file.initWithCommandLine(oldDefault);
key =
APP_DESC_TO_KEY[file.getVersionInfoField("FileDescription")] ||
key;
// Save the value for future callers.
gPreviousDefaultBrowserKey = key;
} catch (ex) {
console.error(
"Could not convert old default browser value to description."
);
}
}
}
}
return key;
}

View File

@@ -690,13 +690,6 @@ async function prepareContentForReact(content) {
return content;
}
// Change content for Windows 7 because non-light themes aren't quite right.
if (AppConstants.isPlatformAndVersionAtMost("win", "6.1")) {
await lazy.AWScreenUtils.removeScreens(screens, screen =>
["theme"].includes(screen.content?.tiles?.type)
);
}
// Set the primary import button source based on attribution.
if (content?.ua) {
// If available, add the browser source to action data

View File

@@ -196,11 +196,6 @@ add_task(async function test_multistage_aboutwelcome_default() {
await onButtonClick(browser, "button.primary");
// No 3rd screen to go to for win7.
if (win7Content) {
return;
}
await test_screen_content(
browser,
"multistage step 3",
@@ -368,9 +363,6 @@ add_task(async function test_AWMultistage_Primary_Action() {
});
add_task(async function test_AWMultistage_Secondary_Open_URL_Action() {
if (win7Content) {
return;
}
let browser = await openAboutWelcome();
let aboutWelcomeActor = await getAboutWelcomeParent(browser);
const sandbox = sinon.createSandbox();
@@ -437,11 +429,6 @@ add_task(async function test_AWMultistage_Secondary_Open_URL_Action() {
});
add_task(async function test_AWMultistage_Themes() {
// No theme screen to test for win7.
if (win7Content) {
return;
}
let browser = await openAboutWelcome();
let aboutWelcomeActor = await getAboutWelcomeParent(browser);
@@ -588,10 +575,6 @@ add_task(async function test_AWMultistage_can_restore_theme() {
});
add_task(async function test_AWMultistage_Import() {
// No import screen to test for win7.
if (win7Content) {
return;
}
let browser = await openAboutWelcome();
let aboutWelcomeActor = await getAboutWelcomeParent(browser);

View File

@@ -257,8 +257,7 @@ add_task(async function test_multistage_aboutwelcome_experimentAPI() {
sandbox.restore();
});
// Test first (theme) screen for non-win7.
if (!win7Content) {
// Test first (theme) screen.
await test_screen_content(
browser,
"multistage step 1",
@@ -301,7 +300,6 @@ add_task(async function test_multistage_aboutwelcome_experimentAPI() {
"MY-MOCHITEST-EXPERIMENT_0_AW_STEP1",
"Telemetry should join id defined in feature value with screen"
);
}
await test_screen_content(
browser,

View File

@@ -115,7 +115,7 @@ add_task(async function test_aboutwelcome_mr_template_easy_setup() {
"default",
]);
if (!AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
if (AppConstants.platform !== "win") {
return;
}

View File

@@ -22,8 +22,6 @@ const { sinon } = ChromeUtils.importESModule(
);
// Set the content pref to make it available across tests
const ABOUT_WELCOME_OVERRIDE_CONTENT_PREF = "browser.aboutwelcome.screens";
// Test differently for windows 7 as theme screens are removed.
const win7Content = AppConstants.isPlatformAndVersionAtMost("win", "6.1");
// Feature callout constants
const calloutId = "feature-callout";
const calloutSelector = `#${calloutId}.featureCallout`;

View File

@@ -487,11 +487,10 @@ var gMainPane = {
document.getElementById("dataMigrationGroup").remove();
}
// For media control toggle button, we support it on Windows 8.1+ (NT6.3),
// MacOs 10.4+ (darwin8.0, but we already don't support that) and
// For media control toggle button, we support it on Windows, macOS and
// gtk-based Linux.
if (
AppConstants.isPlatformAndVersionAtLeast("win", "6.3") ||
AppConstants.platform == "win" ||
AppConstants.platform == "macosx" ||
AppConstants.MOZ_WIDGET_GTK
) {

View File

@@ -9,7 +9,6 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
WindowsRegistry: "resource://gre/modules/WindowsRegistry.sys.mjs",
});
XPCOMUtils.defineLazyServiceGetter(
@@ -61,26 +60,6 @@ let ShellServiceInternal = {
return false;
},
isDefaultBrowserOptOut() {
if (AppConstants.platform == "win") {
let optOutValue = lazy.WindowsRegistry.readRegKey(
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Firefox",
"DefaultBrowserOptOut"
);
lazy.WindowsRegistry.removeRegKey(
Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
"Software\\Mozilla\\Firefox",
"DefaultBrowserOptOut"
);
if (optOutValue == "True") {
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", false);
return true;
}
}
return false;
},
/**
* Used to determine whether or not to show a "Set Default Browser"
* query dialog. This attribute is true if the application is starting
@@ -99,10 +78,6 @@ let ShellServiceInternal = {
return false;
}
if (this.isDefaultBrowserOptOut()) {
return false;
}
return true;
},
@@ -340,9 +315,9 @@ let ShellServiceInternal = {
// override nsIShellService.setDefaultBrowser() on the ShellService proxy.
setDefaultBrowser(forAllUsers) {
// On Windows 10, our best chance is to set UserChoice, so try that first.
// On Windows, our best chance is to set UserChoice, so try that first.
if (
AppConstants.isPlatformAndVersionAtLeast("win", "10") &&
AppConstants.platform == "win" &&
lazy.NimbusFeatures.shellService.getVariable(
"setDefaultBrowserUserChoice"
)
@@ -386,7 +361,7 @@ let ShellServiceInternal = {
return;
}
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
if (AppConstants.platform == "win") {
this.setAsDefaultPDFHandlerUserChoice();
}
},

View File

@@ -46,11 +46,8 @@ var gSetBackground = {
multiMonitors = monitors.length > 1;
}
if (
!multiMonitors ||
AppConstants.isPlatformAndVersionAtMost("win", 6.1)
) {
// Hide span option if < Win8 since that's when it was introduced.
if (!multiMonitors) {
// Hide span option on single monitor systems.
document.getElementById("spanPosition").hidden = true;
}
}

View File

@@ -49,11 +49,8 @@ add_task(async function ready() {
await ExperimentAPI.ready();
});
// Everything here is Windows 10+.
Assert.ok(
AppConstants.isPlatformAndVersionAtLeast("win", "10"),
"Windows version 10+"
);
// Everything here is Windows.
Assert.ok(AppConstants.platform == "win", "Platform is Windows");
add_task(async function remoteEnableWithPDF() {
let doCleanup = await ExperimentFakes.enrollWithRollout({

View File

@@ -1821,7 +1821,7 @@ export var UITour = {
let canSetDefaultBrowserInBackground = true;
if (
AppConstants.isPlatformAndVersionAtLeast("win", "6.2") ||
AppConstants.platform == "win" ||
AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")
) {
canSetDefaultBrowserInBackground = false;

View File

@@ -177,7 +177,7 @@ this.browserInfo = class extends ExtensionAPI {
memoryMb,
};
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) {
if (AppConstants.platform == "win") {
data.sec = getSecurityAppData();
}

View File

@@ -255,8 +255,8 @@ add_task(condition, async function testInstallationTelemetry() {
// New timestamp and a check to make sure we can find installed MSIX packages
// by overriding the prefixes a bit further down.
fullData.install_timestamp = "2";
// This check only works on Windows 10 and above
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
// This check only works on Windows
if (AppConstants.platform == "win") {
fullExtra.other_msix_inst = "true";
}
await writeJsonUtf16(dataFilePath, fullData);

View File

@@ -8,9 +8,6 @@ const DUMMY_URL =
"http://example.com"
) + "/dummy.html";
const HAS_THREAD_NAMES =
AppConstants.platform != "win" ||
AppConstants.isPlatformAndVersionAtLeast("win", 10);
const isFissionEnabled = SpecialPowers.useRemoteSubframes;
const SAMPLE_SIZE = 10;
@@ -67,13 +64,10 @@ add_task(async function test_proc_info() {
checkProcessCpuTime(parentProc);
// Under Windows, thread names appeared with Windows 10.
if (HAS_THREAD_NAMES) {
Assert.ok(
parentProc.threads.some(thread => thread.name),
"At least one of the threads of the parent process is named"
);
}
Assert.ok(parentProc.memory > 0, "Memory was set");

View File

@@ -8,9 +8,6 @@
"use strict";
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { FormHistory } = ChromeUtils.importESModule(
"resource://gre/modules/FormHistory.sys.mjs"
);
@@ -805,10 +802,7 @@ add_task(async function unresolvable_server() {
Assert.equal(result.local[0].value, "Unresolvable Server Entry");
Assert.equal(result.remote.length, 0);
// This latency assert fails on Windows 7 (NT version 6.1), so skip it there.
if (!AppConstants.isPlatformAndVersionAtMost("win", "6.1")) {
assertLatencyHistogram(histogram, true);
}
});
// Exception handling

View File

@@ -2081,15 +2081,11 @@ EnvironmentCache.prototype = {
data = { winPackageFamilyName, ...data };
}
data = { ...this._getProcessData(), ...data };
data.sec = this._getSecurityAppData();
} else if (AppConstants.platform == "android") {
data.device = this._getDeviceData();
}
// Windows 8+
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) {
data.sec = this._getSecurityAppData();
}
return data;
},

View File

@@ -696,8 +696,8 @@ export var TelemetryEnvironmentTesting = {
lazy.Assert.ok(this.checkNullOrString(data.system.appleModelId));
}
// This feature is only available on Windows 8+
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) {
// This feature is only available on Windows
if (AppConstants.platform == "win") {
lazy.Assert.ok(
"sec" in data.system,
"sec must be available under data.system"

View File

@@ -580,20 +580,13 @@ add_task(async function sessionTimeExcludingAndIncludingSuspend() {
"In test condition, the two uptimes should be close to each other"
);
// This however should always hold, except on Windows < 10, where the two
// clocks are from different system calls, and it can fail in test condition
// because the machine has not been suspended.
if (
AppConstants.platform != "win" ||
AppConstants.isPlatformAndVersionAtLeast("win", "10.0")
) {
// This however should always hold.
Assert.greaterOrEqual(
withSuspend,
withoutSuspend,
`The uptime with suspend must always been greater or equal to the uptime
without suspend`
);
}
Services.prefs.setBoolPref(
"toolkit.telemetry.testing.overrideProductsCheck",

View File

@@ -4,7 +4,6 @@
* 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/. */
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import {
BaseProcess,
PromiseWorker,
@@ -36,10 +35,7 @@ class WinPromiseWorker extends PromiseWorker {
this.call("init", [
{
breakAwayFromJob: !AppConstants.isPlatformAndVersionAtLeast(
"win",
"6.2"
),
breakAwayFromJob: false,
comspec: Services.env.get("COMSPEC"),
signalEvent: String(
ctypes.cast(this.signalEvent, ctypes.uintptr_t).value

View File

@@ -446,7 +446,7 @@ add_task(async function test_subprocess_invalid_json() {
equal(exitCode, 0, "Got expected exit code");
});
if (AppConstants.isPlatformAndVersionAtLeast("win", "6")) {
if (AppConstants.platform == "win") {
add_task(async function test_subprocess_inherited_descriptors() {
let { libc, win32 } = ChromeUtils.importESModule(
"resource://gre/modules/subprocess/subprocess_win.sys.mjs"

View File

@@ -362,7 +362,7 @@ add_task(async function testEmeSupport() {
let item = getAddonCard(win, addon.id);
if (addon.id == WIDEVINE_ID) {
if (
AppConstants.isPlatformAndVersionAtLeast("win", "6") ||
AppConstants.platform == "win" ||
AppConstants.platform == "macosx" ||
AppConstants.platform == "linux"
) {