Skip to main content

tests: add some extra test cases for browser fixtures

ID
96fd414
date
2026-10-29 22:16:41+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
0dbcaca
message
tests: add some extra test cases for browser fixtures

In particular, add tests that external media files (audio/video) are
rejected as not-self-contained.
changed files
3 files, 51 additions, 3 deletions

Changed files

tests/fixtures/media/A_Tale_of_Distant_Lands.mp3 (0 → 1974450)

diff --git a/tests/fixtures/media/A_Tale_of_Distant_Lands.mp3 b/tests/fixtures/media/A_Tale_of_Distant_Lands.mp3
new file mode 100644
index 0000000..3c46860
Binary files /dev/null and b/tests/fixtures/media/A_Tale_of_Distant_Lands.mp3 differ

tests/fixtures/media/_attribution.md (0 → 180)

diff --git a/tests/fixtures/media/_attribution.md b/tests/fixtures/media/_attribution.md
new file mode 100644
index 0000000..64e1afa
--- /dev/null
+++ b/tests/fixtures/media/_attribution.md
@@ -0,0 +1,3 @@
+# Media files
+
+*   `A_Tale_of_Distant_Lands.mp3` – download from [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:A_Tale_of_Distant_Lands.mp3), public domain license.

tests/python/test_browser_fixtures.py (19145 → 20777)

diff --git a/tests/python/test_browser_fixtures.py b/tests/python/test_browser_fixtures.py
index 57ff927..f4592c8 100644
--- a/tests/python/test_browser_fixtures.py
+++ b/tests/python/test_browser_fixtures.py
@@ -440,7 +440,7 @@ class TestVerifyLocalPageIntegrity:
             browser, p, match="Unexpected console warnings/errors"
         )
 
-    def test_loading_empty_audio(self, tmp_path: Path, browser: Browser) -> None:
+    def test_audio_empty(self, tmp_path: Path, browser: Browser) -> None:
         """
         An empty <audio> tag is not reported as a validation error.
         """
@@ -452,11 +452,37 @@ class TestVerifyLocalPageIntegrity:
 
         self.assert_page_verifies_ok(browser, p)
 
-    def test_video_over_http(
+    def test_audio_local(self, tmp_path: Path, browser: Browser) -> None:
+        """
+        An <audio> tag which loads a local MP3 file is valid.
+        """
+        shutil.copyfile(
+            "tests/fixtures/media/A_Tale_of_Distant_Lands.mp3",
+            tmp_path / "A_Tale_of_Distant_Lands.mp3",
+        )
+        p = tmp_path / "audio.html"
+        p.write_text('<audio src="A_Tale_of_Distant_Lands.mp3"></audio>')
+
+        self.assert_page_verifies_ok(browser, p)
+
+    def test_audio_external(self, tmp_path: Path, browser: Browser) -> None:
+        """
+        An <audio> tag which loads an external MP3 file is an error.
+        """
+        p = tmp_path / "audio.html"
+        p.write_text(
+            '<audio src="https://upload.wikimedia.org/wikipedia/commons/e/ec/A_Tale_of_Distant_Lands.mp3"></audio>'
+        )
+
+        self.assert_page_fails_verification(
+            browser, p, match="Page made requests for external resources"
+        )
+
+    def test_video_local_http(
         self, tmp_path: Path, static_server: str, browser: Browser
     ) -> None:
         """
-        Load a <video> over HTTP.
+        A <video> tag which loads a local file over HTTP is valid.
         """
         shutil.copyfile(
             "tests/fixtures/media/wings_tracking_shot.mp4",
@@ -473,6 +499,25 @@ class TestVerifyLocalPageIntegrity:
         page = browser.new_page()
         verify_local_page_integrity(page, url=static_server + "/video.html")
 
+    def test_video_external(
+        self, tmp_path: Path, static_server: str, browser: Browser
+    ) -> None:
+        """
+        A <video> tag which loads an external file is an error.
+        """
+        p = tmp_path / "video.html"
+        p.write_text(
+            """
+            <video controls height="300">
+              <source src="https://upload.wikimedia.org/wikipedia/commons/d/d8/Canada_Water_railway_station_platform%2C_East_London_Line_Southwark.webm">
+            </video>
+            """
+        )
+
+        self.assert_page_fails_verification(
+            browser, p, match="Page made requests for external resources"
+        )
+
     def test_loading_svg_from_file_uri(self, tmp_path: Path, browser: Browser) -> None:
         """
         Loading an external SVG from a file:/// URI is fine if the SVG exists,