summaryrefslogtreecommitdiffstats
path: root/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about_default_pin_promo.js
blob: 1c8b172c29695772ef91a56f3a9bb538ee38af05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* 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/. */

const { sinon } = ChromeUtils.importESModule(
  "resource://testing-common/Sinon.sys.mjs"
);

const sandbox = sinon.createSandbox();

add_setup(async function () {
  ASRouter.resetMessageState();
  await SpecialPowers.pushPrefEnv({
    set: [["browser.promo.pin.enabled", true]],
  });
  await ASRouter.onPrefChange();
  // Stub out the doesAppNeedPin to true so that Pin Promo targeting evaluates true

  sandbox.stub(ShellService, "doesAppNeedPin").withArgs(true).returns(true);
  registerCleanupFunction(async () => {
    sandbox.restore();
  });
});

add_task(async function test_pin_promo() {
  let { win: win1, tab: tab1 } = await openTabAndWaitForRender();

  await SpecialPowers.spawn(tab1, [], async function () {
    const promoContainer = content.document.querySelector(".promo");
    const promoHeader = content.document.getElementById("promo-header");

    ok(promoContainer, "Pin promo is shown");
    is(
      promoHeader.textContent,
      "Private browsing freedom in one click",
      "Correct default values are shown"
    );
  });

  let { win: win2 } = await openTabAndWaitForRender();
  let { win: win3 } = await openTabAndWaitForRender();
  let { win: win4, tab: tab4 } = await openTabAndWaitForRender();

  await SpecialPowers.spawn(tab4, [], async function () {
    is(
      content.document.getElementById(".private-browsing-promo-link"),
      null,
      "should no longer render the promo after 3 impressions"
    );
  });

  await BrowserTestUtils.closeWindow(win1);
  await BrowserTestUtils.closeWindow(win2);
  await BrowserTestUtils.closeWindow(win3);
  await BrowserTestUtils.closeWindow(win4);
});

add_task(async function test_pin_promo_mr2022_holdback() {
  ASRouter.resetMessageState();
  // Set majorRelease2022 feature onboarding variable fallback pref
  // for inMr2022Holdback targeting to evaluate true
  await SpecialPowers.pushPrefEnv({
    set: [["browser.majorrelease.onboarding", false]],
  });
  await ASRouter.onPrefChange();
  let { win: win1, tab: tab1 } = await openTabAndWaitForRender();

  await SpecialPowers.spawn(tab1, [], async function () {
    const promoContainer = content.document.querySelector(".promo");
    const promoButtonText = content.document.querySelector(
      "#private-browsing-promo-link"
    ).textContent;

    ok(promoContainer, "Promo is shown");

    Assert.equal(
      promoButtonText,
      "Download Firefox Focus",
      "Pin Promo not shown for holdback user"
    );
  });

  await BrowserTestUtils.closeWindow(win1);
});

add_task(async function test_pin_promo_mr2022_not_holdback() {
  ASRouter.resetMessageState();
  // Set majorRelease2022 feature onboarding variable fallback pref
  // for inMr2022Holdback targeting to evaluate false
  await SpecialPowers.pushPrefEnv({
    set: [["browser.majorrelease.onboarding", true]],
  });
  await ASRouter.onPrefChange();
  let { win: win1, tab: tab1 } = await openTabAndWaitForRender();

  await SpecialPowers.spawn(tab1, [], async function () {
    const promoContainer = content.document.querySelector(".promo");
    const promoHeader = content.document.getElementById("promo-header");

    ok(promoContainer, "Promo is shown");

    is(
      promoHeader.textContent,
      "Private browsing freedom in one click",
      "Pin Promo is shown"
    );
  });

  await BrowserTestUtils.closeWindow(win1);
});