Bug 1559353 - fix test_blocklist_clients.js to actually work, r=leplatrem
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 19 Jun 2019 14:20:38 +0000
changeset 479225 40860d14200df2bc1219d2018fa1b56ac178ac26
parent 479224 4948b0bacf30949db7175783bc9f84151a6d64b0
child 479226 eba0ea8c0a9e2a2eee0c6a013b1006a4b131d14f
push id36174
push useropoprus@mozilla.com
push dateWed, 19 Jun 2019 21:38:13 +0000
treeherdermozilla-central@5b9a3de04646 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersleplatrem
bugs1559353, 1548542
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1559353 - fix test_blocklist_clients.js to actually work, r=leplatrem It's unclear to me how this is passing on infra. After bug 1548542, as far as I can tell the only time this test passes is when it somehow finishes before it does any of the filter testing. The filter functions as-is (which predates that bug) does not allow these items to be in the blocklist without something to identify what they're blocking (a guid/name for addons, a matchXXXXX prop for plugins). Also, we no longer have a separate bucket pref for the extension blocklist. Before this patch, when this (rarely) passes for me on the local machine, it does so because we bail out immediately after the initial run_test, as if the add_task functions have somehow not registered. I do not understand why this would happen. In any case, after these changes, we definitely run the rest of the test and it passes for me locally. Differential Revision: https://phabricator.services.mozilla.com/D35030
toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js
--- a/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js
@@ -12,113 +12,134 @@ async function clear_state() {
 
     // Clear local DB.
     const collection = await client.openCollection();
     await collection.clear();
   }
 }
 
 
-function run_test() {
+add_task(async function setup() {
   AddonTestUtils.createAppInfo("XPCShell", "xpcshell@tests.mozilla.org", "1", "");
 
   // This will initialize the remote settings clients for blocklists.
   BlocklistGlobal.ExtensionBlocklistRS.ensureInitialized();
   BlocklistGlobal.PluginBlocklistRS.ensureInitialized();
   BlocklistGlobal.GfxBlocklistRS._ensureInitialized();
 
   gBlocklistClients = [
     {client: BlocklistGlobal.ExtensionBlocklistRS._client, testData: ["i808", "i720", "i539"]},
     {client: BlocklistGlobal.PluginBlocklistRS._client, testData: ["p1044", "p32", "p28"]},
     {client: BlocklistGlobal.GfxBlocklistRS._client, testData: ["g204", "g200", "g36"]},
   ];
 
-  promiseStartupManager().then(run_next_test);
-}
+  await promiseStartupManager();
+});
 
 add_task(async function test_initial_dump_is_loaded_as_synced_when_collection_is_empty() {
   for (let {client} of gBlocklistClients) {
     if (IS_ANDROID && client.collectionName != BlocklistGlobal.ExtensionBlocklistRS._client.collectionName) {
       // On Android we don't ship the dumps of plugins and gfx.
       continue;
     }
     Assert.ok(await RemoteSettingsUtils.hasLocalDump(client.bucketName, client.collectionName));
   }
 });
 add_task(clear_state);
 
 add_task(async function test_data_is_filtered_for_target() {
   const initial = [{
+    "guid": "foo",
+    "matchName": "foo",
     "versionRange": [{
       "targetApplication": [],
       "maxVersion": "*",
       "minVersion": "0",
       "severity": "1",
     }],
   }];
   const noMatchingTarget = [{
+    "guid": "foo",
+    "matchName": "foo",
     "versionRange": [{
-      "targetApplication": [],
+      "targetApplication": [{guid: "Foo"}],
       "maxVersion": "*",
       "minVersion": "0",
       "severity": "3",
     }],
   }, {
+    "guid": "foo",
+    "matchName": "foo",
     "versionRange": [{
-      "targetApplication": [],
+      "targetApplication": [{guid: "XPCShell", maxVersion: "0.1"}],
       "maxVersion": "*",
       "minVersion": "0",
       "severity": "1",
     }],
   }];
   const oneMatch = [{
+    "guid": "foo",
+    "matchName": "foo",
     "versionRange": [{
       "targetApplication": [{
-        "guid": "some-guid",
+        "guid": "XPCShell",
       }],
     }],
   }];
 
   const records = initial.concat(noMatchingTarget).concat(oneMatch);
 
   for (let {client} of gBlocklistClients) {
     // Initialize the collection with some data
     const collection = await client.openCollection();
     for (const record of records) {
       await collection.create(record);
     }
 
     const { data: internalData } = await collection.list();
     Assert.equal(internalData.length, records.length);
-    Assert.equal((await client.get()).length, 2); // only two matches.
+    let filtered = await client.get({syncIfEmpty: false});
+    Assert.equal(filtered.length, 2); // only two matches.
   }
 });
 add_task(clear_state);
 
 add_task(async function test_entries_are_filtered_when_jexl_filter_expression_is_present() {
   const records = [{
+      guid: "foo",
+      matchName: "foo",
       willMatch: true,
     }, {
+      guid: "foo",
+      matchName: "foo",
       willMatch: true,
       filter_expression: null,
     }, {
+      guid: "foo",
+      matchName: "foo",
       willMatch: true,
       filter_expression: "1 == 1",
     }, {
+      guid: "foo",
+      matchName: "foo",
       willMatch: false,
       filter_expression: "1 == 2",
     }, {
+      guid: "foo",
+      matchName: "foo",
       willMatch: true,
       filter_expression: "1 == 1",
       versionRange: [{
         targetApplication: [{
           guid: "some-guid",
         }],
       }],
     }, {
+      guid: "foo",
+      matchName: "foo",
       willMatch: false,  // jexl prevails over versionRange.
       filter_expression: "1 == 2",
       versionRange: [{
         targetApplication: [{
           guid: "xpcshell@tests.mozilla.org",
           minVersion: "0",
           maxVersion: "*",
         }],
@@ -126,32 +147,28 @@ add_task(async function test_entries_are
     },
   ];
   for (let {client} of gBlocklistClients) {
     const collection = await client.openCollection();
     for (const record of records) {
       await collection.create(record);
     }
     await collection.db.saveLastModified(42); // Prevent from loading JSON dump.
-    const list = await client.get();
+    const list = await client.get({syncIfEmpty: false});
     equal(list.length, 4);
     ok(list.every(e => e.willMatch));
   }
 });
 add_task(clear_state);
 
 add_task(async function test_bucketname_changes_when_bucket_pref_changes() {
   for (const { client } of gBlocklistClients) {
     equal(client.bucketName, "blocklists");
   }
-  equal(BlocklistGlobal.ExtensionBlocklistRS._client.bucketName, "addons");
 
   Services.prefs.setCharPref("services.blocklist.bucket", "blocklists-preview");
-  Services.prefs.setCharPref("services.blocklist.addons.bucket", "addons-preview");
 
   for (const { client } of gBlocklistClients) {
     equal(client.bucketName, "blocklists-preview", client.identifier);
   }
-  equal(BlocklistGlobal.ExtensionBlocklistRS._client.bucketName, "addons-preview");
   Services.prefs.clearUserPref("services.blocklist.bucket");
-  Services.prefs.clearUserPref("services.blocklist.addons.bucket");
 });
 add_task(clear_state);