summaryrefslogtreecommitdiffstats
path: root/toolkit/components/contentrelevancy/tests
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/contentrelevancy/tests')
-rw-r--r--toolkit/components/contentrelevancy/tests/browser/browser.toml1
-rw-r--r--toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js2
-rw-r--r--toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js28
-rw-r--r--toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js81
-rw-r--r--toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml6
5 files changed, 95 insertions, 23 deletions
diff --git a/toolkit/components/contentrelevancy/tests/browser/browser.toml b/toolkit/components/contentrelevancy/tests/browser/browser.toml
index ec1d3a3e66..8de1bd7c46 100644
--- a/toolkit/components/contentrelevancy/tests/browser/browser.toml
+++ b/toolkit/components/contentrelevancy/tests/browser/browser.toml
@@ -4,3 +4,4 @@ prefs = [
]
["browser_contentrelevancy_nimbus.js"]
+lineno = "6"
diff --git a/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js b/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js
index 47d54c2a87..5147b3792f 100644
--- a/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js
+++ b/toolkit/components/contentrelevancy/tests/browser/browser_contentrelevancy_nimbus.js
@@ -41,6 +41,7 @@ add_task(async function test_NimbusIntegration_enable() {
maxInputUrls: 3,
// Set the timer interval to 0 will trigger the timer right away.
timerInterval: 0,
+ ingestEnabled: false,
},
});
@@ -73,6 +74,7 @@ add_task(async function test_NimbusIntegration_disable() {
maxInputUrls: 3,
// Set the timer interval to 0 will trigger the timer right away.
timerInterval: 0,
+ ingestEnabled: false,
},
});
diff --git a/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js b/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js
index 633f9fc49b..7f89c7d615 100644
--- a/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js
+++ b/toolkit/components/contentrelevancy/tests/xpcshell/test_ContentRelevancyManager.js
@@ -23,11 +23,11 @@ const CATEGORY_UPDATE_TIMER = "update-timer";
let gSandbox;
-add_setup(async () => {
+add_setup(() => {
gSandbox = sinon.createSandbox();
initUpdateTimerManager();
Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, true);
- await ContentRelevancyManager.init();
+ ContentRelevancyManager.init();
registerCleanupFunction(() => {
Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED);
@@ -35,11 +35,11 @@ add_setup(async () => {
});
});
-add_task(async function test_init() {
+add_task(function test_init() {
Assert.ok(ContentRelevancyManager.initialized, "Init should succeed");
});
-add_task(async function test_uninit() {
+add_task(function test_uninit() {
ContentRelevancyManager.uninit();
Assert.ok(!ContentRelevancyManager.initialized, "Uninit should succeed");
@@ -50,7 +50,7 @@ add_task(async function test_timer() {
Services.prefs.setIntPref(PREF_TIMER_INTERVAL, 0);
gSandbox.spy(ContentRelevancyManager, "notify");
- await ContentRelevancyManager.init();
+ ContentRelevancyManager.init();
await TestUtils.waitForCondition(
() => ContentRelevancyManager.notify.called,
@@ -100,24 +100,6 @@ add_task(async function test_call_disable_twice() {
Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED);
});
-add_task(async function test_doClassification() {
- Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, true);
- await TestUtils.waitForCondition(() => ContentRelevancyManager._isStoreReady);
- await ContentRelevancyManager._test_doClassification([]);
-
- // Disable it to reset the store.
- Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, false);
- await TestUtils.waitForTick();
-
- await Assert.rejects(
- ContentRelevancyManager._test_doClassification([]),
- /Store is not available/,
- "Should throw with an unset store"
- );
-
- Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED);
-});
-
/**
* Sets up the update timer manager for testing: makes it fire more often,
* removes all existing timers, and initializes it for testing. The body of this
diff --git a/toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js b/toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js
new file mode 100644
index 0000000000..9deef6bad5
--- /dev/null
+++ b/toolkit/components/contentrelevancy/tests/xpcshell/test_Telemetry.js
@@ -0,0 +1,81 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { ContentRelevancyManager } = ChromeUtils.importESModule(
+ "resource://gre/modules/ContentRelevancyManager.sys.mjs"
+);
+
+const PREF_CONTENT_RELEVANCY_ENABLED = "toolkit.contentRelevancy.enabled";
+
+add_setup(async function setup() {
+ // FOG needs a profile directory to put its data in.
+ do_get_profile();
+
+ // FOG needs to be initialized in order for data to flow.
+ Services.fog.initializeFOG();
+
+ Services.prefs.setBoolPref(PREF_CONTENT_RELEVANCY_ENABLED, true);
+ ContentRelevancyManager.init();
+
+ registerCleanupFunction(() => {
+ Services.prefs.clearUserPref(PREF_CONTENT_RELEVANCY_ENABLED);
+ });
+});
+
+/**
+ * Test classification metrics - succeed.
+ */
+add_task(async function test_classify_succeed() {
+ Services.fog.testResetFOG();
+
+ Assert.equal(null, Glean.relevancyClassify.succeed.testGetValue());
+ Assert.equal(null, Glean.relevancyClassify.duration.testGetValue());
+
+ await ContentRelevancyManager._test_doClassification();
+
+ Assert.deepEqual(
+ {
+ input_size: 0,
+ input_classified_size: 0,
+ input_inconclusive_size: 0,
+ output_interest_size: 0,
+ interest_top_1_hits: 0,
+ interest_top_2_hits: 0,
+ interest_top_3_hits: 0,
+ },
+ Glean.relevancyClassify.succeed.testGetValue()[0].extra,
+ "Should record the succeed event"
+ );
+ Assert.ok(
+ Glean.relevancyClassify.duration.testGetValue().sum > 0,
+ "Should record the duration"
+ );
+});
+
+/**
+ * Test classification metrics - fail - insufficient-input.
+ */
+add_task(async function test_classify_fail_case1() {
+ Services.fog.testResetFOG();
+
+ Assert.equal(null, Glean.relevancyClassify.fail.testGetValue());
+ Assert.equal(null, Glean.relevancyClassify.duration.testGetValue());
+
+ // Require at least 1 input to trigger the failure.
+ await ContentRelevancyManager._test_doClassification({ minUrlsForTest: 1 });
+
+ Assert.deepEqual(
+ {
+ reason: "insufficient-input",
+ },
+ Glean.relevancyClassify.fail.testGetValue()[0].extra,
+ "Should record the fail event"
+ );
+ Assert.equal(
+ null,
+ Glean.relevancyClassify.duration.testGetValue(),
+ "Should not record the duration"
+ );
+});
diff --git a/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml b/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml
index 70f6d45c2d..0d76584e6c 100644
--- a/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml
+++ b/toolkit/components/contentrelevancy/tests/xpcshell/xpcshell.toml
@@ -4,6 +4,12 @@ firefox-appdir = "browser"
["test_ContentRelevancyManager.js"]
skip-if = ["os == 'android'"] # bug 1886601
+lineno = "5"
["test_InputUtils.js"]
skip-if = ["os == 'android'"] # bug 1886601
+lineno = "9"
+
+["test_Telemetry.js"]
+skip-if = ["os == 'android'"] # bug 1886601
+run-sequentially = "concurrent runs would interfere with each other"