From 78b503946c5ca8ba9f4bf1fa4d41abcb131902fa Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sun, 29 Jan 2023 03:07:16 +0300 Subject: [PATCH] Tests: Add LibWeb layout tests --- .github/workflows/libweb-layout.yml | 57 ++++++++++++++++++++++++++ Tests/LibWeb/Layout/expected/blank.txt | 6 +++ Tests/LibWeb/Layout/input/blank.html | 8 ++++ Tests/LibWeb/Layout/layout_test.sh | 20 +++++++++ 4 files changed, 91 insertions(+) create mode 100644 .github/workflows/libweb-layout.yml create mode 100644 Tests/LibWeb/Layout/expected/blank.txt create mode 100644 Tests/LibWeb/Layout/input/blank.html create mode 100755 Tests/LibWeb/Layout/layout_test.sh diff --git a/.github/workflows/libweb-layout.yml b/.github/workflows/libweb-layout.yml new file mode 100644 index 0000000000..0c7ebd383b --- /dev/null +++ b/.github/workflows/libweb-layout.yml @@ -0,0 +1,57 @@ +name: Test LibWeb layout +on: [ push, pull_request ] + +env: + SERENITY_SOURCE_DIR: ${{ github.workspace }} + +concurrency: libweb-layout + +jobs: + build: + runs-on: ubuntu-22.04 + if: github.repository == 'SerenityOS/serenity' + strategy: + fail-fast: true + steps: + - uses: actions/checkout@v3 + - name: "Install Ubuntu dependencies" + run: | + sudo apt-get update + sudo apt-get install -y ninja-build gcc-12 g++-12 libstdc++-12-dev \ + libgl1-mesa-dev qt6-base-dev qt6-tools-dev-tools \ + - name: "Create build directories" + run: | + mkdir -p ${{ github.workspace }}/Build/caches/TZDB + mkdir -p ${{ github.workspace }}/Build/caches/UCD + mkdir -p ${{ github.workspace }}/Build/caches/CLDR + - name: "TimeZoneData cache" + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + with: + path: ${{ github.workspace }}/Build/caches/TZDB + key: TimeZoneData-${{ hashFiles('Meta/CMake/time_zone_data.cmake') }} + - name: "UnicodeData cache" + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + with: + path: ${{ github.workspace }}/Build/caches/UCD + key: UnicodeData-${{ hashFiles('Meta/CMake/unicode_data.cmake') }} + - name: "UnicodeLocale cache" + uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b + with: + path: ${{ github.workspace }}/Build/caches/CLDR + key: UnicodeLocale-${{ hashFiles('Meta/CMake/locale_data.cmake') }} + - name: "Create Ladybird build environment" + run: | + cmake -GNinja \ + -B ${{ github.workspace }}/Build/ladybird \ + -S ${{ github.workspace }}/Ladybird \ + -DCMAKE_C_COMPILER=gcc-12 \ + -DCMAKE_CXX_COMPILER=g++-12 \ + -DSERENITY_CACHE_DIR=${{ github.workspace }}/Build/cachess + - name: "Build Ladybird" + run: | + ninja -C ${{ github.workspace }}/Build/ladybird + - name: "Run layout tests" + run: | + ${{ github.workspace }}/Tests/LibWeb/Layout/layout_test.sh + env: + QT_QPA_PLATFORM: "offscreen" diff --git a/Tests/LibWeb/Layout/expected/blank.txt b/Tests/LibWeb/Layout/expected/blank.txt new file mode 100644 index 0000000000..2d4ca4d59d --- /dev/null +++ b/Tests/LibWeb/Layout/expected/blank.txt @@ -0,0 +1,6 @@ +InitialContainingBlock <#document> at (0,0) content-size 0x0 children: not-inline + BlockContainer at (0,0) content-size 0x16 children: not-inline + BlockContainer <(anonymous)> at (0,0) content-size 0x0 children: inline + TextNode <#text> + BlockContainer at (8,8) content-size 0x0 children: inline + TextNode <#text> diff --git a/Tests/LibWeb/Layout/input/blank.html b/Tests/LibWeb/Layout/input/blank.html new file mode 100644 index 0000000000..8677849ac7 --- /dev/null +++ b/Tests/LibWeb/Layout/input/blank.html @@ -0,0 +1,8 @@ + + + +Blank + + + + diff --git a/Tests/LibWeb/Layout/layout_test.sh b/Tests/LibWeb/Layout/layout_test.sh new file mode 100755 index 0000000000..1632423aa6 --- /dev/null +++ b/Tests/LibWeb/Layout/layout_test.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +set -eo pipefail + +SCRIPT_DIR="$(dirname "${0}")" +SERENITY_ROOT="$(realpath "${SCRIPT_DIR}"/../../..)" +LADYBIRD_BUILD_DIR="${SERENITY_ROOT}/Build/ladybird" + +for filename in "$SCRIPT_DIR"/input/*; do + name=$(basename "$filename" .html) + input_html_path=$(realpath "$SCRIPT_DIR")/input/"$name".html + output_layout_dump=$(cd "$LADYBIRD_BUILD_DIR"; ./ladybird -d "$input_html_path") + expected_layout_dump_path="$(realpath "$SCRIPT_DIR")/expected/$name.txt" + if cmp <(echo "$output_layout_dump") "$expected_layout_dump_path"; then + echo "$name PASSED" + else + echo "$name FAILED" + diff "$expected_layout_dump_path" <(echo "$output_layout_dump") + fi +done