Skip to content

Commit

Permalink
Remove archType and isARM() from site.js (Fixes mozilla#14404)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgibson committed Apr 9, 2024
1 parent 468ca42 commit 39ba637
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 179 deletions.
52 changes: 1 addition & 51 deletions media/js/base/site.js
Expand Up @@ -78,40 +78,6 @@
}
},

getArchType: function (ua, pf) {
pf = pf === '' ? '' : pf || navigator.platform;
ua = ua || navigator.userAgent;

var re;

// ARM
re = /armv\d+/i;
if (re.test(pf) || re.test(ua)) {
return RegExp.lastMatch.toLowerCase();
}

// ARMv8 64-bit
if (/aarch64/.test(pf)) {
return 'armv8';
}

// We can't detect the type info. It's probably x86 but unsure.
// For example, iOS may be running on ARM-based Apple A7 processor
return 'x86';
},

// Returns true if CPU is an ARM processor.
isARM: function (architecture) {
var arch =
typeof architecture === 'string'
? architecture
: window.site.archType;
if (arch && (arch === 'arm' || arch.match(/armv(\d+)/))) {
return true;
}
return false;
},

getArchSize: function (ua, pf) {
pf = pf === '' ? '' : pf || navigator.platform;
ua = ua || navigator.userAgent;
Expand Down Expand Up @@ -183,12 +149,6 @@
}
}

// Used to display a custom installation message and
// SUMO link on the /firefox/download/thanks/ page.
if (window.site.isARM()) {
classString += ' arm';
}

// Used for 64bit download link on Linux and Firefox Beta on Windows.
if (archSize === 64) {
classString += ' x64';
Expand All @@ -214,7 +174,6 @@

platform: 'other',
platformVersion: undefined,
archType: 'x64',
archSize: 32,
fxSupported: true
};
Expand All @@ -231,7 +190,6 @@

function getHighEntropyFromUAString() {
window.site.platformVersion = window.site.getPlatformVersion();
window.site.archType = window.site.getArchType();
window.site.archSize = window.site.getArchSize();
}

Expand All @@ -245,11 +203,7 @@
typeof navigator.userAgentData.getHighEntropyValues === 'function'
) {
navigator.userAgentData
.getHighEntropyValues([
'architecture',
'bitness',
'platformVersion'
])
.getHighEntropyValues(['bitness', 'platformVersion'])
.then(function (ua) {
if (ua.platformVersion) {
if (window.site.platform === 'windows') {
Expand All @@ -262,10 +216,6 @@
}
}

if (ua.architecture) {
window.site.archType = ua.architecture;
}

if (ua.bitness) {
window.site.archSize =
window.site.getArchSizeClientHint(ua.bitness);
Expand Down
113 changes: 0 additions & 113 deletions tests/unit/spec/base/site.js
Expand Up @@ -215,74 +215,6 @@ describe('site.js', function () {
});
});

describe('getArchType', function () {
it('should identify x86', function () {
expect(
window.site.getArchType(
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0',
'Win64'
)
).toBe('x86');
expect(
window.site.getArchType(
'Mozilla/5.0 (Windows NT 6.3; rv:27.0) Gecko/20100101 Firefox/27.0',
'Win32'
)
).toBe('x86');
expect(
window.site.getArchType(
'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
'Win32'
)
).toBe('x86');
expect(
window.site.getArchType(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko/20100101 Firefox/27.0',
'MacIntel'
)
).toBe('x86');
expect(
window.site.getArchType(
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:27.0) Gecko/20100101 Firefox/27.0',
'Linux x86_64'
)
).toBe('x86');
expect(
window.site.getArchType(
'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:27.0) Gecko/20100101 Firefox/27.0',
'Linux i686'
)
).toBe('x86');
});

it('should identify ARM', function () {
expect(
window.site.getArchType(
'Mozilla/5.0 (Android; Mobile; rv:27.0) Gecko/27.0 Firefox/27.0',
'Linux armv7l'
)
).toBe('armv7');
expect(
window.site.getArchType(
'Mozilla/5.0 (Android 5.0.2; Mobile; rv:42.0) Gecko/42.0 Firefox/42.0',
'Linux aarch64'
)
).toBe('armv8');
expect(
window.site.getArchType(
'Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9.1b2pre) Gecko/20081116 Fennec/1.0a2pre',
'Linux armv6l'
)
).toBe('armv6');
expect(
window.site.getArchType(
'Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:32.0) Gecko/20100101 Firefox/32.0',
'Linux armv7l'
)
).toBe('armv7');
});
});

describe('getArchSize', function () {
it('should identify 64', function () {
expect(
Expand Down Expand Up @@ -469,26 +401,6 @@ describe('site.js', function () {
});
});

describe('isARM', function () {
beforeEach(function () {
// don't fall back to `window.site.archType` in tests.
sinon.stub(window.site, 'archType').value(null);
});

it('should return true for ARM processors', function () {
expect(window.site.isARM('arm')).toBeTrue();
expect(window.site.isARM('armv8')).toBeTrue();
expect(window.site.isARM('armv7')).toBeTrue();
});

it('should return false for other values', function () {
expect(window.site.isARM('x86')).toBeFalse();
expect(window.site.isARM('')).toBeFalse();
expect(window.site.isARM(null)).toBeFalse();
expect(window.site.isARM(undefined)).toBeFalse();
});
});

describe('getPlatformClass', function () {
beforeEach(function () {
document.documentElement.className = 'windows no-js';
Expand All @@ -502,7 +414,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for Windows 10', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'windows',
Expand All @@ -517,15 +428,13 @@ describe('site.js', function () {

it('should return the appropriate HTML class for macOS 10.15', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass('osx', 10.15, 32);
expect(classString).toEqual('osx js is-modern-browser');
});

it('should return the appropriate HTML class for Linux', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'linux',
Expand All @@ -538,7 +447,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for Android', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'android',
Expand All @@ -551,7 +459,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for iOS', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'ios',
Expand All @@ -564,7 +471,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for unknown platforms', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'other',
Expand All @@ -577,7 +483,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for outdated browsers', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(false);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'windows',
Expand All @@ -590,7 +495,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for Firefox browsers', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(true);
const classString = window.site.getPlatformClass(
'windows',
Expand All @@ -603,24 +507,8 @@ describe('site.js', function () {
expect(window.site.fxSupported).toBeTrue;
});

it('should return the appropriate HTML class for ARM based CPUs', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(true);
spyOn(window.site, 'isARM').and.returnValue(true);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'windows',
10.0,
32
);
expect(classString).toEqual(
'windows js windows-10-plus arm is-modern-browser'
);
expect(window.site.fxSupported).toBeTrue;
});

it('should return the appropriate HTML class for outdated Windows operating systems', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(false);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass(
'windows',
Expand All @@ -633,7 +521,6 @@ describe('site.js', function () {

it('should return the appropriate HTML class for outdated macOS operating systems', function () {
spyOn(window.site, 'cutsTheMustard').and.returnValue(false);
spyOn(window.site, 'isARM').and.returnValue(false);
spyOn(window.site, 'isFirefox').and.returnValue(false);
const classString = window.site.getPlatformClass('osx', 10.14, 64);
expect(classString).toEqual('osx js fx-unsupported x64');
Expand Down
15 changes: 0 additions & 15 deletions tests/unit/spec/firefox/new/common/thanks.js
Expand Up @@ -98,27 +98,12 @@ describe('thanks.js', function () {
it('should not return a download for Linux', function () {
const site = {
platform: 'linux',
isARM: function () {
return false;
},
archSize: 32
};
const result = Mozilla.DownloadThanks.getDownloadURL(site);
expect(result).toBeFalsy();
});

it('should not return a download for Linux ARM', function () {
const site = {
platform: 'linux',
isARM: function () {
return true;
},
archSize: 64
};
const result = Mozilla.DownloadThanks.getDownloadURL(site);
expect(result).toBeFalsy();
});

it('should return the correct download for Android', function () {
const site = {
platform: 'android'
Expand Down

0 comments on commit 39ba637

Please sign in to comment.