browser/components/newtab/lib/PanelTestProvider.jsm
author Ed Lee <edilee@mozilla.com>
Tue, 13 Aug 2019 22:36:31 +0000
changeset 541947 feeaf170fca669a675eff2cb16bd56b0a329b508
parent 541708 03b028ae464bb042d8141ba0f45f5bd99ab81833
permissions -rw-r--r--
Bug 1567601 - New "Moments" Page. r=k88hudson, a=RyanVM Includes 15 activity-stream commits: 27b79564 Bug 1561536 - Add new message schema and template type for feature callouts (#5133) d8570e05 Bug 1561540 - CFR messages should have a priority field that allows sorting (#5156) 7c9f5603 Bug 1564898 - Use UpdateManager to get the earliest Firefox version used (#5165) 6ebba35b Bug 1564811 - Badge actions can define a timeout delay after which the action is executed (#5170) 90b5eea2 (nobug) Move the What's New and Badge test messages to PanelTestProvider.jsm (#5171) 23e918ca Port 1561537 - Add badge/feature-callout style that matches the design spec r=r1cky 28bf2f0d (nobug) - Restore the default icon style after removing the badge (#5180) ffcb9a2a Bug 1561554 - Add telemetry events for notification badges (#5176) 4fcf6451 Bug 1566372 - Listen for pref changes as a way to trigger notifications (#5191) 993d0446 Bug 1571818 - handleMessageRequest method does not consider trigger params (#5226) c42d699c Port 1570935 - Remove clip-path property for causing performance regression r=k88hudson e125087c Port 1533846 - Clear WeakMap entries for Messaging System notifications r=k88hudson 84abc9de Bug 1569020 - Add a new badge action for setting homepage_override pref (#5207) f4878d99 Bug 1571846 - Moments pref reset issue (#5223) 2febea0f Bug 1573953 - Don't add impressions for moments page pref check (#5256) Differential Revision: https://phabricator.services.mozilla.com/D41859

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

const FIREFOX_VERSION = parseInt(Services.appinfo.version.match(/\d+/), 10);
const TWO_DAYS = 2 * 24 * 3600 * 1000;

const MESSAGES = () => [
  {
    id: "SIMPLE_FXA_BOOKMARK_TEST_FLUENT",
    template: "fxa_bookmark_panel",
    content: {
      title: { string_id: "cfr-doorhanger-bookmark-fxa-header" },
      text: { string_id: "cfr-doorhanger-bookmark-fxa-body" },
      cta: { string_id: "cfr-doorhanger-bookmark-fxa-link-text" },
      color: "white",
      background_color_1: "#7d31ae",
      background_color_2: "#5033be",
      info_icon: {
        tooltiptext: {
          string_id: "cfr-doorhanger-bookmark-fxa-info-icon-tooltip",
        },
      },
      close_button: {
        tooltiptext: {
          string_id: "cfr-doorhanger-bookmark-fxa-close-btn-tooltip",
        },
      },
    },
    trigger: { id: "bookmark-panel" },
  },
  {
    id: "SIMPLE_FXA_BOOKMARK_TEST_NON_FLUENT",
    template: "fxa_bookmark_panel",
    content: {
      title: "Bookmark Message Title",
      text: "Bookmark Message Body",
      cta: "Sync bookmarks now",
      color: "white",
      background_color_1: "#7d31ae",
      background_color_2: "#5033be",
      info_icon: {
        tooltiptext: "Toggle tooltip",
      },
      close_button: {
        tooltiptext: "Close tooltip",
      },
    },
    trigger: { id: "bookmark-panel" },
  },
  {
    id: "FXA_ACCOUNTS_BADGE",
    template: "toolbar_badge",
    content: {
      target: "fxa-toolbar-menu-button",
    },
    // Never accessed the FxA panel && doesn't use Firefox sync & has FxA enabled
    targeting: `!hasAccessedFxAPanel && !usesFirefoxSync && isFxAEnabled == true`,
    trigger: { id: "toolbarBadgeUpdate" },
  },
  {
    id: "WNP_THANK_YOU",
    template: "update_action",
    content: {
      action: {
        id: "moments-wnp",
        data: {
          url:
            "https://www.mozilla.org/%LOCALE%/etc/firefox/retention/thank-you-a/",
          expireDelta: TWO_DAYS,
        },
      },
    },
    trigger: { id: "momentsUpdate" },
  },
  {
    id: `WHATS_NEW_BADGE_${FIREFOX_VERSION}`,
    template: "toolbar_badge",
    content: {
      // delay: 5 * 3600 * 1000,
      delay: 5000,
      target: "whats-new-menu-button",
      action: { id: "show-whatsnew-button" },
    },
    priority: 1,
    trigger: { id: "toolbarBadgeUpdate" },
    frequency: {
      // Makes it so that we track impressions for this message while at the
      // same time it can have unlimited impressions
      lifetime: Infinity,
    },
    // Never saw this message or saw it in the past 4 days or more recent
    targeting: `isWhatsNewPanelEnabled &&
      (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)`,
  },
];

const PanelTestProvider = {
  getMessages() {
    return MESSAGES().map(message => ({
      ...message,
      targeting: `providerCohorts.panel_local_testing == "SHOW_TEST"`,
    }));
  },
};
this.PanelTestProvider = PanelTestProvider;

const EXPORTED_SYMBOLS = ["PanelTestProvider"];