Skip to content

Commit

Permalink
Bug 1812040 - Avoid remote settings errors emitted in tests when usin…
Browse files Browse the repository at this point in the history
…g the dummy url. r=leplatrem

Differential Revision: https://phabricator.services.mozilla.com/D193304
  • Loading branch information
Standard8 committed Nov 10, 2023
1 parent 9761b67 commit f89598c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion services/settings/RemoteSettingsClient.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ export class RemoteSettingsClient extends EventEmitter {
* @param {Object} options See #maybeSync() options.
*/
async sync(options) {
if (lazy.Utils.shouldSkipRemoteActivityDueToTests) {
return;
}

// We want to know which timestamp we are expected to obtain in order to leverage
// cache busting. We don't provide ETag because we don't want a 304.
const { changes } = await lazy.Utils.fetchLatestChanges(
Expand All @@ -614,7 +618,7 @@ export class RemoteSettingsClient extends EventEmitter {
// According to API, there will be one only (fail if not).
const [{ last_modified: expectedTimestamp }] = changes;

return this.maybeSync(expectedTimestamp, { ...options, trigger: "forced" });
await this.maybeSync(expectedTimestamp, { ...options, trigger: "forced" });
}

/**
Expand Down
7 changes: 7 additions & 0 deletions services/settings/Utils.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export var Utils = {
*/
log,

get shouldSkipRemoteActivityDueToTests() {
return (
(lazy.isRunningTests || Cu.isInAutomation) &&
this.SERVER_URL == "data:,#remote-settings-dummy/v1"
);
},

get CERT_CHAIN_ROOT_IDENTIFIER() {
if (this.SERVER_URL == AppConstants.REMOTE_SETTINGS_SERVER_URL) {
return Ci.nsIContentSignatureVerifier.ContentSignatureProdRoot;
Expand Down
3 changes: 3 additions & 0 deletions services/settings/remote-settings.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ function remoteSettingsFunction() {
trigger = "manual",
full = false,
} = {}) => {
if (lazy.Utils.shouldSkipRemoteActivityDueToTests) {
return;
}
// When running in full mode, we ignore last polling status.
if (full) {
lazy.gPrefs.clearUserPref(PREF_SETTINGS_SERVER_BACKOFF);
Expand Down
5 changes: 0 additions & 5 deletions toolkit/components/search/tests/xpcshell/head_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,6 @@ let consoleAllowList = [
// Harness issues.
'property "localProfileDir" is non-configurable and can\'t be deleted',
'property "profileDir" is non-configurable and can\'t be deleted',
// These can be emitted by `resource://services-settings/Utils.jsm` when
// remote settings is fetched (e.g. via IgnoreLists).
"NetworkError: Network request failed",
// Also remote settings, see bug 1812040.
"Unexpected content-type",
];

let endConsoleListening = TestUtils.listenForConsoleMessages();
Expand Down

0 comments on commit f89598c

Please sign in to comment.