diff options
Diffstat (limited to 'services/settings/test/unit/test_remote_settings_release_prefs.js')
-rw-r--r-- | services/settings/test/unit/test_remote_settings_release_prefs.js | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/services/settings/test/unit/test_remote_settings_release_prefs.js b/services/settings/test/unit/test_remote_settings_release_prefs.js index 251c407631..5d1a9f2e28 100644 --- a/services/settings/test/unit/test_remote_settings_release_prefs.js +++ b/services/settings/test/unit/test_remote_settings_release_prefs.js @@ -1,9 +1,5 @@ "use strict"; -const { AppConstants } = ChromeUtils.importESModule( - "resource://gre/modules/AppConstants.sys.mjs" -); - var nextUniqId = 0; function getNewUtils() { const { Utils } = ChromeUtils.importESModule( @@ -12,7 +8,21 @@ function getNewUtils() { return Utils; } -function clear_state() { +// A collection with a dump that's packaged on all builds where this test runs, +// including on Android at mobile/android/installer/package-manifest.in +const TEST_BUCKET = "main"; +const TEST_COLLECTION = "password-recipes"; + +async function importData(records) { + await RemoteSettingsWorker._execute("_test_only_import", [ + TEST_BUCKET, + TEST_COLLECTION, + records, + records[0]?.last_modified || 0, + ]); +} + +async function clear_state() { Services.env.set("MOZ_REMOTE_SETTINGS_DEVTOOLS", "0"); Services.prefs.clearUserPref("services.settings.server"); Services.prefs.clearUserPref("services.settings.preview_enabled"); @@ -186,6 +196,42 @@ add_task( const Utils = getNewUtils(); Assert.ok(!Utils.LOAD_DUMPS, "Dumps won't be loaded"); + + // The section below ensures that the LOAD_DUMPS flag properly takes effect. + // The client is set up here rather than add_setup to avoid triggering the + // lazy getters that are behind the global Utils.LOAD_DUMPS. If they are + // triggered too early, then they will potentially cache different values + // for the server urls and environment variables and this test then won't be + // testing what we expect it to. + + let client = new RemoteSettingsClient(TEST_COLLECTION); + + const dump = await SharedUtils.loadJSONDump(TEST_BUCKET, TEST_COLLECTION); + let DUMP_LAST_MODIFIED = dump.timestamp; + + // Dump is updated regularly, verify that the dump matches our expectations + // before running the test. + Assert.greater( + DUMP_LAST_MODIFIED, + 1234, + "Assuming dump to be newer than dummy 1234" + ); + + await client.db.clear(); + await importData([{ last_modified: 1234, id: "dummy" }]); + + const after = await client.get(); + Assert.deepEqual( + after, + [{ last_modified: 1234, id: "dummy" }], + "Should have kept the original import" + ); + Assert.equal( + await client.getLastModified(), + 1234, + "Should have kept the import's timestamp" + ); + await client.db.clear(); } ); add_task(clear_state); |