Skip to content

About

This repository contains tests for litethtml

Resources

Stars

1 star

Watchers

2 watching

Forks

Repository files navigation

Tests for litehtml

This repository contains tests for litehtml. Rendering tests depend on the environment. The currently supported Linux distributions are Ubuntu 24.04 and Fedora 40.

Requirements

Building the tests requires CMake 3.20 or newer, C99 and C++17 compilers, pkg-config, and development packages for GTK3, GdkPixbuf, fontconfig, Cairo, Pango and PangoCairo. LITEHTML_PATH must point to a litehtml source checkout that provides the litehtml_render2png library target.

For Ubuntu, install the build dependencies with:

sudo apt-get install -y --no-install-recommends --no-install-suggests 
    build-essential cmake clang-tidy pkg-config libcairo2-dev libpango1.0-dev libgtk-3-dev

GoogleTest is fetched during configuration by default. To use installed GoogleTest headers and libraries instead, configure with -DEXTERNAL_GTEST=ON.

Running tests locally

From the root of this repository, run:

cmake -S . -B build -DLITEHTML_PATH=/absolute/path/to/litehtml
cmake --build build -j4
ctest --test-dir build --output-on-failure -j4

The renderer library is always built for the tests. To also build the render2png executable, configure with -DLITEHTML_BUILD_RENDER2PNG=ON. The executable is disabled by default and runs as build/render2png path/to/page.html output.png.

Running tests in Docker

The provided script builds and runs the tests in a container:

./run_render_tests.sh /absolute/path/to/litehtml 4

The arguments are the path to the litehtml checkout and the number of threads to use for building and testing. The script reuses the litehtml-build:latest image if it already exists. Rebuild that image after updating the Dockerfile:

docker build -t litehtml-build:latest .

The manage-tests tool also reuses this image.

Running tests from the litehtml repository

From a litehtml checkout with a compatible test-suite pin:

cmake -S . -B build-tests -DLITEHTML_BUILD_TESTING=ON
cmake --build build-tests
ctest --test-dir build-tests/litehtml-tests-build --output-on-failure

This workflow fetches a pinned commit of this repository, so it does not use local or newly published changes until the pin is updated. Build this checkout directly as described above to test local changes.

Positioned percentage-padding regressions

render/positioned-percentage-padding-*.htm and render/fixed-percentage-padding.htm cover containing-block padding bases, static offsets, exact-width layout, and replaced images. Their .cfg files fix the viewport at 800x600. The sibling golden images are rendered from independent pixel-sized reference pages in render/support/, verified to match the subject pages in Chrome. The runner compares the golden PNGs; it does not evaluate the HTML rel=match links.

Inline break and line-height regressions

render/inline-break-heights-*.htm covers consecutive, leading, and trailing breaks, nested inline fonts, explicit line-height, vertical alignment, and whitespace/alignment at forced breaks. The three pages exercise quirks, limited-quirks, and standards modes with the suite's Ahem font. In the first two modes all eight boxes in the first row have equal heights; in standards mode the larger parent font makes the last pair taller.

Their golden images come from Chrome through render.py --repo . -w 800, using the sibling viewport configs, and are converted to RGBA for the runner's byte comparison. Existing references affected by the corrected standards-mode strut, per-inline half-leading, and resulting baselines were also checked against Chrome and refreshed with the test renderer. These retain the test renderer's font rasterization and whole-pixel font metrics; they do not rebaseline unrelated Chrome/litehtml differences.

Overflow clipping of out-of-flow boxes

render/overflow-hidden-* and the re-enabled render/css21/abspos-overflow-* tests cover the CSS 2.1 §11.1.1 clipping rules:

  • an absolutely positioned box is not clipped by the overflow of a static ancestor between it and its containing block (overflow-hidden-absolute-child, overflow-hidden-absolute-deep, css21/abspos-overflow-001..009, 012);
  • it is clipped by the overflow of its positioned containing block (overflow-hidden-absolute-positioned-ancestor);
  • a fixed box is not clipped by any ancestor (overflow-hidden-fixed-child);
  • in-flow boxes (including position:relative) stay clipped by every ancestor (overflow-hidden-relative-child).

The pages use only solid colour boxes, so their goldens are pixel-identical between render2png and Chrome; the geometry was cross-checked with render.py -w 800 --no-bestfit. The *.cfg files pin the viewport to 800x600 (bestfit: false) so the escaping boxes are visible.

Paint order of atomic inline-level boxes

render/css21/inline-table-zorder-001..005.htm (including the re-enabled 002 and 005) and render/css21/inline-block-zorder-001..005.htm cover the CSS 2.1 Appendix E §E.2 painting order:

  • step 4 paints the backgrounds and borders of the in-flow, non-positioned block-level descendants before step 7 paints the inline-level content, so the inline-level box paints above a block background that overlaps it through a negative margin (001, 004);
  • within step 7 the inline-level boxes paint in tree order, so of two overlapping inline-level siblings the later one paints on top (003, 004);
  • step 7.2.1 treats an inline-block or inline-table — and, per CSS Display 3, an inline-flex or inline-grid — as if it created a new stacking context, so everything inside it, including its own block-level descendants, paints as one group in that inline pass instead of in the block pass before the parent's other blocks (002, 005).

The pages only use solid colour boxes. The goldens of the two re-enabled tests were produced with render2png and are pixel-identical to the inline-table-zorder-001 and inline-table-zorder-004 goldens, which their rel=reference links point at.

Opacity compositing

render/opacity/ covers the CSS opacity property, which is composited by the container (Cairo groups in container_cairo):

  • opacity-001.htm — the number form over a red sibling; the layer is 20% blue, so the overlap is #cc0033 (blue over red) and the uncovered part is #ccccff (blue over the white page);
  • opacity-002.htm — the 20% form around two overlapping opaque children; the overlap is #ccccff, proving the children are composited inside one layer and do not blend with each other;
  • opacity-003.htm — nested opacity: .5 layers multiply, so black over white composites to #bfbfbf (25%);
  • opacity-004.htm — the opacity element is earlier in the tree but paints in the stack-level-0 layer, above a later in-flow sibling (#cc0033 in the overlap);
  • opacity-005.htm — opacity: 0 hides the element but does not remove it from focus: the .cfg focuses the invisible link and .wrap:focus-within turns the wrapper background yellow.

The solid-colour boxes and fixed colours make the expected pixels independent of fonts and of the Cairo version, so the goldens can be checked against the values above.

Fixed table layout

render/table-layout-fixed-*.htm and the re-enabled render/css21/fixed-table-layout-* tests (including 004, 005, 006, 009, 010, 012, 013–016) cover the CSS 2.1 §17.5.2.1 fixed table-layout algorithm:

  • only first-row cells and <col> elements set column widths; later rows are ignored (table-layout-fixed-first-row.htm);
  • a <col> width beats a first-row cell width, and <colgroup> widths are ignored (table-layout-fixed-col-vs-cell.htm, table-layout-fixed-colgroup.htm);
  • a colspan cell's width is divided over the columns it spans (table-layout-fixed-colspan.htm);
  • pixel column widths widen the table, percentage columns resolve against the table width, and auto columns share the remaining space (table-layout-fixed-overflow-table.htm, table-layout-fixed-percent.htm);
  • an auto-width table falls back to the automatic layout algorithm (table-layout-fixed-auto-width.htm).

The pages use solid colour boxes and bestfit: false configs pinning the viewport to 800x600, so their geometry is pixel-identical between render2png and Chrome (verified with render.py).

The goldens for css21/float-applies-to-005..007, css21/font-applies-to-014, css21/text-align-applies-to-014, and css21/text-indent-applies-to-013 were refreshed because their table-layout: fixed; width: 100% tables now fill their containing block as browsers do.

A table cell's height is now a minimum row height (CSS 2.1 §17.5.3), so empty cells with a declared height get painted backgrounds/borders and rows no longer collapse. Goldens in the css21/*-applies-to-* family that relied on td { height: … } were refreshed for this corrected behavior; their box heights were cross-checked against Chrome.

Table overflow clipping and the rules attribute

render/css21/table-layout-002.htm (table-layout: fixed) and table-layout-003.htm (table-layout: inherit from the parent div) check that overflow: hidden on a table clips the cell content (CSS 2.1 §11.1.1): the two 8-character Ahem cells of the 5em-wide table overflow their 40 px columns, and the table stops them at its own 80 px box instead of painting over the page. The black table bar has to be exactly as wide as the black reference bar below it. Both pages render the same and share identical goldens.

render/css21/table-layout-applies-to-005.htm covers the other half of the property: table-layout does not apply to display: inline-block, so the anonymous table inside it uses the automatic algorithm and gives both columns the width of the longest cell (10 Ahem characters = 160 px). The 320 px table overflows its 160 px inline-block and has to be as wide as the 20em blue reference bar.

render/css21/table-columns-example-001.htm checks the HTML rules presentational hint (HTML 4.01 §11.2.6) against the equivalent CSS: .col1 { border-style: none solid } in a border-collapse: collapse; border-style: hidden table versus <table rules="cols">. Both halves must draw the same vertical rules between the columns; the CSS half differs only in line width (3 px against 1 px).

These pages use solid colour boxes and Ahem text, so their goldens come from render2png; the box geometry (table and bar widths, rule positions, cell sizes) is identical to Chrome, verified with render.py -w 800 --no-bestfit --repo .. One documented difference remains in table-layout-applies-to-005: litehtml sizes a line box that holds only atomic inline-level boxes by the boxes themselves, so the line under the inline-block is 4–5 px shorter than in browsers (the inline-block's baseline is its bottom margin edge here, and the block strut's descent — CSS 2.1 §10.8 — is not added). The bar widths, which the test asserts, are the same in both engines.

render/css21/inline-table-002b.htm (the table-cell-inside-span variant of inline-table-002a.htm) checks that the anonymous inline-table generated around the cell stays in the inline formatting context: abcde is one line, and a display: block box inside the cell does not split the inline boxes around the table (CSS 2.1 §9.2.1.1, §17.2.1). Its golden is identical to inline-table-002a.htm.png, like the inline-table-zorder-002/005 pair.

Table captions

render/css21/caption-vs-table-box-001.htm, caption-vs-table-box-002.htm, table-caption-002.htm, table-caption-003.htm and table-caption-margins-001.htm cover the CSS 2.1 §17.4 caption rules:

  • a caption is a block box inside the table wrapper, outside the table border/padding box, with its own margin, border and padding (caption-vs-table-box-001..002, including inline-table);
  • caption margins do not collapse with the table's margins (table-caption-margins-001);
  • multiple captions and captions between rows are moved above the table in document order (table-caption-002);
  • a caption between cells splits the anonymous rows, so the cells fall into separate rows (table-caption-003);
  • a table without rows or columns still honours a specified width and height (table-caption-margins-001).

These are text-rendering tests, so their goldens come from render2png; box and line geometry was cross-checked against Chrome with render.py --no-bestfit -w 800 --repo .. The goldens for css21/basic-css-table-001.htm and css21/basic-html-table-001.htm were refreshed because the table border no longer surrounds the caption.

Table height algorithm and cell baselines

render/css21/table-height-algorithm-001.htm, 004, 009, 010, 011, 012, 016, 019–026, 029, 031, 032 cover the CSS 2.1 §17.5.3 height and vertical-align rules for tables:

  • a table with height: auto is as tall as its rows plus cell spacing and borders, and a cell's height is a minimum row height (001, 004, 009, 010);
  • sub, super, text-top, text-bottom and <length>/<percentage> values of vertical-align on a table cell behave as baseline (019–024);
  • cells with vertical-align: baseline share the row baseline, which is the largest distance from a cell-box top to its baseline; the remaining cells are placed at the top, middle or bottom afterwards (011, 012, 016, 029);
  • a cell's baseline is the baseline of its first in-flow line box or table row, and an inline-table uses the baseline of its first row (025, 031, 032);
  • a caption does not move the baseline of the table it belongs to (031, 032);
  • a button's label defines the baseline of the control, so a button and a block next to it line up (026).

render/table-baseline-nested-no-overlap.htm checks that an empty anonymous context before a nested table does not supply the cell baseline, and that rows grow to contain baseline-shifted cells. Spanning cells use the aligned row heights and the spacing between rows; a cell's specified minimum height is not increased merely because its content shifts to the row baseline.

render/css21/table-valign-002.htm (re-enabled dbaron test, "Table Cell Vertical Alignment with Specified Height") checks that baseline alignment moves the cell content, not the cell box: the cell background still covers the whole row, so the three floats produce a single yellow stripe across the blue box. It is covered by the rule that internal table elements have no margins (CSS 2.1 §17.5) and that a cell's content margins do not collapse through the cell (CSS 2.1 §8.3.1); render/table-cell-child-margin.htm and render/inline-block-child-margin.htm check that rule directly for a first child's margin-top and a last child's margin-bottom — the cell or inline-block background covers those margins and the row/box includes them. Those two box pages use only solid colour boxes, so their goldens are pixel-identical to Chrome (verified with headless Chrome at the same viewport); table-valign-002 contains text, so its golden comes from render2png with the box geometry cross-checked against Chrome.

Tables inherit the font properties of their ancestors in standards mode (§6.2), so em lengths inside a table resolve against the inherited font size. The HTML4-era reset of the table font (font-size: medium, font-weight: normal, font-style: normal) is applied in quirks mode only, matching Gecko.

These pages mix Ahem box tests with text-rendering tests, so their goldens come from render2png; the box, row and baseline geometry was cross-checked against Chrome with headless Chrome using the fonts/ directory and serif/sans-serif aliases (see render.py).

The goldens for render/acid1.htm, render/css21/c5526c-display-000.htm, render/css21/floats-wrap-bfc-005.htm and render/table-flex-github.htm were refreshed because their tables now inherit the page font, and the goldens for render/button-inline-content.htm, render/button-inline-formatting.htm and render/focus-checkbox-keyboard.htm because form controls are baseline-aligned like in browsers. The goldens for render/css21/table-anonymous-block-014.htm and render/css21/table-caption-optional-002.htm were refreshed because the baseline of an inline-table is now the baseline of its first row. The empty-cells-applies-to-002, 003, and 005 and table-height-algorithm-012 and 025 goldens were refreshed for the corrected row heights; their visible content is unchanged. table-height-algorithm-014 was refreshed for the adjusted distribution of a specified table height between rows when a cell spans them.

Tables as flex items

render/flex/table-as-item-caption-*.htm, render/flex/table-as-item-specified-height-column.htm, render/grid/table-caption-grid-item-stretch.htm and the re-enabled CSSWG render/flex/table-as-item-*.htm tests cover a table used as a flex or grid item. A table generates a table wrapper box that contains the table box and the caption boxes, and the flex/grid item is that wrapper (CSS 2.1 §17.4):

  • the caption heights are part of the item, so a column flex container's grown main size is caption height + table box height (table-as-item-caption-column-grow, -fixed-basis, -auto-height, -bottom, table-as-item-flex-cross-size, table-as-item-stretch-cross-size, -2); a specified min-height is a minimum for the wrapper as well (table-as-item-caption-column-min-height);
  • height and flex-basis size the table box, not the wrapper, and follow box-sizing (table-as-item-caption-column-borders-content-box, -borders-border-box); the table's specified height is not an extra min-size for the flex algorithm (table-as-item-specified-height-column, and the re-enabled table-as-item-specified-height and table-as-item-inflexible-in-* tests);
  • the exact main or cross size that flex/grid hand to a table item applies to the wrapper; the table grid takes the remaining height after the captions (table-as-item-caption-row-stretch, table-caption-grid-item-stretch). A stretched grid item is also sized to the area width instead of shrinking to fit its content.

These pages use only solid colour boxes and bestfit: false configs with a pinned width, so their goldens are pixel-identical to Chrome (checked with render.py -w 800 --no-bestfit --repo .). The goldens for render/flex/table-as-item-stretch-cross-size-3.htm and render/css21/overflow-applies-to-001.htm, 004, 006 were refreshed for the corrected wrapper height (a content-box table's specified height no longer loses its padding and borders); their box geometry was verified against Chrome.

Float avoidance by tables and replaced elements

render/css21/floats-wrap-bfc-001/002/003-left|right-table.htm, the re-enabled render/css21/floats-wrap-bfc-003-left-table.htm and the 003-left|right-overflow.htm siblings cover the CSS 2.1 §9.5 rule that the border box of a table, a block-level replaced element, or an element that establishes a new block formatting context must not overlap the floats in its containing block:

  • a table that does not fit next to a float is cleared below it: in 003-left-table the 250 px table in a 300 px cell next to a 100 px float ends up below the float instead of overflowing the cell; the same holds for a block-level replaced element;
  • a block that starts with floats only has to be as wide as the wider of the float and the cleared element (max, not the sum); the sum is only the max-content width, which still puts them side by side in a shrink-to-fit container;
  • an overflow: hidden block may be narrowed next to the float, so it stays beside it (003-left|right-overflow).

These pages use solid colour boxes only, so their render2png goldens are pixel-identical to Chrome; the box geometry was cross-checked with render.py --repo . -w 800 --no-bestfit and with headless Firefox.

Inline SVG images

render/svg/ covers inline <svg> elements rendered as replaced images by the Cairo container:

  • svg-basic.htm — an SVG with width/height attributes uses its intrinsic size (red 100×100 box);
  • svg-intrinsic.htm — an SVG without width/height gets its intrinsic size from the 0 0 50 40 viewBox (orange 50×40 box);
  • svg-viewbox-meet.htm — the default preserveAspectRatio is xMidYMid meet, so a 0 0 100 50 viewBox in a 100×100 viewport is centred vertically (blue band from y=25 to y=74);
  • svg-viewbox-align.htm — xMinYMin meet aligns the same band at the top (y=0 to y=49);
  • svg-viewbox-slice.htm — xMidYMid slice covers the viewport and crops the left/right edges (green then blue halves);
  • svg-viewbox-none.htm — preserveAspectRatio="none" stretches a 20×20 user-space square into 20×40 pixels;
  • svg-css-size.htm — CSS width: 200px; height: 100px sizes the viewport while the 0 0 10 10 viewBox keeps the square content at 100×100, centred horizontally;
  • svg-no-viewbox.htm — without a viewBox, user units stay 1:1, so a CSS-resized 200×200 viewport still shows the 100×100 content in its top-left corner;
  • svg-gradient.htm — a <linearGradient> plus a stroked <circle> exercise nanosvg's gradient and stroke support;
  • svg-hidpi.htm — rendered with scale: 1.75, the icon is rasterized at the physical device resolution and snapped to the device pixel grid, so the circle edge stays crisp (60×42 golden);
  • svg-current-color.htm — fill="currentColor" resolves to black by default and to #3366cc when the element sets color: #3366cc;
  • svg-current-color-hover.htm — with :hover changing color from red to blue and the mouse positioned over the icon, the golden is blue, proving the container re-parses the SVG for the new computed color.

The pages use solid colours and no text, so the goldens do not depend on fonts. The viewBox/preserveAspectRatio geometry was cross-checked against headless Chrome.

About

This repository contains tests for litethtml

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages