Files
deepgrain-foundry/test/firefox_smoke.py
T

40 lines
1.6 KiB
Python

"""An isolated Firefox title screen and three seconds of a new pixel world."""
import json
from pathlib import Path
import sys
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'tools'))
from use_venv import ensure_playwright
ensure_playwright()
from browser import capabilities, consume_gpu_option, installed, launch
consume_gpu_option()
if not installed('firefox'):
print('SKIP firefox_smoke.py: Playwright Firefox is not installed')
sys.exit(0)
with launch(browser_name='firefox') as (_, page, url):
errors = []
page.on('pageerror', lambda e: errors.append(str(e)))
page.add_init_script("localStorage.setItem('deepgrain.settings', JSON.stringify({look:'pixel', sv:2}));")
page.goto(url)
caps = capabilities(page)
print('Firefox: ' + json.dumps(caps))
assert caps['isolated']
if not caps['webgpu']:
assert page.locator('#cap-notice').is_visible()
text = page.inner_text('#cap-notice')
assert 'about:config' in text and 'dom.webgpu.enabled' in text and 'Firefox Nightly' in text
print('PASS Firefox isolation and capability notice')
if not caps['webgpu']:
assert not page.evaluate('canStartGame()')
assert not page.evaluate('startNewWorld(424242,512,384)')
assert not page.evaluate('GAME.running')
print('PASS Firefox without WebGPU cannot start a world')
else:
page.evaluate('startNewWorld(424242,512,384)')
page.wait_for_function('GAME.running && !GAME.loading',timeout=60000)
before=page.evaluate('tick');page.wait_for_timeout(3000)
assert page.evaluate('tick')>before
assert not errors,errors