diff options
Diffstat (limited to 'testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py')
-rw-r--r-- | testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py index 40497ce6ac..414f5ae2d0 100644 --- a/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py +++ b/testing/web-platform/tests/webdriver/tests/bidi/browsing_context/capture_screenshot/capture_screenshot.py @@ -1,6 +1,6 @@ import pytest -from math import floor +from math import ceil, floor from tests.support.image import png_dimensions from . import get_physical_viewport_dimensions @@ -79,3 +79,29 @@ async def test_capture_with_viewport(bidi_session, new_tab, delta_width, delta_h result = await bidi_session.browsing_context.capture_screenshot( context=new_tab["context"]) assert png_dimensions(result) == (expected_size["width"], expected_size["height"]) + + +@pytest.mark.parametrize("dpr", [0.5, 2]) +@pytest.mark.asyncio +async def test_capture_with_different_dpr(bidi_session, new_tab, inline, dpr): + page = inline("<div style='background-color: black; width: 100px; height: 100px;'></div>") + await bidi_session.browsing_context.navigate( + context=new_tab["context"], url=page, wait="complete" + ) + + original_viewport = await get_viewport_dimensions(bidi_session, new_tab) + + await bidi_session.browsing_context.set_viewport( + context=new_tab["context"], + device_pixel_ratio=dpr) + + expected_width = original_viewport["width"] * dpr + expected_height = original_viewport["height"] * dpr + + data = await bidi_session.browsing_context.capture_screenshot(context=new_tab["context"]) + (actual_width, actual_height) = png_dimensions(data) + # The rounding is implementation-specific and can be either floor, ceil or round depending on the browser + # implementation. Tolerate any value between floor and ceil. + assert floor(expected_width) <= actual_width <= ceil(expected_width) + assert floor(expected_height) <= actual_height <= ceil(expected_height) + |