1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
6 const { ExperimentAPI } = ChromeUtils.importESModule(
7 "resource://nimbus/ExperimentAPI.sys.mjs"
9 const { ExperimentFakes } = ChromeUtils.importESModule(
10 "resource://testing-common/NimbusTestUtils.sys.mjs"
12 const { ContentRelevancyManager } = ChromeUtils.importESModule(
13 "resource://gre/modules/ContentRelevancyManager.sys.mjs"
17 * Test classification metrics - succeed.
19 add_task(async function test_classify_succeed() {
20 Services.fog.testResetFOG();
21 await ExperimentAPI.ready();
22 const doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
23 featureId: "contentRelevancy",
32 await TestUtils.waitForCondition(
33 () => ContentRelevancyManager.shouldEnable,
34 "Should enable it via Nimbus"
37 Assert.equal(undefined, Glean.relevancyClassify.succeed.testGetValue());
38 Assert.equal(undefined, Glean.relevancyClassify.duration.testGetValue());
40 await TestUtils.waitForCondition(
41 () => !ContentRelevancyManager.isInProgress,
42 "Ensure no classification is in-progress"
45 await ContentRelevancyManager._test_doClassification();
50 input_classified_size: 0,
51 input_inconclusive_size: 0,
52 output_interest_size: 0,
53 interest_top_1_hits: 0,
54 interest_top_2_hits: 0,
55 interest_top_3_hits: 0,
57 Glean.relevancyClassify.succeed.testGetValue()[0].extra,
58 "Should record the succeed event"
61 Glean.relevancyClassify.duration.testGetValue().sum > 0,
62 "Should record the duration"
65 await doExperimentCleanup();
69 * Test classification metrics - fail - insufficient-input.
71 add_task(async function test_classify_fail_case1() {
72 Services.fog.testResetFOG();
73 await ExperimentAPI.ready();
74 const doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
75 featureId: "contentRelevancy",
78 // Require at least 1 input to trigger the failure.
85 await TestUtils.waitForCondition(
86 () => ContentRelevancyManager.shouldEnable,
87 "Should enable it via Nimbus"
90 Assert.equal(undefined, Glean.relevancyClassify.fail.testGetValue());
91 Assert.equal(undefined, Glean.relevancyClassify.duration.testGetValue());
93 await TestUtils.waitForCondition(
94 () => !ContentRelevancyManager.isInProgress,
95 "Ensure no classification is in-progress"
98 await ContentRelevancyManager._test_doClassification();
102 reason: "insufficient-input",
104 Glean.relevancyClassify.fail.testGetValue()[0].extra,
105 "Should record the fail event"
109 Glean.relevancyClassify.duration.testGetValue(),
110 "Should not record the duration"
113 await doExperimentCleanup();
117 * Test classification metrics - fail - store-not-ready.
119 add_task(async function test_classify_fail_case2() {
120 Services.fog.testResetFOG();
121 await ExperimentAPI.ready();
122 const doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
123 featureId: "contentRelevancy",
125 // Disable the feature so the `store` won't be ready.
133 await TestUtils.waitForCondition(
134 () => !ContentRelevancyManager.shouldEnable,
135 "Should be disabled it via Nimbus"
138 Assert.equal(undefined, Glean.relevancyClassify.fail.testGetValue());
139 Assert.equal(undefined, Glean.relevancyClassify.duration.testGetValue());
141 await TestUtils.waitForCondition(
142 () => !ContentRelevancyManager.isInProgress,
143 "Ensure no classification is in-progress"
146 await ContentRelevancyManager._test_doClassification();
150 reason: "store-not-ready",
152 Glean.relevancyClassify.fail.testGetValue()[0].extra,
153 "Should record the fail event"
157 Glean.relevancyClassify.duration.testGetValue(),
158 "Should not record the duration"
161 await doExperimentCleanup();