Bug 1742788 - Enable loading from the local dump if it is newer for the search-config remote settings collection. r=robwu,daleharvey a=pascalc
authorMark Banner <standard8@mozilla.com>
Tue, 30 Nov 2021 10:11:50 +0000
changeset 671278 c1fae07a3ae43807dcdba5e81270b4091ab73f7e
parent 671277 16f146ce02075f41fba700b8887083cf6c44551b
child 671279 360501cf14e99fab76d2d5f19c9ec06dd3244552
push id2713
push userpchevrel@mozilla.com
push dateWed, 15 Dec 2021 17:30:39 +0000
treeherdermozilla-release@126673f222be [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobwu, daleharvey, pascalc
bugs1742788
milestone95.0.1
Bug 1742788 - Enable loading from the local dump if it is newer for the search-config remote settings collection. r=robwu,daleharvey a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D132033
services/settings/dumps/gen_last_modified.py
toolkit/components/search/SearchEngineSelector.jsm
toolkit/components/search/tests/xpcshell/searchconfigs/test_selector_db_out_of_date.js
toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.ini
--- a/services/settings/dumps/gen_last_modified.py
+++ b/services/settings/dumps/gen_last_modified.py
@@ -53,26 +53,37 @@ def main(output):
         "browser",
         "mobile/android",
         "comm/mail",
         "comm/suite",
     )
 
     remotesettings_dumps = {}
 
-    # For simplicity, let's hardcode the path of the first and (so far) only
-    # RemoteSettings dump whose last_modified date is looked up (bug 1717068),
-    # i.e. blocklists/addons-bloomfilters.
+    # For simplicity, let's hardcode the path of the RemoteSettings dumps whose
+    # last_modified date is looked up.
     # TODO bug 1719560: Replace hardcoded values with something more generic.
     if buildconfig.substs["MOZ_BUILD_APP"] != "mobile/android":
         # Until bug 1639050 is resolved, the dump isn't packaged with Android.
         remotesettings_dumps["blocklists/addons-bloomfilters"] = mozpath.join(
             buildconfig.topsrcdir,
             "services/settings/dumps/blocklists/addons-bloomfilters.json",
         )
+    if buildconfig.substs["MOZ_BUILD_APP"] == "browser":
+        # This is only packaged with browser.
+        remotesettings_dumps["main/search-config"] = mozpath.join(
+            buildconfig.topsrcdir,
+            "services/settings/dumps/main/search-config.json",
+        )
+    if buildconfig.substs["MOZ_BUILD_APP"] == "comm/mail":
+        # This is only packaged with Thunderbird.
+        remotesettings_dumps["main/search-config"] = mozpath.join(
+            buildconfig.topsrcdir,
+            "comm/mail/app/settings/dumps/thunderbird/search-config.json",
+        )
 
     output_dict = {}
     input_files = set()
 
     for key, input_file in remotesettings_dumps.items():
         input_files.add(input_file)
         output_dict[key] = get_last_modified(input_file)
 
--- a/toolkit/components/search/SearchEngineSelector.jsm
+++ b/toolkit/components/search/SearchEngineSelector.jsm
@@ -135,17 +135,20 @@ class SearchEngineSelector {
    * @returns {array}
    *   An array of objects in the database, or an empty array if none
    *   could be obtained.
    */
   async _getConfiguration(firstTime = true) {
     let result = [];
     let failed = false;
     try {
-      result = await this._remoteConfig.get({ order: "id" });
+      result = await this._remoteConfig.get({
+        order: "id",
+        loadDumpIfNewer: true,
+      });
     } catch (ex) {
       logConsole.error(ex);
       failed = true;
     }
     if (!result.length) {
       logConsole.error("Received empty search configuration!");
       failed = true;
     }
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/test_selector_db_out_of_date.js
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+  RemoteSettingsWorker: "resource://services-settings/RemoteSettingsWorker.jsm",
+  SearchEngineSelector: "resource://gre/modules/SearchEngineSelector.jsm",
+});
+
+do_get_profile();
+
+add_task(async function test_selector_db_out_of_date() {
+  let searchConfig = RemoteSettings(SearchUtils.SETTINGS_KEY);
+
+  // Do an initial get to pre-seed the database.
+  await searchConfig.get();
+
+  // Now clear the database and re-fill it.
+  let db = searchConfig.db;
+  await db.clear();
+  let databaseEntries = await db.list();
+  Assert.equal(databaseEntries.length, 0, "Should have cleared the database.");
+
+  // Add a dummy record with an out-of-date last modified.
+  await RemoteSettingsWorker._execute("_test_only_import", [
+    "main",
+    SearchUtils.SETTINGS_KEY,
+    [
+      {
+        id: "b70edfdd-1c3f-4b7b-ab55-38cb048636c0",
+        default: "yes",
+        webExtension: { id: "outofdate@search.mozilla.org" },
+        appliesTo: [{ included: { everywhere: true } }],
+        last_modified: 1606227264000,
+      },
+    ],
+  ]);
+
+  // Now load the configuration and check we get what we expect.
+  let engineSelector = new SearchEngineSelector();
+  let result = await engineSelector.fetchEngineConfiguration({
+    // Use the fallback default locale/regions to get a simple list.
+    locale: "default",
+    region: "default",
+  });
+  Assert.deepEqual(
+    result.engines.map(e => e.webExtension.id),
+    [
+      "google@search.mozilla.org",
+      "wikipedia@search.mozilla.org",
+      "ddg@search.mozilla.org",
+    ],
+    "Should have returned the correct data."
+  );
+});
--- a/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/searchconfigs/xpcshell.ini
@@ -18,10 +18,11 @@ requesttimeoutfactor = 2
 [test_distributions.js]
 [test_duckduckgo.js]
 [test_ebay.js]
 [test_ecosia.js]
 [test_google.js]
 [test_mailru.js]
 [test_qwant.js]
 [test_rakuten.js]
+[test_selector_db_out_of_date.js]
 [test_yahoojp.js]
 [test_yandex.js]