Browser widget tests started.

This commit is contained in:
Erik Moqvist
2026-07-04 17:02:36 +02:00
parent ccc90e6fed
commit 6a62f4a907
7 changed files with 134 additions and 0 deletions
+3
View File
@@ -105,3 +105,6 @@ test/*.dot
test/logs
test/files/
__pycache__
test/tests/websites/*.jpg
test/tests/websites/*.mp4
+2
View File
@@ -7,6 +7,7 @@ from tests import stream
from tests import scenes
from tests import ingests
from tests import record
from tests import browser_widget
from utils.config import Config
from utils.moblin import Moblin
from utils.dependencies import check_dependencies
@@ -32,6 +33,7 @@ def main():
record.tests(moblin),
scenes.tests(moblin),
stream.tests(moblin),
browser_widget.tests(moblin),
)
sequencer.report_and_exit()
+48
View File
@@ -0,0 +1,48 @@
import logging
from pathlib import Path
import subprocess
import time
from utils.ffmpeg import create_qr_codes_video
from utils.utils import WEBSITES_ROOT
from utils.web_server import WebServer
from utils.moblin import Moblin
from utils.test_case import TestCase
LOGGER = logging.getLogger(__name__)
class BrowserWidgetHighFpsVideo(TestCase):
"""Play a 30 FPS video for a few seconds. A QR code image should only be
visible when the video is playing. Each frame in the video has a unique QR
code.
"""
def run(self):
command = [
"qrtool",
"encode",
"--output",
str(WEBSITES_ROOT / "BrowserWidgetHighFpsVideo.jpg"),
"BrowserWidgetHighFpsVideo",
]
print(" ".join(command))
subprocess.run(command, check=True)
create_qr_codes_video(WEBSITES_ROOT / "BrowserWidgetHighFpsVideo.mp4")
with WebServer(WEBSITES_ROOT):
time.sleep(1)
class BrowserWidgetScriptDefer(TestCase):
"""Webpage with <script src="" defer> should show up."""
def run(self):
pass
def tests(moblin: Moblin):
return [
BrowserWidgetHighFpsVideo(moblin),
BrowserWidgetScriptDefer(moblin),
]
@@ -0,0 +1,14 @@
<html>
<script>
window.setTimeout(() => {
var player = document.getElementById('player');
player.play();
}, 5000)
</script>
<body>
<img src="BrowserWidgetHighFpsVideo.jpg" width="400"/>
<video id="player" width="400">
<source src="BrowserWidgetHighFpsVideo.mp4"/>
</video>
</body>
</html>
+33
View File
@@ -322,3 +322,36 @@ def remove_duplicated_frames(path: Path, crop: Crop | None = None) -> Path:
command += [", ".join(filters), "-an", str(filtered_path)]
_run(command)
return filtered_path
def create_qr_codes_video(output_file: Path):
command = [
"ffmpeg",
"-hide_banner",
"-nostdin",
"-y",
"-t",
"10",
"-f",
"lavfi",
"-i",
"nullsrc=size=400x400:rate=30",
"-c:v",
"libx264",
"-b:v",
"1M",
"-maxrate",
"1M",
"-preset",
"veryfast",
"-pix_fmt",
"yuv420p",
"-g",
"60",
"-keyint_min",
"60",
"-vf",
"qrencode=text=n %{frame_num} pts %{pts}:q=400:x=0",
str(output_file),
]
_run(command)
+4
View File
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from logging import Logger
import logging
from pathlib import Path
import threading
@@ -33,3 +34,6 @@ class Crop:
y: int
width: int
height: int
WEBSITES_ROOT = Path(__file__).parent.parent.resolve() / "tests" / "websites"
+30
View File
@@ -0,0 +1,30 @@
import logging
from pathlib import Path
import subprocess
from .utils import log_output
LOGGER = logging.getLogger(__name__)
class WebServer:
def __init__(self, static_root: Path):
self._server = None
self._static_root = static_root
def __enter__(self):
self._server = subprocess.Popen(
["python", "-m", "http.server", "6967"],
cwd=self._static_root,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
log_output(self._server.stdout, LOGGER)
log_output(self._server.stderr, LOGGER)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if self._server is not None:
self._server.kill()
self._server.wait()