@@ -332,6 +332,89 @@ describe("findAccessibleWindow", () => {
332332 bounds : { x : 100 , y : 200 , width : 800 , height : 600 } ,
333333 } ;
334334
335+ const chromeCapture = {
336+ title : "Issues · pingdotgg/t3code" ,
337+ bounds : { x : 0 , y : 33 , width : 1470 , height : 857 } ,
338+ platform : "darwin" as const ,
339+ bundleId : "com.google.Chrome" ,
340+ } ;
341+
342+ it . each ( [
343+ [ "com.google.Chrome" , "Google Chrome" ] ,
344+ [ "com.google.Chrome.beta" , "Google Chrome" ] ,
345+ [ "com.google.Chrome.dev" , "Google Chrome" ] ,
346+ [ "com.google.Chrome.canary" , "Google Chrome" ] ,
347+ [ "org.chromium.Chromium" , "Chromium" ] ,
348+ ] ) ( "matches a macOS browser profile suffix for %s" , ( bundleId , browserName ) => {
349+ const window = {
350+ name : `${ chromeCapture . title } - ${ browserName } – Profile` ,
351+ bounds : chromeCapture . bounds ,
352+ } ;
353+ expect ( findAccessibleWindow ( [ window ] , { ...chromeCapture , bundleId } ) ) . toBe ( window ) ;
354+ } ) ;
355+
356+ it ( "matches a Chrome title without a profile suffix" , ( ) => {
357+ const window = {
358+ name : `${ chromeCapture . title } - Google Chrome` ,
359+ bounds : chromeCapture . bounds ,
360+ } ;
361+ expect ( findAccessibleWindow ( [ window ] , chromeCapture ) ) . toBe ( window ) ;
362+ } ) ;
363+
364+ it . each ( [
365+ { platform : "linux" as const , bundleId : "com.google.Chrome" } ,
366+ { platform : "win32" as const , bundleId : "com.google.Chrome" } ,
367+ { platform : "darwin" as const , bundleId : "com.example.Editor" } ,
368+ { platform : "darwin" as const , bundleId : undefined } ,
369+ ] ) ( "keeps strict titles outside macOS Chrome: %j" , ( identity ) => {
370+ const window = {
371+ name : `${ chromeCapture . title } - Google Chrome – Profile` ,
372+ bounds : chromeCapture . bounds ,
373+ } ;
374+ expect ( findAccessibleWindow ( [ window ] , { ...chromeCapture , ...identity } ) ) . toBeUndefined ( ) ;
375+ } ) ;
376+
377+ it . each ( [
378+ "Different page - Google Chrome – Profile" ,
379+ "Issues · pingdotgg/t3code copied - Google Chrome – Profile" ,
380+ "Issues · pingdotgg/t3code - Google ChromeSomething" ,
381+ ] ) ( "rejects unrelated browser titles: %s" , ( name ) => {
382+ expect (
383+ findAccessibleWindow ( [ { name, bounds : chromeCapture . bounds } ] , chromeCapture ) ,
384+ ) . toBeUndefined ( ) ;
385+ } ) ;
386+
387+ it ( "keeps bounds checks and rejects ambiguous browser suffix matches" , ( ) => {
388+ const window = {
389+ name : `${ chromeCapture . title } - Google Chrome – Profile` ,
390+ bounds : chromeCapture . bounds ,
391+ } ;
392+ expect (
393+ findAccessibleWindow ( [ { ...window , bounds : { ...window . bounds , x : 3 } } ] , chromeCapture ) ,
394+ ) . toBeUndefined ( ) ;
395+ expect (
396+ findAccessibleWindow ( [ window , { ...window , active : true } ] , chromeCapture ) ,
397+ ) . toBeUndefined ( ) ;
398+ expect ( findAccessibleWindow ( [ window ] , chromeCapture , "wayland" ) ) . toBeUndefined ( ) ;
399+ } ) ;
400+
401+ it ( "prefers an exact title over a browser suffix match" , ( ) => {
402+ const exact = { name : chromeCapture . title , bounds : chromeCapture . bounds } ;
403+ const browser = {
404+ name : `${ chromeCapture . title } - Google Chrome – Profile` ,
405+ bounds : chromeCapture . bounds ,
406+ active : true ,
407+ } ;
408+ expect ( findAccessibleWindow ( [ browser , exact ] , chromeCapture ) ) . toBe ( exact ) ;
409+ } ) ;
410+
411+ it ( "does not strip browser suffixes from captured page titles" , ( ) => {
412+ const window = { name : "Page - Google Chrome – Profile" , bounds : chromeCapture . bounds } ;
413+ expect (
414+ findAccessibleWindow ( [ window ] , { ...chromeCapture , title : "Page - Google Chrome" } ) ,
415+ ) . toBeUndefined ( ) ;
416+ } ) ;
417+
335418 it ( "matches one window by its captured bounds" , ( ) => {
336419 const windows = [
337420 { name : "Private" , bounds : { x : 0 , y : 0 , width : 400 , height : 300 } } ,
0 commit comments