From 4b949ce27cbd3186b4ff4fcf9561af601b0bd9f0 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Tue, 23 May 2017 21:45:50 -0700 Subject: [PATCH] Bug 1366917 - Include the system's RAM in the %SYSTEM_CAPABILITIES% value of the update URL. r=mhowell --- toolkit/modules/UpdateUtils.jsm | 28 +++++++++++++++++-- .../tests/xpcshell/test_UpdateUtils_url.js | 23 ++++++++++++--- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/toolkit/modules/UpdateUtils.jsm b/toolkit/modules/UpdateUtils.jsm index 65de0cc76466..5d8783d276ab 100644 --- a/toolkit/modules/UpdateUtils.jsm +++ b/toolkit/modules/UpdateUtils.jsm @@ -68,7 +68,7 @@ this.UpdateUtils = { url = url.replace(/%BUILD_ID%/g, Services.appinfo.appBuildID); url = url.replace(/%BUILD_TARGET%/g, Services.appinfo.OS + "_" + this.ABI); url = url.replace(/%OS_VERSION%/g, this.OSVersion); - url = url.replace(/%SYSTEM_CAPABILITIES%/g, gSystemCapabilities); + url = url.replace(/%SYSTEM_CAPABILITIES%/g, getSystemCapabilities()); if (/%LOCALE%/.test(url)) { url = url.replace(/%LOCALE%/g, this.Locale); } @@ -119,10 +119,32 @@ XPCOMUtils.defineLazyGetter(UpdateUtils, "Locale", function() { return null; }); +function getSystemCapabilities() { + return gInstructionSet + "," + getMemoryMB(); +} + /** - * Provides adhoc system capability information for application update. + * Gets the RAM size in megabytes. This will round the value because sysinfo + * doesn't always provide RAM in multiples of 1024. */ -XPCOMUtils.defineLazyGetter(this, "gSystemCapabilities", function aus_gSC() { +function getMemoryMB() { + let memoryMB = "unknown"; + try { + memoryMB = Services.sysinfo.getProperty("memsize"); + if (memoryMB) { + memoryMB = Math.round(memoryMB / 1024 / 1024); + } + } catch (e) { + Cu.reportError("Error getting system info memsize property. " + + "Exception: " + e); + } + return memoryMB; +} + +/** + * Gets the supported CPU instruction set. + */ +XPCOMUtils.defineLazyGetter(this, "gInstructionSet", function aus_gIS() { if (AppConstants.platform == "win") { const PF_MMX_INSTRUCTIONS_AVAILABLE = 3; // MMX const PF_XMMI_INSTRUCTIONS_AVAILABLE = 6; // SSE diff --git a/toolkit/modules/tests/xpcshell/test_UpdateUtils_url.js b/toolkit/modules/tests/xpcshell/test_UpdateUtils_url.js index efc8e8b4b79c..3649ad093937 100644 --- a/toolkit/modules/tests/xpcshell/test_UpdateUtils_url.js +++ b/toolkit/modules/tests/xpcshell/test_UpdateUtils_url.js @@ -129,9 +129,8 @@ function getProcArchitecture() { } } -// Provides system capability information for application update though it may -// be used by other consumers. -function getSystemCapabilities() { +// Gets the supported CPU instruction set. +function getInstructionSet() { if (AppConstants.platform == "win") { const PF_MMX_INSTRUCTIONS_AVAILABLE = 3; // MMX const PF_XMMI_INSTRUCTIONS_AVAILABLE = 6; // SSE @@ -166,6 +165,21 @@ function getSystemCapabilities() { return "NA"; } +// Gets the RAM size in megabytes. This will round the value because sysinfo +// doesn't always provide RAM in multiples of 1024. +function getMemoryMB() { + let memoryMB = "unknown"; + try { + memoryMB = Services.sysinfo.getProperty("memsize"); + if (memoryMB) { + memoryMB = Math.round(memoryMB / 1024 / 1024); + } + } catch (e) { + do_throw("Error getting system info memsize property. Exception: " + e); + } + return memoryMB; +} + // Helper function for formatting a url and getting the result we're // interested in function getResult(url) { @@ -331,6 +345,7 @@ add_task(function* test_custom() { // url constructed with %SYSTEM_CAPABILITIES% add_task(function* test_systemCapabilities() { let url = URL_PREFIX + "%SYSTEM_CAPABILITIES%/"; - Assert.equal(getResult(url), getSystemCapabilities(), + let systemCapabilities = getInstructionSet() + "," + getMemoryMB(); + Assert.equal(getResult(url), systemCapabilities, "the url param for %SYSTEM_CAPABILITIES%" + MSG_SHOULD_EQUAL); });