tests: a screenshot draws the text of the bundled fonts as the content drew it (from firefox-66)

page.screenshot rebuilds the text in the parent; on Linux the parent recreates the font from its path through fontconfig, which does not know the folder of the bundle, and the run is drawn with the glyph numbers of the bundle and the outlines of DejaVu Sans. The new e2e puts, for each of Arial, Times New Roman, Consolas and Segoe UI, the same block of text as HTML and as a canvas onto which an SVG image with a foreignObject of the same markup was drawn, takes one page.screenshot, cuts the two boxes out and asks for the same bytes: no threshold, no stored image. It runs on both systems and says which family differs.

It saves the screenshot, the two boxes and a result.json under RUNNER_TEMP/invpw-evidence (green or red, only on a runner), and e2e.yml uploads that folder. The test is a row of wrapper.e2e.compositing (3 -> 7) and the first row of ci/regressions.json; the crop, the PNG writer and the pixel comparison are helpers of _page_bytes.py with unit tests (wrapper.unit.compositing 19 -> 30, the two whole-suite rows +11).
This commit is contained in:
feder-cr committed 2026-11-17 14:30:10 +01:00
1 parent 39b303923a
commit 7a572baf95
6 files changed
+356 -8

No files matched your search

+20
View File
@@ -288,6 +288,18 @@ jobs:
if-no-files-found: warn
retention-days: 14
# What the tests that measure save for a reader (the boxes of tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py:
# the two PNG files, the screenshot and a result.json per case), under RUNNER_TEMP/invpw-evidence, whether the run is green or red. Nothing there
# when no such test ran (an engine older than firefox-66 skips it), which is not a warning.
- name: Upload what the tests saved
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: invpw-evidence-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/invpw-evidence
if-no-files-found: ignore
retention-days: 14
# ``Control+A`` selects all in a field, on the PUBLISHED engine and the core this package pins, on Windows, where the keyboard of a real
# user is: the shortcut letter used to reach the browser as Control+Shift+A (invisible-core 63.66.0 fixes it). The e2e is red on the
# keyboard that held Shift for the capital A (tests/test_control_a_selects_all_in_a_field_e2e.py: 5 ways to press it x an <input> and a
@@ -403,3 +415,11 @@ jobs:
path: ${{ runner.temp }}/e2e-junit-*.xml
if-no-files-found: warn
retention-days: 14
- name: Upload what the tests saved
if: always()
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: invpw-evidence-windows-${{ matrix.part }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/invpw-evidence
if-no-files-found: ignore
retention-days: 14
+3
View File
@@ -0,0 +1,3 @@
[
{"id": "screenshot-bundled-font-outlines", "error": "page.screenshot draws the text of the bundled fonts with the outlines of DejaVu Sans on Linux: the parent rebuilds the font from its path through fontconfig, which does not know the folder of the bundle, and keeps the glyph numbers of the bundle with the outlines of another font", "test": "tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py", "engine": "firefox-66", "fix": "engine firefox-66 (the commit of the series is added here when it lands)"}
]
+4 -4
View File
@@ -10,8 +10,8 @@
{"id": "wrapper.unit.udp", "giro": "G1", "os": ["linux", "windows"], "min_tests": 259, "exact": true, "tests": ["tests/test_the_server_says_nothing_about_the_launch_counter.py", "tests/test_the_witness_picks_a_port_both_sockets_bind.py", "tests/test_preload_newtab_reaches_the_core_only_when_asked.py", "tests/test_the_resolver_trap_counts_its_own_users.py", "tests/test_the_doh_e2e_launch_on_a_virtual_display.py", "tests/test_the_realness_helpers.py", "tests/test_the_h3_line_helpers.py", "tests/test_the_fake_doh_delays_and_refuses.py", "tests/test_the_host_address_helper.py", "tests/test_the_udp_chain_helper.py", "tests/test_the_fake_doh_answers.py", "tests/test_doh_session_prefs_unit.py", "tests/test_the_leak_watcher_sees_a_direct_connection.py", "tests/test_the_http_proxy_helper_asks_for_credentials.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_the_network_declaration_reaches_the_engine.py", "tests/test_the_resolver_trap_is_required_by_the_gate.py", "tests/test_the_exit_of_a_context_is_discovered_through_its_own_gateway.py", "tests/test_the_witness_hears_a_direct_send.py", "tests/test_the_egress_sink_helpers.py", "tests/test_the_lab_ca_and_its_ocsp_leaf.py", "tests/test_the_udp_bench_survives_what_a_loaded_machine_does_to_it.py"], "marker": "unit", "needs_root": false, "note": "92 = 6+32+21+7+8+3+9+6. The leak watcher file defines exactly one of its two resolver-trap tests per host (7 everywhere), so no test is skipped. `exact`: min_tests is raised by hand when a test is added. The sink of the egress gate (tests/test_the_egress_sink_helpers.py, 20): the engine's log (the same on Linux and Windows) and the witness read on known inputs, and a blind log that must raise, never answer 'nothing'. The lab CA of its OCSP case (tests/test_the_lab_ca_and_its_ocsp_leaf.py, 17; tests/test_the_fake_doh_answers.py +1, the DoH serving a lab-CA leaf): the leaf's AIA, trusted and untrusted issuers, the responder, the xpcshell step."},
{"id": "wrapper.e2e.page", "giro": "G2", "os": ["linux", "windows"], "min_tests": 124, "exact": true, "tests": ["tests/test_a_tiny_download_on_a_served_browser_is_saved_e2e.py", "tests/test_a_page_that_moves_on_e2e.py", "tests/test_a_popup_is_reported_when_the_engine_says_it_is_ready_as_playwright_does_e2e.py", "tests/test_a_popup_of_a_link_reaches_the_client_e2e.py", "tests/test_popup_destinations_e2e.py", "tests/test_popups_reach_the_client_e2e.py", "tests/test_route_superseded_e2e.py", "tests/test_closing_one_of_four_browsers_does_not_hold_the_loop_e2e.py"], "marker": "e2e", "needs_root": false, "note": "114 + the 9 of test_closing_one_of_four_browsers_does_not_hold_the_loop_e2e.py (four browsers in one process, one closes: the loop is never seen inside a step of the close, the removal of the profile is held still and reached on a thread of the reaper while the close has returned, the other three keep answering; one control holds the loop on purpose, the other leaves it late in its selector and must not be charged). 114 = 100 + the 14 of test_a_page_that_moves_on_e2e.py (a navigation the page overtook with location.replace ends; the engine fix 860ef8a6d9 is proved by it). 100 counted at the collection; was 96 = 10+32+16+34+4 before the popup tests of 6200bc2). A page is handed over when the engine says Page.ready; a popup reaches the client (link, noopener, window.open; own site and another; with and without a route; in-process and over launch_server) as Playwright's does; a superseded route. Needs the candidate binary, and the stock Playwright client of the dev extra."},
{"id": "wrapper.unit.page", "giro": "G1", "os": ["linux", "windows"], "min_tests": 72, "exact": true, "tests": ["tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_page_number_follows_the_call.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_the_hand_over_of_a_popup_holds_under_concurrency.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py"], "marker": "unit", "needs_root": false, "note": "72 = 44 + 3+9+5+1+10 of the popup hand-over (24 counted at the collection before; was 20 = 3+8+1+8 before 6200bc2). The page dispatcher's wait for Page.ready and what it hands over; the drive gate goes through the core (the engine waits for the session's road)."},
{"id": "wrapper.e2e.compositing", "giro": "G2", "os": ["linux", "windows"], "min_tests": 3, "exact": true, "tests": ["tests/test_software_compositing_is_declared_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The engine DECLARES software compositing on every machine (core: the compositing entries of zoom.stealth.gfx.feature_status carry the VM decision, and on Windows gfx.webrender.software=true, gfx.webrender.software.d3d11=false). 3 = (1) the compositor read from a privileged context is 'WebRender (Software)' on Windows and on Linux (windowUtils.layerManagerType of each window: Troubleshoot.snapshot().graphics throws on this engine, `ext is null`, so it is not the route); (2) the GPU process uses under 1.5 s of CPU on the fixed 10-scene loop of one browser (Windows runner: 0.32 s declared, 2.7-4.2 s not, runs 43652292533 and 43642744101; on Linux it is held to the bound if a GPU process exists); (3) the 86 keys of the page-bytes probe plus the canvas 2D scenes (drawImage scaled with smoothing off/low/medium/high, text with linear/radial/conic gradients) equal tests/data/page_bytes_<os>.json, PNGs on decoded pixels. EXPECTED RED on the core 64.71.0 (tests 1 and 2 on Windows). The reference of Windows holds the 75 stable keys and 6 of the 11 PNG keys of run 43652292533; the five other PNG keys and the new canvas keys, and all of Linux, are written from the first run on the engine of the reference (the failure of test 3 prints RECORD-BEGIN ... RECORD-END with the entries to merge): a reference that is not complete is red, never skipped."},
{"id": "wrapper.unit.compositing", "giro": "G1", "os": ["linux", "windows"], "min_tests": 19, "exact": true, "tests": ["tests/test_the_page_bytes_reference_compares_decoded_pixels.py"], "marker": "unit", "needs_root": false, "note": "The helpers of wrapper.e2e.compositing on known inputs, no browser: the PNG compared on decoded pixels (another deBG chunk and compression are the same, one pixel is not, every scanline filter), the comparison with a reference (changed, missing and extra keys named, the entry to record), the type of an engine process, an engine process known by its executable and not by the name it gives itself (Linux), and the CPU of a window, and the shape of the committed Windows reference."},
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 2059, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_backcompat.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_css_calc_is_windows_e2e.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.py", "tests/test_preload_newtab_reaches_the_core_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proxy_reaches_the_browser.py", "tests/test_publish_gate_wiring.py", "tests/test_pyproject_names_real_paths.py", "tests/test_Line truncated
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2060, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_backcompat.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_css_calc_is_windows_e2e.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.py", "tests/test_prefs_composition_arm_on_windows.py", "tests/test_preload_newtab_reaches_the_core_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proxy_reaches_the_browser.py", "tests/test_publish_gate_wiring.py", "tests/test_pyproject_names_real_pathsLine truncated
{"id": "wrapper.e2e.compositing", "giro": "G2", "os": ["linux", "windows"], "min_tests": 7, "exact": true, "tests": ["tests/test_software_compositing_is_declared_e2e.py", "tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py"], "marker": "e2e", "needs_root": false, "note": "The engine DECLARES software compositing on every machine (core: the compositing entries of zoom.stealth.gfx.feature_status carry the VM decision, and on Windows gfx.webrender.software=true, gfx.webrender.software.d3d11=false). 3 = (1) the compositor read from a privileged context is 'WebRender (Software)' on Windows and on Linux (windowUtils.layerManagerType of each window: Troubleshoot.snapshot().graphics throws on this engine, `ext is null`, so it is not the route); (2) the GPU process uses under 1.5 s of CPU on the fixed 10-scene loop of one browser (Windows runner: 0.32 s declared, 2.7-4.2 s not, runs 43652292533 and 43642744101; on Linux it is held to the bound if a GPU process exists); (3) the 86 keys of the page-bytes probe plus the canvas 2D scenes (drawImage scaled with smoothing off/low/medium/high, text with linear/radial/conic gradients) equal tests/data/page_bytes_<os>.json, PNGs on decoded pixels. EXPECTED RED on the core 64.71.0 (tests 1 and 2 on Windows). The reference of Windows holds the 75 stable keys and 6 of the 11 PNG keys of run 43652292533; the five other PNG keys and the new canvas keys, and all of Linux, are written from the first run on the engine of the reference (the failure of test 3 prints RECORD-BEGIN ... RECORD-END with the entries to merge): a reference that is not complete is red, never skipped. 7 = those 3 + the 4 families of tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py (from firefox-66, engine_at_least): a screenshot draws the text of Arial, Times New Roman, Consolas and Segoe UI, with accents, the typographic apostrophe, the euro sign, Chinese, Arabic and Russian, with the same bytes as the content process drew them in a canvas (an SVG image with a foreignObject of the same markup), cut from the same page.screenshot, on both systems and with no threshold. EXPECTED RED on every engine that rebuilds the text in the parent with another font than the bundle (Linux: fontconfig answers DejaVu Sans), and skipped, hence red here, on an engine older than firefox-66. It saves the screenshot, the two boxes and a result.json under RUNNER_TEMP/invpw-evidence."},
{"id": "wrapper.unit.compositing", "giro": "G1", "os": ["linux", "windows"], "min_tests": 30, "exact": true, "tests": ["tests/test_the_page_bytes_reference_compares_decoded_pixels.py"], "marker": "unit", "needs_root": false, "note": "The helpers of wrapper.e2e.compositing on known inputs, no browser: the PNG compared on decoded pixels (another deBG chunk and compression are the same, one pixel is not, every scanline filter), the comparison with a reference (changed, missing and extra keys named, the entry to record), the type of an engine process, an engine process known by its executable and not by the name it gives itself (Linux), and the CPU of a window, and the shape of the committed Windows reference, and the box cut out of a screenshot (its pixels, a box outside the picture refused, written as a PNG and read back, two boxes told apart by a pixel that is named, the pixels that are not grey)."},
{"id": "wrapper.unit.all.linux", "giro": "G1", "os": ["linux"], "min_tests": 2070, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_backcompat.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_css_calc_is_windows_e2e.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_posix_pipe.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.py", "tests/test_preload_newtab_reaches_the_core_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proxy_reaches_the_browser.py", "tests/test_publish_gate_wiring.py", "tests/test_pyproject_names_real_paths.py", "tests/test_Line truncated
{"id": "wrapper.unit.all.windows", "giro": "G1", "os": ["windows"], "min_tests": 2071, "exact": true, "tests": ["tests/test_a_162_message_is_read_like_a_161_one.py", "tests/test_a_click_makes_one_mousemove_at_its_point.py", "tests/test_a_closed_context_leaves_nothing_in_the_registry.py", "tests/test_a_closed_page_says_nothing.py", "tests/test_a_closed_pipe_is_a_closed_target.py", "tests/test_a_commit_at_any_point_of_the_hand_over_reaches_the_client_once.py", "tests/test_a_context_proxy_carries_its_measured_udp_exit.py", "tests/test_a_context_route_disables_the_cache.py", "tests/test_a_detached_frame_answers_detached.py", "tests/test_a_dialog_is_a_protocol_object.py", "tests/test_a_dialog_is_answered_after_a_pause.py", "tests/test_a_download_finished_before_it_was_announced_is_finished.py", "tests/test_a_failed_expect_carries_its_call_log.py", "tests/test_a_failed_launch_stops_the_display.py", "tests/test_a_field_is_typed_after_a_pause.py", "tests/test_a_launch_asks_nobody_on_the_internet_where_it_leaves_from.py", "tests/test_a_launch_has_one_deadline.py", "tests/test_a_launch_without_a_session_gets_one.py", "tests/test_a_live_event_does_not_overtake_the_replay_of_a_new_page.py", "tests/test_a_module_that_leaves_a_browser_open_fails.py", "tests/test_a_new_page_waits_for_the_engine.py", "tests/test_a_non_finite_number_crosses_the_wire_as_a_tag.py", "tests/test_a_page_closed_before_its_announcement_is_not_announced.py", "tests/test_a_page_is_handed_over_only_when_the_engine_says_it_is_ready.py", "tests/test_a_path_leaves_as_one_stroke.py", "tests/test_a_port_number_is_held_until_it_is_used.py", "tests/test_a_request_and_a_response_are_light.py", "tests/test_a_request_says_what_it_is.py", "tests/test_a_session_ends_before_the_next_test_starts.py", "tests/test_a_stroke_is_judged_by_its_shape_not_its_length.py", "tests/test_a_unit_test_does_not_read_the_seal_of_the_job.py", "tests/test_actions_without_a_point.py", "tests/test_add_script_tag.py", "tests/test_an_expect_reads_its_value_once.py", "tests/test_async_api.py", "tests/test_backcompat.py", "tests/test_browser_output_is_drained.py", "tests/test_ci_downloads_are_authenticated.py", "tests/test_ci_drive_gate_goes_through_the_core.py", "tests/test_ci_host_gate.py", "tests/test_ci_lab_geoip.py", "tests/test_ci_lab_geoip_verify.py", "tests/test_ci_real_geoip_check.py", "tests/test_ci_real_geoip_exit_code.py", "tests/test_ci_runs_once_per_commit.py", "tests/test_ci_verdict.py", "tests/test_ci_workflows_build_the_geoip_database.py", "tests/test_cli.py", "tests/test_click_rhythm.py", "tests/test_connect_does_not_start_threads_on_the_loop.py", "tests/test_context_locale_is_a_list.py", "tests/test_core_pin.py", "tests/test_cpu_by_type_window.py", "tests/test_cross_origin_iframe.py", "tests/test_css_calc_is_windows_e2e.py", "tests/test_cursor_dispatch.py", "tests/test_cursor_wiring.py", "tests/test_docs_name_the_mcp_repo_as_it_is.py", "tests/test_doh_session_prefs_unit.py", "tests/test_drag_motion.py", "tests/test_e2e_hermetic.py", "tests/test_element_handle_actions.py", "tests/test_every_order_of_the_events_of_a_popup_gives_one_page_event.py", "tests/test_every_page_draws_its_own_acts.py", "tests/test_every_refusal_is_declared.py", "tests/test_every_route_command_is_answered_may_fail.py", "tests/test_every_suite_runs_on_linux_and_windows.py", "tests/test_expose_binding_refusal.py", "tests/test_fission_identity_parity_e2e.py", "tests/test_fixtures_name_why_the_package_is_missing.py", "tests/test_fork.py", "tests/test_frame_dispatch.py", "tests/test_geoip_used.py", "tests/test_goto_follows_the_base_url.py", "tests/test_hook_wiring.py", "tests/test_imports.py", "tests/test_integration.py", "tests/test_juggler_event_buffer.py", "tests/test_juggler_event_listeners.py", "tests/test_juggler_injected.py", "tests/test_juggler_lives_in_the_core.py", "tests/test_juggler_transport.py", "tests/test_key_delay_reaches_the_keyboard.py", "tests/test_keyboard_rhythm.py", "tests/test_launch_counters_run_on_github.py", "tests/test_launcher_config.py", "tests/test_launcher_helpers.py", "tests/test_math_sin_cos_tan_are_windows_e2e.py", "tests/test_motion_never_hides_a_programming_error.py", "tests/test_navigation_response.py", "tests/test_new_page_defaults.py", "tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py", "tests/test_no_override_leaves_the_persona_scheme.py", "tests/test_no_thread_is_started_on_the_reader.py", "tests/test_page_number_follows_the_call.py", "tests/test_persistent_profile_keeps_state.py", "tests/test_pin.py", "tests/test_pin_dicts_are_valid.py", "tests/test_pinning_doc.py", "tests/test_pointer_server.py", "tests/test_popup_adoption_unit.py", "tests/test_prefs_composition_arm.py", "tests/test_prefs_composition_arm_on_windows.py", "tests/test_preload_newtab_reaches_the_core_only_when_asked.py", "tests/test_protocol_names_are_declared.py", "tests/test_proxy_reaches_the_browser.py", "tests/test_publish_gate_wiring.py", "tests/test_pyproject_names_real_pathsLine truncated
]
+61 -4
View File
@@ -60,9 +60,9 @@ def _paeth(a: int, b: int, c: int) -> int:
return a if pa <= pb and pa <= pc else (b if pb <= pc else c)
def decode_png(png: bytes) -> Dict[str, Any]:
"""{w, h, ct, sha256} of a non-interlaced 8-bit PNG (grey, RGB, grey+alpha, RGBA): the sha256 is over the unfiltered
scanlines, so two files with the same pixels and different ancillary chunks or compression give the same answer."""
def unfiltered(png: bytes) -> Dict[str, Any]:
"""{w, h, ct, channels, data} of a non-interlaced 8-bit PNG (grey, RGB, grey+alpha, RGBA): `data` is the scanlines with their filters
undone, `w * channels` bytes a row and `h` rows."""
chunks = png_chunks(png)
head = [d for t, d in chunks if t == b"IHDR"]
if not head:
@@ -102,7 +102,64 @@ def decode_png(png: bytes) -> Dict[str, Any]:
raise NotAPng("filter type %d" % ftype)
out += line
prev = line
return {"w": w, "h": h, "ct": ct, "sha256": hashlib.sha256(bytes(out)).hexdigest()}
return {"w": w, "h": h, "ct": ct, "channels": channels, "data": bytes(out)}
def decode_png(png: bytes) -> Dict[str, Any]:
"""{w, h, ct, sha256} of a non-interlaced 8-bit PNG (grey, RGB, grey+alpha, RGBA): the sha256 is over the unfiltered
scanlines, so two files with the same pixels and different ancillary chunks or compression give the same answer."""
u = unfiltered(png)
return {"w": u["w"], "h": u["h"], "ct": u["ct"], "sha256": hashlib.sha256(u["data"]).hexdigest()}
def crop(image: Dict[str, Any], x: int, y: int, w: int, h: int) -> Dict[str, Any]:
"""The box (x, y, w, h) of an `unfiltered` image, as an image of its own (same colour type). A box that is not inside it is an error:
a crop that silently ends at the edge would compare less than it was asked to."""
if w <= 0 or h <= 0 or x < 0 or y < 0 or x + w > image["w"] or y + h > image["h"]:
raise ValueError("the box %r is not inside the %dx%d image" % ((x, y, w, h), image["w"], image["h"]))
ch, stride = image["channels"], image["w"] * image["channels"]
rows = [image["data"][(y + r) * stride + x * ch:(y + r) * stride + (x + w) * ch] for r in range(h)]
return {"w": w, "h": h, "ct": image["ct"], "channels": ch, "data": b"".join(rows)}
def encode_png(image: Dict[str, Any]) -> bytes:
"""The PNG file of an `unfiltered`-shaped image (no filter, one IDAT): what a crop is kept as."""
w, h, ch = image["w"], image["h"], image["channels"]
stride = w * ch
raw = b"".join(b"\x00" + image["data"][r * stride:(r + 1) * stride] for r in range(h))
def chunk(tag: bytes, data: bytes) -> bytes:
return struct.pack(">I", len(data)) + tag + data + struct.pack(">I", zlib.crc32(tag + data) & 0xFFFFFFFF)
return (PNG_SIGNATURE + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, image["ct"], 0, 0, 0))
+ chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b""))
def pixels_differ(a: Dict[str, Any], b: Dict[str, Any]) -> Dict[str, Any]:
"""How two images of the same size and colour type differ: {pixels, first: [x, y] | None, box: [x0, y0, x1, y1] | None}; a pixel
differs when any of its channels does. Different sizes or colour types are an error, not a difference."""
if (a["w"], a["h"], a["ct"]) != (b["w"], b["h"], b["ct"]):
raise ValueError("%dx%d (colour type %d) against %dx%d (colour type %d)" % (a["w"], a["h"], a["ct"], b["w"], b["h"], b["ct"]))
ch, w = a["channels"], a["w"]
count, first, x0, y0, x1, y1 = 0, None, w, a["h"], -1, -1
da, db = a["data"], b["data"]
for i in range(0, len(da), ch):
if da[i:i + ch] != db[i:i + ch]:
x, y = (i // ch) % w, (i // ch) // w
count += 1
first = first or [x, y]
x0, y0, x1, y1 = min(x0, x), min(y0, y), max(x1, x), max(y1, y)
return {"pixels": count, "first": first, "box": [x0, y0, x1, y1] if count else None}
def coloured_pixels(image: Dict[str, Any]) -> int:
"""How many pixels of an RGB or RGBA image have a red, green and blue that are not equal: black text on white that is drawn with grey
antialiasing has none, and one drawn with subpixel (LCD) antialiasing has them at its edges."""
ch = image["channels"]
if ch < 3:
return 0
d = image["data"]
return sum(1 for i in range(0, len(d), ch) if not d[i] == d[i + 1] == d[i + 2])
def png_bytes_of(value: Dict[str, Any]) -> Optional[bytes]:
@@ -0,0 +1,221 @@
"""A screenshot draws the text of the bundled fonts with the outlines of those fonts (e2e, every OS, from firefox-66).
`page.screenshot` is not taken from the screen: the parent process replays what the content process recorded, and a text run in that
recording carries its font as a path, which the parent must turn into a font again. On Linux the parent asked fontconfig for it, and
fontconfig does not know the folder of the bundle: it answered another font (DejaVu Sans), and the run was drawn with the glyph NUMBERS
of the bundled font and the OUTLINES of that one. Latin text came out in the shape of DejaVu (Times New Roman without serifs); accents,
the typographic apostrophe, the euro sign, Chinese, Arabic and Russian came out as other glyphs. The screen, the canvas 2D and
`measureText` were right: the defect is only in what the parent rebuilds. Retail Firefox on Windows has no such step to get wrong in
this way, so whether Windows has the defect is what this test answers there, with the same page and the same assertion.
The reference is not a stored image and not a threshold. One page holds, for a family of the bundle, the same block of text twice:
* as HTML (``#dom``), which the screenshot rebuilds in the parent;
* as a ``<canvas>`` (``#cv``) onto which the content process drew an SVG image with a ``foreignObject`` holding the same markup
(the same string, the same styles), after the image had loaded: the pixels of that box are made in the content process and the
parent only copies them.
Both are in the SAME ``page.screenshot``, at integer positions of a device pixel ratio of 1, and the test cuts the two boxes out of the
PNG and asks that they are the same bytes. A parent that rebuilds the text with another font cannot give the bytes of one that does not.
The blocks are black on white, drawn with greyscale antialiasing (the persona's text quality is pinned to antialiased, not ClearType,
which an SVG image does not draw), so a difference is a difference of outline and not of the colour of an edge.
One case for each family, so the failure says which one: Arial, Times New Roman, Consolas and Segoe UI, the four faces of the bundle that
the persona answers to on every Windows. Each block holds accents (é è à ü), the typographic apostrophe, the euro sign and the
quotation marks, Chinese, Arabic and Russian.
Evidence, whether the case passes or fails: when ``RUNNER_TEMP`` is set (a GitHub runner) the case writes the screenshot, the two boxes
as PNG files and a ``result.json`` (family, operating system, engine, sizes, sha256 of each box, how many pixels differ and where, and how
many pixels of each box are not grey) under ``$RUNNER_TEMP/invpw-evidence/screenshot-bundle-fonts/<family>/``, which the e2e jobs upload.
Outside a runner it writes nothing.
Run: pytest tests/test_a_screenshot_draws_the_text_of_the_bundled_fonts_as_the_content_does_e2e.py -m e2e -v
"""
from __future__ import annotations
import hashlib
import json
import os
import re
import sys
from pathlib import Path
import pytest
import _page_bytes as pb
pytestmark = pytest.mark.e2e
OS_NAME = "windows" if sys.platform == "win32" else "linux"
#: The families the persona declares and the bundle holds (the `f|` rows of the manifest in invisible_core: Arial, Times New Roman,
#: Consolas and Segoe UI each have their files).
FAMILIES = ["Arial", "Times New Roman", "Consolas", "Segoe UI"]
#: The device pixel ratio is 1 and the text is greyscale: see the docstring. 4 is ANTIALIASED_QUALITY (5 is ClearType).
PIN = {"screen.dpr": 1.0, "font.system_text_quality": 4}
#: Where the evidence goes under $RUNNER_TEMP; the workflows upload this folder by this name.
EVIDENCE_FOLDER = "invpw-evidence"
BLOCK_W, BLOCK_H = 480, 214
VIEWPORT = {"width": 520, "height": 480}
PAGE = """<!doctype html><meta charset="utf-8">
<style>
html, body { margin: 0; padding: 0; background: #fff; }
#dom, #cv { position: absolute; left: 10px; display: block; }
#dom { top: 10px; width: %(w)dpx; height: %(h)dpx; }
#cv { top: %(cv_top)dpx; }
</style>
<div id="dom"></div>
<canvas id="cv" width="%(w)d" height="%(h)d"></canvas>
<script>
const W = %(w)d, H = %(h)d;
// The XML namespaces of the SVG image: names, not hosts, and nothing is fetched from them. They are written in two pieces because the
// scan of the e2e files for real hosts (tests/_e2e_clocks.py) reads a whole URL as one.
const NS = 'http' + '://www.w3.org/';
const XHTML = NS + '1999/xhtml', SVG = NS + '2000/svg';
// ONE string is the block, as HTML in the page and inside the SVG image. Everything that decides how the text is drawn is in it:
// the family, the size, the line height, the languages (which choose the fallback font of the Han and Arabic runs) and the colours.
function markup(family) {
const lines = [
'<div lang="en">Hamburgefonstiv 0123456789 fi fl</div>',
'<div lang="fr">\\u00e9 \\u00e8 \\u00e0 \\u00fc \\u00c9 \\u00c8 \\u00c0 \\u00dc \\u00f1 \\u00e7 \\u00f8 \\u00df</div>',
'<div lang="en">It\\u2019s \\u00ab\\u20ac \\u00a9 \\u2013 \\u2026\\u00bb \\u2018x\\u2019 \\u201cy\\u201d</div>',
'<div lang="zh-CN">\\u4e2d\\u6587\\u6c49\\u5b57\\u6d4b\\u8bd5 \\u6f22\\u5b57</div>',
'<div lang="ar" dir="rtl">\\u0645\\u0631\\u062d\\u0628\\u0627 \\u0628\\u0627\\u0644\\u0639\\u0627\\u0644\\u0645 \\u0627\\u0644\\u0639\\u0631\\u0628\\u064a</div>',
'<div lang="ru">\\u041f\\u0440\\u0438\\u0432\\u0435\\u0442, \\u043c\\u0438\\u0440! \\u0421\\u044a\\u0435\\u0448\\u044c \\u0435\\u0449\\u0451</div>',
];
const style = 'box-sizing:border-box;width:' + W + 'px;height:' + H + 'px;padding:5px 8px;overflow:hidden;white-space:nowrap;'
+ 'margin:0;background:#fff;color:#000;font-family:\\'' + family + '\\';font-size:20px;line-height:34px;'
+ 'font-weight:400;font-style:normal;';
return '<div xmlns="' + XHTML + '" style="' + style + '">' + lines.join('') + '</div>';
}
async function draw(family) {
const html = markup(family);
document.getElementById('dom').innerHTML = html;
const svg = '<svg xmlns="' + SVG + '" width="' + W + '" height="' + H + '">'
+ '<foreignObject x="0" y="0" width="' + W + '" height="' + H + '">' + html + '</foreignObject></svg>';
const img = new Image();
await new Promise((resolve, reject) => {
img.onload = resolve;
img.onerror = () => reject(new Error('the SVG image did not load'));
img.src = 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(svg);
});
const ctx = document.getElementById('cv').getContext('2d');
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, W, H);
ctx.drawImage(img, 0, 0);
await document.fonts.ready;
// one frame after the drawing, so that what is on the screen is what was drawn
await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
const box = id => { const r = document.getElementById(id).getBoundingClientRect();
return {x: r.x, y: r.y, width: r.width, height: r.height}; };
return {dpr: window.devicePixelRatio, dom: box('dom'), cv: box('cv'),
lines: document.getElementById('dom').firstElementChild.childElementCount};
}
</script>
"""
def _page():
return PAGE % {"w": BLOCK_W, "h": BLOCK_H, "cv_top": 10 + BLOCK_H + 10}
def _slug(family):
return re.sub(r"[^a-z0-9]+", "-", family.lower()).strip("-")
def _evidence_dir(family):
"""The folder of this case under $RUNNER_TEMP, or None outside a runner."""
base = os.environ.get("RUNNER_TEMP")
if not base:
return None
return Path(base) / EVIDENCE_FOLDER / "screenshot-bundle-fonts" / _slug(family)
def _sha(data):
return hashlib.sha256(data).hexdigest()
def _dark(image):
"""How many pixels of a box are not the white of the background: a box that is blank is not a text that matches."""
ch, d = image["channels"], image["data"]
return sum(1 for i in range(0, len(d), ch) if d[i:i + 3] != b"\xff\xff\xff")
def _integer_box(name, box):
for key in ("x", "y", "width", "height"):
assert box[key] == int(box[key]), (
"the %s box is not on whole device pixels (%s = %r): a block off the pixel grid would be drawn twice with two "
"positions and the two boxes could differ for that alone" % (name, key, box[key]))
return {key: int(box[key]) for key in box}
@pytest.mark.timeout(300, method="thread")
@pytest.mark.parametrize("family", FAMILIES)
def test_the_text_of_a_bundled_family_is_drawn_by_the_screenshot_as_the_content_drew_it(firefox_binary, engine_at_least, family):
engine_at_least("firefox-66")
from invisible_core.seal import active_seal
from invisible_playwright import InvisiblePlaywright
tag = active_seal().tag
with InvisiblePlaywright(seed=21, binary_path=firefox_binary, headless=True, pin=PIN) as b:
page = b.new_context(viewport=VIEWPORT).new_page()
page.set_content(_page())
page.evaluate("fam => { window.DONE = false; window.ERR = null;"
" draw(fam).then(r => { window.R = r; window.DONE = true; },"
" e => { window.ERR = String(e); window.DONE = true; }); }", family)
page.wait_for_function("window.DONE === true", timeout=60_000)
err = page.evaluate("window.ERR")
assert err is None, "the page could not draw the two blocks: %s" % err
measured = page.evaluate("window.R")
shot = page.screenshot(type="png")
assert measured["dpr"] == 1, "the device pixel ratio is %r, not 1: the boxes would be resampled" % measured["dpr"]
dom, cv = _integer_box("DOM", measured["dom"]), _integer_box("canvas", measured["cv"])
assert (dom["width"], dom["height"]) == (cv["width"], cv["height"]) == (BLOCK_W, BLOCK_H), (dom, cv)
assert measured["lines"] == 6, "the block has %r lines, not 6" % measured["lines"]
whole = pb.unfiltered(shot)
assert (whole["w"], whole["h"]) == (VIEWPORT["width"], VIEWPORT["height"]), (
"the screenshot is %dx%d for a viewport of %dx%d: the boxes are not where the page measured them"
% (whole["w"], whole["h"], VIEWPORT["width"], VIEWPORT["height"]))
dom_img = pb.crop(whole, dom["x"], dom["y"], dom["width"], dom["height"])
cv_img = pb.crop(whole, cv["x"], cv["y"], cv["width"], cv["height"])
diff = pb.pixels_differ(dom_img, cv_img)
identical = dom_img["data"] == cv_img["data"]
assert identical == (diff["pixels"] == 0)
result = {
"test": "screenshot-draws-the-bundled-fonts-as-the-content-does", "family": family, "os": OS_NAME,
"platform": sys.platform, "engine": tag, "seed": 21, "pin": PIN,
"viewport": VIEWPORT, "screenshot": {"w": whole["w"], "h": whole["h"], "sha256": _sha(shot)},
"dom": {"box": dom, "sha256": _sha(dom_img["data"]), "png_sha256": None, "not_white_pixels": _dark(dom_img),
"coloured_pixels": pb.coloured_pixels(dom_img)},
"canvas": {"box": cv, "sha256": _sha(cv_img["data"]), "png_sha256": None, "not_white_pixels": _dark(cv_img),
"coloured_pixels": pb.coloured_pixels(cv_img)},
"identical": identical, "differing_pixels": diff["pixels"], "first_differing_pixel": diff["first"],
"differing_box": diff["box"],
}
where = _evidence_dir(family)
if where is not None:
where.mkdir(parents=True, exist_ok=True)
dom_png, cv_png = pb.encode_png(dom_img), pb.encode_png(cv_img)
result["dom"]["png_sha256"], result["canvas"]["png_sha256"] = _sha(dom_png), _sha(cv_png)
(where / "page.png").write_bytes(shot)
(where / "dom.png").write_bytes(dom_png)
(where / "canvas.png").write_bytes(cv_png)
(where / "result.json").write_text(json.dumps(result, indent=1, sort_keys=True) + "\n", encoding="utf-8")
# a box with no text in it would be equal to another box with no text in it
assert result["dom"]["not_white_pixels"] > 0, "the DOM box of %s is blank: the screenshot has no text there" % family
assert result["canvas"]["not_white_pixels"] > 0, "the canvas box of %s is blank: the SVG image drew no text" % family
assert identical, (
"%s: the text the screenshot rebuilt in the parent (the DOM box) is not the text the content drew (the canvas box): "
"%d of %d pixels differ, the first at %r, inside the box %r. DOM sha256 %s, canvas sha256 %s. Not grey pixels: DOM %d, "
"canvas %d (greyscale antialiasing has none: if they are not 0 the two boxes were antialiased in two ways)."
% (family, diff["pixels"], BLOCK_W * BLOCK_H, diff["first"], diff["box"], result["dom"]["sha256"],
result["canvas"]["sha256"], result["dom"]["coloured_pixels"], result["canvas"]["coloured_pixels"]))
@@ -89,6 +89,53 @@ def test_something_that_is_not_a_png_is_refused():
pb.decode_png(b"GIF89a....")
def test_a_box_cut_out_of_a_screenshot_is_the_pixels_of_that_box():
"""The crop the screenshot-of-text e2e compares: the rows of the box, in the colour type of the picture, by the pixels the PNG holds."""
w, h = 7, 6
pixels = bytes((13 * i + 5) % 256 for i in range(w * h * 4))
whole = pb.unfiltered(_png(w, h, pixels))
box = pb.crop(whole, 2, 1, 3, 4)
want = b"".join(pixels[((1 + r) * w + 2) * 4:((1 + r) * w + 5) * 4] for r in range(4))
assert (box["w"], box["h"], box["ct"], box["channels"], box["data"]) == (3, 4, 6, 4, want)
@pytest.mark.parametrize("bad", [(-1, 0, 2, 2), (0, 0, 8, 2), (0, 0, 2, 7), (6, 5, 2, 2), (0, 0, 0, 2), (0, 0, 2, 0)])
def test_a_box_that_is_not_inside_the_picture_is_refused_and_not_cut_short(bad):
whole = pb.unfiltered(_png(7, 6, bytes(7 * 6 * 4)))
with pytest.raises(ValueError):
pb.crop(whole, *bad)
def test_a_box_written_as_a_png_decodes_to_the_same_box():
whole = pb.unfiltered(_png(5, 5, bytes((9 * i) % 256 for i in range(5 * 5 * 4))))
box = pb.crop(whole, 1, 2, 3, 2)
back = pb.unfiltered(pb.encode_png(box))
assert (back["w"], back["h"], back["ct"], back["data"]) == (3, 2, 6, box["data"])
def test_two_boxes_are_told_apart_by_one_pixel_and_it_is_named():
a = pb.unfiltered(_png(4, 5, PIXELS))
same = pb.pixels_differ(a, pb.unfiltered(_png(4, 5, PIXELS)))
assert same == {"pixels": 0, "first": None, "box": None}
changed = bytearray(PIXELS)
changed[(3 * 4 + 1) * 4 + 2] ^= 1 # a blue byte of the pixel (1, 3)
changed[(4 * 4 + 2) * 4] ^= 1 # a red byte of the pixel (2, 4)
got = pb.pixels_differ(a, pb.unfiltered(_png(4, 5, bytes(changed))))
assert got == {"pixels": 2, "first": [1, 3], "box": [1, 3, 2, 4]}
def test_boxes_of_two_sizes_are_not_compared_as_different():
with pytest.raises(ValueError):
pb.pixels_differ(pb.unfiltered(_png(4, 5, PIXELS)), pb.unfiltered(_png(5, 4, PIXELS)))
def test_the_pixels_that_are_not_grey_are_the_ones_of_a_subpixel_edge():
grey = bytes([0, 0, 0, 255, 128, 128, 128, 255, 255, 255, 255, 255])
fringe = bytes([0, 0, 0, 255, 128, 129, 128, 255, 255, 255, 255, 255])
assert pb.coloured_pixels(pb.unfiltered(_png(3, 1, grey))) == 0
assert pb.coloured_pixels(pb.unfiltered(_png(3, 1, fringe))) == 1
def _reference_of(measured):
ref = {"keys": {}, "pngs": {}}
for key, value in measured.items():