Skip to content

Commit

Permalink
Bug 1856104 - Remove useless version checks from JavaScript code. r=G…
Browse files Browse the repository at this point in the history
…ijs,webcompat-reviewers,settings-reviewers,search-reviewers,Standard8,twisniewski

Differential Revision: https://phabricator.services.mozilla.com/D189696
  • Loading branch information
vyv03354 committed Oct 2, 2023
1 parent 8975c30 commit bcd7d26
Show file tree
Hide file tree
Showing 29 changed files with 85 additions and 296 deletions.
10 changes: 3 additions & 7 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions browser/base/content/test/touch/browser_menu_touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
});
Expand Down
5 changes: 2 additions & 3 deletions browser/components/customizableui/CustomizeMode.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
47 changes: 0 additions & 47 deletions browser/components/migration/MigrationUtils.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -23,7 +22,6 @@ var gMigrators = null;
var gFileMigrators = null;
var gProfileStartup = null;
var gL10n = null;
var gPreviousDefaultBrowserKey = "";
var gHasOpenedLegacyWizard = false;

let gForceExitSpinResolve = false;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,52 +257,50 @@ add_task(async function test_multistage_aboutwelcome_experimentAPI() {
sandbox.restore();
});

// Test first (theme) screen for non-win7.
if (!win7Content) {
await test_screen_content(
browser,
"multistage step 1",
// Expected selectors:
[
"div.onboardingContainer",
"main.AW_STEP1",
"div.secondary-cta",
"div.secondary-cta.top",
"button[value='secondary_button']",
"button[value='secondary_button_top']",
"label.theme",
"input[type='radio']",
],
// Unexpected selectors:
["main.AW_STEP2", "main.AW_STEP3", "div.tiles-container.info"]
);

await onButtonClick(browser, "button.primary");

const { callCount } = aboutWelcomeActor.onContentMessage;
ok(callCount >= 1, `${callCount} Stub was called`);
let clickCall;
for (let i = 0; i < callCount; i++) {
const call = aboutWelcomeActor.onContentMessage.getCall(i);
info(`Call #${i}: ${call.args[0]} ${JSON.stringify(call.args[1])}`);
if (call.calledWithMatch("", { event: "CLICK_BUTTON" })) {
clickCall = call;
}
}
// Test first (theme) screen.
await test_screen_content(
browser,
"multistage step 1",
// Expected selectors:
[
"div.onboardingContainer",
"main.AW_STEP1",
"div.secondary-cta",
"div.secondary-cta.top",
"button[value='secondary_button']",
"button[value='secondary_button_top']",
"label.theme",
"input[type='radio']",
],
// Unexpected selectors:
["main.AW_STEP2", "main.AW_STEP3", "div.tiles-container.info"]
);

await onButtonClick(browser, "button.primary");

Assert.equal(
clickCall.args[0],
"AWPage:TELEMETRY_EVENT",
"send telemetry event"
);

Assert.equal(
clickCall.args[1].message_id,
"MY-MOCHITEST-EXPERIMENT_0_AW_STEP1",
"Telemetry should join id defined in feature value with screen"
);
const { callCount } = aboutWelcomeActor.onContentMessage;
ok(callCount >= 1, `${callCount} Stub was called`);
let clickCall;
for (let i = 0; i < callCount; i++) {
const call = aboutWelcomeActor.onContentMessage.getCall(i);
info(`Call #${i}: ${call.args[0]} ${JSON.stringify(call.args[1])}`);
if (call.calledWithMatch("", { event: "CLICK_BUTTON" })) {
clickCall = call;
}
}

Assert.equal(
clickCall.args[0],
"AWPage:TELEMETRY_EVENT",
"send telemetry event"
);

Assert.equal(
clickCall.args[1].message_id,
"MY-MOCHITEST-EXPERIMENT_0_AW_STEP1",
"Telemetry should join id defined in feature value with screen"
);

await test_screen_content(
browser,
"multistage step 2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions browser/components/newtab/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
Loading

0 comments on commit bcd7d26

Please sign in to comment.