First runtime step of the New Tab AdsClient integration. Instantiate the MozAdsClient singleton (from the ads-client UniFFI bindings added in bug 2048346) in the New Tab parent process, gated behind a feature flag. This only proves the bindings load and the singleton initializes; it is not yet used to request or serve ads. - Add AdsClient.sys.mjs exposing a shared singleton (AdsClient) with isEnabled(prefValues) and getClient(). - Gate on trainhopConfig.adsClient.enabled (primary, train-hop-compatible) plus a local unifiedAds.adsClient.enabled about:config override; default off. - Use a console-logging LoggerTelemetry stub (no Glean) and no SQLite cache; the existing PersistentCache is untouched. - Load the bindings via lazy getters and gate on Firefox 154+, so the train-hopped add-on keeps working on Beta/Release builds that predate them. - Load the singleton from AdsFeed, TopSitesFeed and DiscoveryStreamFeed at startup when the flag is on, storing a reference for later use. This also references the generated bindings, so the browser_all_files_referenced.js allowlist entry for RustAdsClient.sys.mjs is no longer needed. Differential Revision: https://phabricator.services.mozilla.com/D309444
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
const lazy = {};
|
|
ChromeUtils.defineESModuleGetters(lazy, {
|
|
AdsClient: "resource://newtab/lib/AdsClient.sys.mjs",
|
|
_AdsClient: "resource://newtab/lib/AdsClient.sys.mjs",
|
|
});
|
|
|
|
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"
|
|
);
|
|
});
|