128 lines
8.4 KiB
Python
128 lines
8.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Check the native navigation surface follows Gaia's active application."""
|
|
import importlib.util
|
|
import json
|
|
from pathlib import Path
|
|
import time
|
|
from marionette_client import Client
|
|
from project import ROOT
|
|
|
|
spec=importlib.util.spec_from_file_location('probe',Path(__file__).with_name('probe-desktop.py'))
|
|
probe=importlib.util.module_from_spec(spec);spec.loader.exec_module(probe)
|
|
with Client(2857) as c:
|
|
probe.register(c)
|
|
probe.evaluate(c,'system',"ScreenManager.turnScreenOn(true);if(Service.query('locked'))await Service.request('unlock',{forcibly:true});return true;")
|
|
hit_area=c.execute("const d=Services.wm.getMostRecentWindow('vulpes:host').document,b=d.getElementById('home'),r=b.getBoundingClientRect(),y=r.y+r.height/2;return [d.elementFromPoint(r.x+r.width/2,y)===b,d.elementFromPoint(2,y)===b,r.width];")
|
|
assert hit_area == [True,False,44],hit_area
|
|
def state():
|
|
return c.execute("const w=Services.wm.getMostRecentWindow('vulpes:host'),d=w.document,b=d.getElementById('home-bar');return {app:d.documentElement.dataset.navApp,home:d.documentElement.hasAttribute('home-active'),bottom:d.documentElement.hasAttribute('home-at-bottom'),height:w.innerHeight,screen:d.getElementById('screen').clientHeight,bar:b.clientHeight,background:w.getComputedStyle(b).backgroundImage,color:w.getComputedStyle(b).backgroundColor,ring:w.getComputedStyle(d.getElementById('home'),'::before').color};")
|
|
def wait(home, app=None):
|
|
for _ in range(100):
|
|
s=state()
|
|
if s['home']==home and (app is None or s['app']==app) and s['screen']==s['height']-(0 if home else s['bar']):return s
|
|
time.sleep(.15)
|
|
raise AssertionError(s)
|
|
c.execute("Services.wm.getMostRecentWindow('vulpes:host').document.getElementById('home').click();")
|
|
wait(True)
|
|
probe.evaluate(c,'homescreen',"document.querySelector('#apps-panel > .scrollable').scrollTop=0;return true;")
|
|
for _ in range(50):
|
|
if not state()['bottom']:break
|
|
time.sleep(.05)
|
|
home=wait(True);assert 'linear-gradient' in home['background'],home
|
|
c.execute("const b=Services.wm.getMostRecentWindow('vulpes:host').document.getElementById('home');InspectorUtils.addPseudoClassLock(b,':active');")
|
|
pressed=state();assert pressed['background']==home['background'] and pressed['color']==home['color'],pressed
|
|
c.execute("InspectorUtils.removePseudoClassLock(Services.wm.getMostRecentWindow('vulpes:host').document.getElementById('home'),':active');")
|
|
probe.evaluate(c,'homescreen',"const p=document.querySelector('#apps-panel > .scrollable');p.scrollTop=p.scrollHeight;return true;")
|
|
for _ in range(100):
|
|
bottom=state()
|
|
if bottom['bottom']:break
|
|
time.sleep(.1)
|
|
assert bottom['background']=='none' and bottom['color']=='rgba(0, 0, 0, 0)',bottom
|
|
for open_overlay,close_overlay in [
|
|
("dispatchEvent(new CustomEvent('holdsleep'))", "document.querySelector('#sleep-menu button').click()"),
|
|
("UtilityTray.show(true)", "UtilityTray.hide(true)"),
|
|
]:
|
|
probe.evaluate(c,'system',open_overlay+';return true;')
|
|
if open_overlay.startswith('UtilityTray'):
|
|
for _ in range(50):
|
|
if c.execute("return Services.wm.getMostRecentWindow('vulpes:host').document.documentElement.hasAttribute('tray-over-home');"):break
|
|
time.sleep(.05)
|
|
tray=state()
|
|
assert tray['home'] and tray['screen']==home['screen'] and tray['bar']==0,tray
|
|
else:
|
|
power = wait(False)
|
|
footer = probe.evaluate(c,'system',"const b=document.querySelector('#sleep-menu button'),r=b.getBoundingClientRect();return [getComputedStyle(b.closest('gaia-buttons')).backgroundColor,r.bottom,document.elementFromPoint(r.x+r.width/2,r.y+r.height/2)===b];")['value']
|
|
assert power['color']==footer[0] and power['ring']=='rgb(255, 255, 255)',power
|
|
assert footer[1]<=power['screen'] and footer[2],footer
|
|
probe.evaluate(c,'system',close_overlay+';return true;')
|
|
wait(True)
|
|
if open_overlay.startswith('UtilityTray'):
|
|
for _ in range(50):
|
|
restored=state()
|
|
if restored['bar']:break
|
|
time.sleep(.05)
|
|
assert restored['bar']==home['bar'] and restored['screen']==home['screen'],restored
|
|
result=probe.evaluate(c,'system','await VulpesCompat.call("apps.launch",{manifestURL:"http://settings.localhost:8765/manifest.webapp"});return true;')
|
|
assert result.get('value'),result
|
|
app=wait(False,'settings');assert app['background']=='none' and app['color']=='rgba(0, 0, 0, 0)',app
|
|
assert app['ring']=='rgb(101, 112, 115)',app
|
|
x,y=c.execute("const r=Services.wm.getMostRecentWindow('vulpes:host').document.getElementById('home').getBoundingClientRect();return [Math.floor(r.x+r.width/2),Math.floor(r.y+r.height/2)];")
|
|
c.call("WebDriver:PerformActions",{"actions":[{"type":"pointer","id":"home-mouse",
|
|
"parameters":{"pointerType":"mouse"},"actions":[{"type":"pointerMove","x":x,"y":y},
|
|
{"type":"pointerDown","button":0},{"type":"pause","duration":950},{"type":"pointerUp","button":0}]}]})
|
|
for _ in range(100):
|
|
if c.execute("return Services.wm.getMostRecentWindow('vulpes:host').document.documentElement.hasAttribute('recents');"):
|
|
break
|
|
time.sleep(.1)
|
|
else:
|
|
raise AssertionError('Recent apps did not open')
|
|
recent=state()
|
|
assert recent['screen']==recent['height'] and recent['background']=='none' and recent['color']=='rgba(0, 0, 0, 0)',recent
|
|
denied=probe.evaluate(c,'settings','try {await VulpesCompat.call("desktop.navigation",{home:true});return false;} catch(e) {return true;}')
|
|
assert denied.get('value'),denied
|
|
deniedScroll=probe.evaluate(c,'settings','try {await VulpesCompat.call("desktop.homeScroll",{bottom:true});return false;} catch(e) {return true;}')
|
|
assert deniedScroll.get('value'),deniedScroll
|
|
frames = c.call("WebDriver:ExecuteAsyncScript", {"script": """
|
|
const done=arguments[arguments.length-1],w=Services.wm.getMostRecentWindow('vulpes:host');
|
|
const d=w.document,root=d.documentElement,bar=d.getElementById('home-bar'),screen=d.getElementById('screen');
|
|
let frames=0,settled=0;
|
|
function paint(){
|
|
const style=w.getComputedStyle(bar);
|
|
if(screen.clientHeight!==w.innerHeight || style.backgroundColor!=='rgba(0, 0, 0, 0)')
|
|
return done({error:'Exposed navigation strip',height:screen.clientHeight,background:style.backgroundColor});
|
|
if(root.hasAttribute('home-active') && !root.hasAttribute('recents')) settled++;
|
|
if(++frames>400 || settled>=3) return done({frames,settled});
|
|
w.requestAnimationFrame(paint);
|
|
}
|
|
w.requestAnimationFrame(paint);
|
|
d.getElementById('home').click();
|
|
""","args":[],"sandbox":"system","newSandbox":True,"scriptTimeout":12000})['value']
|
|
assert frames.get('settled',0)>=3,frames
|
|
wait(True)
|
|
probe.evaluate(c,'homescreen',"document.querySelector('#apps-panel > .scrollable').scrollTop=0;return true;")
|
|
for _ in range(100):
|
|
top=state()
|
|
if not top['bottom']:break
|
|
time.sleep(.1)
|
|
assert 'linear-gradient' in top['background'],top
|
|
iconRecovery=probe.evaluate(c,'homescreen', '''
|
|
const source=document.querySelectorAll('gaia-app-icon')[1],box=document.createElement('div');
|
|
box.style.cssText='display:none;position:fixed;top:0;left:0;width:100px';
|
|
document.body.append(box);
|
|
const icon=document.createElement('gaia-app-icon');icon.style.width='100px';box.append(icon);icon.size=icon.clientWidth;icon.app=source.app;
|
|
try {
|
|
await new Promise(r=>requestAnimationFrame(()=>requestAnimationFrame(r)));
|
|
const initial=icon.size;
|
|
box.style.display='block';
|
|
for(let i=0;i<100;i++){
|
|
const image=icon.shadowRoot?.querySelector('img');
|
|
if(image?.complete && image.naturalWidth>0)return {initial,width:icon.size,naturalWidth:image.naturalWidth};
|
|
await new Promise(r=>setTimeout(r,50));
|
|
}
|
|
return {initial,width:icon.size,failed:true};
|
|
} finally {box.remove();}
|
|
''')
|
|
assert iconRecovery.get('value',{}).get('initial')==0 and iconRecovery['value'].get('naturalWidth',0)>0,iconRecovery
|
|
report={'passed':True,'home':home,'pressed':pressed,'bottom':bottom,'application':app,'recents':recent,'returnFrames':frames,'returnHome':top,'nonSystemCallerDenied':True,'nonHomeScrollCallerDenied':True,'zeroWidthIconRecovery':iconRecovery['value']}
|
|
(ROOT/'logs/home-surface-test.json').write_text(json.dumps(report,indent=2)+'\n')
|
|
print(json.dumps(report,indent=2))
|