Bug 1257565 - move addon blocklist tests from services/common to the blocklist dir, r=leplatrem
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 07 May 2019 00:56:01 +0000
changeset 534692 bb4e78986eed98bb51eaa06e20e9ea032d62f3fe
parent 534691 c4f071c9887145606f28db1e31a076f691777461
child 534693 6a17951bc4b981f455e3b8f54db29b5ed28fa122
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersleplatrem
bugs1257565
milestone68.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 1257565 - move addon blocklist tests from services/common to the blocklist dir, r=leplatrem Differential Revision: https://phabricator.services.mozilla.com/D29835
services/common/tests/unit/test_blocklist_clients.js
services/common/tests/unit/test_blocklist_targetapp_filter.js
services/common/tests/unit/xpcshell.ini
toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/head.js
toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js
toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js
toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/xpcshell.ini
--- a/services/common/tests/unit/xpcshell.ini
+++ b/services/common/tests/unit/xpcshell.ini
@@ -7,20 +7,16 @@ support-files =
 
 # Test load modules first so syntax failures are caught early.
 [test_load_modules.js]
 
 [test_blocklist_onecrl.js]
 # Skip signature tests for Thunderbird (Bug 1341983).
 skip-if = appname == "thunderbird"
 tags = blocklist
-[test_blocklist_clients.js]
-tags = blocklist
-[test_blocklist_targetapp_filter.js]
-tags = blocklist
 [test_blocklist_pinning.js]
 tags = blocklist
 
 [test_kinto.js]
 tags = blocklist
 [test_blocklist_signatures.js]
 tags = remote-settings blocklist
 [test_storage_adapter.js]
--- a/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/head.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/head.js
@@ -1,6 +1,7 @@
 // Appease eslint.
 /* import-globals-from ../head_addons.js */
 {
   let {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
   Services.prefs.setBoolPref("extensions.blocklist.useXML", false);
 }
+
rename from services/common/tests/unit/test_blocklist_clients.js
rename to toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js
--- a/services/common/tests/unit/test_blocklist_clients.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js
@@ -1,39 +1,30 @@
-const { Constructor: CC } = Components;
-
-const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
-const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
-const { FileUtils } = ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
-
-const { RemoteSettings } = ChromeUtils.import("resource://services-settings/remote-settings.js");
-const BlocklistClients = ChromeUtils.import("resource://services-common/blocklist-clients.js", null);
-
-const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
-  "nsIBinaryInputStream", "setInputStream");
+const BlocklistGlobal = ChromeUtils.import("resource://gre/modules/Blocklist.jsm", null);
 
 const IS_ANDROID = AppConstants.platform == "android";
 
-
 let gBlocklistClients;
 let server;
 
 async function clear_state() {
   for (let {client} of gBlocklistClients) {
     // Remove last server times.
     Services.prefs.clearUserPref(client.lastCheckTimePref);
 
     // Clear local DB.
     const collection = await client.openCollection();
     await collection.clear();
   }
 }
 
 
 function run_test() {
+  AddonTestUtils.createAppInfo("XPCShell", "xpcshell@tests.mozilla.org", "1", "");
+
   // Set up an HTTP Server
   server = new HttpServer();
   server.start(-1);
 
   // Point the blocklist clients to use this local HTTP server.
   Services.prefs.setCharPref("services.settings.server",
                              `http://localhost:${server.identity.primaryPort}/v1`);
   // Ensure that signature verification is disabled to prevent interference
@@ -42,24 +33,25 @@ function run_test() {
 
   // Unfortunately security settings are coupled with blocklists clients,
   // this will be fixed in Bug 1526018
   // We disable intermediate preloading because it runs when polling ends, and
   // interferes with `clear_state()` from this test suite.
   Services.prefs.setBoolPref("security.remote_settings.intermediates.enabled", false);
 
   // This will initialize the remote settings clients for blocklists.
-  BlocklistClients.initialize();
+  BlocklistGlobal.ExtensionBlocklistRS._ensureInitialized();
+  BlocklistGlobal.PluginBlocklistRS._ensureInitialized();
+  BlocklistGlobal.GfxBlocklistRS._ensureInitialized();
+
 
-  // FIXME: once all the clients are migrated to Blocklist.jsm, we should move
-  // the test there, too. This note is here so I don't forget.
   gBlocklistClients = [
-    {client: BlocklistClients.AddonBlocklistClient, testData: ["i808", "i720", "i539"]},
-    {client: BlocklistClients.PluginBlocklistClient, testData: ["p1044", "p32", "p28"]},
-    {client: BlocklistClients.GfxBlocklistClient, testData: ["g204", "g200", "g36"]},
+    {client: BlocklistGlobal.ExtensionBlocklistRS._client, testData: ["i808", "i720", "i539"]},
+    {client: BlocklistGlobal.PluginBlocklistRS._client, testData: ["p1044", "p32", "p28"]},
+    {client: BlocklistGlobal.GfxBlocklistRS._client, testData: ["g204", "g200", "g36"]},
   ];
 
   // Setup server fake responses.
   function handleResponse(request, response) {
     try {
       const sample = getSampleResponse(request, server.identity.primaryPort);
       if (!sample) {
         do_throw(`unexpected ${request.method} request for ${request.path}?${request.queryString}`);
@@ -87,28 +79,27 @@ function run_test() {
   const pluginsRecordsPath = "/v1/buckets/blocklists/collections/plugins/records";
   server.registerPathHandler(configPath, handleResponse);
   server.registerPathHandler(monitorChangesPath, handleResponse);
   server.registerPathHandler(addonsRecordsPath, handleResponse);
   server.registerPathHandler(gfxRecordsPath, handleResponse);
   server.registerPathHandler(pluginsRecordsPath, handleResponse);
 
 
-  run_next_test();
-
   registerCleanupFunction(function() {
     server.stop(() => { });
   });
+  promiseStartupManager().then(run_next_test);
 }
 
 add_task(async function test_initial_dump_is_loaded_as_synced_when_collection_is_empty() {
   const november2016 = 1480000000000;
 
   for (let {client} of gBlocklistClients) {
-    if (IS_ANDROID && client.collectionName != BlocklistClients.AddonBlocklistClient.collectionName) {
+    if (IS_ANDROID && client.collectionName != BlocklistGlobal.ExtensionBlocklistRS._client.collectionName) {
       // On Android we don't ship the dumps of plugins and gfx.
       continue;
     }
 
     // Test an empty db populates, but don't reach server (specified timestamp <= dump).
     await client.maybeSync(1);
 
     // Verify the loaded data has status to synced:
@@ -120,17 +111,17 @@ add_task(async function test_initial_dum
     const timestamp = await collection.db.getLastModified();
     ok(timestamp > november2016, `Loaded dump of ${client.collectionName} has timestamp ${timestamp}`);
   }
 });
 add_task(clear_state);
 
 add_task(async function test_initial_dump_is_loaded_when_using_get_on_empty_collection() {
   for (let {client} of gBlocklistClients) {
-    if (IS_ANDROID && client.collectionName != BlocklistClients.AddonBlocklistClient.collectionName) {
+    if (IS_ANDROID && client.collectionName != BlocklistGlobal.ExtensionBlocklistRS._client.collectionName) {
       // On Android we don't ship the dumps of plugins and gfx.
       continue;
     }
     // Internal database is empty.
     const collection = await client.openCollection();
     const { data: list } = await collection.list();
     equal(list.length, 0);
 
@@ -261,25 +252,27 @@ add_task(async function test_inspect_wit
   }
 });
 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(BlocklistClients.PinningBlocklistClient.bucketName, "pinning");
+  equal(BlocklistGlobal.ExtensionBlocklistRS._client.bucketName, "addons");
 
   Services.prefs.setCharPref("services.blocklist.bucket", "blocklists-preview");
-  Services.prefs.setCharPref("services.blocklist.pinning.bucket", "pinning-preview");
+  Services.prefs.setCharPref("services.blocklist.addons.bucket", "addons-preview");
 
   for (const { client } of gBlocklistClients) {
     equal(client.bucketName, "blocklists-preview", client.identifier);
   }
-  equal(BlocklistClients.PinningBlocklistClient.bucketName, "pinning-preview");
+  equal(BlocklistGlobal.ExtensionBlocklistRS._client.bucketName, "addons-preview");
+  Services.prefs.clearUserPref("services.blocklist.bucket");
+  Services.prefs.clearUserPref("services.blocklist.addons.bucket");
 });
 add_task(clear_state);
 
 
 // get a response for a given request from sample data
 function getSampleResponse(req, port) {
   const responses = {
     "OPTIONS": {
rename from services/common/tests/unit/test_blocklist_targetapp_filter.js
rename to toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js
--- a/services/common/tests/unit/test_blocklist_targetapp_filter.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js
@@ -1,9 +1,9 @@
-const { BlocklistClients } = ChromeUtils.import("resource://services-common/blocklist-clients.js");
+const BlocklistGlobal = ChromeUtils.import("resource://gre/modules/Blocklist.jsm", null);
 const { RemoteSettings } = ChromeUtils.import("resource://services-settings/remote-settings.js");
 
 const APP_ID = "xpcshell@tests.mozilla.org";
 const TOOLKIT_ID = "toolkit@mozilla.org";
 
 let client;
 
 async function clear_state() {
@@ -17,138 +17,152 @@ async function createRecords(records) {
   for (const record of records) {
     await collection.create(record);
   }
   collection.db.saveLastModified(42); // Simulate sync (and prevent load dump).
 }
 
 
 function run_test() {
+  AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "58", "");
   // This will initialize the remote settings clients for blocklists,
   // with their specific options etc.
-  BlocklistClients.initialize();
+  BlocklistGlobal.PluginBlocklistRS._ensureInitialized();
   // Obtain one of the instantiated client for our tests.
   client = RemoteSettings("plugins", { bucketName: "blocklists" });
 
   run_next_test();
 }
 
 add_task(async function test_returns_all_without_target() {
   await createRecords([{
     matchName: "Adobe Flex",
   }, {
+    matchName: "foopydoo",
     versionRange: [],
   }, {
     matchName: "PDF reader",
     versionRange: [{
       severity: 0,
       vulnerabilityStatus: 1,
       targetApplication: [],
     }],
   }, {
     matchName: "Java(\\(TM\\))? Plug-in 11\\.(7[6-9]|[8-9]\\d|1([0-6]\\d|70))(\\.\\d+)?([^\\d\\._]|$)",
     versionRange: [{
       severity: 0,
       vulnerabilityStatus: 1,
     }],
     matchFilename: "libnpjp2\\.so",
   }, {
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [],
       maxVersion: "1",
       minVersion: "0",
       severity: "1",
     }],
   }]);
 
   const list = await client.get();
   equal(list.length, 5);
 });
 add_task(clear_state);
 
 add_task(async function test_returns_without_guid_or_with_matching_guid() {
   await createRecords([{
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
       }],
     }],
   }, {
     willMatch: false,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: "some-guid",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: TOOLKIT_ID,
       }],
     }],
   }]);
 
   const list = await client.get();
+  info(JSON.stringify(list, null, 2));
   equal(list.length, 3);
   ok(list.every(e => e.willMatch));
 });
 add_task(clear_state);
 
 add_task(async function test_returns_without_app_version_or_with_matching_version() {
   await createRecords([{
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         minVersion: "0",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         minVersion: "0",
         maxVersion: "9999",
       }],
     }],
   }, {
     willMatch: false,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         minVersion: "0",
         maxVersion: "1",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: TOOLKIT_ID,
         minVersion: "0",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: TOOLKIT_ID,
         minVersion: "0",
         maxVersion: "9999",
       }],
     }],
     // We can't test the false case with maxVersion for toolkit, because the toolkit version
@@ -159,41 +173,44 @@ add_task(async function test_returns_wit
   equal(list.length, 5);
   ok(list.every(e => e.willMatch));
 });
 add_task(clear_state);
 
 add_task(async function test_multiple_version_and_target_applications() {
   await createRecords([{
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: "other-guid",
       }],
     }, {
       targetApplication: [{
         guid: APP_ID,
         minVersion: "0",
         maxVersion: "*",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: "other-guid",
       }],
     }, {
       targetApplication: [{
         guid: APP_ID,
         minVersion: "0",
       }],
     }],
   }, {
     willMatch: false,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         maxVersion: "57.*",
       }],
     }, {
       targetApplication: [{
         guid: APP_ID,
@@ -209,32 +226,35 @@ add_task(async function test_multiple_ve
   equal(list.length, 2);
   ok(list.every(e => e.willMatch));
 });
 add_task(clear_state);
 
 add_task(async function test_complex_version() {
   await createRecords([{
     willMatch: false,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         maxVersion: "57.*",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         maxVersion: "9999.*",
       }],
     }],
   }, {
     willMatch: true,
+    matchName: "foopydoo",
     versionRange: [{
       targetApplication: [{
         guid: APP_ID,
         minVersion: "19.0a1",
       }],
     }],
   }]);
 
--- a/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/xpcshell.ini
@@ -4,16 +4,17 @@ tags = addons blocklist
 head = head.js ../head_addons.js
 firefox-appdir = browser
 support-files =
   ../data/**
 
 [test_blocklist_appversion.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
+[test_blocklist_clients.js]
 [test_blocklist_gfx.js]
 [test_blocklist_metadata_filters.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 [test_blocklist_osabi.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 [test_blocklist_plugin_flashonly.js]
@@ -24,16 +25,17 @@ skip-if = os == "android"
 skip-if = os == "android"
 [test_blocklist_plugin_severities.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
 [test_blocklist_prefs.js]
 [test_blocklist_severities.js]
 # Bug 676992: test consistently hangs on Android
 skip-if = os == "android"
+[test_blocklist_targetapp_filter.js]
 [test_blocklistchange.js]
 # Times out during parallel runs on desktop
 requesttimeoutfactor = 2
 [test_gfxBlacklist_Device.js]
 [test_gfxBlacklist_DriverNew.js]
 [test_gfxBlacklist_Equal_DriverNew.js]
 [test_gfxBlacklist_Equal_DriverOld.js]
 [test_gfxBlacklist_Equal_OK.js]