Bug 1640228 - Hide extended triplets on about:home with multistage onboarding r=Mardak
authorPunam Dahiya <punamdahiya@yahoo.com>
Fri, 29 May 2020 19:59:12 +0000
changeset 533049 f909996cb9a0024407aee5d49b8c172ba328f88e
parent 533048 9e0971e05ec02af35917176c3fffc5b17f8fa82b
child 533050 a7395b8a770653da17905eeb991203f897058b22
push id37462
push usermalexandru@mozilla.com
push dateSat, 30 May 2020 09:46:43 +0000
treeherdermozilla-central@8aaca63ec5c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1640228
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1640228 - Hide extended triplets on about:home with multistage onboarding r=Mardak Differential Revision: https://phabricator.services.mozilla.com/D77400
browser/components/newtab/lib/ASRouter.jsm
browser/components/newtab/test/unit/asrouter/ASRouter.test.js
--- a/browser/components/newtab/lib/ASRouter.jsm
+++ b/browser/components/newtab/lib/ASRouter.jsm
@@ -33,16 +33,22 @@ XPCOMUtils.defineLazyModuleGetters(this,
   RemoteL10n: "resource://activity-stream/lib/RemoteL10n.jsm",
   ExperimentAPI: "resource://messaging-system/experiments/ExperimentAPI.jsm",
   SpecialMessageActions:
     "resource://messaging-system/lib/SpecialMessageActions.jsm",
 });
 XPCOMUtils.defineLazyServiceGetters(this, {
   BrowserHandler: ["@mozilla.org/browser/clh;1", "nsIBrowserHandler"],
 });
+XPCOMUtils.defineLazyPreferenceGetter(
+  this,
+  "multiStageAboutWelcome",
+  "browser.aboutwelcome.overrideContent",
+  ""
+);
 const { actionTypes: at, actionCreators: ac } = ChromeUtils.import(
   "resource://activity-stream/common/Actions.jsm"
 );
 
 const { CFRMessageProvider } = ChromeUtils.import(
   "resource://activity-stream/lib/CFRMessageProvider.jsm"
 );
 const { OnboardingMessageProvider } = ChromeUtils.import(
@@ -1932,16 +1938,38 @@ class _ASRouter {
   isPreloadedBrowser(browser) {
     return browser.getAttribute("preloadedState") === "preloaded";
   }
 
   dispatch(action, target) {
     this.onMessage({ data: action, target });
   }
 
+  hasMultiStageAboutWelcome() {
+    // Verify if user has onboarded using multistage about:welcome by
+    // checking overridecontent pref has content or aboutwelcome group experiment value
+    // has template as multistage
+    let experimentData;
+    try {
+      experimentData = ExperimentAPI.getExperiment({
+        group: "aboutwelcome",
+      });
+    } catch (e) {
+      Cu.reportError(e);
+    }
+
+    return !!(
+      multiStageAboutWelcome ||
+      (experimentData &&
+        experimentData.branch &&
+        experimentData.branch.value &&
+        experimentData.branch.value.template === "multistage")
+    );
+  }
+
   async sendNewTabMessage(target, options = {}) {
     const { endpoint } = options;
     let message;
 
     // Load preview endpoint for snippets if one is sent
     if (endpoint) {
       await this._addPreviewEndpoint(endpoint.url, target.portID);
     }
@@ -1956,21 +1984,23 @@ class _ASRouter {
       if (message) {
         await this.setState(state => ({
           messages: state.messages.filter(m => m.id !== message.id),
         }));
       }
     } else {
       const telemetryObject = { port: target.portID };
       TelemetryStopwatch.start("MS_MESSAGE_REQUEST_TIME_MS", telemetryObject);
-      // On new tab, send cards if they match; othwerise send a snippet
-      message = await this.handleMessageRequest({
-        template: "extended_triplets",
-      });
-
+      // On new tab, send cards if they match and not part of multistage onboarding experiment;
+      // othwerise send a snippet
+      if (!this.hasMultiStageAboutWelcome()) {
+        message = await this.handleMessageRequest({
+          template: "extended_triplets",
+        });
+      }
       // If no extended triplets message was returned, show snippets instead
       if (!message) {
         message = await this.handleMessageRequest({ provider: "snippets" });
       }
       TelemetryStopwatch.finish("MS_MESSAGE_REQUEST_TIME_MS", telemetryObject);
     }
 
     await this._sendMessageToTarget(message, target);
--- a/browser/components/newtab/test/unit/asrouter/ASRouter.test.js
+++ b/browser/components/newtab/test/unit/asrouter/ASRouter.test.js
@@ -178,16 +178,17 @@ describe("ASRouter", () => {
       // importing these modules into the global scope ourselves.
       GroupsConfigurationProvider: { getMessages: () => [] },
       ASRouterPreferences,
       TARGETING_PREFERENCES,
       ASRouterTargeting,
       ASRouterTriggerListeners,
       QueryCache,
       gURLBar: {},
+      multiStageAboutWelcome: null,
       AttributionCode: fakeAttributionCode,
       SnippetsTestMessageProvider,
       PanelTestProvider,
       BookmarkPanelHub: FakeBookmarkPanelHub,
       ToolbarBadgeHub: FakeToolbarBadgeHub,
       ToolbarPanelHub: FakeToolbarPanelHub,
       MomentsPageHub: FakeMomentsPageHub,
       KintoHttpClient: class {
@@ -3994,16 +3995,42 @@ describe("ASRouter", () => {
 
       assert.calledOnce(Router.setGroupState);
       assert.calledWithExactly(Router.setGroupState, {
         id: "unblock",
         value: true,
       });
     });
   });
+  describe("#hideExtendedTripletsOnMultiStageWelcome", () => {
+    it("should return false by default", async () => {
+      global.ExperimentAPI.getExperiment.returns(null);
+      let result = Router.hasMultiStageAboutWelcome();
+      assert.isFalse(result);
+    });
+    it("should return true if experiment has multistage template", async () => {
+      global.ExperimentAPI.getExperiment.returns({
+        branch: {
+          slug: "branch01",
+          value: { id: "id01", template: "multistage" },
+        },
+      });
+      let result = Router.hasMultiStageAboutWelcome();
+      assert.calledOnce(global.ExperimentAPI.getExperiment);
+      assert.calledWithExactly(global.ExperimentAPI.getExperiment, {
+        group: "aboutwelcome",
+      });
+      assert.isTrue(result);
+    });
+    it("should return false by default when fails to get ExperimentData", async () => {
+      global.ExperimentAPI.getExperiment.throws();
+      let result = Router.hasMultiStageAboutWelcome();
+      assert.isFalse(result);
+    });
+  });
   describe("#loadMessagesForProvider", () => {
     it("should fetch messages from the ExperimentAPI", async () => {
       const args = {
         type: "remote-experiments",
         messageGroups: ["asrouter"],
       };
 
       await MessageLoaderUtils.loadMessagesForProvider(args);