Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wdspec] browsingContext.print: fix rounding error in page.py test #40504

Merged
merged 5 commits into from
Jun 16, 2023

Commits on Jun 13, 2023

  1. [wdspec] browsingContext.print: fix rounding error in page.py test

    [pytest](https://github.com/web-platform-tests/wpt/blob/7a087d54be8b6c0ca0181a86dc1ff0b28461c383/webdriver/tests/support/image.py)
    uses:
    
        def cm_to_px(cm): return round(cm * 96 / 2.54)
    
    [js](https://github.com/web-platform-tests/wpt/blob/7a087d54be8b6c0ca0181a86dc1ff0b28461c383/tools/wptrunner/wptrunner/print_pdf_runner.html)
    uses:
    
        const viewport = page.getViewport({ scale: 96. / 72. });
        ...
        canvas.height = viewport.height;
        canvas.width = viewport.width;
    
    This produces a rounding error, even though the dimension is correct:
    
        >       assert cm_to_px(expected_dimensions["height"]) == height
        E       assert 454 == 453
        E         +454
        E         -453
    
    The inconsistency of rounding in both ends becomes clear when we
    eliminate "round" in the pytest side:
    
        >       assert cm_to_px(expected_dimensions["height"]) == height
        E       assert 453.54330708661416 == 453
        E         +453.54330708661416
        E         -453
    
    There are multiple ways to fix this issue.
    
    Option #1: Use "floor" instead of "round" in pytest.
    
    Option #2: Use a range in the assertion comparison, allowing a
    difference of up to +-1.0. This is what this PR does.
    
    The comparison is performed in
    [`assert_pdf_dimensions`](https://github.com/web-platform-tests/wpt/blob/b6107cc1ac8b9c2800b4c8e58af719b8e4d9b8db/webdriver/tests/support/fixtures_bidi.py#L210).
    
    The problematic part is .96 / .72 which evaluates to 4/3 = 1.333333....
    thiagowfx committed Jun 13, 2023
    Configuration menu
    Copy the full SHA
    f20a9d5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7e65d91 View commit details
    Browse the repository at this point in the history
  3. 1 Configuration menu
    Copy the full SHA
    63f894e View commit details
    Browse the repository at this point in the history

Commits on Jun 14, 2023

  1. Revert "compare to floor and to round instead of a range"

    This reverts commit 63f894e.
    thiagowfx committed Jun 14, 2023
    Configuration menu
    Copy the full SHA
    d2f73a9 View commit details
    Browse the repository at this point in the history
  2. Revert "use floor in cm_to_px instead of round"

    This reverts commit 7e65d91.
    thiagowfx committed Jun 14, 2023
    1 Configuration menu
    Copy the full SHA
    f00a6e1 View commit details
    Browse the repository at this point in the history