Commit 372acec1 authored by Kagami Sascha Rosylight's avatar Kagami Sascha Rosylight
Browse files

Bug 1830384 - Skip cleanup when no sanitization happened r=hpeuckmann

D176147 falsely let the process always run; this should now skip it when not needed.

Differential Revision: https://phabricator.services.mozilla.com/D176709
parent 09eab830
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -963,10 +963,12 @@ async function maybeSanitizeSessionPrincipals(progress, principals, flags) {
  });

  progress.step = "promises:" + promises.length;
  if (promises.length) {
    await Promise.all(promises);
    await new Promise(resolve =>
      Services.clearData.cleanupAfterDeletionAtShutdown(flags, resolve)
    );
  }
  progress.step = "promises resolved";
}

+58 −1
Original line number Diff line number Diff line
@@ -21,7 +21,35 @@ class MovedOriginDirectoryCleanupTestCase(MarionetteTestCase):
        self.moved_origin_directory = (
            Path(self.marionette.profile_path) / "storage" / "to-be-removed" / "foo"
        )
        self.moved_origin_directory.mkdir(parents=True)
        self.moved_origin_directory.mkdir(parents=True, exist_ok=True)

        # Add a cookie to get a principal to be cleaned up
        with self.marionette.using_context("chrome"):
            self.marionette.execute_script(
                """
                Services.cookies.add(
                    "example.local",
                    "path",
                    "name",
                    "value",
                    false,
                    false,
                    false,
                    Math.floor(Date.now() / 1000) + 24 * 60 * 60,
                    {},
                    Ci.nsICookie.SAMESITE_NONE,
                    Ci.nsICookie.SCHEME_UNSET
                );
                """
            )

    def removeAllCookies(self):
        with self.marionette.using_context("chrome"):
            self.marionette.execute_script(
                """
                Services.cookies.removeAll();
                """
            )

    def test_ensure_cleanup_by_quit(self):
        self.assertTrue(
@@ -75,3 +103,32 @@ class MovedOriginDirectoryCleanupTestCase(MarionetteTestCase):
            lambda _: not self.moved_origin_directory.exists(),
            message="to-be-removed subdirectory must disappear",
        )

    def test_ensure_no_cleanup_when_disabled(self):
        self.assertTrue(
            self.moved_origin_directory.exists(),
            "to-be-removed subdirectory must exist",
        )

        self.marionette.set_pref("privacy.sanitize.sanitizeOnShutdown", False)
        self.marionette.quit()

        self.assertTrue(
            self.moved_origin_directory.exists(),
            "to-be-removed subdirectory must not disappear",
        )

    def test_ensure_no_cleanup_when_no_cookie(self):
        self.assertTrue(
            self.moved_origin_directory.exists(),
            "to-be-removed subdirectory must exist",
        )

        self.removeAllCookies()

        self.marionette.quit()

        self.assertTrue(
            self.moved_origin_directory.exists(),
            "to-be-removed subdirectory must not disappear",
        )