@@ -318,6 +318,237 @@ describe("cookieDatabaseCandidatePaths", () => {
318318
319319const firefox = BROWSER_IMPORT_SOURCES . find ( ( source ) => source . id === "firefox" ) ! ;
320320
321+ const zen = BROWSER_IMPORT_SOURCES . find ( ( source ) => source . id === "zen" ) ! ;
322+
323+ describe ( "Zen" , ( ) => {
324+ it . effect ( "resolves Zen's native user-data roots on every supported platform" , ( ) =>
325+ run (
326+ Effect . gen ( function * ( ) {
327+ const darwinContext = yield * sourcePathContext . pipe (
328+ Effect . provideService ( HostProcess . Environment , { HOME : "/Users/zen-user" } ) ,
329+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
330+ ) ;
331+ const windowsContext = yield * sourcePathContext . pipe (
332+ Effect . provideService ( HostProcess . Environment , {
333+ HOME : "C:\\Users\\zen-user" ,
334+ APPDATA : "C:\\Users\\zen-user\\AppData\\Roaming" ,
335+ } ) ,
336+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
337+ ) ;
338+ const linuxContext = yield * sourcePathContext . pipe (
339+ Effect . provideService ( HostProcess . Environment , { HOME : "/home/zen-user" } ) ,
340+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
341+ ) ;
342+
343+ assert . equal ( zen . name , "Zen" ) ;
344+ assert . equal ( zen . engine , "firefox" ) ;
345+ assert . deepEqual ( [ ...zen . platforms ] , [ "darwin" , "win32" , "linux" ] ) ;
346+ assert . equal (
347+ zen . userDataDirectory ( darwinContext ) ,
348+ darwinContext . path . join ( "/Users/zen-user" , "Library" , "Application Support" , "zen" ) ,
349+ ) ;
350+ assert . equal (
351+ zen . userDataDirectory ( windowsContext ) ,
352+ windowsContext . path . join ( "C:\\Users\\zen-user\\AppData\\Roaming" , "zen" ) ,
353+ ) ;
354+ assert . equal (
355+ zen . userDataDirectory ( linuxContext ) ,
356+ linuxContext . path . join ( "/home/zen-user" , ".config" , "zen" ) ,
357+ ) ;
358+ assert . deepEqual ( zen . alternateLinuxRoots ?.( linuxContext ) , [
359+ linuxContext . path . join ( "/home/zen-user" , ".zen" ) ,
360+ linuxContext . path . join ( "/home/zen-user" , ".var" , "app" , "app.zen_browser.zen" , "zen" ) ,
361+ ] ) ;
362+ } ) ,
363+ ) ,
364+ ) ;
365+
366+ it . effect ( "discovers Zen profiles through its Firefox-compatible metadata" , ( ) =>
367+ run (
368+ Effect . gen ( function * ( ) {
369+ const fileSystem = yield * FileSystem . FileSystem ;
370+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-" } ) ;
371+ const context = yield * sourcePathContext . pipe (
372+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
373+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
374+ ) ;
375+ const root = zen . userDataDirectory ( context ) ! ;
376+ yield * fileSystem . makeDirectory ( root , { recursive : true } ) ;
377+ const profile = context . path . join ( root , "Profiles" , "zen.default" ) ;
378+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
379+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 2 , 1 ) ;
380+ yield * fileSystem . makeDirectory ( context . path . join ( root , "Profiles" , "empty.default" ) , {
381+ recursive : true ,
382+ } ) ;
383+ yield * fileSystem . writeFileString (
384+ context . path . join ( root , "profiles.ini" ) ,
385+ [
386+ "[Profile0]" ,
387+ "Name=Zen" ,
388+ "IsRelative=1" ,
389+ "Path=Profiles/zen.default" ,
390+ "ZenAvatarPath=chrome://browser/content/zen-avatars/avatar-55.svg" ,
391+ "Default=1" ,
392+ "" ,
393+ "[Profile1]" ,
394+ "Name=Empty" ,
395+ "IsRelative=1" ,
396+ "Path=Profiles/empty.default" ,
397+ "" ,
398+ ] . join ( "\n" ) ,
399+ ) ;
400+
401+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
402+ {
403+ directory : context . path . join ( "Profiles" , "zen.default" ) ,
404+ name : "Zen" ,
405+ cookieCount : 2 ,
406+ } ,
407+ ] ) ;
408+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
409+ assert . isFalse ( yield * isSourceRunning ( zen , context ) ) ;
410+ assert . equal (
411+ yield * resolveCookieDatabase ( zen , context , context . path . join ( "Profiles" , "zen.default" ) ) ,
412+ context . path . join ( profile , "cookies.sqlite" ) ,
413+ ) ;
414+ } ) ,
415+ ) ,
416+ ) ;
417+
418+ it . effect ( "discovers Zen profiles in both current and legacy Linux roots" , ( ) =>
419+ run (
420+ Effect . gen ( function * ( ) {
421+ const fileSystem = yield * FileSystem . FileSystem ;
422+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-linux-" } ) ;
423+ const context = yield * sourcePathContext . pipe (
424+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
425+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
426+ ) ;
427+ const currentRoot = context . path . join ( home , ".config" , "zen" ) ;
428+ const legacyRoot = context . path . join ( home , ".zen" ) ;
429+ const currentProfile = context . path . join ( currentRoot , "current.default" ) ;
430+ const legacyProfile = context . path . join ( legacyRoot , "legacy.default" ) ;
431+
432+ for ( const [ root , profile , name ] of [
433+ [ currentRoot , currentProfile , "Current" ] ,
434+ [ legacyRoot , legacyProfile , "Legacy" ] ,
435+ ] as const ) {
436+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
437+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 1 , 0 ) ;
438+ yield * fileSystem . writeFileString (
439+ context . path . join ( root , "profiles.ini" ) ,
440+ [
441+ "[Profile0]" ,
442+ `Name=${ name } ` ,
443+ "IsRelative=1" ,
444+ `Path=${ context . path . basename ( profile ) } ` ,
445+ ] . join ( "\n" ) ,
446+ ) ;
447+ }
448+
449+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
450+ { directory : "current.default" , name : "Current" , cookieCount : 1 } ,
451+ { directory : legacyProfile , name : "Legacy" , cookieCount : 1 } ,
452+ ] ) ;
453+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
454+ assert . equal (
455+ yield * resolveCookieDatabase ( zen , context , legacyProfile ) ,
456+ context . path . join ( legacyProfile , "cookies.sqlite" ) ,
457+ ) ;
458+
459+ yield * fileSystem . writeFileString (
460+ context . path . join ( currentRoot , "profiles.ini" ) ,
461+ `[Profile0]\nName=Shared\nIsRelative=0\nPath=${ legacyProfile } \n` ,
462+ ) ;
463+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
464+ { directory : legacyProfile , name : "Shared" , cookieCount : 1 } ,
465+ ] ) ;
466+
467+ yield * fileSystem . remove ( currentRoot , { recursive : true } ) ;
468+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
469+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
470+ { directory : legacyProfile , name : "Legacy" , cookieCount : 1 } ,
471+ ] ) ;
472+ } ) ,
473+ ) ,
474+ ) ;
475+
476+ it . effect ( "discovers a Flatpak-only Zen installation and resolves its cookies" , ( ) =>
477+ run (
478+ Effect . gen ( function * ( ) {
479+ const fileSystem = yield * FileSystem . FileSystem ;
480+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-flatpak-" } ) ;
481+ const context = yield * sourcePathContext . pipe (
482+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
483+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
484+ ) ;
485+ const root = context . path . join ( home , ".var" , "app" , "app.zen_browser.zen" , "zen" ) ;
486+ const profile = context . path . join ( root , "flatpak.default" ) ;
487+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
488+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 2 , 1 ) ;
489+ yield * fileSystem . writeFileString (
490+ context . path . join ( root , "profiles.ini" ) ,
491+ "[Profile0]\nName=Flatpak\nIsRelative=1\nPath=flatpak.default\n" ,
492+ ) ;
493+
494+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
495+ { directory : profile , name : "Flatpak" , cookieCount : 2 } ,
496+ ] ) ;
497+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
498+ assert . equal (
499+ yield * resolveCookieDatabase ( zen , context , profile ) ,
500+ context . path . join ( profile , "cookies.sqlite" ) ,
501+ ) ;
502+ } ) ,
503+ ) ,
504+ ) ;
505+
506+ it . effect ( "does not mistake Firefox Snap installs for Zen profiles" , ( ) =>
507+ run (
508+ Effect . gen ( function * ( ) {
509+ const fileSystem = yield * FileSystem . FileSystem ;
510+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-snap-" } ) ;
511+ const context = yield * sourcePathContext . pipe (
512+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
513+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
514+ ) ;
515+ const zenRoot = context . path . join ( home , ".config" , "zen" ) ;
516+ const snapRoot = context . path . join (
517+ home ,
518+ "snap" ,
519+ "firefox" ,
520+ "common" ,
521+ ".mozilla" ,
522+ "firefox" ,
523+ ) ;
524+ const zenProfile = context . path . join ( zenRoot , "zen.default" ) ;
525+ const snapProfile = context . path . join ( snapRoot , "snap.default" ) ;
526+ for ( const root of [ zenRoot , snapRoot ] ) {
527+ const profile = root === zenRoot ? zenProfile : snapProfile ;
528+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
529+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 1 , 0 ) ;
530+ yield * fileSystem . writeFileString (
531+ context . path . join ( root , "profiles.ini" ) ,
532+ [
533+ "[Profile0]" ,
534+ "Name=Personal" ,
535+ "IsRelative=1" ,
536+ `Path=${ profile === zenProfile ? "zen.default" : "snap.default" } ` ,
537+ ] . join ( "\n" ) ,
538+ ) ;
539+ }
540+
541+ const profiles = yield * listSourceProfiles ( zen , context ) ;
542+ assert . deepEqual (
543+ profiles . map ( ( profile ) => profile . directory ) ,
544+ [ "zen.default" ] ,
545+ ) ;
546+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
547+ } ) ,
548+ ) ,
549+ ) ;
550+ } ) ;
551+
321552describe ( "Firefox Snap profiles" , ( ) => {
322553 it . effect . skipIf ( ! symlinksSupported ) (
323554 "finds Snap profiles with or without profiles.ini and checks their locks" ,
0 commit comments