summaryrefslogtreecommitdiffstats
path: root/browser/extensions/formautofill/test/browser/address/browser_address_autofill_nimbus.js
blob: 0ea100cf8fdbcc5e99f070c8c721f800f54c3bf7 (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
"use strict";

const { ExperimentAPI } = ChromeUtils.importESModule(
  "resource://nimbus/ExperimentAPI.sys.mjs"
);

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

const { FormAutofill } = ChromeUtils.importESModule(
  "resource://autofill/FormAutofill.sys.mjs"
);

add_setup(async function () {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.formautofill.addresses.experiments.enabled", false],
      ["extensions.formautofill.addresses.supportedCountries", "FR"],
    ],
  });
});

add_task(async function test_address_autofill_feature_enabled() {
  await ExperimentAPI.ready();

  const cleanupExperiment = await ExperimentFakes.enrollWithFeatureConfig({
    featureId: "address-autofill-feature",
    value: { status: true },
  });

  is(
    NimbusFeatures["address-autofill-feature"].getVariable("status"),
    true,
    "Nimbus feature should be enabled"
  );

  is(
    FormAutofill.isAutofillAddressesAvailable,
    true,
    "Address autofill should be available when feature is enabled in nimbus."
  );

  await cleanupExperiment();
});

add_task(async function test_address_autofill_feature_disabled() {
  await ExperimentAPI.ready();

  const cleanupExperiment = await ExperimentFakes.enrollWithFeatureConfig({
    featureId: "address-autofill-feature",
    value: { status: false },
  });

  NimbusFeatures["address-autofill-feature"].recordExposureEvent();

  is(
    NimbusFeatures["address-autofill-feature"].getVariable("status"),
    false,
    "Nimbus feature shouldn't be enabled"
  );

  is(
    FormAutofill.isAutofillAddressesAvailable,
    false,
    "Address autofill shouldn't be available when feature is off in nimbus."
  );

  await cleanupExperiment();
});