"""Focused browsing checks for the real onn; all captures stay private.""" import io,json,time from PIL import Image,ImageChops,ImageStat from device import adb,OUT,screenshot from verify_ui import key,snapshot,labels,focus,wait,focused,launch def capture_bytes(name): raw=adb('exec-out','screencap','-p');(OUT/(name+'.png')).write_bytes(raw) return Image.open(io.BytesIO(raw)).convert('RGB') launch();key(20);focused('Play');key(22,2);focused('Next featured title') # Explicitly advance to see all three categories without waiting for the carousel timer. reasons=[] for i in range(3): root=snapshot();reasons.append(next((s for s in labels(root) if s in ('RECENTLY RELEASED','HIGHLY RATED ยท UNWATCHED','SUGGESTED FOR YOU')),'')) if i<2: focused('Next featured title');key(23);time.sleep(.7);focused('Next featured title') assert len(set(reasons))==3,reasons print('PASS real hero cycles recent releases, highly rated unwatched, and suggestions',flush=True) key(21,2);focused('Play');key(20);time.sleep(1) first=focus(snapshot());a=capture_bytes('updates-home-focus-one') key(22);time.sleep(1);second=focus(snapshot());b=capture_bytes('updates-home-focus-two') assert first!=second w,h=a.size # Above the row and below navigation, only the backdrop occupies this region. region=(int(w*.58),int(h*.10),int(w*.94),int(h*.16)) difference=sum(ImageStat.Stat(ImageChops.difference(a.crop(region),b.crop(region))).mean)/3 assert difference>3,f'Focused Home background did not change: {difference}' print('PASS Home backdrop follows focused title (mean pixel change %.1f)'%difference,flush=True) key(20);single_row=focus(snapshot()) launch();key(20);focused('Play');key(20);snapshot() for _ in range(6):adb('shell','input','keyevent','20');time.sleep(.08) held=focus(snapshot()) assert held!=single_row,f'Rapid Down kept restarting the same row: {held}' print('PASS rapid Down advances beyond one animated row',flush=True) launch();key(22,2);focused('TV Shows');key(20);focused('Discover');key(22);focused('Library');key(23) root=wait(lambda r:any('episodes remaining' in n.get('content-desc','') for n in r.iter('node')),'Show episode counts') screenshot('updates-show-counts');print('PASS show library exposes remaining episode badges',flush=True) # Leave the device in a useful Home state. key(4);key(4);focused('Home') (OUT/'browse-updates-results.json').write_text(json.dumps({'hero_categories':reasons,'backdrop_pixel_difference':difference},indent=2),encoding='utf-8')