Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test runs only with pattern: os != 'android'
- Manifest: browser/extensions/newtab/test/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
});
const PREF_UNIFIED_ADS_ADSCLIENT_ENABLED = "unifiedAds.adsClient.enabled";
add_task(function test_isEnabled() {
Assert.strictEqual(
lazy.AdsClient.isEnabled({}),
false,
"Gated off by default (no pref, no trainhopConfig)"
);
Assert.strictEqual(
lazy.AdsClient.isEnabled(undefined),
false,
"Gated off when prefs are missing"
);
Assert.strictEqual(
lazy.AdsClient.isEnabled({ [PREF_UNIFIED_ADS_ADSCLIENT_ENABLED]: true }),
true,
"Enabled by the local about:config pref"
);
Assert.strictEqual(
lazy.AdsClient.isEnabled({
trainhopConfig: { adsClient: { enabled: true } },
}),
true,
"Enabled by trainhopConfig.adsClient.enabled"
);
Assert.strictEqual(
lazy.AdsClient.isEnabled({
trainhopConfig: { adsClient: { enabled: false } },
}),
false,
"Disabled when trainhopConfig.adsClient.enabled is false"
);
});
add_task(function test_getClient_singleton() {
const adsClient = new lazy._AdsClient();
const client = adsClient.getClient();
Assert.ok(client, "getClient builds and returns a MozAdsClient");
const sameClient = adsClient.getClient();
Assert.strictEqual(
sameClient,
client,
"getClient returns the same cached singleton"
);
});