summaryrefslogtreecommitdiffstats
path: root/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_about_focus_promo.js
blob: 80333ead743dc52b4a7a7d1dbe04882ef86c0d8d (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
const { Region } = ChromeUtils.importESModule(
  "resource://gre/modules/Region.sys.mjs"
);
const { ASRouter } = ChromeUtils.import(
  "resource://activity-stream/lib/ASRouter.jsm"
);

const initialHomeRegion = Region._home;
const intialCurrentRegion = Region._current;
const initialLocale = Services.locale.appLocaleAsBCP47;

// Helper to run tests for specific regions
async function setupRegions(home, current) {
  Region._setHomeRegion(home || "");
  Region._setCurrentRegion(current || "");
}

// Helper to run tests for specific locales
function setLocale(locale) {
  Services.locale.availableLocales = [locale];
  Services.locale.requestedLocales = [locale];
}

add_task(async function test_focus_promo_in_allowed_region() {
  ASRouter.resetMessageState();

  const allowedRegion = "ES"; // Spain
  setupRegions(allowedRegion, allowedRegion);

  const { win, tab } = await openTabAndWaitForRender();

  await SpecialPowers.spawn(tab, [], async function () {
    const promoContainer = content.document.querySelector(".promo"); // container which is present if promo is enabled and should show

    ok(promoContainer, "Focus promo is shown for allowed region");
  });

  await BrowserTestUtils.closeWindow(win);
  setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
});

add_task(async function test_focus_promo_in_disallowed_region() {
  ASRouter.resetMessageState();

  const disallowedRegion = "CN"; // China
  setupRegions(disallowedRegion);

  const { win, tab } = await openTabAndWaitForRender();

  await SpecialPowers.spawn(tab, [], async function () {
    const promoContainer = content.document.querySelector(".promo"); // container which is removed if promo is disabled and/or should not show

    ok(!promoContainer, "Focus promo is not shown for disallowed region");
  });

  await BrowserTestUtils.closeWindow(win);
  setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
});

add_task(
  async function test_klar_promo_in_certain_regions_with_English_locale() {
    const testLocale = "en-US"; // US English
    setLocale(testLocale);

    const testRegion = async region => {
      setupRegions(region);
      ASRouter.resetMessageState();
      const { win, tab } = await openTabAndWaitForRender();
      await SpecialPowers.spawn(tab, [], async function () {
        const buttonText = content.document.querySelector(
          "#private-browsing-promo-link"
        ).textContent;
        Assert.equal(
          buttonText,
          "Download Firefox Klar",
          "The promo button text reads 'Download Firefox Klar'"
        );
      });
      await BrowserTestUtils.closeWindow(win);
    };

    await testRegion("AT"); // Austria
    await testRegion("DE"); // Germany
    await testRegion("CH"); // Switzerland

    setupRegions(initialHomeRegion, intialCurrentRegion); // revert changes to regions
    setLocale(initialLocale); // revert changes to locale
  }
);