tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 1635d321d55364f0840e6a40c11eaa6e120acfcf
parent e8a2667bdcf48f5d6dfeed21500bda4c8bd6a305
Author: Kui-Feng Lee <thinker.li@gmail.com>
Date:   Mon, 29 Dec 2025 21:08:19 +0000

Bug 2003137 - Add XDG test for legacy directory without profiles.ini r=gerard-majax

Add a new marionette test to verify that when the legacy Firefox directory
(~/.mozilla/firefox) exists but profiles.ini does not, Firefox correctly
falls back to XDG Base Directory specification and creates profiles in
~/.config/mozilla/firefox instead.

The test verifies:
- Profile is created in XDG location (.config/mozilla/firefox)
- profiles.ini is created in XDG directory, not legacy directory

This covers the edge case where the legacy directory exists but was never
properly initialized (e.g., manually created, incomplete installation, or
profiles.ini was deleted).

Differential Revision: https://phabricator.services.mozilla.com/D275907

Diffstat:
Mtoolkit/xre/test/marionette/xdg_config/manifest.toml | 3+++
Atoolkit/xre/test/marionette/xdg_config/test_xdg_config_legacy_dir_only.py | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools/lint/dot-mozilla-reference.yml | 1+
3 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/toolkit/xre/test/marionette/xdg_config/manifest.toml b/toolkit/xre/test/marionette/xdg_config/manifest.toml @@ -1,5 +1,8 @@ [DEFAULT] +["test_xdg_config_legacy_dir_only.py"] +run-if = ["os == 'linux'"] + ["test_xdg_config_legacy_existing.py"] run-if = ["os == 'linux'"] diff --git a/toolkit/xre/test/marionette/xdg_config/test_xdg_config_legacy_dir_only.py b/toolkit/xre/test/marionette/xdg_config/test_xdg_config_legacy_dir_only.py @@ -0,0 +1,81 @@ +import os +import sys + +import mozfile + +sys.path.append(os.path.dirname(__file__)) + +from xdg_config_home_test_case import XdgConfigHomeTestCase + + +class TestXdgConfigHomeLegacyDirOnly(XdgConfigHomeTestCase): + """ + Test that when legacy directory exists but profiles.ini doesn't, + Firefox uses XDG directory instead. + + This tests the scenario where ~/.mozilla/firefox directory exists + (perhaps from a previous Firefox version or manual creation) but + profiles.ini does not exist. In this case, Firefox should treat it + as a fresh install and use the XDG Base Directory specification, + creating the profile in ~/.config/mozilla/firefox/ instead. + """ + + def setUp(self): + # Create legacy directory WITHOUT profiles.ini + self.legacy_dir = os.path.join(self.homedir, ".mozilla", "firefox") + os.makedirs(self.legacy_dir, exist_ok=True) + + # Verify profiles.ini does NOT exist + legacy_profiles_ini = os.path.join(self.legacy_dir, "profiles.ini") + assert not os.path.exists( + legacy_profiles_ini + ), "profiles.ini should not exist in legacy directory" + + # Also create some dummy files in legacy dir to make it look "real" + # This simulates a case where the directory exists but was never + # properly initialized by Firefox + dummy_file = os.path.join(self.legacy_dir, "dummy.txt") + with open(dummy_file, "w") as f: + f.write("This is a dummy file\n") + + super().setUp() + + def tearDown(self): + if os.path.exists(self.legacy_dir): + mozfile.remove(self.legacy_dir) + assert not os.path.exists(self.legacy_dir) + super().tearDown() + + def test_profile_dir_uses_xdg(self): + """Should create profile in XDG directory, not legacy""" + self.client.navigate(self.about_support) + + profile_subdir = self.get_asserted_profile_subdir() + print(f"profile_subdir={profile_subdir}") + + # Should use XDG, not legacy + self.assertTrue( + profile_subdir.startswith(".config/mozilla/firefox"), + f"Profile should be under XDG .config/mozilla/firefox, " + f"not legacy .mozilla/firefox. Got: {profile_subdir}", + ) + + def test_profiles_ini_created_in_xdg(self): + """Verify profiles.ini was created in XDG location, not legacy""" + self.client.navigate(self.about_support) + + # profiles.ini should be in XDG directory + xdg_profiles_ini = os.path.join( + self.homedir, ".config", "mozilla", "firefox", "profiles.ini" + ) + self.assertTrue( + os.path.exists(xdg_profiles_ini), + f"profiles.ini should be created in XDG directory: {xdg_profiles_ini}", + ) + + # profiles.ini should NOT be in legacy directory + legacy_profiles_ini = os.path.join(self.legacy_dir, "profiles.ini") + self.assertFalse( + os.path.exists(legacy_profiles_ini), + f"profiles.ini should NOT be created in legacy directory: {legacy_profiles_ini}", + ) diff --git a/tools/lint/dot-mozilla-reference.yml b/tools/lint/dot-mozilla-reference.yml @@ -39,6 +39,7 @@ avoid-dot-mozilla-without-xdg: - toolkit/crashreporter/crash_helper_server/src/logging/env.rs - toolkit/moz.configure - toolkit/xre/nsXREDirProvider.cpp + - toolkit/xre/test/marionette/xdg_config/test_xdg_config_legacy_dir_only.py - toolkit/xre/test/marionette/xdg_config/test_xdg_config_legacy_existing.py - toolkit/tests/gtest/TestXREAppDir.cpp - xpcom/io/nsAppFileLocationProvider.cpp