diff --git a/content-src/asrouter/docs/targeting-attributes.md b/content-src/asrouter/docs/targeting-attributes.md index db629fa68..9ab7a3d16 100644 --- a/content-src/asrouter/docs/targeting-attributes.md +++ b/content-src/asrouter/docs/targeting-attributes.md @@ -36,6 +36,7 @@ Please note that some targeting attributes require stricter controls on the tele * [hasPinnedTabs](#haspinnedtabs) * [hasAccessedFxAPanel](#hasaccessedfxapanel) * [isWhatsNewPanelEnabled](#iswhatsnewpanelenabled) +* [earliestFirefoxVersion](#earliestfirefoxversion) ## Detailed usage @@ -496,3 +497,13 @@ Boolean pref that controls if the What's New panel feature is enabled ```ts declare const isWhatsNewPanelEnabled: boolean; ``` + +### `earliestFirefoxVersion` + +Integer value of the first Firefox version the profile ran on + +#### Definition + +```ts +declare const earliestFirefoxVersion: boolean; +``` diff --git a/lib/ASRouter.jsm b/lib/ASRouter.jsm index e9863f039..7dd8dc60d 100644 --- a/lib/ASRouter.jsm +++ b/lib/ASRouter.jsm @@ -753,16 +753,12 @@ class _ASRouter { (await this._storage.get("providerImpressions")) || {}; const previousSessionEnd = (await this._storage.get("previousSessionEnd")) || 0; - // Infinity so that we default to false (firefoxVersion > previousSessionFirefoxVersion) - const previousSessionFirefoxVersion = - (await this._storage.get("previousSessionFirefoxVersion")) || Infinity; await this.setState({ messageBlockList, providerBlockList, messageImpressions, providerImpressions, previousSessionEnd, - previousSessionFirefoxVersion, }); this._updateMessageProviders(); await this.loadMessagesFromAllProviders(); @@ -782,10 +778,6 @@ class _ASRouter { uninit() { this._storage.set("previousSessionEnd", Date.now()); - this._storage.set( - "previousSessionFirefoxVersion", - ASRouterTargeting.Environment.firefoxVersion - ); this.messageChannel.sendAsyncMessage(OUTGOING_MESSAGE_NAME, { type: "CLEAR_ALL", @@ -1048,7 +1040,6 @@ class _ASRouter { const { messageImpressions, previousSessionEnd, - previousSessionFirefoxVersion, trailheadInterrupt, trailheadTriplet, } = this.state; @@ -1060,12 +1051,6 @@ class _ASRouter { get previousSessionEnd() { return previousSessionEnd; }, - get previousSessionFirefoxVersion() { - // Any comparison with `undefined` will return false - return isNaN(previousSessionFirefoxVersion) - ? undefined - : previousSessionFirefoxVersion; - }, get trailheadInterrupt() { return trailheadInterrupt; }, diff --git a/lib/ASRouterTargeting.jsm b/lib/ASRouterTargeting.jsm index 686aaf030..8f5915b05 100644 --- a/lib/ASRouterTargeting.jsm +++ b/lib/ASRouterTargeting.jsm @@ -2,6 +2,9 @@ const { FilterExpressions } = ChromeUtils.import( "resource://gre/modules/components-utils/FilterExpressions.jsm" ); const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); ChromeUtils.defineModuleGetter( this, @@ -43,6 +46,12 @@ ChromeUtils.defineModuleGetter( "AttributionCode", "resource:///modules/AttributionCode.jsm" ); +XPCOMUtils.defineLazyServiceGetter( + this, + "UpdateManager", + "@mozilla.org/updates/update-manager;1", + "nsIUpdateManager" +); const FXA_USERNAME_PREF = "services.sync.username"; const FXA_ENABLED_PREF = "identity.fxaccounts.enabled"; @@ -400,6 +409,16 @@ const TargetingGetters = { false ); }, + get earliestFirefoxVersion() { + if (UpdateManager.updateCount) { + const earliestFirefoxVersion = UpdateManager.getUpdateAt( + UpdateManager.updateCount - 1 + ).previousAppVersion; + return parseInt(earliestFirefoxVersion.match(/\d+/), 10); + } + + return null; + }, }; this.ASRouterTargeting = { diff --git a/lib/OnboardingMessageProvider.jsm b/lib/OnboardingMessageProvider.jsm index 04a8b17a0..7c6beb066 100644 --- a/lib/OnboardingMessageProvider.jsm +++ b/lib/OnboardingMessageProvider.jsm @@ -492,8 +492,8 @@ const ONBOARDING_MESSAGES = async () => [ }, // Never saw this message or saw it in the past 4 days or more recent targeting: `isWhatsNewPanelEnabled && - (firefoxVersion > previousSessionFirefoxVersion && - messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length == 0) || + (earliestFirefoxVersion && firefoxVersion > earliestFirefoxVersion) && + messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length == 0 || (messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length >= 1 && currentDate|date - messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}'][0] <= 4 * 24 * 3600 * 1000)`, }, diff --git a/test/unit/asrouter/ASRouter.test.js b/test/unit/asrouter/ASRouter.test.js index 43451a8d9..04b346659 100644 --- a/test/unit/asrouter/ASRouter.test.js +++ b/test/unit/asrouter/ASRouter.test.js @@ -60,7 +60,6 @@ describe("ASRouter", () => { let messageImpressions; let providerImpressions; let previousSessionEnd; - let previousSessionFirefoxVersion; let fetchStub; let clock; let getStringPrefStub; @@ -88,9 +87,6 @@ describe("ASRouter", () => { getStub .withArgs("previousSessionEnd") .returns(Promise.resolve(previousSessionEnd)); - getStub - .withArgs("previousSessionFirefoxVersion") - .returns(Promise.resolve(previousSessionFirefoxVersion)); return { get: getStub, set: sandbox.stub().returns(Promise.resolve()), @@ -117,7 +113,6 @@ describe("ASRouter", () => { messageImpressions = {}; providerImpressions = {}; previousSessionEnd = 100; - previousSessionFirefoxVersion = 69; sandbox = sinon.createSandbox(); sandbox.spy(ASRouterPreferences, "init"); @@ -843,13 +838,6 @@ describe("ASRouter", () => { assert.deepEqual(result, message1); }); - it("should have previousSessionFirefoxVersion in the message context", () => { - assert.propertyVal( - Router._getMessagesContext(), - "previousSessionFirefoxVersion", - parseInt(AppConstants.MOZ_APP_VERSION, 10) - ); - }); it("should have messageImpressions in the message context", () => { assert.propertyVal( Router._getMessagesContext(), @@ -967,17 +955,12 @@ describe("ASRouter", () => { it("should save previousSessionEnd", () => { Router.uninit(); - assert.calledTwice(Router._storage.set); + assert.calledOnce(Router._storage.set); assert.calledWithExactly( Router._storage.set, "previousSessionEnd", sinon.match.number ); - assert.calledWithExactly( - Router._storage.set, - "previousSessionFirefoxVersion", - sinon.match.number - ); }); });