Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(ssim-cie94): make sure a single off pixel yields diff in comparator (#24348)

Andrey Lushnikovd307c8e63afe
diff --git a/packages/playwright-core/src/image_tools/compare.ts b/packages/playwright-core/src/image_tools/compare.ts
index 9ce86d91ec..e3be162675 100644
--- a/packages/playwright-core/src/image_tools/compare.ts
+++ b/packages/playwright-core/src/image_tools/compare.ts
@@ -86,8 +86,6 @@ export function compare(actual: Buffer, expected: Buffer, diff: Buffer|null, wid
continue;
}
- // if this pixel is a part of a flood fill of a 3x3 square then it cannot be
- // anti-aliasing pixel so it must be a pixel difference.
if (!fastR || !fastG || !fastB) {
fastR = new FastStats(r1, r2);
fastG = new FastStats(g1, g2);
@@ -97,7 +95,9 @@ export function compare(actual: Buffer, expected: Buffer, diff: Buffer|null, wid
const [varX2, varY2] = r1.boundXY(x + VARIANCE_WINDOW_RADIUS, y + VARIANCE_WINDOW_RADIUS);
const var1 = fastR.varianceC1(varX1, varY1, varX2, varY2) + fastG.varianceC1(varX1, varY1, varX2, varY2) + fastB.varianceC1(varX1, varY1, varX2, varY2);
const var2 = fastR.varianceC2(varX1, varY1, varX2, varY2) + fastG.varianceC2(varX1, varY1, varX2, varY2) + fastB.varianceC2(varX1, varY1, varX2, varY2);
- if (var1 === 0 && var2 === 0) {
+ // if this pixel is a part of a flood fill of a 3x3 square of either of the images, then it cannot be
+ // anti-aliasing pixel so it must be a pixel difference.
+ if (var1 === 0 || var2 === 0) {
drawRedPixel(x, y);
++diffCount;
continue;
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/README.md b/tests/image_tools/fixtures/should-fail/looks-same-tests/README.md
new file mode 100644
index 0000000000..e3fedc8230
--- /dev/null
+++ b/tests/image_tools/fixtures/should-fail/looks-same-tests/README.md
@@ -0,0 +1,2 @@
+These tests are coming from the `looks-same` library:
+- https://github.com/gemini-testing/looks-same/blob/b9399bce8fd980e6e59cf740bee3cd3fe66c3eae/test/test.js
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/blue-actual.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/blue-actual.png
new file mode 100644
index 0000000000..f9bcd4d00f
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/blue-actual.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/blue-expected.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/blue-expected.png
new file mode 100644
index 0000000000..14dc4e75e5
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/blue-expected.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/green-actual.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/green-actual.png
new file mode 100644
index 0000000000..f9bcd4d00f
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/green-actual.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/green-expected.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/green-expected.png
new file mode 100644
index 0000000000..c2f298cfae
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/green-expected.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/no-caret-actual.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/no-caret-actual.png
new file mode 100644
index 0000000000..70a8b137b9
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/no-caret-actual.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/no-caret-expected.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/no-caret-expected.png
new file mode 100644
index 0000000000..d10e6d6266
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/no-caret-expected.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/red-actual.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/red-actual.png
new file mode 100644
index 0000000000..f9bcd4d00f
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/red-actual.png differ
diff --git a/tests/image_tools/fixtures/should-fail/looks-same-tests/red-expected.png b/tests/image_tools/fixtures/should-fail/looks-same-tests/red-expected.png
new file mode 100644
index 0000000000..c6ea115f3b
Binary files /dev/null and b/tests/image_tools/fixtures/should-fail/looks-same-tests/red-expected.png differ
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/README.md b/tests/image_tools/fixtures/should-match/looks-same-tests/README.md
new file mode 100644
index 0000000000..e3fedc8230
--- /dev/null
+++ b/tests/image_tools/fixtures/should-match/looks-same-tests/README.md
@@ -0,0 +1,2 @@
+These tests are coming from the `looks-same` library:
+- https://github.com/gemini-testing/looks-same/blob/b9399bce8fd980e6e59cf740bee3cd3fe66c3eae/test/test.js
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-actual.png b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-actual.png
new file mode 100644
index 0000000000..32ada647b1
Binary files /dev/null and b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-actual.png differ
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-expected.png b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-expected.png
new file mode 100644
index 0000000000..2f14ac0ff4
Binary files /dev/null and b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-expected.png differ
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-1-actual.png b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-1-actual.png
new file mode 100644
index 0000000000..5f99bc3722
Binary files /dev/null and b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-1-actual.png differ
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-1-expected.png b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-1-expected.png
new file mode 100644
index 0000000000..f000e16c8d
Binary files /dev/null and b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-1-expected.png differ
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-2-actual.png b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-2-actual.png
new file mode 100644
index 0000000000..e9a9859ce7
Binary files /dev/null and b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-2-actual.png differ
diff --git a/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-2-expected.png b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-2-expected.png
new file mode 100644
index 0000000000..ec478bd21a
Binary files /dev/null and b/tests/image_tools/fixtures/should-match/looks-same-tests/antialiasing-tolerance-2-expected.png differ