@@ -398,6 +398,85 @@ describe("cookieDatabaseCandidatePaths", () => {
398398
399399const firefox = BROWSER_IMPORT_SOURCES . find ( ( source ) => source . id === "firefox" ) ! ;
400400
401+ describe ( "Firefox Snap profiles" , ( ) => {
402+ it . effect ( "finds Snap profiles with or without profiles.ini and checks their locks" , ( ) =>
403+ run (
404+ Effect . gen ( function * ( ) {
405+ const fileSystem = yield * FileSystem . FileSystem ;
406+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-firefox-snap-" } ) ;
407+ const context = yield * sourcePathContext . pipe (
408+ Effect . provideService ( HostProcessEnvironment , { HOME : home } ) ,
409+ Effect . provideService ( HostProcessPlatform , "linux" ) ,
410+ ) ;
411+ const root = `${ home } /snap/firefox/common/.mozilla/firefox` ;
412+ const directory = `${ root } /abcd.default` ;
413+ yield * fileSystem . makeDirectory ( directory , { recursive : true } ) ;
414+ yield * writeFirefoxCookieDatabase ( `${ directory } /cookies.sqlite` , 2 , 1 ) ;
415+ yield * fileSystem . writeFileString (
416+ `${ root } /profiles.ini` ,
417+ "[Profile0]\nName=Personal\nIsRelative=1\nPath=abcd.default\n" ,
418+ ) ;
419+
420+ assert . isTrue ( yield * isSourceInstalled ( firefox , context ) ) ;
421+ assert . deepEqual ( yield * listSourceProfiles ( firefox , context ) , [
422+ { directory, name : "Personal" , cookieCount : 2 } ,
423+ ] ) ;
424+ assert . equal (
425+ yield * resolveCookieDatabase ( firefox , context , directory ) ,
426+ `${ directory } /cookies.sqlite` ,
427+ ) ;
428+ assert . isFalse ( yield * isSourceRunning ( firefox , context ) ) ;
429+ yield * fileSystem . symlink ( "foreign-host:+4242" , `${ directory } /lock` ) ;
430+ assert . isTrue ( yield * isSourceRunning ( firefox , context ) ) ;
431+ yield * fileSystem . remove ( `${ directory } /lock` ) ;
432+ assert . isFalse ( yield * isSourceRunning ( firefox , context ) ) ;
433+
434+ yield * fileSystem . remove ( `${ root } /profiles.ini` ) ;
435+ assert . deepEqual ( yield * listSourceProfiles ( firefox , context ) , [
436+ { directory, name : "abcd.default" , cookieCount : 2 } ,
437+ ] ) ;
438+ } ) ,
439+ ) ,
440+ ) ;
441+
442+ it . effect ( "keeps matching profile names in native and Snap installs distinct" , ( ) =>
443+ run (
444+ Effect . gen ( function * ( ) {
445+ const fileSystem = yield * FileSystem . FileSystem ;
446+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-firefox-snap-" } ) ;
447+ const context = yield * sourcePathContext . pipe (
448+ Effect . provideService ( HostProcessEnvironment , { HOME : home } ) ,
449+ Effect . provideService ( HostProcessPlatform , "linux" ) ,
450+ ) ;
451+ const native = `${ home } /.mozilla/firefox` ;
452+ const snap = `${ home } /snap/firefox/common/.mozilla/firefox` ;
453+ for ( const root of [ native , snap ] ) {
454+ yield * fileSystem . makeDirectory ( `${ root } /abcd.default` , { recursive : true } ) ;
455+ yield * writeFirefoxCookieDatabase ( `${ root } /abcd.default/cookies.sqlite` , 1 , 0 ) ;
456+ yield * fileSystem . writeFileString (
457+ `${ root } /profiles.ini` ,
458+ "[Profile0]\nName=Personal\nIsRelative=1\nPath=abcd.default\n" +
459+ `[Profile1]\nName=Shared\nIsRelative=0\nPath=${ snap } /abcd.default\n` ,
460+ ) ;
461+ }
462+
463+ const profiles = yield * listSourceProfiles ( firefox , context ) ;
464+ assert . deepEqual (
465+ profiles . map ( ( profile ) => profile . directory ) ,
466+ [ "abcd.default" , `${ snap } /abcd.default` ] ,
467+ ) ;
468+ const databases = yield * Effect . forEach ( profiles , ( profile ) =>
469+ resolveCookieDatabase ( firefox , context , profile . directory ) ,
470+ ) ;
471+ assert . deepEqual ( databases , [
472+ `${ native } /abcd.default/cookies.sqlite` ,
473+ `${ snap } /abcd.default/cookies.sqlite` ,
474+ ] ) ;
475+ } ) ,
476+ ) ,
477+ ) ;
478+ } ) ;
479+
401480describe ( "listSourceProfiles Firefox fallback" , ( ) => {
402481 const cases = [
403482 { platform : "linux" as const , profileDirectory : "linux.default" } ,
0 commit comments