Commit dc4f4226 authored by Nick Alexander's avatar Nick Alexander
Browse files

Bug 1675848 - Part 1: Add "backgroundtask" filter to chrome manifest parsing. r=mossop,kmag

This allows to filter chrome manifest registration by the current
background task(s, in the future).  Filtration behaves just like
filtering by "application":

* filter with `backgroundtask=` means disable for all background
  tasks, since no background task will match ""

* filter with `backgroundtask!=` means enable for all background task,
  since every background task will not match ""

Differential Revision: https://phabricator.services.mozilla.com/D96482
parent 7360317f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
category test-cat1 Cat1RegisteredComponent @unit.test.com/cat1-registered-component;1
category test-cat1 Cat1BackgroundTaskRegisteredComponent @unit.test.com/cat1-backgroundtask-registered-component;1 backgroundtask
category test-cat1 Cat1BackgroundTaskAlwaysRegisteredComponent @unit.test.com/cat1-backgroundtask-alwaysregistered-component;1 backgroundtask=1
category test-cat1 Cat1BackgroundTaskNotRegisteredComponent @unit.test.com/cat1-backgroundtask-notregistered-component;1 backgroundtask=0
+32 −0
Original line number Diff line number Diff line
@@ -189,6 +189,38 @@ add_test(function test_categoryRegistration()
  run_next_test();
});

add_test(function test_categoryBackgroundTaskRegistration()
{
  const CATEGORY_NAME = "test-cat1";

  // Note that this test should succeed whether or not MOZ_BACKGROUNDTASKS is
  // defined.  If it's defined, there's no active task so the `backgroundtask`
  // directive is processed, dropped, and always succeeds.  If it's not defined,
  // then the `backgroundtask` directive is processed and ignored.

  // Load test components.
  do_load_manifest("CatBackgroundTaskRegistrationComponents.manifest");

  const EXPECTED_ENTRIES = new Map([
    ["Cat1RegisteredComponent", "@unit.test.com/cat1-registered-component;1"],
    ["Cat1BackgroundTaskNotRegisteredComponent", "@unit.test.com/cat1-backgroundtask-notregistered-component;1"],
  ]);

  // Verify the correct entries are registered in the "test-cat" category.
  for (let {entry, value} of Services.catMan.enumerateCategory(CATEGORY_NAME)) {
    ok(EXPECTED_ENTRIES.has(entry), `${entry} is expected`);
    Assert.equal(EXPECTED_ENTRIES.get(entry), value);
    EXPECTED_ENTRIES.delete(entry);
  }
  print("Check that all of the expected entries have been deleted.");
  Assert.deepEqual(
    Array.from(EXPECTED_ENTRIES.keys()),
    [],
    "All expected entries have been deleted."
  );
  run_next_test();
});

add_test(function test_generateSingletonFactory()
{
  const XPCCOMPONENT_CONTRACTID = "@mozilla.org/singletonComponentTest;1";
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
head =
support-files =
  CatRegistrationComponents.manifest
  CatBackgroundTaskRegistrationComponents.manifest
  bogus_element_type.jsm
  bogus_exports_type.jsm
  bug451678_subscript.js
+1 −0
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ class Flags(OrderedDict):
        "xpcnativewrappers": Flag,
        "tablet": Flag,
        "process": StringFlag,
        "backgroundtask": StringFlag,
    }
    RE = re.compile(r"([!<>=]+)")

+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ class ManifestEntry(object):
        "tablet",
        "process",
        "contentaccessible",
        "backgroundtask",
    ]

    def __init__(self, base, *flags):
Loading