Bug 1564898 - Use UpdateManager to get the earliest Firefox version used (#5165)

This commit is contained in:
Andrei Oprea 2019-07-11 10:22:48 +02:00 коммит произвёл GitHub
Родитель 096404379f
Коммит 7c9f560372
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 33 добавлений и 35 удалений

Просмотреть файл

@ -36,6 +36,7 @@ Please note that some targeting attributes require stricter controls on the tele
* [hasPinnedTabs](#haspinnedtabs) * [hasPinnedTabs](#haspinnedtabs)
* [hasAccessedFxAPanel](#hasaccessedfxapanel) * [hasAccessedFxAPanel](#hasaccessedfxapanel)
* [isWhatsNewPanelEnabled](#iswhatsnewpanelenabled) * [isWhatsNewPanelEnabled](#iswhatsnewpanelenabled)
* [earliestFirefoxVersion](#earliestfirefoxversion)
## Detailed usage ## Detailed usage
@ -496,3 +497,13 @@ Boolean pref that controls if the What's New panel feature is enabled
```ts ```ts
declare const isWhatsNewPanelEnabled: boolean; declare const isWhatsNewPanelEnabled: boolean;
``` ```
### `earliestFirefoxVersion`
Integer value of the first Firefox version the profile ran on
#### Definition
```ts
declare const earliestFirefoxVersion: boolean;
```

Просмотреть файл

@ -753,16 +753,12 @@ class _ASRouter {
(await this._storage.get("providerImpressions")) || {}; (await this._storage.get("providerImpressions")) || {};
const previousSessionEnd = const previousSessionEnd =
(await this._storage.get("previousSessionEnd")) || 0; (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({ await this.setState({
messageBlockList, messageBlockList,
providerBlockList, providerBlockList,
messageImpressions, messageImpressions,
providerImpressions, providerImpressions,
previousSessionEnd, previousSessionEnd,
previousSessionFirefoxVersion,
}); });
this._updateMessageProviders(); this._updateMessageProviders();
await this.loadMessagesFromAllProviders(); await this.loadMessagesFromAllProviders();
@ -782,10 +778,6 @@ class _ASRouter {
uninit() { uninit() {
this._storage.set("previousSessionEnd", Date.now()); this._storage.set("previousSessionEnd", Date.now());
this._storage.set(
"previousSessionFirefoxVersion",
ASRouterTargeting.Environment.firefoxVersion
);
this.messageChannel.sendAsyncMessage(OUTGOING_MESSAGE_NAME, { this.messageChannel.sendAsyncMessage(OUTGOING_MESSAGE_NAME, {
type: "CLEAR_ALL", type: "CLEAR_ALL",
@ -1048,7 +1040,6 @@ class _ASRouter {
const { const {
messageImpressions, messageImpressions,
previousSessionEnd, previousSessionEnd,
previousSessionFirefoxVersion,
trailheadInterrupt, trailheadInterrupt,
trailheadTriplet, trailheadTriplet,
} = this.state; } = this.state;
@ -1060,12 +1051,6 @@ class _ASRouter {
get previousSessionEnd() { get previousSessionEnd() {
return previousSessionEnd; return previousSessionEnd;
}, },
get previousSessionFirefoxVersion() {
// Any comparison with `undefined` will return false
return isNaN(previousSessionFirefoxVersion)
? undefined
: previousSessionFirefoxVersion;
},
get trailheadInterrupt() { get trailheadInterrupt() {
return trailheadInterrupt; return trailheadInterrupt;
}, },

Просмотреть файл

@ -2,6 +2,9 @@ const { FilterExpressions } = ChromeUtils.import(
"resource://gre/modules/components-utils/FilterExpressions.jsm" "resource://gre/modules/components-utils/FilterExpressions.jsm"
); );
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
this, this,
@ -43,6 +46,12 @@ ChromeUtils.defineModuleGetter(
"AttributionCode", "AttributionCode",
"resource:///modules/AttributionCode.jsm" "resource:///modules/AttributionCode.jsm"
); );
XPCOMUtils.defineLazyServiceGetter(
this,
"UpdateManager",
"@mozilla.org/updates/update-manager;1",
"nsIUpdateManager"
);
const FXA_USERNAME_PREF = "services.sync.username"; const FXA_USERNAME_PREF = "services.sync.username";
const FXA_ENABLED_PREF = "identity.fxaccounts.enabled"; const FXA_ENABLED_PREF = "identity.fxaccounts.enabled";
@ -400,6 +409,16 @@ const TargetingGetters = {
false false
); );
}, },
get earliestFirefoxVersion() {
if (UpdateManager.updateCount) {
const earliestFirefoxVersion = UpdateManager.getUpdateAt(
UpdateManager.updateCount - 1
).previousAppVersion;
return parseInt(earliestFirefoxVersion.match(/\d+/), 10);
}
return null;
},
}; };
this.ASRouterTargeting = { this.ASRouterTargeting = {

Просмотреть файл

@ -492,8 +492,8 @@ const ONBOARDING_MESSAGES = async () => [
}, },
// Never saw this message or saw it in the past 4 days or more recent // Never saw this message or saw it in the past 4 days or more recent
targeting: `isWhatsNewPanelEnabled && targeting: `isWhatsNewPanelEnabled &&
(firefoxVersion > previousSessionFirefoxVersion && (earliestFirefoxVersion && firefoxVersion > earliestFirefoxVersion) &&
messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length == 0) || messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length == 0 ||
(messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length >= 1 && (messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}']|length >= 1 &&
currentDate|date - messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}'][0] <= 4 * 24 * 3600 * 1000)`, currentDate|date - messageImpressions[.id == 'WHATS_NEW_BADGE_${FIREFOX_VERSION}'][0] <= 4 * 24 * 3600 * 1000)`,
}, },

Просмотреть файл

@ -60,7 +60,6 @@ describe("ASRouter", () => {
let messageImpressions; let messageImpressions;
let providerImpressions; let providerImpressions;
let previousSessionEnd; let previousSessionEnd;
let previousSessionFirefoxVersion;
let fetchStub; let fetchStub;
let clock; let clock;
let getStringPrefStub; let getStringPrefStub;
@ -88,9 +87,6 @@ describe("ASRouter", () => {
getStub getStub
.withArgs("previousSessionEnd") .withArgs("previousSessionEnd")
.returns(Promise.resolve(previousSessionEnd)); .returns(Promise.resolve(previousSessionEnd));
getStub
.withArgs("previousSessionFirefoxVersion")
.returns(Promise.resolve(previousSessionFirefoxVersion));
return { return {
get: getStub, get: getStub,
set: sandbox.stub().returns(Promise.resolve()), set: sandbox.stub().returns(Promise.resolve()),
@ -117,7 +113,6 @@ describe("ASRouter", () => {
messageImpressions = {}; messageImpressions = {};
providerImpressions = {}; providerImpressions = {};
previousSessionEnd = 100; previousSessionEnd = 100;
previousSessionFirefoxVersion = 69;
sandbox = sinon.createSandbox(); sandbox = sinon.createSandbox();
sandbox.spy(ASRouterPreferences, "init"); sandbox.spy(ASRouterPreferences, "init");
@ -843,13 +838,6 @@ describe("ASRouter", () => {
assert.deepEqual(result, message1); 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", () => { it("should have messageImpressions in the message context", () => {
assert.propertyVal( assert.propertyVal(
Router._getMessagesContext(), Router._getMessagesContext(),
@ -967,17 +955,12 @@ describe("ASRouter", () => {
it("should save previousSessionEnd", () => { it("should save previousSessionEnd", () => {
Router.uninit(); Router.uninit();
assert.calledTwice(Router._storage.set); assert.calledOnce(Router._storage.set);
assert.calledWithExactly( assert.calledWithExactly(
Router._storage.set, Router._storage.set,
"previousSessionEnd", "previousSessionEnd",
sinon.match.number sinon.match.number
); );
assert.calledWithExactly(
Router._storage.set,
"previousSessionFirefoxVersion",
sinon.match.number
);
}); });
}); });