Backed out 7 changesets (bug 1942424) for causing frequent crashes. a=backout
[gecko.git] / toolkit / components / contentrelevancy / tests / browser / browser_contentrelevancy_nimbus.js
blob849d55bfc1cd1dfa8e41dc768d06422ff46c23be
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 "use strict";
6 const { ExperimentAPI } = ChromeUtils.importESModule(
7 "resource://nimbus/ExperimentAPI.sys.mjs"
8 );
9 const { ExperimentFakes } = ChromeUtils.importESModule(
10 "resource://testing-common/NimbusTestUtils.sys.mjs"
12 const { ContentRelevancyManager } = ChromeUtils.importESModule(
13 "resource://gre/modules/ContentRelevancyManager.sys.mjs"
15 const { sinon } = ChromeUtils.importESModule(
16 "resource://testing-common/Sinon.sys.mjs"
19 let gSandbox;
21 add_setup(() => {
22 gSandbox = sinon.createSandbox();
24 registerCleanupFunction(() => {
25 gSandbox.restore();
26 });
27 });
29 /**
30 * Test Nimbus integration - enable.
32 add_task(async function test_NimbusIntegration_enable() {
33 gSandbox.spy(ContentRelevancyManager, "notify");
35 await ExperimentAPI.ready();
36 const doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
37 featureId: "contentRelevancy",
38 value: {
39 enabled: true,
40 minInputUrls: 1,
41 maxInputUrls: 3,
42 // Set the timer interval to 0 will trigger the timer right away.
43 timerInterval: 0,
44 ingestEnabled: false,
46 });
48 await TestUtils.waitForCondition(
49 () => ContentRelevancyManager.shouldEnable,
50 "Should enable it via Nimbus"
53 await TestUtils.waitForCondition(
54 () => ContentRelevancyManager.notify.called,
55 "The timer callback should be called"
58 doExperimentCleanup();
59 gSandbox.restore();
60 });
62 /**
63 * Test Nimbus integration - disable.
65 add_task(async function test_NimbusIntegration_disable() {
66 gSandbox.spy(ContentRelevancyManager, "notify");
68 await ExperimentAPI.ready();
69 const doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
70 featureId: "contentRelevancy",
71 value: {
72 enabled: false,
73 minInputUrls: 1,
74 maxInputUrls: 3,
75 // Set the timer interval to 0 will trigger the timer right away.
76 timerInterval: 0,
77 ingestEnabled: false,
79 });
81 await TestUtils.waitForCondition(
82 () => !ContentRelevancyManager.shouldEnable,
83 "Should disable it via Nimbus"
86 await TestUtils.waitForCondition(
87 () => ContentRelevancyManager.notify.notCalled,
88 "The timer callback should not be called"
91 doExperimentCleanup();
92 gSandbox.restore();
93 });